Working on autosetup
This commit is contained in:
parent
9f9dd4b6e3
commit
656c6431a5
103
host_autosetup/host_autosetup.sh
Executable file
103
host_autosetup/host_autosetup.sh
Executable file
@ -0,0 +1,103 @@
|
||||
#!/bin/sh
|
||||
|
||||
# bootstrapping with sh until we have bash installed
|
||||
|
||||
# check if we are running as root
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "Please run the script with sudo privileges or as root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# install bash if not already installed.
|
||||
if ! command -v bash > /dev/null 2>&1; then
|
||||
echo "bash is not installed"
|
||||
apt update
|
||||
apt install -y bash
|
||||
fi
|
||||
|
||||
# switch to bash as our shell
|
||||
chsh -s /bin/bash
|
||||
|
||||
if [ -n "$BASH_VERSION" ]; then
|
||||
echo "Running in Bash $BASH_VERSION"
|
||||
else
|
||||
echo "Not running in Bash"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# check if curl, wget, bash installed, and install if not
|
||||
PREREQUISITES=("curl" "wget")
|
||||
|
||||
# check if all prerequisites are installed
|
||||
ALLINSTALLED=true
|
||||
for prerequisite in "${PREREQUISITES[@]}"; do
|
||||
if ! command -v "${prerequisite}" &> /dev/null; then
|
||||
echo "Prerequisite: ${prerequisite} is not installed."
|
||||
ALLINSTALLED=false
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$ALLINSTALLED" = false ]; then
|
||||
echo "Installing prerequisites..."
|
||||
apt update
|
||||
apt install -y "${PREREQUISITES[@]}"
|
||||
fi
|
||||
|
||||
#--------------------------------
|
||||
|
||||
# check docker installation
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo "Docker is not installed."
|
||||
echo "Installing docker..."
|
||||
curl -fsSL https://get.docker.com -o get-docker.sh
|
||||
sh get-docker.sh
|
||||
rm get-docker.sh
|
||||
fi
|
||||
|
||||
# check dropshell user exists
|
||||
if ! id "dropshell" &> /dev/null; then
|
||||
echo "Dropshell user does not exist."
|
||||
echo "Creating dropshell user..."
|
||||
useradd -m dropshell
|
||||
fi
|
||||
|
||||
# add dropshell user to docker group
|
||||
# check if already in docker group
|
||||
if ! id "dropshell" | grep -q "docker" &> /dev/null; then
|
||||
echo "Adding dropshell user to docker group..."
|
||||
usermod -aG docker dropshell
|
||||
fi
|
||||
|
||||
# check .ssh/authorized_keys file exists
|
||||
if [ ! -f "/home/dropshell/.ssh/authorized_keys" ]; then
|
||||
echo "Creating .ssh/authorized_keys file..."
|
||||
mkdir -p /home/dropshell/.ssh
|
||||
cp /root/.ssh/authorized_keys /home/dropshell/.ssh/authorized_keys
|
||||
chown -R dropshell:dropshell /home/dropshell/.ssh
|
||||
chmod 600 /home/dropshell/.ssh/authorized_keys
|
||||
fi
|
||||
|
||||
# also check known_hosts file exists
|
||||
if [ ! -f "/home/dropshell/.ssh/known_hosts" ]; then
|
||||
echo "Creating .ssh/known_hosts file..."
|
||||
mkdir -p /home/dropshell/.ssh
|
||||
touch /home/dropshell/.ssh/known_hosts
|
||||
fi
|
||||
|
||||
#--------------------------------
|
||||
|
||||
# download dropshell
|
||||
|
||||
# determine if x86_64 or arm64
|
||||
ARCH=$(uname -m)
|
||||
|
||||
# check is aarch64 or x86_64 and error if neither
|
||||
if [ "$ARCH" != "aarch64" ] && [ "$ARCH" != "x86_64" ]; then
|
||||
echo "Unsupported architecture: $ARCH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Installation complete."
|
||||
|
||||
#--------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user