Files
HamPackServer/install.sh
2026-04-11 06:51:32 -06:00

251 lines
8.6 KiB
Bash
Executable File

#!/bin/bash
#
# Purpose : HamPack installer
# Print the logo
print_logo() {
cat << "EOF"
██╗ ██╗ █████╗ ███╗ ███╗██████╗ █████╗ ██████╗██╗ ██╗
██║ ██║██╔══██╗████╗ ████║██╔══██╗██╔══██╗██╔════╝██║ ██╔╝
███████║███████║██╔████╔██║██████╔╝███████║██║ █████╔╝
██╔══██║██╔══██║██║╚██╔╝██║██╔═══╝ ██╔══██║██║ ██╔═██╗
██║ ██║██║ ██║██║ ╚═╝ ██║██║ ██║ ██║╚██████╗██║ ██╗
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝
███████╗███████╗██████╗ ██╗ ██╗███████╗██████╗
██╔════╝██╔════╝██╔══██╗██║ ██║██╔════╝██╔══██╗
███████╗█████╗ ██████╔╝██║ ██║█████╗ ██████╔╝
╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██╔══╝ ██╔══██╗
███████║███████╗██║ ██║ ╚████╔╝ ███████╗██║ ██║
╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝
EOF
}
# --- Main ---
set -e
export PATH="$HOME/.local/bin:$PATH"
if ! grep -q 'LOCAL_BIN_PATH' "$HOME/.bashrc"; then
echo '' >> "$HOME/.bashrc"
echo '# HamPack: add user local bin to PATH' >> "$HOME/.bashrc"
echo 'export PATH="$HOME/.local/bin:$PATH" # LOCAL_BIN_PATH' >> "$HOME/.bashrc"
fi
clear
print_logo
cd ~
sudo -v
# Grant passwordless sudo for the duration of the install, revoke on exit
echo "$USER ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/99-hampack-install > /dev/null
sudo chmod 440 /etc/sudoers.d/99-hampack-install
trap "sudo rm -f /etc/sudoers.d/99-hampack-install" EXIT
if ! command -v git &> /dev/null; then
echo "Installing git..."
sudo pacman -S --noconfirm git
fi
if ! pacman -Qi base-devel &> /dev/null; then
echo "Installing base-devel..."
sudo pacman -S --noconfirm base-devel
else
echo "base-devel is already installed, skipping."
fi
echo "Getting the latest version of HamPackServer..."
rm -rf ~/.local/share/HamPackServer
git clone https://gitea.young.computer/david/HamPackServer.git "$HOME/.local/share/HamPackServer" > /dev/null
mkdir -p "$HOME/.local/bin"
cp "$HOME/.local/share/HamPackServer/hampackserverrefresh" "$HOME/.local/bin/hampackserverrefresh"
cp "$HOME/.local/share/HamPackServer/hampackserverupdate" "$HOME/.local/bin/hampackserverupdate"
cp "$HOME/.local/share/HamPackServer/scripts/start-hamclock.sh" "$HOME/.local/bin/start-hamclock.sh"
chmod +x "$HOME/.local/bin/start-hamclock.sh"
cd ~/.local/share/HamPackServer
echo "Updating system..."
sudo pacman -Syu --noconfirm
install_yay() {
rm -rf /tmp/yay
git clone https://aur.archlinux.org/yay.git /tmp/yay
cd /tmp/yay
makepkg -si --noconfirm
cd ~/.local/share/HamPackServer
rm -rf /tmp/yay
}
if ! command -v yay &> /dev/null; then
echo "Installing yay AUR helper..."
install_yay
else
echo "yay is already installed, skipping."
fi
if ! yay --version &> /dev/null; then
echo "yay does not appear to be working, reinstalling..."
install_yay
fi
# Source utility functions
source utils.sh
# Source package list
if [ ! -f "packages.conf" ]; then
echo "Error: packages.conf not found!"
exit 1
fi
source packages.conf
echo "Installing servers..."
install_packages "${SERVERS[@]}"
# Initialize and start MariaDB if not already running
if ! systemctl is-active --quiet mariadb; then
if [ ! -d /var/lib/mysql/mysql ]; then
echo "Initializing MariaDB..."
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
fi
echo "Starting MariaDB..."
sudo systemctl enable --now mariadb
fi
# Start Apache if not already running
if ! systemctl is-active --quiet httpd; then
echo "Starting Apache..."
sudo systemctl enable --now httpd
fi
echo "Installing utilities..."
install_packages "${UTILITIES[@]}"
if ! command -v pm2 &> /dev/null; then
npm install pm2 -g --prefix "$HOME/.local"
fi
cd ~/.local/share/HamPackServer
echo "Enabling PHP extensions in /etc/php/php.ini..."
for ext in curl mbstring xml pdo_mysql mysqli openssl; do
sudo sed -i "s/^;extension=${ext}$/extension=${ext}/" /etc/php/php.ini
done
echo "Configuring PHP module in httpd.conf..."
if ! grep -q 'LoadModule php_module' /etc/httpd/conf/httpd.conf; then
printf '\nLoadModule php_module modules/libphp.so\nAddHandler php-script .php\nInclude conf/extra/php_module.conf\n' | sudo tee -a /etc/httpd/conf/httpd.conf > /dev/null
fi
echo "Switching Apache MPM to prefork in httpd.conf..."
sudo sed -i 's|^LoadModule mpm_event_module|#LoadModule mpm_event_module|' /etc/httpd/conf/httpd.conf
sudo sed -i 's|^LoadModule mpm_worker_module|#LoadModule mpm_worker_module|' /etc/httpd/conf/httpd.conf
if grep -q '^#LoadModule mpm_prefork_module' /etc/httpd/conf/httpd.conf; then
sudo sed -i 's|^#LoadModule mpm_prefork_module|LoadModule mpm_prefork_module|' /etc/httpd/conf/httpd.conf
elif ! grep -q '^LoadModule mpm_prefork_module' /etc/httpd/conf/httpd.conf; then
printf 'LoadModule mpm_prefork_module modules/mod_mpm_prefork.so\n' | sudo tee -a /etc/httpd/conf/httpd.conf > /dev/null
fi
# Install Cloudlog
CLOUDLOG_DIR="/srv/http/cloudlog"
CLOUDLOG_DB="cloudlog"
CLOUDLOG_DB_USER="cloudlog"
CLOUDLOG_DB_PASS="cloudlog"
install_cloudlog() {
local reinstall="${1:-false}"
echo "Installing Cloudlog..."
sudo rm -rf "$CLOUDLOG_DIR"
sudo git clone https://github.com/magicbug/Cloudlog.git "$CLOUDLOG_DIR"
# Set ownership and permissions (Arch Apache runs as 'http')
sudo chown -R http:http "$CLOUDLOG_DIR"
sudo chmod -R g+rw "$CLOUDLOG_DIR"
# Create MariaDB database and user
echo "Creating Cloudlog database..."
if [ "$reinstall" = "true" ]; then
sudo mariadb -u root <<EOF
DROP DATABASE IF EXISTS ${CLOUDLOG_DB};
DROP USER IF EXISTS '${CLOUDLOG_DB_USER}'@'localhost';
CREATE DATABASE ${CLOUDLOG_DB};
CREATE USER '${CLOUDLOG_DB_USER}'@'localhost' IDENTIFIED BY '${CLOUDLOG_DB_PASS}';
GRANT ALL PRIVILEGES ON ${CLOUDLOG_DB}.* TO '${CLOUDLOG_DB_USER}'@'localhost';
FLUSH PRIVILEGES;
EOF
else
sudo mariadb -u root <<EOF
CREATE DATABASE IF NOT EXISTS ${CLOUDLOG_DB};
CREATE USER IF NOT EXISTS '${CLOUDLOG_DB_USER}'@'localhost' IDENTIFIED BY '${CLOUDLOG_DB_PASS}';
GRANT ALL PRIVILEGES ON ${CLOUDLOG_DB}.* TO '${CLOUDLOG_DB_USER}'@'localhost';
FLUSH PRIVILEGES;
EOF
fi
sudo systemctl restart httpd
echo "Cloudlog installed. Complete setup by visiting http://localhost/cloudlog/install"
}
if [ ! -d "$CLOUDLOG_DIR" ]; then
install_cloudlog
else
read -rp "Cloudlog is already installed. Re-install? [y/N] " response </dev/tty
case "$response" in
[yY][eE][sS]|[yY]) install_cloudlog true ;;
*) echo "Cloudlog installation skipped." ;;
esac
fi
# Install Cockpit
if ! pacman -Qi cockpit &> /dev/null; then
echo "Installing Cockpit..."
sudo pacman -S --noconfirm cockpit
sudo systemctl enable --now cockpit.socket
echo "Cockpit installed. Access it at http://localhost:9090"
else
echo "Cockpit is already installed, skipping."
fi
# Install openhamclock
echo "Installing openhamclock..."
INSTALL_SUCCESS=true
if ! bash install-openhamclock.sh; then
echo "Warning: install-openhamclock.sh encountered errors. openhamclock may not have installed correctly."
INSTALL_SUCCESS=false
fi
# Install Compiled Servers
echo "Installing compiled servers..."
if ! bash install-compiled.sh; then
echo "Warning: install-compiled.sh encountered errors. Some applications may not have installed correctly."
INSTALL_SUCCESS=false
fi
echo ""
if [ "$INSTALL_SUCCESS" = true ]; then
echo "HamPackServer is installed successfully!"
else
echo "HamPackServer installation completed with errors. Please review the output above."
fi
echo ""
read -rp "A reboot is required to complete setup. Reboot now? [y/N] " response </dev/tty
case "$response" in
[yY][eE][sS]|[yY])
echo "Rebooting..."
sudo reboot
;;
*)
echo "Reboot skipped. Please reboot when convenient."
;;
esac