From 300c1037a67b2fae989a6af87feb9b7319dd305c Mon Sep 17 00:00:00 2001 From: "J. Patrick Fulton" Date: Fri, 25 Aug 2023 17:01:10 -0500 Subject: [PATCH 01/11] Add missing space. --- linux/samba/create-samba-users.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/samba/create-samba-users.sh b/linux/samba/create-samba-users.sh index 5cdc584..2697689 100755 --- a/linux/samba/create-samba-users.sh +++ b/linux/samba/create-samba-users.sh @@ -19,7 +19,7 @@ sudo adduser --no-create-home --disabled-password --shell /sbin/nologin --gecos sudo echo "${LINUX_BACKUP_USER}:$(openssl rand -base64 12)" | sudo chpasswd; # Set the linux back up user smb password -(echo "$LINUX_BACKUP_USER_PASS"; echo "$LINUX_BACKUP_USER_PASS") |sudo smbpasswd -s -a $LINUX_BACKUP_USER; +(echo "$LINUX_BACKUP_USER_PASS"; echo "$LINUX_BACKUP_USER_PASS") | sudo smbpasswd -s -a $LINUX_BACKUP_USER; # Create a deployment output file with smb users and password for secure transfer to # the control workstation later From dee44667ad4e8ebed067d66bff722ab10d25c7b5 Mon Sep 17 00:00:00 2001 From: "J. Patrick Fulton" Date: Fri, 25 Aug 2023 17:02:10 -0500 Subject: [PATCH 02/11] First pass at desktop, rdp and dev tools setup. --- linux/dev-tools/README.md | 4 ++++ linux/dev-tools/create-dev-user.sh | 27 +++++++++++++++++++++++++++ linux/dev-tools/install-chrome.sh | 7 +++++++ linux/dev-tools/install-desktop.sh | 25 +++++++++++++++++++++++++ linux/dev-tools/install-vscode.sh | 14 ++++++++++++++ scripts/create-linux-server.sh | 28 +++++++++++++++++++++++++++- 6 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 linux/dev-tools/README.md create mode 100755 linux/dev-tools/create-dev-user.sh create mode 100755 linux/dev-tools/install-chrome.sh create mode 100755 linux/dev-tools/install-desktop.sh create mode 100755 linux/dev-tools/install-vscode.sh diff --git a/linux/dev-tools/README.md b/linux/dev-tools/README.md new file mode 100644 index 0000000..79700e2 --- /dev/null +++ b/linux/dev-tools/README.md @@ -0,0 +1,4 @@ +# dev-tools + +Scripts in this folder install a Gnome Desktop environment and +developer tools on the target virtual machine. diff --git a/linux/dev-tools/create-dev-user.sh b/linux/dev-tools/create-dev-user.sh new file mode 100755 index 0000000..5455e45 --- /dev/null +++ b/linux/dev-tools/create-dev-user.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +DEPLOYMENT_OUTPUT_FILE="dev-users.txt"; + +if [ "$#" -ne 1 ] + then + echo "ERROR: This script requires one argument. Exiting..."; + echo "INFO: Required argument one: Admin user name."; + echo; + + exit 1; +fi + +ADMIN_USERNAME="$1"; + +DEV_USER="${ADMIN_USERNAME}-dev"; +DEV_USER_PASS="$(openssl rand -base64 12)"; # generate random password + +sudo adduser --disabled-password --gecos "Development User" $DEV_USER; +sudo echo "${DEV_USER}:${DEV_USER_PASS}" | sudo chpasswd; + +# Create a deployment output file with dev users and password for secure transfer to +# the control workstation later +touch $DEPLOYMENT_OUTPUT_FILE; +echo "Developer Users:" > $DEPLOYMENT_OUTPUT_FILE; +echo "" >> $DEPLOYMENT_OUTPUT_FILE; +echo "${DEV_USER}:${DEV_USER_PASS}" >> $DEPLOYMENT_OUTPUT_FILE; diff --git a/linux/dev-tools/install-chrome.sh b/linux/dev-tools/install-chrome.sh new file mode 100755 index 0000000..f31803d --- /dev/null +++ b/linux/dev-tools/install-chrome.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +DEBIAN_FRONTEND="noninteractive"; + +wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb; +chmod a+w ./google-chrome-stable_current_amd64.deb; +sudo apt-get install ./google-chrome-stable_current_amd64.deb -y; diff --git a/linux/dev-tools/install-desktop.sh b/linux/dev-tools/install-desktop.sh new file mode 100755 index 0000000..0eb2e8c --- /dev/null +++ b/linux/dev-tools/install-desktop.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +BASE_REPO_URL="https://raw.githubusercontent.com/jpfulton/example-linux-configs/main"; +XRDP_CONFIG_DIR="/etc/xrdp/"; +XRDP_WM_STARTUP_SCRIPT="startwm.sh"; + +DEBIAN_FRONTEND="noninteractive"; +sudo -E apt-get update; + +# Install a minimal version of Gnome Desktop +# This step essentially upgrades from Ubuntu Server version to a minimal Ubuntu Desktop version +# X11 is a dependency +sudo -E apt-get install ubuntu-desktop-minimal -y; + +# Install xRDP server +sudo -E apt-get install xrdp -y; + +# Update xRDP start up script to provide traditional Gnome experience +sudo wget -q ${BASE_REPO_URL}${XRDP_CONFIG_DIR}${XRDP_WM_STARTUP_SCRIPT}; +sudo chmod a+x ./${XRDP_WM_STARTUP_SCRIPT}; +sudo mv ./${XRDP_WM_STARTUP_SCRIPT} ${XRDP_CONFIG_DIR}${XRDP_WM_STARTUP_SCRIPT}; + +# Open firewall to RDP port +sudo ufw allow 3389/tcp; +sudo ufw status numbered; diff --git a/linux/dev-tools/install-vscode.sh b/linux/dev-tools/install-vscode.sh new file mode 100755 index 0000000..8c387c3 --- /dev/null +++ b/linux/dev-tools/install-vscode.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +DEBIAN_FRONTEND="noninteractive"; + +# Install VSCode + +# Get dependencies +sudo -E apt-get install software-properties-common apt-transport-https -y; +# Install the GPG key +wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -; +# Add the VSCode package repo +sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" -y; +# Install VS Code package +sudo apt-get install code -y; \ No newline at end of file diff --git a/scripts/create-linux-server.sh b/scripts/create-linux-server.sh index 46e76b8..e8017e1 100755 --- a/scripts/create-linux-server.sh +++ b/scripts/create-linux-server.sh @@ -30,7 +30,7 @@ parse-script-inputs () { fi SCRIPT_NAME=$(basename "$0"); - OPTIONS=$(getopt --options obs --long allow-ssh,samba,openvpn --name "$SCRIPT_NAME" -- "$@"); + OPTIONS=$(getopt --options dobs --long dev-tools,allow-ssh,samba,openvpn --name "$SCRIPT_NAME" -- "$@"); if [ $? -ne 0 ] then echo "Incorrect options."; @@ -41,6 +41,7 @@ parse-script-inputs () { ALLOW_SSH_RULE=0; OPENVPN=0; SAMBA=0; + DEV_TOOLS=0; eval set -- "$OPTIONS"; shift 6; # jump past the getopt options in the options string @@ -49,6 +50,8 @@ parse-script-inputs () { case "$1" in -o|--openvpn) OPENVPN=1; shift ;; + -d|--dev-tools) + DEV_TOOLS=1; shift ;; -b|--samba) SAMBA=1; shift ;; -s|--allow-ssh) @@ -75,6 +78,11 @@ parse-script-inputs () { echo "Enabling Samba installation."; fi + if [ "$DEV_TOOLS" -eq 1 ] + then + echo "Enabling development tools installation."; + fi + RESOURCE_GROUP="$1"; if [ "$RESOURCE_GROUP" == "" ] then @@ -452,6 +460,24 @@ main () { scp-to-deployment-outputs-dir "~/samba-users.txt"; fi + if [ "$DEV_TOOLS" -eq 1 ] + then + echo "Copying development tools setup scripts to server..."; + scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-desktop.sh; + scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/create-dev-user.sh; + scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-vscode.sh; + scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-chrome.sh; + + echo "Executing development tools setup scripts..."; + run-script-from-admin-home install-desktop.sh; + run-script-from-admin-home "create-dev-user.sh ${ADMIN_USERNAME}"; + run-script-from-admin-home install-vscode.sh; + run-script-from-admin-home install-chrome.sh; + + echo "Gathering outputs to deployment output directory..."; + scp-to-deployment-outputs-dir "~/dev-users.txt"; + fi + run-script-from-admin-home clean-up.sh; if [ "$OPENVPN" -eq 1 ] && [ "$ALLOW_SSH_RULE" -eq 1 ]; From 00b6253f2b3fc6273cc53dd7c49698538acfa894 Mon Sep 17 00:00:00 2001 From: "J. Patrick Fulton" Date: Fri, 25 Aug 2023 17:27:37 -0500 Subject: [PATCH 03/11] Add dotnet sdk installation. --- linux/dev-tools/install-dotnet-sdk.sh | 21 +++++++++++++++++++++ scripts/create-linux-server.sh | 2 ++ 2 files changed, 23 insertions(+) create mode 100755 linux/dev-tools/install-dotnet-sdk.sh diff --git a/linux/dev-tools/install-dotnet-sdk.sh b/linux/dev-tools/install-dotnet-sdk.sh new file mode 100755 index 0000000..4b9b5e9 --- /dev/null +++ b/linux/dev-tools/install-dotnet-sdk.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +DEBIAN_FRONTEND="noninteractive"; + +# Get Ubuntu version +declare repo_version=$(if command -v lsb_release &> /dev/null; then lsb_release -r -s; else grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"'; fi); + +# Download Microsoft signing key and repository +wget https://packages.microsoft.com/config/ubuntu/$repo_version/packages-microsoft-prod.deb -O packages-microsoft-prod.deb; + +# Install Microsoft signing key and repository +sudo dpkg -i packages-microsoft-prod.deb; + +# Clean up +rm packages-microsoft-prod.deb; + +# Update packages +sudo apt-get update; + +# Install the .NET 7 SDK +sudo apt-get install dotnet-sdk-7.0 -y; diff --git a/scripts/create-linux-server.sh b/scripts/create-linux-server.sh index e8017e1..3874f75 100755 --- a/scripts/create-linux-server.sh +++ b/scripts/create-linux-server.sh @@ -465,12 +465,14 @@ main () { echo "Copying development tools setup scripts to server..."; scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-desktop.sh; scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/create-dev-user.sh; + scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-dotnet-sdk.sh; scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-vscode.sh; scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-chrome.sh; echo "Executing development tools setup scripts..."; run-script-from-admin-home install-desktop.sh; run-script-from-admin-home "create-dev-user.sh ${ADMIN_USERNAME}"; + run-script-from-admin-home install-dotnet-sdk.sh; run-script-from-admin-home install-vscode.sh; run-script-from-admin-home install-chrome.sh; From 2ecd569e81daca78767c9e48e5ce8904a40340fd Mon Sep 17 00:00:00 2001 From: "J. Patrick Fulton" Date: Fri, 25 Aug 2023 20:40:14 -0500 Subject: [PATCH 04/11] Update order of installs and account for MS package repo usage. --- linux/dev-tools/install-dotnet-sdk.sh | 19 ++++++++++++++++++- scripts/create-linux-server.sh | 4 ++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/linux/dev-tools/install-dotnet-sdk.sh b/linux/dev-tools/install-dotnet-sdk.sh index 4b9b5e9..07fa187 100755 --- a/linux/dev-tools/install-dotnet-sdk.sh +++ b/linux/dev-tools/install-dotnet-sdk.sh @@ -2,11 +2,15 @@ DEBIAN_FRONTEND="noninteractive"; +# Purge old packages +sudo apt-get remove 'dotnet.*' -y; +sudo apt-get remove 'aspnet.*' -y; + # Get Ubuntu version declare repo_version=$(if command -v lsb_release &> /dev/null; then lsb_release -r -s; else grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"'; fi); # Download Microsoft signing key and repository -wget https://packages.microsoft.com/config/ubuntu/$repo_version/packages-microsoft-prod.deb -O packages-microsoft-prod.deb; +wget -q https://packages.microsoft.com/config/ubuntu/$repo_version/packages-microsoft-prod.deb -O packages-microsoft-prod.deb; # Install Microsoft signing key and repository sudo dpkg -i packages-microsoft-prod.deb; @@ -14,6 +18,19 @@ sudo dpkg -i packages-microsoft-prod.deb; # Clean up rm packages-microsoft-prod.deb; +# Establish preferences for MS feed +sudo sh -c "cat > /etc/apt/preferences.d/dotnet <<'EOF' +Package: dotnet* +Pin: origin packages.microsoft.com +Pin-Priority: 1001 +EOF"; + +sudo sh -c "cat > /etc/apt/preferences.d/aspnet <<'EOF' +Package: aspnet* +Pin: origin packages.microsoft.com +Pin-Priority: 1001 +EOF"; + # Update packages sudo apt-get update; diff --git a/scripts/create-linux-server.sh b/scripts/create-linux-server.sh index 3874f75..3a13baf 100755 --- a/scripts/create-linux-server.sh +++ b/scripts/create-linux-server.sh @@ -463,16 +463,16 @@ main () { if [ "$DEV_TOOLS" -eq 1 ] then echo "Copying development tools setup scripts to server..."; + scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-dotnet-sdk.sh; scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-desktop.sh; scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/create-dev-user.sh; - scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-dotnet-sdk.sh; scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-vscode.sh; scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-chrome.sh; echo "Executing development tools setup scripts..."; + run-script-from-admin-home install-dotnet-sdk.sh; run-script-from-admin-home install-desktop.sh; run-script-from-admin-home "create-dev-user.sh ${ADMIN_USERNAME}"; - run-script-from-admin-home install-dotnet-sdk.sh; run-script-from-admin-home install-vscode.sh; run-script-from-admin-home install-chrome.sh; From 8ffa04f6bd8002ecc9209aec78e50c55cc1eecad Mon Sep 17 00:00:00 2001 From: "J. Patrick Fulton" Date: Fri, 25 Aug 2023 21:16:02 -0500 Subject: [PATCH 05/11] Enable nodejs corepack during installation. --- linux/dev-tools/enable-node-corepack.sh | 4 ++++ scripts/create-linux-server.sh | 2 ++ 2 files changed, 6 insertions(+) create mode 100755 linux/dev-tools/enable-node-corepack.sh diff --git a/linux/dev-tools/enable-node-corepack.sh b/linux/dev-tools/enable-node-corepack.sh new file mode 100755 index 0000000..d3604c1 --- /dev/null +++ b/linux/dev-tools/enable-node-corepack.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +# Enable corepack to support yarn upgrades among other things +sudo corepack enable; diff --git a/scripts/create-linux-server.sh b/scripts/create-linux-server.sh index 3a13baf..6bc3a7d 100755 --- a/scripts/create-linux-server.sh +++ b/scripts/create-linux-server.sh @@ -466,6 +466,7 @@ main () { scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-dotnet-sdk.sh; scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-desktop.sh; scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/create-dev-user.sh; + scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/enable-node-corepack.sh; scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-vscode.sh; scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/dev-tools/install-chrome.sh; @@ -473,6 +474,7 @@ main () { run-script-from-admin-home install-dotnet-sdk.sh; run-script-from-admin-home install-desktop.sh; run-script-from-admin-home "create-dev-user.sh ${ADMIN_USERNAME}"; + run-script-from-admin-home enable-node-corepack.sh; run-script-from-admin-home install-vscode.sh; run-script-from-admin-home install-chrome.sh; From bbc4dbdc0cf42dc4dfa0fe7c3e6104f8514ebeff Mon Sep 17 00:00:00 2001 From: "J. Patrick Fulton" Date: Fri, 25 Aug 2023 21:25:56 -0500 Subject: [PATCH 06/11] Add dev user to sudoers. --- linux/dev-tools/create-dev-user.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/linux/dev-tools/create-dev-user.sh b/linux/dev-tools/create-dev-user.sh index 5455e45..b8a0ebd 100755 --- a/linux/dev-tools/create-dev-user.sh +++ b/linux/dev-tools/create-dev-user.sh @@ -19,6 +19,10 @@ DEV_USER_PASS="$(openssl rand -base64 12)"; # generate random password sudo adduser --disabled-password --gecos "Development User" $DEV_USER; sudo echo "${DEV_USER}:${DEV_USER_PASS}" | sudo chpasswd; +# Add dev user to sudoers +SUDOERS_FILE="/etc/sudoers.d/${DEV_USER}"; +echo -n "${DEV_USER} ALL=(root) NOPASSWD:ALL" | sudo tee $SUDOERS_FILE > /dev/null; + # Create a deployment output file with dev users and password for secure transfer to # the control workstation later touch $DEPLOYMENT_OUTPUT_FILE; From 8ba3905a12be72ea42f44815c633f18ec5a0c6f4 Mon Sep 17 00:00:00 2001 From: "J. Patrick Fulton" Date: Sat, 26 Aug 2023 14:39:39 -0500 Subject: [PATCH 07/11] Update markdown guides for a linux development server. --- SETUP_BASIC_NETWORK.md | 7 ++++++ SETUP_LINUX_DEV_SERVER.md | 53 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 SETUP_LINUX_DEV_SERVER.md diff --git a/SETUP_BASIC_NETWORK.md b/SETUP_BASIC_NETWORK.md index b527085..3e71ca0 100644 --- a/SETUP_BASIC_NETWORK.md +++ b/SETUP_BASIC_NETWORK.md @@ -124,3 +124,10 @@ place. It is not added to the key chain. Once the disk has been set up, the backup will begin in 60 seconds. The first backup operation is complete and may take some time. Future backup operations are incremental and significantly faster. + +## Next Steps + +Once the basic infrastructure is in place from the steps described here, other +servers can now be created: + +- [Setup a Linux Development Server](./SETUP_LINUX_DEV_SERVER.md) diff --git a/SETUP_LINUX_DEV_SERVER.md b/SETUP_LINUX_DEV_SERVER.md new file mode 100644 index 0000000..e48ca37 --- /dev/null +++ b/SETUP_LINUX_DEV_SERVER.md @@ -0,0 +1,53 @@ +# Setup a Linux Development Server + +In this guide, a Linux development server will be created with the following +features: + +- A minimal installation of Gnome Desktop +- An xRDP server allowing access to the desktop environment using an RDP client +- Git +- Nodejs v18 +- Nodejs Corepack Enabled +- Yarn package manager +- .NET 7 SDK +- Google Chrome +- VS Code + +## Install a Local RDP Client + +For macOS, use the App Store to install the +[Microsoft Remote Desktop Client](https://apps.apple.com/us/app/microsoft-remote-desktop/id1295203466?mt=12). + +## Create a Linux Development Server + +From the root of this repository navigate to the control scripts folder in +a terminal with the command: + +```bash +cd scripts +``` + +The next command creates a Linux development server with the features listed +above. An account name and initial randomly generated password will be securely transferred +to a deployment outputs folder in your local account's home folder in file named +`dev-users.txt`. The output folder will be located in the current local +user's home folder and will be labeled `deployment-outputs-{UUID}`. Output lines +at the end of the script will identify this folder. + +Instead of selecting the default virtual machine size, select a larger version +for this installation: `Standard_DS2_v2`. A two core instance with a larger RAM +profile will make the system more responsive for the desktop environment. + +```bash +./create-linux-server.sh -d personal-network linux-dev +``` + +## Log into the Server via RDP + +Open the Microsoft Remote Desktop App, and from the **Connections** menu select +**Add PC**. In the **Add PC** dialog, enter `linux-dev.yourprivatednszonehere.com` as +the PC name. In the User account drop down, select **Add a User Account**, in the next +step enter the credentials found in `dev-users.txt` within the deployment outputs folder. +Select **Add** and then select **Add** in the Add PC dialog accepting the default settings +for the connection. The new machine will be visible in the main application window. Double +click the connection to log into the Linux server. From 062470d147157b05b70c76f249b784d5a28e7983 Mon Sep 17 00:00:00 2001 From: "J. Patrick Fulton" Date: Sat, 26 Aug 2023 15:21:31 -0500 Subject: [PATCH 08/11] Refactor lines from main function to separate functions. --- scripts/create-linux-server.sh | 58 ++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/scripts/create-linux-server.sh b/scripts/create-linux-server.sh index 6bc3a7d..5c7da97 100755 --- a/scripts/create-linux-server.sh +++ b/scripts/create-linux-server.sh @@ -370,26 +370,9 @@ az-remove-allow-ssh-nsg-rule () { echo; } -main () { - validate-az-cli-install; - - # parse script inputs and gather user inputs - parse-script-inputs $@; - get-user-inputs; - - # check for signed in Azure CLI user - check-signed-in-user; - - # deploy bicep template - deploy; - - # create outputs directory - create-local-deployment-outputs-dir; - - # log into admin account and record host key - login-to-admin-acct; - +perform-core-setup () { # copy setup scripts to server + echo "Copying base platform setup scripts..."; scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/core/update-base-packages.sh; scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/core/setup-firewall.sh; scp-file-to-admin-home ${CURRENT_SCRIPT_DIR}../linux/core/setup-motd.sh; @@ -407,7 +390,9 @@ main () { run-script-from-admin-home setup-node-and-yarn.sh; run-script-from-admin-home setup-sms-notifier.sh; scp-notifier-config; - +} + +perform-spot-setup () { if [ "$IS_SPOT" = "true" ] then echo "Executing spot instance setup scripts..."; @@ -421,7 +406,9 @@ main () { az-add-tag-to-resource $VM_ID "AttemptRestartAfterEviction=true"; fi fi +} +perform-openvpn-setup () { if [ "$OPENVPN" -eq 1 ] then echo "Copying OpenVPN setup scripts to server..."; @@ -439,7 +426,9 @@ main () { echo "Gathering outputs to deployment output directory..."; scp-to-deployment-outputs-dir "~/personal-network-client.ovpn"; fi +} +perform-samba-setup () { if [ "$SAMBA" -eq 1 ] then echo "Copying Samba setup scripts to server..."; @@ -459,7 +448,9 @@ main () { echo "Gathering outputs to deployment output directory..."; scp-to-deployment-outputs-dir "~/samba-users.txt"; fi +} +perform-dev-tools-setup () { if [ "$DEV_TOOLS" -eq 1 ] then echo "Copying development tools setup scripts to server..."; @@ -481,6 +472,33 @@ main () { echo "Gathering outputs to deployment output directory..."; scp-to-deployment-outputs-dir "~/dev-users.txt"; fi +} + +main () { + validate-az-cli-install; + + # parse script inputs and gather user inputs + parse-script-inputs $@; + get-user-inputs; + + # check for signed in Azure CLI user + check-signed-in-user; + + # deploy bicep template + deploy; + + # create outputs directory + create-local-deployment-outputs-dir; + + # log into admin account and record host key + login-to-admin-acct; + + # perform setups for core platform and user elected features + perform-core-setup; + perform-spot-setup; + perform-openvpn-setup; + perform-samba-setup; + perform-dev-tools-setup; run-script-from-admin-home clean-up.sh; From 0fa4ca36a556ae153f51cdc05b4940bbc40e8b5e Mon Sep 17 00:00:00 2001 From: "J. Patrick Fulton" Date: Sat, 26 Aug 2023 15:34:30 -0500 Subject: [PATCH 09/11] Further clean up of the main function. --- scripts/create-linux-server.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/scripts/create-linux-server.sh b/scripts/create-linux-server.sh index 5c7da97..1489bd5 100755 --- a/scripts/create-linux-server.sh +++ b/scripts/create-linux-server.sh @@ -474,6 +474,16 @@ perform-dev-tools-setup () { fi } +close-ssh-nsg-rule-if-needed () { + if [ "$OPENVPN" -eq 1 ] && [ "$ALLOW_SSH_RULE" -eq 1 ]; + then + echo "OpenVPN was sucessfully installed over the open SSH port."; + echo "Closing SSH port in the server NSG. Future access should be performed over the VPN tunnel."; + + az-remove-allow-ssh-nsg-rule; + fi +} + main () { validate-az-cli-install; @@ -500,15 +510,11 @@ main () { perform-samba-setup; perform-dev-tools-setup; + # clean up the remote home folder run-script-from-admin-home clean-up.sh; - if [ "$OPENVPN" -eq 1 ] && [ "$ALLOW_SSH_RULE" -eq 1 ]; - then - echo "OpenVPN was sucessfully installed over the open SSH port."; - echo "Closing SSH port in the server NSG. Future access should be performed over the VPN tunnel."; - - az-remove-allow-ssh-nsg-rule; - fi + # remove the allow SSH rule if needed (OpenVPN and AllowSsh were both true) + close-ssh-nsg-rule-if-needed; echo; echo "---"; From 7ecfa5808dec7bea94c138dadc5dcc1da050877b Mon Sep 17 00:00:00 2001 From: "J. Patrick Fulton" Date: Sat, 26 Aug 2023 15:51:49 -0500 Subject: [PATCH 10/11] Add removal of empty deployment directory feature and finish main function clean up. --- scripts/create-linux-server.sh | 48 +++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/scripts/create-linux-server.sh b/scripts/create-linux-server.sh index 1489bd5..288d20f 100755 --- a/scripts/create-linux-server.sh +++ b/scripts/create-linux-server.sh @@ -484,6 +484,37 @@ close-ssh-nsg-rule-if-needed () { fi } +remove-empty-deployment-outputs-dir () { + local IS_EMPTY=$(find $DEPLOYMENT_OUTPUTS_DIR -maxdepth 0 -empty -exec echo 1 \;); + + if [ "$IS_EMPTY" -eq 1 ] + then + echo "Deployment outputs directory is empty. Removing it..."; + rm -rf $DEPLOYMENT_OUTPUTS_DIR; + fi +} + +display-end-of-run-outputs () { + echo; + echo "---"; + echo "Server name: $SERVER_NAME"; + + if [ "$ALLOW_SSH_RULE" -eq 0 ] + then + echo "Server private FQDN: $SERVER_FQDN"; + fi + + echo "Server public IP: $PUBLIC_IP"; + echo "Deployment name: $DEPLOYMENT_NAME"; + + if [ -d "$DEPLOYMENT_OUTPUTS_DIR" ] + then + echo "Deployment outputs directory: $DEPLOYMENT_OUTPUTS_DIR"; + fi + + echo; +} + main () { validate-az-cli-install; @@ -516,20 +547,11 @@ main () { # remove the allow SSH rule if needed (OpenVPN and AllowSsh were both true) close-ssh-nsg-rule-if-needed; - echo; - echo "---"; - echo "Server name: $SERVER_NAME"; + # remove deployment outputs directory if empty + remove-empty-deployment-outputs-dir; - if [ "$ALLOW_SSH_RULE" -eq 0 ] - then - echo "Server private FQDN: $SERVER_FQDN"; - fi - - echo "Server public IP: $PUBLIC_IP"; - echo "Deployment name: $DEPLOYMENT_NAME"; - echo "Deployment outputs directory: $DEPLOYMENT_OUTPUTS_DIR"; - echo "---"; - echo; + # display deployment results to user + display-end-of-run-outputs; echo "---"; echo "Done."; From 14888a075e5b5ca9ffdf8cde3f669e4ddbb1bd81 Mon Sep 17 00:00:00 2001 From: "J. Patrick Fulton" Date: Sat, 26 Aug 2023 19:09:57 -0500 Subject: [PATCH 11/11] Correct bug around empty directory detection. --- scripts/create-linux-server.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/create-linux-server.sh b/scripts/create-linux-server.sh index 288d20f..5dd38e1 100755 --- a/scripts/create-linux-server.sh +++ b/scripts/create-linux-server.sh @@ -485,10 +485,10 @@ close-ssh-nsg-rule-if-needed () { } remove-empty-deployment-outputs-dir () { - local IS_EMPTY=$(find $DEPLOYMENT_OUTPUTS_DIR -maxdepth 0 -empty -exec echo 1 \;); - - if [ "$IS_EMPTY" -eq 1 ] + if [ "$(ls -A $DEPLOYMENT_OUTPUTS_DIR)" ] then + echo "Deployments output directory contains files. Leaving in place..."; + else echo "Deployment outputs directory is empty. Removing it..."; rm -rf $DEPLOYMENT_OUTPUTS_DIR; fi