From 844ab60834efaf39dbeae0fd5cf09a5c09790cc3 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 2 May 2025 22:22:52 +1200 Subject: [PATCH] . --- host_autosetup/host_autosetup.sh | 14 ++++++---- templates/dropshell-agent/install.sh | 42 +--------------------------- 2 files changed, 10 insertions(+), 46 deletions(-) diff --git a/host_autosetup/host_autosetup.sh b/host_autosetup/host_autosetup.sh index 0d68506..06197e7 100755 --- a/host_autosetup/host_autosetup.sh +++ b/host_autosetup/host_autosetup.sh @@ -1,6 +1,4 @@ -#!/bin/sh - -# bootstrapping with sh until we have bash installed +# can you make this script run in bash, but fall back to sh if bash is not installed? # check if we are running as root if [ "$(id -u)" -ne 0 ]; then @@ -15,8 +13,11 @@ if ! command -v bash > /dev/null 2>&1; then apt install -y bash fi -# switch to bash as our shell -chsh -s /bin/bash +# re-exec this script in bash if not already running in bash +if [ -z "$BASH_VERSION" ]; then + echo "Re-executing script in Bash..." + exec /bin/bash "$0" "$@" +fi if [ -n "$BASH_VERSION" ]; then echo "Running in Bash $BASH_VERSION" @@ -84,6 +85,9 @@ if [ ! -f "/home/dropshell/.ssh/known_hosts" ]; then touch /home/dropshell/.ssh/known_hosts fi +# ensure default shell for dropshell user is bash +chsh -s /bin/bash dropshell + #-------------------------------- # download dropshell diff --git a/templates/dropshell-agent/install.sh b/templates/dropshell-agent/install.sh index 624c61f..4bcdea4 100644 --- a/templates/dropshell-agent/install.sh +++ b/templates/dropshell-agent/install.sh @@ -6,46 +6,6 @@ # It is called with the path to the server specific env file as an argument. -attempt_install_prerequisite() { - local prerequisite="${1}" - echo "Attempting to install prerequisite: ${prerequisite}" - - # test if root, and test sudo otherwise. - SUDO_CMD="" - if [ "$EUID" -ne 0 ]; then - if ! sudo -v; then - echo "--------------------------------" - echo "Prerequisite: ${prerequisite} is not installed." - echo "Please run the script with sudo privileges or as root to automatically install the prerequisite." - echo "--------------------------------" - exit 1 - fi - SUDO_CMD="sudo " - fi - - - # separate install for each prerequisite - case "${prerequisite}" in - bash|curl|wget) - $SUDO_CMD apt-get update - $SUDO_CMD apt-get install -y wget curl bash - ;; - "docker") - # install docker using the official script. - curl -fsSL https://get.docker.com -o get-docker.sh - $SUDO_CMD sh get-docker.sh - rm get-docker.sh - ;; - *) - echo "--------------------------------" - echo "Prerequisite: ${prerequisite} is not installed." - echo "Please install it manually and try again." - echo "--------------------------------" - exit 1 - esac -} - - install_prerequisites() { # this script works on debian, ubuntu and Raspberry Pi OS # it checks the following prerequisites, and installs them if missing. @@ -63,7 +23,7 @@ install_prerequisites() { # check if all prerequisites are installed for prerequisite in "${PREREQUISITES[@]}"; do if ! command -v "${prerequisite}" &> /dev/null; then - attempt_install_prerequisite "${prerequisite}" + echo "Prerequisite: ${prerequisite} is not installed." exit 1 fi done