#!/bin/bash # Example Usage # ssh user@host "sudo -n bash -s" -- < ./commands/bx-webpage/bx-webpage-setup.sh # TODO: allow for input to setup domains if [ "$1" == "-h" ]; then echo "Usage:" echo " ./bx-webpage-setup.sh" exit 0 fi # setup node LTS # curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash # export NVM_DIR="$HOME/.nvm" # [ -s"$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm # [ -s"$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion # nvm install --lts # Install node for all users # https://computingforgeeks.com/installing-node-js-10-lts-on-ubuntu-18-04-16-04-debian-9/ # curl -sL https://deb.nodesource.com/setup_12.x | bash # apt install -y nodejs # Setup website # mkdir /bergx # mkdir /bergx/bx-webpage # mkdir /bergx/bx-webpage/dist # touch /bergx/bx-webpage/dist/index.html # Setup console # mkdir /bergx/bx-webpage # mkdir /bergx/bx-console/dist # touch /bergx/bx-console/dist/index.html # Setup service # mkdir /bergx/bx-service # mkdir /bergx/bx-service/build # mkdir /bergx/bx-service/build/bin/ # touch /bergx/bx-service/build/bin/www.js # cat > /bergx/bx-webpage/dist/index.html << EndOfIndex # # # Yo # # # EndOfIndex # Config can be found in bx-webpage.conf cat > /etc/nginx/conf.d/bx-webpage.conf << EndOfConfig server { listen 80; server_name www.bergx.io; return 301 https://\$server_name\$request_uri; } server { listen 80; server_name p01.bergx.io; return 301 https://\$server_name\$request_uri; } server { listen 80; server_name bergx.io; return 301 https://\$server_name\$request_uri; } upstream bergx-api { server localhost:3030; } server { listen 443 ssl; server_name ^p01.bergx.io; keepalive_timeout 70; ssl_certificate /etc/letsencrypt/live/p01.bergx.io/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/p01.bergx.io/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot location / { root /bergx/bx-console; try_files \$uri /index.html; } location ~^/(api|auth|public|oauth) { proxy_pass http://bergx-api; proxy_http_version 1.1; proxy_set_header Upgrade \$http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host \$host; proxy_cache_bypass \$http_upgrade; } } server { listen 443 ssl; server_name bergx.io ~^(www.)?bergx.io; keepalive_timeout 70; ssl_certificate /etc/letsencrypt/live/p01.bergx.io/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/p01.bergx.io/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot location / { root /bergx/bx-webpage; try_files \$uri /index.html; } } EndOfConfig # cat > /etc/systemd/system/bergx.service << EndOfFile # [Unit] # Description=Bergx server # After=mysql.service # # [Service] # WorkingDirectory=/bergx/bx-service # ExecStart=/usr/bin/node /bergx/bx-service/build/bin/www.js # Restart=always # # Restart service after 10 seconds if node service crashes # RestartSec=10 # # Output to syslog # StandardOutput=syslog # # Output to syslog # StandardError=syslog # SyslogIdentifier=bergx-server # # User=nginx # # Group=nginx # Environment=NODE_ENV=production PORT=3030 # # [Install] # WantedBy=multi-user.target # EndOfFile # cat > /bergx/bx-service/.env << EndOfEnv # DEBUG=am-feature-switches:* # # ENVIRONMENT_NAME=gc-p01 # # ADMIN_ACCOUNTS=mason.payne@bergx.io # # ADMIN_ACCOUNTS= # # SESSION_SECRET=ZxsgDIUIF2eShEmK0CkAwE0aBGHQ5olV7HfeRV8QEfvV40QwoMkObpJdSAaQGtsr # JWT_SECRET=7srhHUVuQYX4O8JlCKqCRcWgOKB2w5bcWwO7zUv74dolGh0WCsuDbj5cgjMN9ivY # JWT_EXPIRATION=30m # ACCESS_TOKEN_EXPIRATION=30m # # CURRENT_HOST=https://p01.bergx.io # SEND_EMAILS=true # # SES_ACCESSKEY_ID=AKIATA3T2WIUTKFCYQVU # SES_SECRETKEY=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 # SES_REGION=us-west-2 # SES_SQS_BOUNCE=https://sqs.us-west-2.amazonaws.com/208011964969/ses-bounce-dev1 # SES_SQS_COMPLAINT=https://sqs.us-west-2.amazonaws.com/208011964969/ses-complaint-dev1 # # DOMAIN=p01.bergx.io # # DB_HOST=127.0.0.1 # DB_USER=bxmodules # DB_PASSWORD=LaiwRssM5QDy7j # DB_NAME=bxmodules # # SESSION_DB_HOST=127.0.0.1 # SESSION_DB_USER=session # SESSION_DB_PASSWORD=LaiwRssM5QDy7j # SESSION_DB_NAME=session # # NSQLOOKUP_HOST='localhost' # NSQLOOKUP_PORT='4161' # NSQD_HOST='localhost' # NSQD_PORT='4150' # # # Loki settings # AUTOLOAD=true # AUTOSAVE=true # # # File storage configuration # STORAGE_ENDPOINT=https://s3.wasabisys.com # STORAGE_ACCESSKEY=JVVBXJPQ6S9KBBC0CCHE # STORAGE_SECRETKEY=9odWv7cwzOJOHkAhpU86NSKaQi6aBK3PfzHeYbzw # LOGO_BUCKET=bx-images # # EndOfEnv # # systemctl daemon-reload # systemctl start bergx systemctl restart nginx # Init domains # domains=("p01.bergx.io" "www.bergx.io" "bergx.io") # Certbot # add-apt-repository ppa:certbot/certbot -y # apt install -y python-certbot-nginx # for elem in "${domains[@]}"; do # certbot_domains+=( "-d $elem" ) # done # # certbot -m mason.payne@bergx.io --nginx "${certbot_domains[@]}" exit 0