Add docker extension, fix up some other stuffs

This commit is contained in:
VetheonGames 2024-05-24 09:02:55 -06:00
parent 4d30d000cd
commit ba045baf55
3 changed files with 111 additions and 3 deletions

View File

@ -115,7 +115,7 @@ setup_firewall() {
fi fi
done done
if command -v firewall-cmd &>/dev/null; then if command -v firewall-cmd &>/dev/null; then
firewall_cmd --reload firewall-cmd --reload
fi fi
fi fi
} }
@ -136,6 +136,10 @@ run_additional_setup() {
if prompt_yes_no "Do you want to run additional setup scripts?"; then if prompt_yes_no "Do you want to run additional setup scripts?"; then
SCRIPT_DIR=$(dirname "$0") SCRIPT_DIR=$(dirname "$0")
if [[ -f "$SCRIPT_DIR/extender.sh" ]]; then if [[ -f "$SCRIPT_DIR/extender.sh" ]]; then
if [[ ! -x "$SCRIPT_DIR/extender.sh" ]]; then
log "Making extender.sh executable"
chmod +x "$SCRIPT_DIR/extender.sh"
fi
bash "$SCRIPT_DIR/extender.sh" | tee -a "$LOG_FILE" bash "$SCRIPT_DIR/extender.sh" | tee -a "$LOG_FILE"
else else
log "No extender.sh script found in the script directory." log "No extender.sh script found in the script directory."
@ -183,6 +187,16 @@ setup_motd() {
fi fi
} }
# Function to prompt for a reboot
prompt_reboot() {
if prompt_yes_no "Do you want to reboot the system now?"; then
log "Rebooting the system..."
reboot
else
log "Reboot skipped. Please remember to reboot the system later."
fi
}
# Main script execution # Main script execution
check_root check_root
detect_os detect_os
@ -223,3 +237,6 @@ add_users
# Set up MOTD if requested # Set up MOTD if requested
setup_motd setup_motd
# Prompt for reboot
prompt_reboot

80
extensions/docker.sh Normal file
View File

@ -0,0 +1,80 @@
#!/bin/bash
LOG_FILE="$(dirname "$(dirname "$0")")/setup.log"
# Log function
log() {
echo "$1" | tee -a "$LOG_FILE"
}
# Function to prompt for yes/no input
prompt_yes_no() {
while true; do
read -r -p "$1 (y/n): " REPLY
case "$REPLY" in
[Yy]* ) return 0 ;;
[Nn]* ) return 1 ;;
* ) log "Please answer yes or no." ;;
esac
done
}
# Function to install Docker
install_docker() {
log "Installing Docker..."
if command -v apt &>/dev/null; then
apt update
apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt update
apt install -y docker-ce
elif command -v yum &>/dev/null; then
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io
else
log "Unsupported package manager. Please install Docker manually."
exit 1
fi
log "Docker installed successfully."
}
# Function to start Docker service
start_docker() {
log "Starting Docker service..."
systemctl start docker
log "Docker service started."
}
# Function to enable Docker service at boot
enable_docker_boot() {
if prompt_yes_no "Do you want Docker to start at boot?"; then
systemctl enable docker
log "Docker service enabled to start at boot."
else
log "Docker service will not start at boot."
fi
}
# Function to add user to Docker group
add_user_to_docker_group() {
log "Please enter the username to add to the Docker group:"
read -r USERNAME
usermod -aG docker "$USERNAME"
log "User $USERNAME added to the Docker group. You may need to log out and log back in for this change to take effect."
}
# Main script execution
log "Starting Docker setup..."
if prompt_yes_no "Do you want to install Docker?"; then
install_docker
start_docker
enable_docker_boot
if prompt_yes_no "Do you want to add a user to the Docker group?"; then
add_user_to_docker_group
fi
fi
log "Docker setup complete."

View File

@ -25,8 +25,6 @@ install_mariadb() {
apt update && apt install -y mariadb-server apt update && apt install -y mariadb-server
elif command -v yum &>/dev/null; then elif command -v yum &>/dev/null; then
yum install -y mariadb-server yum install -y mariadb-server
systemctl start mariadb
systemctl enable mariadb
else else
log "Unsupported package manager. Please install MariaDB manually." log "Unsupported package manager. Please install MariaDB manually."
exit 1 exit 1
@ -79,6 +77,16 @@ EOF
log "Database and user created successfully." log "Database and user created successfully."
} }
# Function to enable MariaDB to start at boot
enable_mariadb_startup() {
if prompt_yes_no "Do you want MariaDB to start at boot?"; then
systemctl enable mariadb
log "MariaDB enabled to start at boot."
else
log "MariaDB will not start at boot."
fi
}
# Main script execution # Main script execution
log "Starting MariaDB setup..." log "Starting MariaDB setup..."
@ -94,4 +102,7 @@ while prompt_yes_no "Do you want to create a new database and user?"; do
create_database_user create_database_user
done done
# Enable MariaDB to start at boot
enable_mariadb_startup
log "MariaDB setup complete." log "MariaDB setup complete."