This commit is contained in:
Your Name 2025-05-02 22:22:52 +12:00
parent 656c6431a5
commit 844ab60834
2 changed files with 10 additions and 46 deletions

View File

@ -1,6 +1,4 @@
#!/bin/sh # can you make this script run in bash, but fall back to sh if bash is not installed?
# bootstrapping with sh until we have bash installed
# check if we are running as root # check if we are running as root
if [ "$(id -u)" -ne 0 ]; then if [ "$(id -u)" -ne 0 ]; then
@ -15,8 +13,11 @@ if ! command -v bash > /dev/null 2>&1; then
apt install -y bash apt install -y bash
fi fi
# switch to bash as our shell # re-exec this script in bash if not already running in bash
chsh -s /bin/bash if [ -z "$BASH_VERSION" ]; then
echo "Re-executing script in Bash..."
exec /bin/bash "$0" "$@"
fi
if [ -n "$BASH_VERSION" ]; then if [ -n "$BASH_VERSION" ]; then
echo "Running in Bash $BASH_VERSION" echo "Running in Bash $BASH_VERSION"
@ -84,6 +85,9 @@ if [ ! -f "/home/dropshell/.ssh/known_hosts" ]; then
touch /home/dropshell/.ssh/known_hosts touch /home/dropshell/.ssh/known_hosts
fi fi
# ensure default shell for dropshell user is bash
chsh -s /bin/bash dropshell
#-------------------------------- #--------------------------------
# download dropshell # download dropshell

View File

@ -6,46 +6,6 @@
# It is called with the path to the server specific env file as an argument. # 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() { install_prerequisites() {
# this script works on debian, ubuntu and Raspberry Pi OS # this script works on debian, ubuntu and Raspberry Pi OS
# it checks the following prerequisites, and installs them if missing. # it checks the following prerequisites, and installs them if missing.
@ -63,7 +23,7 @@ install_prerequisites() {
# check if all prerequisites are installed # check if all prerequisites are installed
for prerequisite in "${PREREQUISITES[@]}"; do for prerequisite in "${PREREQUISITES[@]}"; do
if ! command -v "${prerequisite}" &> /dev/null; then if ! command -v "${prerequisite}" &> /dev/null; then
attempt_install_prerequisite "${prerequisite}" echo "Prerequisite: ${prerequisite} is not installed."
exit 1 exit 1
fi fi
done done