#!/bin/bash # # Purpose : Install HamPackServer (run by CoreDesktop's `sibling add`) # Print the logo print_logo() { cat << "EOF" ██╗ ██╗ █████╗ ███╗ ███╗██████╗ █████╗ ██████╗██╗ ██╗ ██║ ██║██╔══██╗████╗ ████║██╔══██╗██╔══██╗██╔════╝██║ ██╔╝ ███████║███████║██╔████╔██║██████╔╝███████║██║ █████╔╝ ██╔══██║██╔══██║██║╚██╔╝██║██╔═══╝ ██╔══██║██║ ██╔═██╗ ██║ ██║██║ ██║██║ ╚═╝ ██║██║ ██║ ██║╚██████╗██║ ██╗ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ███████╗███████╗██████╗ ██╗ ██╗███████╗██████╗ ██╔════╝██╔════╝██╔══██╗██║ ██║██╔════╝██╔══██╗ ███████╗█████╗ ██████╔╝██║ ██║█████╗ ██████╔╝ ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██╔══╝ ██╔══██╗ ███████║███████╗██║ ██║ ╚████╔╝ ███████╗██║ ██║ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝ EOF } # Install Wavelog in Docker, once; its database password is generated here install_wavelog() { WAVELOG_DIR="$HOME/.local/bin/wavelog" if [ -d "$WAVELOG_DIR" ]; then echo "Wavelog is already installed, skipping." return fi echo "Installing Wavelog..." mkdir -p "$WAVELOG_DIR" cp "$SELF/wavelog/docker-compose.yaml" "$WAVELOG_DIR/docker-compose.yaml" WAVELOG_DB_PASS=$(openssl rand -base64 32 | tr -d '=/+' | cut -c1-24) sed -i "s|MARIADB_PASSWORD: wavelog # <- Insert a strong password here|MARIADB_PASSWORD: ${WAVELOG_DB_PASS}|" "$WAVELOG_DIR/docker-compose.yaml" if ! systemctl is-active --quiet docker; then echo "Starting Docker..." sudo systemctl enable --now docker fi echo "Waiting for Docker socket..." local timeout=30 while [ ! -S /var/run/docker.sock ] && [ $timeout -gt 0 ]; do sleep 1 timeout=$((timeout - 1)) done if [ ! -S /var/run/docker.sock ]; then echo "Error: Docker socket not available after 30 seconds." return 1 fi sudo usermod -aG docker "$USER" sudo chown root:docker /var/run/docker.sock sudo chmod 660 /var/run/docker.sock sg docker -c "docker compose -f '$WAVELOG_DIR/docker-compose.yaml' up -d" echo "Wavelog installed. Access it at http://localhost:8086" } # --- Main --- set -e SELF="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" COREDESKTOP="$HOME/.local/share/coredesktop" LEGACY_DIR="$HOME/.local/share/HamPackServer" SUDOERS_FILE=/etc/sudoers.d/99-hampack-install clear || true print_logo if [ ! -d "$COREDESKTOP" ]; then echo "HamPackServer requires CoreDesktop to be installed first." echo "Please install CoreDesktop: https://coredesktop.federated.computer" exit 1 fi # HamPackServer used to clone itself to ~/.local/share/HamPackServer. It now # lives wherever `sibling` cloned it. if [ -d "$LEGACY_DIR/.git" ] && [ "$LEGACY_DIR" != "$SELF" ]; then echo "Removing the old HamPackServer install at $LEGACY_DIR..." rm -rf "$LEGACY_DIR" fi sudo -v # Grant passwordless sudo for the duration of the install, revoke on exit echo "$USER ALL=(ALL) NOPASSWD: ALL" | sudo tee "$SUDOERS_FILE" > /dev/null sudo chmod 440 "$SUDOERS_FILE" trap 'sudo rm -f "$SUDOERS_FILE"' EXIT INSTALL_SUCCESS=true # Let install-compiled.sh ask before building apps whose version it can't tell if ! HAMPACKSERVER_INTERACTIVE=1 bash "$SELF/update.sh"; then INSTALL_SUCCESS=false fi if ! install_wavelog; then echo "Warning: Wavelog may not have installed correctly." INSTALL_SUCCESS=false fi # Revoke passwordless sudo now, before a possible reboot skips the trap sudo rm -f "$SUDOERS_FILE" echo "" if [ "$INSTALL_SUCCESS" = true ]; then echo "HamPackServer is installed successfully!" else echo "HamPackServer installation completed with errors. Please review the output above." fi if [ -n "$WAVELOG_DB_PASS" ]; then echo "" echo "Wavelog database password: $WAVELOG_DB_PASS (Please save this.)" echo "(also stored in $WAVELOG_DIR/docker-compose.yaml)" fi echo "" read -rp "A reboot is required to complete setup. Reboot now? [y/N] " response