From ad98d893d3903a214c807748b9fbada260c5984e Mon Sep 17 00:00:00 2001 From: Brad Miller Date: Mon, 5 Jun 2023 11:04:41 -0500 Subject: [PATCH 1/6] feat: adding installer scripts and github action to update versions on each release --- .github/workflows/release.yml | 12 ++ scripts/installers/linux-install.sh | 86 ++++++++++ scripts/installers/mac-install.sh | 226 +++++++++++++++++++++++++ scripts/installers/windows-install.bat | 84 +++++++++ 4 files changed, 408 insertions(+) create mode 100644 scripts/installers/linux-install.sh create mode 100644 scripts/installers/mac-install.sh create mode 100644 scripts/installers/windows-install.bat diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7071dd5..dace5cd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -54,3 +54,15 @@ jobs: HONEYBADGER_API_KEY: ${{ secrets.HONEYBADGER_API_KEY }} NDT7_CLIENT_NAME: ${{ secrets.NDT7_CLIENT_NAME }} run: npx -p @semantic-release/changelog -p @semantic-release/exec -p @semantic-release/git semantic-release --debug=true + + - name: Increment version and update installer scripts + id: increment_version + run: | + # Get the latest release tag + latest_tag=$(git describe --tags --abbrev=0) + release_version=${latest_tag#v} + remote_file="client_${release_version}_darwin_amd64.tar.gz" + + # Update the installer scripts with the new version and file name + sed -i "s/^release_version=.*/release_version=\"${release_version}\"/" ./scripts/installers/*.sh + sed -i "s/^remote_file=.*/remote_file=\"${remote_file}\"/" ./scripts/installers/*.sh diff --git a/scripts/installers/linux-install.sh b/scripts/installers/linux-install.sh new file mode 100644 index 0000000..8f049db --- /dev/null +++ b/scripts/installers/linux-install.sh @@ -0,0 +1,86 @@ +#!/bin/sh + +set -e +install_script_version=0.2.0 +file="/tmp/imUp-darwin-amd64.tar.gz" +build="stable" +base_url="https://github.com/imup-io/client/releases/download/" +release_version="v0.14.0" +remote_file="client_0.14.0_darwin_amd64.tar.gz" +DOWNLOAD_URL="$base_url/$release_version/$remote_file" +install_dir="$HOME/imUp" + +# Uninstall the client if the uninstall flag is set and then exit. +if [ "$UNINSTALL" ]; then + # Terminate the imUp process + sudo pkill -f "imUp" || true + + # Remove the imUp.plist file + sudo launchctl unload /Library/LaunchAgents/imUp.plist || true + sudo rm /Library/LaunchAgents/imUp.plist || true + + # Remove the imUp binary + sudo rm -rf "$install_dir" || true + exit 0 +fi + +# Read the variables from the environment and catch errors +if [ -z "$KEY" ] && [ -z "$EMAIL" ]; then + echo "Error: Either KEY or EMAIL are required." + exit 1 +fi + +params = [ + KEY="$KEY" + GROUP="$GROUP" + EMAIL="$EMAIL" + UNINSTALL="$UNINSTALL" + ALLOWLISTED_IPS="$ALLOWLISTED_IPS" + BLOCKLISTED_IPS="$BLOCKLISTED_IPS" + PING="$PING" + PING_ADDRESS="$PING_ADDRESS" + PING_ADDRESS_INTERNAL="$PING_ADDRESS_INTERNAL" + PING_DELAY="$PING_DELAY" + PING_INTERVAL="$PING_INTERVAL" + PING_REQUESTS="$PING_REQUESTS" +] + + +on_error() { + printf "\033[31m$ERROR_MESSAGE +It looks like you hit an issue when trying to install the imUp Client. Please reach out to support@imup.io for help.\n\033[0m\n" +} +trap on_error ERR # NOTE: trapping ERR is undefined in posix sh + + +# Download and install the client +header "Downloading imUp client" +rm -rf $file +curl --fail --progress-bar -L $DOWNLOAD_URL -o $file + +header "Extracting client" +rm -rf $install_dir +mkdir -p $install_dir +tar -xzf $file -C $install_dir +ls -la $install_dir +rm -f $file + +# Create the systemd service file +cat > $SYSTEMD_SERVICE_FILE +<\n" +printf "\n" +printf "\n" +printf "\n" +printf " Label\n" +printf " io.imUp\n" +printf " ProgramArguments\n" +printf " " +printf " $program_arguments" +printf " \n" +printf " RunAtLoad\n" +printf " \n" +printf "\n" +printf "\n" +) > "$tmpPLIST_PATH" + +# Set the correct permissions on the launch agent plist file +sudo cp $tmpPLIST_PATH $PLIST_PATH +sudo chown root:wheel "$PLIST_PATH" +sudo chmod 644 "$PLIST_PATH" + +# Load the launch agent +echo "" +echo "Loading launch agent..." +sudo launchctl load "$PLIST_PATH" + +echo "Launch agent installed at $PLIST_PATH" \ No newline at end of file diff --git a/scripts/installers/windows-install.bat b/scripts/installers/windows-install.bat new file mode 100644 index 0000000..881aa5e --- /dev/null +++ b/scripts/installers/windows-install.bat @@ -0,0 +1,84 @@ +$ErrorActionPreference = "Stop" + +$install_script_version = "0.2.0" +$file = "$env:TEMP\imUp-windows-amd64.zip" +$build = "stable" +$base_url = "https://github.com/imup-io/client/releases/download/" +$release_version = "v0.17.0" +$remote_file = "client_0.17.0_windows_amd64.zip" +$url = "$base_url/$release_version/$remote_file" +$install_dir = "$env:UserProfile\imUp" + +$key = $env:key +$email = $env:email +$host_id = $env:host_id +$group_id = $env:group_id +$SpeedTestEnabled = $env:SpeedTestEnabled +$allowlisted_ips = $env:allowlisted_ips +$blocklisted_ips = $env:blocklisted_ips +$ping = $env:ping +$ping_addresses_external = $env:ping_addresses_external +$ping_address_internal = $env:ping_address_internal +$ping_delay = $env:ping_delay +$ping_interval = $env:ping_interval +$ping_requests = $env:ping_requests + +if not "%email%" == "" set "serviceArguments=!serviceArguments! --email=!email!" +if not "%key%" == "" set "serviceArguments=!serviceArguments! --key=!key!" +if not "%host_id%" == "" set "serviceArguments=!serviceArguments! --host-id=!host_id!" +if not "%group_id%" == "" set "serviceArguments=!serviceArguments! --group-id=!group_id!" +if not "%SpeedTestEnabled%" == "" set "serviceArguments=!serviceArguments! --SpeedTestEnabled=!SpeedTestEnabled!" +if not "%allowlisted_ips%" == "" set "serviceArguments=!serviceArguments! --allowlisted-ips=!allowlisted_ips!" +if not "%blocklisted_ips%" == "" set "serviceArguments=!serviceArguments! --blocklisted-ips=!blocklisted_ips!" +if not "%ping%" == "" set "serviceArguments=!serviceArguments! --ping=!ping!" +if not "%ping_addresses_external%" == "" set "serviceArguments=!serviceArguments! --ping-addresses-external=!ping_addresses_external!" +if not "%ping_address_internal%" == "" set "serviceArguments=!serviceArguments! --ping-address-internal=!ping_address_internal!" +if not "%ping_delay%" == "" set "serviceArguments=!serviceArguments! --ping-delay=!ping_delay!" +if not "%ping_interval%" == "" set "serviceArguments=!serviceArguments! --ping-interval=!ping_interval!" +if not "%ping_requests%" == "" set "serviceArguments=!serviceArguments! --ping-requests=!ping_requests!" + + +if (-not $email) { + Write-Host "Email not provided. Please set the email address in the environment variable `email`." -ForegroundColor Red + exit 1 +} + + +# Download and install the client +Write-Host "Downloading imUp client" +Remove-Item -Path $file -Force -ErrorAction SilentlyContinue +Invoke-WebRequest -Uri $url -OutFile $file -ErrorAction Stop + +Write-Host "Extracting client" +Remove-Item -Path $install_dir -Recurse -Force -ErrorAction SilentlyContinue +New-Item -ItemType Directory -Path $install_dir | Out-Null +Add-Type -AssemblyName System.IO.Compression.FileSystem +[System.IO.Compression.ZipFile]::ExtractToDirectory($file, $install_dir) +Get-ChildItem -Path $install_dir +Remove-Item -Path $file -Force -ErrorAction SilentlyContinue + +# Create the windows service that runs the extracted imUp binary +$serviceName = "imUp13" +$serviceExePath = Join-Path $install_dir "imUp.exe" +$serviceDescription = "imUp.io is an internet performance measurement tool" +$serviceCredential = $null +$serviceArguments = "--email=$email -log-to-file=true --key=$key --host-id=$host-id" +$serviceDisplayName = $serviceName +$serviceStartMode = "Automatic" +$type = "Own" + +# Create the service +$serviceArgs = @{ + Name = $serviceName + DisplayName = $serviceName + Description = $serviceDescription + BinaryPathName = "$serviceExePath $serviceArguments" + start = $serviceStartMode +} + +Write-Host @serviceArgs +New-Service @serviceArgs + + + +Write-Host "imUp service successfully installed" \ No newline at end of file From 4ef9188a5c159d503d9b63c3b316794bd8483668 Mon Sep 17 00:00:00 2001 From: Steven Aldinger Date: Sat, 17 Jun 2023 02:09:39 -0400 Subject: [PATCH 2/6] feat: combine mac/linux install scripts and refactor --- scripts/installers/darwin-linux-install.sh | 443 +++++++++++++++++++++ scripts/installers/linux-install.sh | 86 ---- scripts/installers/mac-install.sh | 226 ----------- 3 files changed, 443 insertions(+), 312 deletions(-) create mode 100755 scripts/installers/darwin-linux-install.sh delete mode 100644 scripts/installers/linux-install.sh delete mode 100644 scripts/installers/mac-install.sh diff --git a/scripts/installers/darwin-linux-install.sh b/scripts/installers/darwin-linux-install.sh new file mode 100755 index 0000000..44f8366 --- /dev/null +++ b/scripts/installers/darwin-linux-install.sh @@ -0,0 +1,443 @@ +#!/bin/bash + +# ======================== imUp Client Installer ======================== # +# This script installs the imUp client on MacOS and Linux systems. # +# # +# ----------------------------- Dependencies ---------------------------- # +# - cat # +# - chmod (mac only, sets permissions on the launch agent plist file) # +# - chown (mac only, sets permissions on the launch agent plist file) # +# - curl (used to download imUp) # +# - grep # +# - launchctl (mac only) # +# - mkdir (makes the imUp install directory) # +# - mktemp (used to create a temp directory to store the imUp tarball) # +# - pkill (used to kill the imUp process during uninstall) # +# - printf # +# - sed # +# - sudo (linux if != root user, and mac always) # +# - systemctl (linux only) # +# - tar # +# - uname # +# ======================================================================= # + +# exit on any error +set -e + +# =================== [START] Constants and Variables =================== # +# TODO: doesn't do anything yet +install_script_version=0.2.0 +build="stable" + +operating_system=$(uname | tr '[:upper:]' '[:lower:]') + +imup_github_releases_url="https://github.com/imup-io/client/releases" +imup_github_downloads_url="$imup_github_releases_url/download" +# this is a special URL that redirects to the latest tag +imup_github_latest_url="$imup_github_releases_url/latest" + +# TODO: make sure $HOME exists or let them set a variable for this? +imup_install_dir="$HOME/imUp" + +terms_of_service_error_message=" +Error: You must accept the Terms of Service in order to install the imUp client. https://app.imup.io/terms +Please set the ACCEPT_THE_TOS environment variable to 'yes' to accept the Terms of Service. +" + +required_dependencies=( + "cat" + "curl" + "grep" + "ls" + "mkdir" + "mktemp" + "pkill" + "printf" + "rm" + "sed" + "tar" + "uname" +) + +required_dependencies_darwin=( + "chmod" + "chown" + "launchctl" + "sudo" +) + +required_dependencies_linux=( + "systemctl" +) + +declare -a options=() +# ==================== [END] Constants and Variables ==================== # + +# ========================== [START] Functions ========================== # +# use sudo if the user isn't root +sudo() { + if [ "$EUID" -ne 0 ] + then + command sudo "$@" + else + "$@" + fi +} + +uninstall_client_darwin() { + # terminate the imUp process + sudo pkill -f "imUp" || true + + # Remove the imUp.plist file + sudo launchctl unload /Library/LaunchAgents/imUp.plist || true + sudo rm /Library/LaunchAgents/imUp.plist || true + + # remove the imUp files + sudo rm -rf "$imup_install_dir" + + exit 0 +} + +uninstall_client_linux() { + # terminate the imUp process + sudo pkill -f "imUp" || true + + # Remove the imUp.service file + sudo systemctl stop imUp.service + sudo systemctl disable imUp.service + sudo rm -f /etc/systemd/system/imUp.service + sudo systemctl daemon-reload + + # remove the imUp files + sudo rm -rf "$imup_install_dir" || true + + exit 0 +} + +# exit with error message if the user doesn't accept the ToS +check_user_accepted_tos() { + if [ "$ACCEPT_THE_TOS" != "yes" ] + then + echo "$terms_of_service_error_message" + exit 1 + fi +} + +# if any of the required dependencies are not installed, prints +# an error message with the missing dependencies and exits +check_required_dependencies_are_installed() { + declare -a missing_dependencies=() + + for dependency in "${required_dependencies[@]}" + do + if ! command -v "$dependency" &> /dev/null + then + missing_dependencies+=("$dependency") + fi + done + + # if on mac, check for mac specific dependencies + if [ "$operating_system" == "darwin" ] + then + for dependency in "${required_dependencies_darwin[@]}" + do + if ! command -v "$dependency" &> /dev/null + then + missing_dependencies+=("$dependency") + fi + done + fi + + # if on linux, check for linux specific dependencies + if [ "$operating_system" == "linux" ] + then + for dependency in "${required_dependencies_linux[@]}" + do + if ! command -v "$dependency" &> /dev/null + then + missing_dependencies+=("$dependency") + fi + done + fi + + # if there are any missing dependencies, print an error message and exit + if [ ${#missing_dependencies[@]} -ne 0 ] + then + echo "Error: The following dependencies are required to install the imUp client:" + for dependency in "${missing_dependencies[@]}" + do + echo "- $dependency" + done + exit 1 + fi +} + +# exits if required environment variables are not set +check_required_environment_variables() { + if [ -z "$KEY" ] && [ -z "$EMAIL" ]; then + echo "Error: One or both of the 'KEY' and 'EMAIL' environment variables need to be set." + exit 1 + fi +} + +# read environment variables and build an array +# of options to pass to the client +create_options_array() { + if [ -n "$ALLOWLISTED_IPS" ]; then + options+=("--allowlisted-ips='$ALLOWLISTED_IPS'") + fi + if [ -n "$API_POST_PING_DATA" ]; then + options+=("--api-post-connection-data='$API_POST_CONNECTION_DATA'") + fi + if [ -n "$API_POST_SPEED_TEST_DATA" ]; then + options+=("--api-post-speed-test-data='$API_POST_SPEED_TEST_DATA'") + fi + if [ -n "$BLOCKLISTED_IPS" ]; then + options+=("--blocklisted-ips='$BLOCKLISTED_IPS'") + fi + if [ -n "$EMAIL" ]; then + options+=("--email='$EMAIL'") + fi + if [ -n "$GROUP" ]; then + options+=("--group-id='$GROUP'") + fi + if [ -n "$ID" ]; then + options+=("--host-id='$ID'") + fi + if [ -n "$KEY" ]; then + options+=("--key='$KEY'") + fi + if [ -n "$PING" ]; then + options+=("--ping='$PING'") + fi + if [ -n "$PING_ADDRESSES_EXTERNAL" ]; then + options+=("--ping-addresses-external='$PING_ADDRESSES_EXTERNAL'") + fi + if [ -n "$PING_ADDRESS_INTERNAL" ]; then + options+=("--ping-address-internal='$PING_ADDRESS_INTERNAL'") + fi + if [ -n "$PING_DELAY" ]; then + options+=("--ping-delay='$PING_DELAY'") + fi + if [ -n "$PING_INTERVAL" ]; then + options+=("--ping-interval='$PING_INTERVAL'") + fi + if [ -n "$PING_REQUESTS" ]; then + options+=("--ping-requests='$PING_REQUESTS'") + fi + if [ "$SPEEDTEST_ENABLED" == "false" ]; then + options+=("--no-speed-test") + fi +} + +# pretty prints the options array +print_options_array() { + echo "Options:" + for option in "${options[@]}" + do + echo "- $option" + done + echo "" +} + +log_msg() { + msg=$1 + printf "%s\n" "$msg" +} + +log_msg_blue() { + msg=$1 + printf "\033[34m%s\033[0m\n" "$msg" +} + +log_msg_red() { + msg=$1 + printf "\033[31m%s\033[0m\n" "$msg" +} + +# sets architecture variable based on uname -m +get_arch() { + set +e + + uname -m | grep -q x86_64 + is_x86="$?" + + uname -a | grep -q arm64 + is_arm64="$?" + + uname -m | grep -q 'i.*86' + is_32bit="$?" + + architecture="$(uname -m)" + + set -e + + # account for running under rosetta + if [ "$is_x86" -eq 0 ]; then + if [ "$is_arm64" -eq 0 ]; then + architecture='arm64' + else + architecture='amd64' + fi + elif [ "$is_32bit" -eq 0 ]; then + architecture='x32' + elif [ "$architecture" = "arm64" ]; then + architecture='arm64' + elif [ "$architecture" = "aarch64" ]; then + architecture='arm64' + else + log_msg_red "Architecture '$architecture' not supported" + exit 1 + fi +} + +# creates a temporary directory and sets the imup_tarball_filepath variable +get_temp_tarball_filepath() { + # create a temporary directory to store the imUp tarball + imup_temp_dir=$(mktemp -d -t 'imup-installer.XXXXXX') + imup_tarball_filepath="$imup_temp_dir/imUp-$operating_system-$architecture.tar.gz" +} + +# gets the latest imUp release version and builds the download URL +get_download_url() { + # follow the redirect and get the URL + imup_github_latest_tag_url=$(curl -s -L -o /dev/null -w '%{url_effective}' "$imup_github_latest_url") + # get the version number from the URL + imup_github_latest_release_version=$(echo "$imup_github_latest_tag_url" | sed -e 's/.*\/v//g') + + imup_github_asset_name="client_"$imup_github_latest_release_version"_"$operating_system"_$architecture.tar.gz" + + download_url="$imup_github_downloads_url/v$imup_github_latest_release_version/$imup_github_asset_name" +} + +download_and_install_imup() { + # Download and install the client + log_msg_blue "Downloading imUp client from $download_url" + curl --fail --progress-bar -L $download_url -o $imup_tarball_filepath + + log_msg_blue "Extracting client to $imup_install_dir" + + # make clean install dir + rm -rf $imup_install_dir + mkdir -p $imup_install_dir + + # extract tarball directly to install dir + tar -xzf $imup_tarball_filepath -C $imup_install_dir + rm -f $imup_tarball_filepath + + echo "" + echo "Installed contents at $imup_install_dir:" + ls -la $imup_install_dir +} +# =========================== [END] Functions =========================== # + +# ========================= [START] Main Script ========================= # + +# if the UNINSTALL env var is set to "true", uninstall the client and exit +if [ "$UNINSTALL" ] +then + if [ "$operating_system" == "darwin" ] + then + uninstall_client_darwin + elif [ "$operating_system" == "linux" ] + then + uninstall_client_linux + fi +fi + +check_user_accepted_tos + +check_required_dependencies_are_installed + +check_required_environment_variables + +get_temp_tarball_filepath + +get_arch + +get_download_url + +create_options_array + +print_options_array + +on_error() { + printf "\033[31m$ERROR_MESSAGE +It looks like you hit an issue when trying to install the imUp Client. Please reach out to support@imup.io for help.\n\033[0m\n" +} +trap on_error ERR + +download_and_install_imup + +# MacOS launch agent install +if [ "$operating_system" == "darwin" ] +then + # Set the launch agent properties + tmpPLIST_PATH="./imUp.plist" + PLIST_PATH="/Library/LaunchAgents/imUp.plist" + LABEL="io.imUp" + RUN_AT_LOAD="true" + USER_ID="0" + + # build the ProgramArguments array for the .plist file + program_arguments="" + program_arguments+="\n $imup_install_dir/imUp" + for option in "${options[@]}"; do + if [ ! -z "$option" ]; then + program_arguments+="\n $option" + fi + done + program_arguments+="\n" + + # create the .plist file + echo "Heads up: This next step requires SUDO permissions" + echo "" + ( + printf "\n" + printf "\n" + printf "\n" + printf "\n" + printf " Label\n" + printf " io.imUp\n" + printf " ProgramArguments\n" + printf " " + printf " $program_arguments" + printf " \n" + printf " RunAtLoad\n" + printf " \n" + printf "\n" + printf "\n" + ) > "$tmpPLIST_PATH" + + # set the correct permissions on the launch agent plist file + sudo cp $tmpPLIST_PATH $PLIST_PATH + sudo chown root:wheel "$PLIST_PATH" + sudo chmod 644 "$PLIST_PATH" + + # load the launch agent + echo "" + echo "Loading launch agent..." + sudo launchctl load "$PLIST_PATH" + + echo "Launch agent installed at $PLIST_PATH" +fi + +# linux systemd install +if [ "$operating_system" == "linux" ] +then + # create the systemd service file + cat > /etc/systemd/system/imUp.service < $SYSTEMD_SERVICE_FILE -<\n" -printf "\n" -printf "\n" -printf "\n" -printf " Label\n" -printf " io.imUp\n" -printf " ProgramArguments\n" -printf " " -printf " $program_arguments" -printf " \n" -printf " RunAtLoad\n" -printf " \n" -printf "\n" -printf "\n" -) > "$tmpPLIST_PATH" - -# Set the correct permissions on the launch agent plist file -sudo cp $tmpPLIST_PATH $PLIST_PATH -sudo chown root:wheel "$PLIST_PATH" -sudo chmod 644 "$PLIST_PATH" - -# Load the launch agent -echo "" -echo "Loading launch agent..." -sudo launchctl load "$PLIST_PATH" - -echo "Launch agent installed at $PLIST_PATH" \ No newline at end of file From 518950d052cf3fe900d5493c7b65f5aed991d962 Mon Sep 17 00:00:00 2001 From: Steven Aldinger Date: Sat, 17 Jun 2023 14:43:48 -0400 Subject: [PATCH 3/6] fix: env var names --- scripts/installers/darwin-linux-install.sh | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/scripts/installers/darwin-linux-install.sh b/scripts/installers/darwin-linux-install.sh index 44f8366..9fe53a4 100755 --- a/scripts/installers/darwin-linux-install.sh +++ b/scripts/installers/darwin-linux-install.sh @@ -186,11 +186,8 @@ create_options_array() { if [ -n "$ALLOWLISTED_IPS" ]; then options+=("--allowlisted-ips='$ALLOWLISTED_IPS'") fi - if [ -n "$API_POST_PING_DATA" ]; then - options+=("--api-post-connection-data='$API_POST_CONNECTION_DATA'") - fi - if [ -n "$API_POST_SPEED_TEST_DATA" ]; then - options+=("--api-post-speed-test-data='$API_POST_SPEED_TEST_DATA'") + if [ -n "$API_KEY" ]; then + options+=("--key='$API_KEY'") fi if [ -n "$BLOCKLISTED_IPS" ]; then options+=("--blocklisted-ips='$BLOCKLISTED_IPS'") @@ -198,20 +195,23 @@ create_options_array() { if [ -n "$EMAIL" ]; then options+=("--email='$EMAIL'") fi - if [ -n "$GROUP" ]; then - options+=("--group-id='$GROUP'") + if [ -n "$GROUP_ID" ]; then + options+=("--group-id='$GROUP_ID'") + fi + if [ -n "$HOST_ID" ]; then + options+=("--host-id='$HOST_ID'") fi - if [ -n "$ID" ]; then - options+=("--host-id='$ID'") + if [ -n "$IMUP_ADDRESS" ]; then + options+=("--api-post-connection-data='$IMUP_ADDRESS'") fi - if [ -n "$KEY" ]; then - options+=("--key='$KEY'") + if [ -n "$IMUP_ADDRESS_SPEEDTEST" ]; then + options+=("--api-post-speed-test-data='$IMUP_ADDRESS_SPEEDTEST'") fi - if [ -n "$PING" ]; then - options+=("--ping='$PING'") + if [ "$NO_SPEED_TEST" == "true" ]; then + options+=("--no-speed-test") fi - if [ -n "$PING_ADDRESSES_EXTERNAL" ]; then - options+=("--ping-addresses-external='$PING_ADDRESSES_EXTERNAL'") + if [ -n "$PING_ADDRESS" ]; then + options+=("--ping-addresses-external='$PING_ADDRESS'") fi if [ -n "$PING_ADDRESS_INTERNAL" ]; then options+=("--ping-address-internal='$PING_ADDRESS_INTERNAL'") @@ -219,15 +219,15 @@ create_options_array() { if [ -n "$PING_DELAY" ]; then options+=("--ping-delay='$PING_DELAY'") fi + if [ -n "$PING_ENABLED" ]; then + options+=("--ping='$PING_ENABLED'") + fi if [ -n "$PING_INTERVAL" ]; then options+=("--ping-interval='$PING_INTERVAL'") fi if [ -n "$PING_REQUESTS" ]; then options+=("--ping-requests='$PING_REQUESTS'") fi - if [ "$SPEEDTEST_ENABLED" == "false" ]; then - options+=("--no-speed-test") - fi } # pretty prints the options array From 1654353b422b36317b94e578725cb0f47b49b8b3 Mon Sep 17 00:00:00 2001 From: Steven Aldinger Date: Sat, 17 Jun 2023 14:54:20 -0400 Subject: [PATCH 4/6] chore: refactor logic into functions --- scripts/installers/darwin-linux-install.sh | 104 +++++++++++---------- 1 file changed, 56 insertions(+), 48 deletions(-) diff --git a/scripts/installers/darwin-linux-install.sh b/scripts/installers/darwin-linux-install.sh index 9fe53a4..de7aadb 100755 --- a/scripts/installers/darwin-linux-install.sh +++ b/scripts/installers/darwin-linux-install.sh @@ -174,8 +174,8 @@ check_required_dependencies_are_installed() { # exits if required environment variables are not set check_required_environment_variables() { - if [ -z "$KEY" ] && [ -z "$EMAIL" ]; then - echo "Error: One or both of the 'KEY' and 'EMAIL' environment variables need to be set." + if [ -z "$API_KEY" ] && [ -z "$EMAIL" ]; then + echo "Error: One or both of the 'API_KEY' and 'EMAIL' environment variables need to be set." exit 1 fi } @@ -329,49 +329,8 @@ download_and_install_imup() { echo "Installed contents at $imup_install_dir:" ls -la $imup_install_dir } -# =========================== [END] Functions =========================== # - -# ========================= [START] Main Script ========================= # - -# if the UNINSTALL env var is set to "true", uninstall the client and exit -if [ "$UNINSTALL" ] -then - if [ "$operating_system" == "darwin" ] - then - uninstall_client_darwin - elif [ "$operating_system" == "linux" ] - then - uninstall_client_linux - fi -fi - -check_user_accepted_tos - -check_required_dependencies_are_installed - -check_required_environment_variables - -get_temp_tarball_filepath - -get_arch -get_download_url - -create_options_array - -print_options_array - -on_error() { - printf "\033[31m$ERROR_MESSAGE -It looks like you hit an issue when trying to install the imUp Client. Please reach out to support@imup.io for help.\n\033[0m\n" -} -trap on_error ERR - -download_and_install_imup - -# MacOS launch agent install -if [ "$operating_system" == "darwin" ] -then +install_macos_launch_agent() { # Set the launch agent properties tmpPLIST_PATH="./imUp.plist" PLIST_PATH="/Library/LaunchAgents/imUp.plist" @@ -420,11 +379,9 @@ then sudo launchctl load "$PLIST_PATH" echo "Launch agent installed at $PLIST_PATH" -fi +} -# linux systemd install -if [ "$operating_system" == "linux" ] -then +install_linux_systemd_service() { # create the systemd service file cat > /etc/systemd/system/imUp.service < Date: Sat, 17 Jun 2023 15:31:15 -0400 Subject: [PATCH 5/6] refactor plist file generation --- scripts/installers/darwin-linux-install.sh | 49 ++++++++++++---------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/scripts/installers/darwin-linux-install.sh b/scripts/installers/darwin-linux-install.sh index de7aadb..c805cd3 100755 --- a/scripts/installers/darwin-linux-install.sh +++ b/scripts/installers/darwin-linux-install.sh @@ -340,36 +340,41 @@ install_macos_launch_agent() { # build the ProgramArguments array for the .plist file program_arguments="" - program_arguments+="\n $imup_install_dir/imUp" for option in "${options[@]}"; do - if [ ! -z "$option" ]; then - program_arguments+="\n $option" - fi + if [ ! -z "$option" ]; then + program_arguments+=" + $option + " + fi done - program_arguments+="\n" # create the .plist file echo "Heads up: This next step requires SUDO permissions" + echo "Please enter your password when prompted" echo "" - ( - printf "\n" - printf "\n" - printf "\n" - printf "\n" - printf " Label\n" - printf " io.imUp\n" - printf " ProgramArguments\n" - printf " " - printf " $program_arguments" - printf " \n" - printf " RunAtLoad\n" - printf " \n" - printf "\n" - printf "\n" - ) > "$tmpPLIST_PATH" + + # create the plist file + cat > "$tmpPLIST_PATH" < + + + + Label + io.imUp + ProgramArguments + + $imup_install_dir/imUp + $program_arguments + + RunAtLoad + + + +EOF + # set the correct permissions on the launch agent plist file - sudo cp $tmpPLIST_PATH $PLIST_PATH + sudo cp -f $tmpPLIST_PATH $PLIST_PATH sudo chown root:wheel "$PLIST_PATH" sudo chmod 644 "$PLIST_PATH" From f05ce551dd661470970779bd27bb2be8d1921b3b Mon Sep 17 00:00:00 2001 From: Steven Aldinger Date: Sat, 17 Jun 2023 15:32:19 -0400 Subject: [PATCH 6/6] fix: clean up temporary plist file --- scripts/installers/darwin-linux-install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/installers/darwin-linux-install.sh b/scripts/installers/darwin-linux-install.sh index c805cd3..9a0f11a 100755 --- a/scripts/installers/darwin-linux-install.sh +++ b/scripts/installers/darwin-linux-install.sh @@ -377,6 +377,7 @@ EOF sudo cp -f $tmpPLIST_PATH $PLIST_PATH sudo chown root:wheel "$PLIST_PATH" sudo chmod 644 "$PLIST_PATH" + rm -f $tmpPLIST_PATH # load the launch agent echo ""