From f196a224afffd692208ebc0928acb0825670db64 Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Sat, 14 Dec 2019 11:12:13 +1000 Subject: [PATCH 1/8] Applied shellcheck recommendations Specifically https://www.shellcheck.net/wiki/SC2181 --- docs/installers/apt.sh | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/docs/installers/apt.sh b/docs/installers/apt.sh index ed2cfaaa58..fd852d53ef 100755 --- a/docs/installers/apt.sh +++ b/docs/installers/apt.sh @@ -35,10 +35,7 @@ echo "Installing [${REPO_VENDOR}] repository..."; echo "${repo_entry}" > /etc/apt/sources.list.d/${REPO_VENDOR}_vscode.list; echo "Updating APT cache..." -apt-get update -yq; -echo "Done!" - -if [ $? -eq 0 ]; then +if apt-get update -yq; then echo "Repository install complete."; else echo "Repository install failed."; @@ -46,10 +43,7 @@ else fi; echo "Installing Visual Studio Code from [${repo_name}]..."; -apt-get install -t ${repo_name} -y ${code_executable_name}; -#apt-get install -t ${repo_name} -y --allow-unauthenticated ${code_executable_name}; - -if [ $? -eq 0 ]; then +if apt-get install -t ${repo_name} -y ${code_executable_name}; then echo "Visual Studio Code install complete."; else echo "Visual Studio Code install failed."; @@ -57,9 +51,7 @@ else fi; echo "Installing git..."; -apt-get install -y git; - -if [ $? -eq 0 ]; then +if apt-get install -y git; then echo "git install complete."; else echo "git install failed."; @@ -67,9 +59,7 @@ else fi; echo "Installing any dependencies that may have been missed..."; -apt-get install -y -f; - -if [ $? -eq 0 ]; then +if apt-get install -y -f; then echo "Missed dependency install complete."; else echo "Missed dependency install failed."; From 52b9850c9b4ba9097a8838c8881ff94191d42f46 Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Sat, 14 Dec 2019 12:32:48 +1000 Subject: [PATCH 2/8] Dynamic dependency installation Test for and only install missing dependencies --- docs/installers/apt.sh | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/docs/installers/apt.sh b/docs/installers/apt.sh index fd852d53ef..48c8f92b82 100755 --- a/docs/installers/apt.sh +++ b/docs/installers/apt.sh @@ -4,9 +4,27 @@ echo "Detecting architecture..."; MACHINE_MTYPE="$(uname -m)"; ARCH="${MACHINE_MTYPE}"; REPO_VENDOR="headmelted"; +DEPENDENCIES="" -echo "Ensuring curl is installed"; -apt-get install -y curl; +echo "Updating APT cache..." +if apt-get update -yq; then + echo "Update complete."; +else + echo "Update failed."; + exit 1; +fi; + +#test what dependencies need to be installed +test -f "/usr/share/doc/apt-transport-https/copyright" || DEPENDENCIES="${DEPENDENCIES} apt-transport-https" +sudo command -v update-ca-certificates >/dev/null 2>&1 || DEPENDENCIES="${DEPENDENCIES} ca-certificates" +command -v curl >/dev/null 2>&1 || DEPENDENCIES="${DEPENDENCIES} curl" +command -v git >/dev/null 2>&1 || DEPENDENCIES="${DEPENDENCIES} git" +command -v gpg-agent >/dev/null 2>&1 || DEPENDENCIES="${DEPENDENCIES} gnupg-agent" + +if [ "X${DEPENDENCIES}" != "X" ]; then + echo "Installing dependencies: ${DEPENDENCIES}" >&2 + apt-get -f -qq -y install "${DEPENDENCIES}" >/dev/null 2>&1 +fi if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "i386" ]; then REPO_VENDOR="microsoft"; fi; @@ -34,7 +52,7 @@ rm -rf /etc/apt/sources.list.d/codebuilds.list; echo "Installing [${REPO_VENDOR}] repository..."; echo "${repo_entry}" > /etc/apt/sources.list.d/${REPO_VENDOR}_vscode.list; -echo "Updating APT cache..." +echo "Refreshing APT cache again..." if apt-get update -yq; then echo "Repository install complete."; else @@ -50,14 +68,6 @@ else exit 1; fi; -echo "Installing git..."; -if apt-get install -y git; then - echo "git install complete."; -else - echo "git install failed."; - exit 1; -fi; - echo "Installing any dependencies that may have been missed..."; if apt-get install -y -f; then echo "Missed dependency install complete."; @@ -75,4 +85,3 @@ You can start code at any time by calling \"${code_executable_name}\" within a t A shortcut should also now be available in your desktop menus (depending on your distribution). "; - From fa4722093c13843b99f0a171071871d64b7ab86c Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Sat, 14 Dec 2019 12:38:04 +1000 Subject: [PATCH 3/8] Add root priv check The install script generally needs root priv, so will now gracefully bug out if it don't have them. --- docs/installers/apt.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/installers/apt.sh b/docs/installers/apt.sh index 48c8f92b82..e57113fff2 100755 --- a/docs/installers/apt.sh +++ b/docs/installers/apt.sh @@ -1,5 +1,11 @@ #!/bin/sh +#check for root priv +if [ "$(id -u)" != "0" ]; then + echo "This installation script must be executed as root (i.e. run via sudo). Exiting" >&2 + exit 1 +fi + echo "Detecting architecture..."; MACHINE_MTYPE="$(uname -m)"; ARCH="${MACHINE_MTYPE}"; From 60c83544554b9c0f5bc43309934b785088b481eb Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Sat, 14 Dec 2019 12:47:30 +1000 Subject: [PATCH 4/8] Use apt-key to install GPG key Closes several issue around GPG key not being properly installed --- docs/installers/apt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/installers/apt.sh b/docs/installers/apt.sh index e57113fff2..c121850d80 100755 --- a/docs/installers/apt.sh +++ b/docs/installers/apt.sh @@ -49,7 +49,7 @@ else fi; echo "Retrieving GPG key [${REPO_VENDOR}] ($gpg_key)..."; -curl -L $gpg_key | gpg --dearmor > /etc/apt/trusted.gpg.d/${REPO_VENDOR}_vscode.gpg; +curl -fsSL $gpg_key | sudo apt-key add - echo "Removing any previous entry to headmelted repository"; rm -rf /etc/apt/sources.list.d/headmelted_codebuilds.list; From 9ba928d45fb41ccaf0dcab60bd27637672b86c4d Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 20 Dec 2019 11:45:54 +1000 Subject: [PATCH 5/8] Quieten apt, remove duplicate architecture message Quieten apt-get update and install without completely quashing output, remove duplicate architecture message --- docs/installers/apt.sh | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/installers/apt.sh b/docs/installers/apt.sh index c121850d80..6ed8c0ce41 100755 --- a/docs/installers/apt.sh +++ b/docs/installers/apt.sh @@ -6,14 +6,17 @@ if [ "$(id -u)" != "0" ]; then exit 1 fi -echo "Detecting architecture..."; MACHINE_MTYPE="$(uname -m)"; ARCH="${MACHINE_MTYPE}"; REPO_VENDOR="headmelted"; DEPENDENCIES="" +if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "i386" ]; then REPO_VENDOR="microsoft"; fi; + +echo "Architecture detected as $ARCH..."; + echo "Updating APT cache..." -if apt-get update -yq; then +if apt-get -qq update; then echo "Update complete."; else echo "Update failed."; @@ -32,10 +35,6 @@ if [ "X${DEPENDENCIES}" != "X" ]; then apt-get -f -qq -y install "${DEPENDENCIES}" >/dev/null 2>&1 fi -if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "i386" ]; then REPO_VENDOR="microsoft"; fi; - -echo "Architecture detected as $ARCH..."; - if [ "${REPO_VENDOR}" = "headmelted" ]; then gpg_key=https://packagecloud.io/headmelted/codebuilds/gpgkey; repo_name="stretch"; @@ -59,7 +58,7 @@ echo "Installing [${REPO_VENDOR}] repository..."; echo "${repo_entry}" > /etc/apt/sources.list.d/${REPO_VENDOR}_vscode.list; echo "Refreshing APT cache again..." -if apt-get update -yq; then +if apt-get -qq update; then echo "Repository install complete."; else echo "Repository install failed."; @@ -67,7 +66,7 @@ else fi; echo "Installing Visual Studio Code from [${repo_name}]..."; -if apt-get install -t ${repo_name} -y ${code_executable_name}; then +if apt-get install -t ${repo_name} -y -qq ${code_executable_name}; then echo "Visual Studio Code install complete."; else echo "Visual Studio Code install failed."; @@ -75,7 +74,7 @@ else fi; echo "Installing any dependencies that may have been missed..."; -if apt-get install -y -f; then +if apt-get install -y -qq -f; then echo "Missed dependency install complete."; else echo "Missed dependency install failed."; From 9dc3d47ad24e21d007a2e633394cb0f809cf580e Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 20 Dec 2019 12:32:45 +1000 Subject: [PATCH 6/8] Mention VSCode install may take a while --- docs/installers/apt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/installers/apt.sh b/docs/installers/apt.sh index 6ed8c0ce41..086a459ced 100755 --- a/docs/installers/apt.sh +++ b/docs/installers/apt.sh @@ -65,7 +65,7 @@ else exit 1; fi; -echo "Installing Visual Studio Code from [${repo_name}]..."; +echo "Installing Visual Studio Code from [${repo_name}] (this may take several minutes)..."; if apt-get install -t ${repo_name} -y -qq ${code_executable_name}; then echo "Visual Studio Code install complete."; else From 588f8ae2b1e0e3ac081ff3973f579badaa325351 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 20 Dec 2019 12:43:39 +1000 Subject: [PATCH 7/8] Removed unnecessary semi-colons Extra characters, can add to confusion as not consistently used in file. --- docs/installers/apt.sh | 76 +++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/docs/installers/apt.sh b/docs/installers/apt.sh index 086a459ced..32b044aa78 100755 --- a/docs/installers/apt.sh +++ b/docs/installers/apt.sh @@ -6,22 +6,22 @@ if [ "$(id -u)" != "0" ]; then exit 1 fi -MACHINE_MTYPE="$(uname -m)"; -ARCH="${MACHINE_MTYPE}"; -REPO_VENDOR="headmelted"; +MACHINE_MTYPE="$(uname -m)" +ARCH="${MACHINE_MTYPE}" +REPO_VENDOR="headmelted" DEPENDENCIES="" -if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "i386" ]; then REPO_VENDOR="microsoft"; fi; +if [ "$ARCH" = "amd64" ] || [ "$ARCH" = "i386" ]; then REPO_VENDOR="microsoft"; fi -echo "Architecture detected as $ARCH..."; +echo "Architecture detected as $ARCH..." echo "Updating APT cache..." if apt-get -qq update; then - echo "Update complete."; + echo "Update complete." else - echo "Update failed."; - exit 1; -fi; + echo "Update failed." + exit 1 +fi #test what dependencies need to be installed test -f "/usr/share/doc/apt-transport-https/copyright" || DEPENDENCIES="${DEPENDENCIES} apt-transport-https" @@ -36,50 +36,50 @@ if [ "X${DEPENDENCIES}" != "X" ]; then fi if [ "${REPO_VENDOR}" = "headmelted" ]; then - gpg_key=https://packagecloud.io/headmelted/codebuilds/gpgkey; - repo_name="stretch"; - repo_entry="deb https://packagecloud.io/headmelted/codebuilds/debian/ ${repo_name} main"; - code_executable_name="code-oss"; + gpg_key=https://packagecloud.io/headmelted/codebuilds/gpgkey + repo_name="stretch" + repo_entry="deb https://packagecloud.io/headmelted/codebuilds/debian/ ${repo_name} main" + code_executable_name="code-oss" else - gpg_key=https://packages.microsoft.com/keys/microsoft.asc; + gpg_key=https://packages.microsoft.com/keys/microsoft.asc repo_name="stable" - repo_entry="deb https://packages.microsoft.com/repos/vscode ${repo_name} main"; - code_executable_name="code-insiders"; -fi; + repo_entry="deb https://packages.microsoft.com/repos/vscode ${repo_name} main" + code_executable_name="code-insiders" +fi -echo "Retrieving GPG key [${REPO_VENDOR}] ($gpg_key)..."; +echo "Retrieving GPG key [${REPO_VENDOR}] ($gpg_key)..." curl -fsSL $gpg_key | sudo apt-key add - -echo "Removing any previous entry to headmelted repository"; -rm -rf /etc/apt/sources.list.d/headmelted_codebuilds.list; -rm -rf /etc/apt/sources.list.d/codebuilds.list; +echo "Removing any previous entry to headmelted repository" +rm -rf /etc/apt/sources.list.d/headmelted_codebuilds.list +rm -rf /etc/apt/sources.list.d/codebuilds.list -echo "Installing [${REPO_VENDOR}] repository..."; -echo "${repo_entry}" > /etc/apt/sources.list.d/${REPO_VENDOR}_vscode.list; +echo "Installing [${REPO_VENDOR}] repository..." +echo "${repo_entry}" > /etc/apt/sources.list.d/${REPO_VENDOR}_vscode.list echo "Refreshing APT cache again..." if apt-get -qq update; then - echo "Repository install complete."; + echo "Repository install complete." else - echo "Repository install failed."; - exit 1; -fi; + echo "Repository install failed." + exit 1 +fi -echo "Installing Visual Studio Code from [${repo_name}] (this may take several minutes)..."; +echo "Installing Visual Studio Code from [${repo_name}] (this may take several minutes)..." if apt-get install -t ${repo_name} -y -qq ${code_executable_name}; then - echo "Visual Studio Code install complete."; + echo "Visual Studio Code install complete." else - echo "Visual Studio Code install failed."; - exit 1; -fi; + echo "Visual Studio Code install failed." + exit 1 +fi -echo "Installing any dependencies that may have been missed..."; +echo "Installing any dependencies that may have been missed..." if apt-get install -y -qq -f; then - echo "Missed dependency install complete."; + echo "Missed dependency install complete." else - echo "Missed dependency install failed."; - exit 1; -fi; + echo "Missed dependency install failed." + exit 1 +fi echo " @@ -89,4 +89,4 @@ You can start code at any time by calling \"${code_executable_name}\" within a t A shortcut should also now be available in your desktop menus (depending on your distribution). -"; +" From 3a98c821036f0ec7fef70393d26f0d69519a8fe0 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 20 Dec 2019 12:55:35 +1000 Subject: [PATCH 8/8] Removed extra newline in closing message --- docs/installers/apt.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/installers/apt.sh b/docs/installers/apt.sh index 32b044aa78..c9e9ce1e1b 100755 --- a/docs/installers/apt.sh +++ b/docs/installers/apt.sh @@ -82,7 +82,6 @@ else fi echo " - Installation complete! You can start code at any time by calling \"${code_executable_name}\" within a terminal.