#!/bin/bash # Documentation # To run this script, use the following 1-liner: # curl -fsSL https://kb.filewave.com/attachments/412 | sudo bash -s -- -v -r [-b for beta] -y # Example for version 15.5.0 with revision 1 in production: # curl -fsSL https://kb.filewave.com/attachments/412 | sudo bash -s -- -v 15.5.0 -r 1 -p -y # Ensure script is run with sudo/root privileges if [ "$EUID" -ne 0 ]; then die "This script must be run with sudo or as root." fi # Ensure script is running on a Debian-based system if ! grep -iq "debian" /etc/os-release; then die "This script must be run on a Debian-based system." fi # Set default values for version, revision, and server type VERSION="15.5.0" REVISION="1" SERVER_TYPE="prod" BASE_URL="https://fwdl.filewave.com" auto_yes=false if [ "$#" -eq 0 ]; then echo "Usage: curl -fsSL https://kb.filewave.com/attachments/409 | sudo bash -s -- -v -r [-b for beta | -p for prod] [-y for auto-yes]" echo "\nOptions:" echo " -v, --version Specify the version of FileWave Booster to install (e.g., 15.5.0)" echo " -r, --revision Specify the revision number (e.g., 1)" echo " -b, --beta Use beta server for downloads (default is production)" echo " -p, --prod Use production server for downloads" echo " -y, --yes Automatically answer 'yes' to all prompts" exit 1 fi # Function to handle errors and display messages die() { echo "[ERROR] $1" >&2 exit 1 } # Log all actions to syslog for audit purposes LOG_FILE="/var/log/filewave_booster_update.log" touch "$LOG_FILE" || die "Failed to create log file $LOG_FILE. Check permissions." chmod 644 "$LOG_FILE" || die "Failed to set permissions on log file $LOG_FILE." if [[ ! -w "$LOG_FILE" ]]; then die "Cannot write to log file $LOG_FILE. Please check permissions." fi exec > >(stdbuf -oL tee -a "$LOG_FILE") 2>&1 echo "Logging to $LOG_FILE" # Parse input arguments while [[ "$#" -gt 0 ]]; do case $1 in -v|--version) VERSION="$2" shift 2 ;; -r|--revision) REVISION="$2" shift 2 ;; -b|--beta) SERVER_TYPE="beta" shift ;; -p|--prod) SERVER_TYPE="prod" shift ;; -y|--yes) auto_yes=true shift ;; *) echo "Unknown option: $1" exit 1 ;; esac done # Confirm actions with the user echo "This script will update your OS and install/upgrade the FileWave Booster packages." echo "Version: $VERSION, Revision: $REVISION, Server Type: $SERVER_TYPE" if [[ "$auto_yes" == "true" ]]; then confirm="yes" else read -p "Do you wish to proceed? (yes/no): " confirm < /dev/tty fi if [[ ! "$confirm" =~ ^[Yy]([Ee][Ss])?$ ]]; then echo "Aborting installation as requested." exit 0 fi # Set the appropriate URL based on server type if [ "$SERVER_TYPE" == "beta" ]; then BASE_URL="https://fwbetas.filewave.com" fi # 1. Install Essential Tools echo "Installing essential tools..." apt-get clean || die "Failed to clean apt cache." apt-get update -y || die "Failed to update package list." apt-get --fix-broken install -y || die "Failed to fix broken installs from apt." apt-get autoremove -y || die "Failed to autoremove from apt." for dep in "curl" "zip" "gdebi"; do if ! command -v $dep &> /dev/null; then echo "$dep not found. Installing $dep..." apt-get install -y $dep || die "Failed to install $dep." fi done if ! dpkg-query -W -f='${Status}' net-tools 2>/dev/null | grep -q "install ok installed"; then echo "net-tools not found. Installing net-tools..." apt-get install -y net-tools || die "Failed to install net-tools." fi # Check the current version of FileWave Booster INSTALLED_VERSION=$(dpkg-query -W -f='${Version}' fwbooster 2>/dev/null || true) # If no FileWave Booster package is installed, set the version to 1.0.0 for comparison purposes if [[ -z "$INSTALLED_VERSION" || "$INSTALLED_VERSION" == "none" ]]; then echo "No FileWave Booster packages are installed. Proceeding with initial installation of version $VERSION..." INSTALLED_VERSION="1.0.0" fi install_packages() { echo "Downloading and installing FileWave Booster package..." PACKAGE="fwbooster_${VERSION}_amd64.deb" DOWNLOAD_DIR="/tmp/filewave_install_$$" mkdir -p "$DOWNLOAD_DIR" || die "Failed to create download directory." trap 'rm -rf "$DOWNLOAD_DIR"' EXIT echo "Downloading $PACKAGE..." for i in {1..3}; do curl -fSL "$BASE_URL/$VERSION/$PACKAGE" -o "$DOWNLOAD_DIR/$PACKAGE" && break echo "Retrying download ($i/3)..." sleep 5 done if [[ ! -f "$DOWNLOAD_DIR/$PACKAGE" ]]; then die "Failed to download $PACKAGE after multiple attempts." fi echo "Installing $PACKAGE..." gdebi -n "$DOWNLOAD_DIR/$PACKAGE" || die "Failed to install $PACKAGE" # Clean up the download directory if [[ -d "$DOWNLOAD_DIR" ]]; then rm -rf "$DOWNLOAD_DIR" || echo "Warning: Failed to remove download directory $DOWNLOAD_DIR" fi } # This is the meat of the script. # The actions to take based on version. if dpkg --compare-versions "$INSTALLED_VERSION" lt "$VERSION"; then echo "Upgrading to FileWave Booster version $VERSION..." install_packages elif dpkg --compare-versions "$INSTALLED_VERSION" eq "$VERSION"; then echo "FileWave Booster is already at version $VERSION, no further installation required." else echo "FileWave Booster is newer than $VERSION and downgrade is not possible with this script." fi # Clean up the download directory if [[ -d "$DOWNLOAD_DIR" ]]; then rm -rf "$DOWNLOAD_DIR" || echo "Warning: Failed to remove download directory $DOWNLOAD_DIR" fi # 4. OS Upgrade echo "Warning: This script will upgrade the entire OS. This is required for security." if [[ "$auto_yes" == "true" ]]; then upgrade_confirm="yes" else read -p "Do you wish to proceed with the OS upgrade? (yes/no): " upgrade_confirm < /dev/tty fi if [[ ! "$upgrade_confirm" =~ ^[Yy]([Ee][Ss])?$ ]]; then echo "Skipping OS upgrade." else echo "Upgrading the system..." apt-get update -y || die "Failed to update package list." DEBIAN_FRONTEND=noninteractive apt-get upgrade -y -o Dpkg::Options::="--force-confold" || die "System upgrade failed." fi # 5. Reboot the system to complete the installation echo "The system will reboot in 15 seconds to complete the installation." if [[ "$auto_yes" == "true" ]]; then reboot_confirm="yes" else read -p "Do you want to reboot now? (yes/no): " reboot_confirm < /dev/tty fi if [[ "$reboot_confirm" =~ ^[Yy]([Ee][Ss])?$ ]]; then echo "Rebooting system in 15 seconds... Please remember that you can check the log file at $LOG_FILE after the reboot to see the full details of the update." sleep 15 reboot else echo "Skipping reboot. Please remember to reboot manually to apply all changes." fi # The end