Last active
July 2, 2024 20:09
-
-
Save Ouwen/e0df7552da82180e1416422673e60fae 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 | |
# "Check if Screen is installed..." | |
if ! command -v screen &> /dev/null; then | |
sudo apt-get install -y -qq screen >/dev/null 2>&1; | |
else | |
echo "screen is already installed."; | |
fi | |
if screen -list | grep -q "vs_code_tunnel"; then | |
screen -S vs_code_tunnel -X quit; | |
echo "Screen session 'vs_code_tunnel' terminated."; | |
fi | |
# "Check if VSCode is installed..." | |
if ! command -v code &> /dev/null; then | |
echo "VSCode not found. Downloading and installing code..." | |
sudo apt-get install -y -qq wget gpg >/dev/null 2>&1 | |
echo "Downloading Microsoft GPG key..." | |
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg | |
sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg | |
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list' | |
rm -f packages.microsoft.gpg | |
sudo apt install -y -qq apt-transport-https >/dev/null 2>&1 | |
echo "Updating package list..." | |
sudo apt-get update -qq | |
echo "Installing VSCode..." | |
sudo apt install -y -qq code >/dev/null 2>&1 | |
else | |
echo "code is already installed." | |
fi | |
echo "Create tunnel in the background..." | |
MACHINE_NAME_DEFAULT="machine-$(date +%Y%m%d)-$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 5 | head -n 1)" | |
MACHINE_NAME_TO_USE="${MACHINE_NAME:-$MACHINE_NAME_DEFAULT}" | |
code tunnel rename $MACHINE_NAME_TO_USE | |
mkdir -p /content/setup | |
screen -dmS vs_code_tunnel bash -c 'code tunnel > /content/setup/output.log 2>&1; exec bash' | |
sleep 1 | |
if screen -list | grep -q "vs_code_tunnel"; then | |
echo "Screen session 'vs_code_tunnel' running"; | |
else | |
echo "Screen session 'vs_code_tunnel' does not exist. Error... contact ouwen@gradienthealth.io"; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment