From ed38c86cbb585a410e6c74d9d423752db2a47756 Mon Sep 17 00:00:00 2001 From: Leonid Lapshin Date: Mon, 12 Oct 2020 17:44:31 +0300 Subject: [PATCH] Move linux provision scripts to virtual-environments (#1714) * add linux-related scripts from MMS provisioner * removed EOL * removed Ubuntu condition * moved PATH checking to cleanup section * add clarification for cgroups names * names alignment * removed memory-configuration and agent specific scripts * renamed folder to psot-generation, added template instructions * moved key import to git installation * moved PATH check to post-deployment instead of cleanup script * add scripts * output tests file * add startup logic * add powershell module for furute helpers * removed unused modules * copy to tmp folder because of permissions, copy to opt on post-generation step * removed Pester test * change post-generation location * incorrect if statement Co-authored-by: Leonid Lapshin --- images/linux/post-generation/homebrew-permissions.sh | 11 +++++++++++ images/linux/post-generation/rust-permissions.sh | 11 +++++++++++ images/linux/scripts/installers/cleanup.sh | 2 +- images/linux/scripts/installers/git.sh | 4 ++++ images/linux/scripts/installers/post-deployment.sh | 10 ++++++++++ images/linux/ubuntu1604.json | 5 +++++ images/linux/ubuntu1804.json | 5 +++++ images/linux/ubuntu2004.json | 5 +++++ 8 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 images/linux/post-generation/homebrew-permissions.sh create mode 100644 images/linux/post-generation/rust-permissions.sh diff --git a/images/linux/post-generation/homebrew-permissions.sh b/images/linux/post-generation/homebrew-permissions.sh new file mode 100644 index 000000000..1dbd043e2 --- /dev/null +++ b/images/linux/post-generation/homebrew-permissions.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Fix permissions for Homebrew +# https://github.com/actions/virtual-environments/issues/1568 +brew_folder="/home/linuxbrew/" +if [ -d "$brew_folder" ]; then + brew_folder_owner=$(ls -ld $brew_folder | awk '{print $3}') + if [ "$USER" != "$brew_folder_owner" ]; then + chown "$USER":docker -R $brew_folder + fi +fi diff --git a/images/linux/post-generation/rust-permissions.sh b/images/linux/post-generation/rust-permissions.sh new file mode 100644 index 000000000..6673686bd --- /dev/null +++ b/images/linux/post-generation/rust-permissions.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Fix permissions for the Rust folder +# https://github.com/actions/virtual-environments/issues/572 +rust_folder="/usr/share/rust" +if [ -d "$rust_folder" ]; then + rust_folder_owner=$(ls -ld $rust_folder | awk '{print $3}') + if [ "$USER" != "$rust_folder_owner" ]; then + chown "$USER":docker -R $rust_folder + fi +fi diff --git a/images/linux/scripts/installers/cleanup.sh b/images/linux/scripts/installers/cleanup.sh index 387a22402..cb6468d67 100644 --- a/images/linux/scripts/installers/cleanup.sh +++ b/images/linux/scripts/installers/cleanup.sh @@ -27,4 +27,4 @@ after=$(df / -Pm | awk 'NR==2{print $4}') # display size echo "Before: $before MB" echo "After : $after MB" - echo "Delta : $(($after-$before)) MB" \ No newline at end of file + echo "Delta : $(($after-$before)) MB" diff --git a/images/linux/scripts/installers/git.sh b/images/linux/scripts/installers/git.sh index 331e5f813..b0cdb6a36 100644 --- a/images/linux/scripts/installers/git.sh +++ b/images/linux/scripts/installers/git.sh @@ -52,3 +52,7 @@ else echo "[!] Hub CLI was not installed" exit 1 fi + +# Add well-known SSH host keys to known_hosts +ssh-keyscan -t rsa github.com >> /etc/ssh/ssh_known_hosts +ssh-keyscan -t rsa ssh.dev.azure.com >> /etc/ssh/ssh_known_hosts diff --git a/images/linux/scripts/installers/post-deployment.sh b/images/linux/scripts/installers/post-deployment.sh index 2864dae4f..f094ca51d 100644 --- a/images/linux/scripts/installers/post-deployment.sh +++ b/images/linux/scripts/installers/post-deployment.sh @@ -4,6 +4,8 @@ ## Desc: Post deployment actions ################################################################################ +mv -f /imagegeneration/post-generation /opt + # set chmod -R 777 /opt if [[ -d "/opt" ]]; then echo "chmod -R 777 /opt" @@ -14,3 +16,11 @@ fi rm -rf $HELPER_SCRIPT_FOLDER rm -rf $INSTALLER_SCRIPT_FOLDER chmod 755 $IMAGE_FOLDER + +# Check PATH +if [[ $PATH == \"*\" ]] +then + echo "ERROR: PATH contains quotes" + echo "PATH = $PATH" + exit 1 +fi diff --git a/images/linux/ubuntu1604.json b/images/linux/ubuntu1604.json index 8a4255ec7..5e45fdedc 100644 --- a/images/linux/ubuntu1604.json +++ b/images/linux/ubuntu1604.json @@ -89,6 +89,11 @@ "source": "{{template_dir}}/scripts/installers", "destination": "{{user `installer_script_folder`}}" }, + { + "type": "file", + "source": "{{ template_dir }}/post-generation", + "destination": "{{user `image_folder`}}" + }, { "type": "file", "source": "{{ template_dir }}/scripts/SoftwareReport", diff --git a/images/linux/ubuntu1804.json b/images/linux/ubuntu1804.json index daf40ce81..e6af0e41e 100644 --- a/images/linux/ubuntu1804.json +++ b/images/linux/ubuntu1804.json @@ -92,6 +92,11 @@ "source": "{{template_dir}}/scripts/installers", "destination": "{{user `installer_script_folder`}}" }, + { + "type": "file", + "source": "{{ template_dir }}/post-generation", + "destination": "{{user `image_folder`}}" + }, { "type": "file", "source": "{{ template_dir }}/scripts/SoftwareReport", diff --git a/images/linux/ubuntu2004.json b/images/linux/ubuntu2004.json index 740fe097f..9b4181ede 100644 --- a/images/linux/ubuntu2004.json +++ b/images/linux/ubuntu2004.json @@ -94,6 +94,11 @@ "source": "{{template_dir}}/scripts/installers", "destination": "{{user `installer_script_folder`}}" }, + { + "type": "file", + "source": "{{ template_dir }}/post-generation", + "destination": "{{user `installer_script_folder`}}" + }, { "type": "file", "source": "{{ template_dir }}/scripts/SoftwareReport",