Created
May 23, 2021 05:50
-
-
Save ianomad/98321ee576ce6e8d1f836886db4c2dc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
# curl -fsSL url/demo_devsbox_setup.sh | sh | |
# ---------------- variables -------------------- | |
sandbox_domain="demo.sb.devsbox.io" | |
email="[email protected]" | |
nginx_conf_content=$(cat << EOM | |
# redirect http to https | |
server { | |
listen 80 default_server; | |
listen [::]:80; | |
server_name _; | |
return 301 https://\$host\$request_uri; | |
} | |
server { | |
listen 8081; | |
listen [::]:8081; | |
server_name $sandbox_domain; | |
location / { | |
proxy_pass http://localhost:8080/; | |
proxy_set_header Host \$host; | |
proxy_set_header Upgrade \$http_upgrade; | |
proxy_set_header Connection upgrade; | |
proxy_set_header Accept-Encoding gzip; | |
} | |
} | |
EOM | |
) | |
vscode_settings=$(cat << EOM | |
{ | |
"window.menuBarVisibility": "visible", | |
"workbench.colorTheme": "Default Dark+", | |
"terminal.integrated.shell.linux": "/bin/bash" | |
} | |
EOM | |
) | |
# ---------------- functions -------------------- | |
codeserver_setup() { | |
# the simplest command to install code-server | |
curl -fsSL https://code-server.dev/install.sh | sh | |
# enable it at the boot time | |
sudo systemctl enable --now code-server@$USER | |
echo 'waiting for 10 seconds for code server to start' | |
sleep 10 | |
# set the password | |
sudo sed -i.bak 's/password: .*/password: demo/' ~/.config/code-server/config.yaml | |
echo "$vscode_settings" | sudo tee -a ~/.local/share/code-server/User/ | |
# restart the box to make the changes take effect | |
sudo systemctl restart code-server@$USER | |
} | |
nginx_setup() { | |
# for amazon linux - sudo amazon-linux-extras install nginx1 -y | |
sudo apt update -y && sudo apt upgrade -y | |
sudo apt install nginx -y | |
echo "$nginx_conf_content" | sudo tee -a /etc/nginx/sites-available/devsbox | |
# this is to remove default 80 server conflict | |
sudo rm /etc/nginx/sites-available/default | |
sudo ln -s /etc/nginx/sites-available/devsbox /etc/nginx/sites-enabled/devsbox | |
sudo systemctl restart nginx | |
} | |
https_setup() { | |
# certbot is a free ssl certificate | |
sudo apt install -y nginx certbot python3-certbot-nginx | |
# this will append configurations to the nginx file (/etc/nginx/sites-enabled/devsbox) | |
sudo certbot --non-interactive --redirect --agree-tos --nginx -d $sandbox_domain -m $email | |
} | |
# ---------------- run -------------------- | |
# setup codeserver | |
codeserver_setup | |
# proxy nginx to code server | |
nginx_setup | |
# enable https | |
https_setup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment