Files
HamPackServer/install.sh
2026-04-09 14:58:24 -06:00

175 lines
5.1 KiB
Bash
Executable File

#!/bin/bash -i
#
# Purpose : HamPack installer
# Print the logo
print_logo() {
cat << "EOF"
██╗ ██╗ █████╗ ███╗ ███╗██████╗ █████╗ ██████╗██╗ ██╗
██║ ██║██╔══██╗████╗ ████║██╔══██╗██╔══██╗██╔════╝██║ ██╔╝
███████║███████║██╔████╔██║██████╔╝███████║██║ █████╔╝
██╔══██║██╔══██║██║╚██╔╝██║██╔═══╝ ██╔══██║██║ ██╔═██╗
██║ ██║██║ ██║██║ ╚═╝ ██║██║ ██║ ██║╚██████╗██║ ██╗
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝
EOF
}
# --- Main ---
set -e
clear
print_logo
cd ~
sudo -v
# Extend sudo timeout for the duration of the install, clean up on exit
echo "Defaults timestamp_timeout=120" | sudo tee /etc/sudoers.d/99-hampack-install > /dev/null
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"
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[@]}"
cd ~/.local/share/HamPackServer
if ! pacman -Qi apache &> /dev/null; then
echo "Installing Apache..."
sudo pacman -S --noconfirm apache
sudo systemctl enable httpd
sudo systemctl start httpd
else
echo "Apache is already installed, skipping."
fi
if ! pacman -Qi mariadb &> /dev/null; then
echo "Installing MariaDB (MySQL)..."
sudo pacman -S --noconfirm mariadb
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
sudo systemctl enable mariadb
sudo systemctl start mariadb
else
echo "MariaDB is already installed, skipping."
fi
if ! pacman -Qi php &> /dev/null; then
sudo pacman -S --noconfirm php
else
echo "PHP is already installed, skipping."
fi
echo "Enabling PHP extensions in /etc/php/php.ini..."
for ext in curl mbstring xml pdo_mysql mysqli; do
sudo sed -i "s/^;extension=${ext}$/extension=${ext}/" /etc/php/php.ini
done
# Install Cloudlog
CLOUDLOG_DIR="/srv/http/cloudlog"
CLOUDLOG_DB="cloudlog"
CLOUDLOG_DB_USER="cloudlog"
CLOUDLOG_DB_PASS="cloudlog"
if [ ! -d "$CLOUDLOG_DIR" ]; then
echo "Installing Cloudlog..."
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..."
sudo mysql -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
sudo systemctl restart httpd
echo "Cloudlog installed. Complete setup by visiting http://localhost/cloudlog/install"
else
echo "Cloudlog is already installed, skipping."
fi
# Install Compiled Servers
echo "Installing compiled servers..."
. install-compiled.sh
if ! ls /usr/lib/modules/$(uname -r) > /dev/null 2>&1; then
echo "HamPack is installed. A newer kernel has been installed, a reboot is recommended."
read -rp "Reboot now? [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
echo "Rebooting..."
sudo reboot
;;
*)
echo "Reboot skipped. Please remember to reboot when convenient."
exit 0
;;
esac
else
echo "Ham Pack is installed. Reboot when convenient."
fi