#!/bin/bash # Installation and uninstallation script for Waterfox # Version: 1.3.7 # MIT License # Copyright (c) 2022 hawkeye116477 # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # # # Script directory Dir=$(cd "$(dirname "$0")" && pwd) # Desktop shortcut path, Applications shortcut path, Waterfox install path, Config path. ConfDir=${XDG_CONFIG_HOME:-$HOME/.config}/install_waterfox ConfFile="$ConfDir"/settings.conf Desktop="$(xdg-user-dir DESKTOP)" Applications=/usr/share/applications InstallDirectory=$HOME/Apps # Read saved installation path if [ -f "$ConfFile" ]; then InstallDirectory=$(grep -oP -m 1 'InstallPath=\K.*' "$ConfFile") fi # Parse arguments usage() { echo "Usage: $0 [ options ... ]" echo "" echo " -v or --version : Print script version" echo " -sp= or --spath= : Set path to directory of installable package(s)" echo " -ip= or --ipath= : Set installation path (folder with package name will be here)" echo " -h : Print this screen" echo "" } for i in "$@"; do case $i in -sp=* | --spath=*) Dir="${i#*=}" ;; -v | --version) printf "%-10s %-10s\n" "Script version: " "$(awk -F': ' '/^# Version:/ {print $2; exit}' "$0")" exit 0 ;; -ip=* | --ipath=*) InstallDirectory="${i#*=}" ;; -h | --help) usage exit 0 ;; esac done # Enter current script directory. cd "$Dir" || exit # Detect installable/installed packages echo "Detecting installable/installed packages..." mapfile -t Packages < <(find "$Dir" -type f -regextype posix-extended -regex ".*waterfox-(classic|current|G3|g3|G4|g4).*(tar\.bz2|AppImage)") if [[ -d "$InstallDirectory" ]]; then mapfile -t -O "${#Packages[@]}" Packages < <(find "$InstallDirectory" -type d -regextype posix-extended -regex ".*waterfox-(classic|current|G3|g3|G4|g4)") fi if [ "${#Packages[@]}" ]; then PackageTypes=() if [[ ${Packages[*]} =~ "waterfox-classic" ]]; then PackageTypes+=("Classic") fi if [[ ${Packages[*]} =~ "waterfox-current" ]]; then PackageTypes+=("Current") fi if [[ ${Packages[*]} =~ waterfox-(G3|g3) ]]; then PackageTypes+=("G3") fi if [[ ${Packages[*]} =~ waterfox-(G4|g4) ]]; then PackageTypes+=("G4") fi fi if [[ "${PackageTypes[*]}" ]]; then echo "Which package are you interested in?" select chosenPackageType in "${PackageTypes[@]}" "None"; do case $chosenPackageType in "None") exit 0 break ;; *) break ;; esac done else echo "No packages detected. Please place this script next to the tarball/AppImage packages or rerun it with flag -sp=." exit 0 fi echo "What do you want to do with Waterfox $chosenPackageType now?" lowerChosenPackageType=$(echo "$chosenPackageType" | tr "[:upper:]" "[:lower:]") if [[ "$lowerChosenPackageType" == "g3" ]]; then packageTypeName="(G3|g3)" elif [[ "$lowerChosenPackageType" == "g4" ]]; then packageTypeName="(G4|g4)" else packageTypeName=$(echo "$chosenPackageType" | tr "[:upper:]" "[:lower:]") fi chosenPackages=() for package in "${Packages[@]}"; do if [[ "$(basename -- "$package")" =~ ^waterfox-$packageTypeName.*(tar\.bz2|AppImage) ]]; then chosenPackages+=("$package") fi done Packages=("${chosenPackages[@]}") # Count how many packages in the directory PackageCount=${#Packages[@]} select yn in "Install" "Uninstall" "Quit"; do case $yn in Install) # Check if more than 1 package exist. if [ "$PackageCount" -gt 1 ]; then echo "Which package do you want to install?" select Package in "${Packages[@]}" "None"; do case $Package in "None") exit 0 break ;; *) mapfile -t Packages < <(echo "$Package") break ;; esac done fi # Make directory if not already exist if ! [ -d "$InstallDirectory" ]; then echo "Making $InstallDirectory directory!" mkdir "$InstallDirectory" fi # Navigate into the install directory echo "Entering $InstallDirectory directory" cd "$InstallDirectory" || exit if [ ! -f "${Packages[0]}" ]; then echo "No installable packages found. Maybe you wanted to uninstall Waterfox $chosenPackageType." exit 0 fi # Remove existing waterfox folder. if [ -d "$InstallDirectory"/waterfox-"$lowerChosenPackageType" ]; then echo "Removing older installed version..." rm -rvf "$InstallDirectory"/waterfox-"$lowerChosenPackageType" fi # Unpack waterfox into the install directory echo "Unpacking ${Packages[0]} into $InstallDirectory directory" mkdir -p "$InstallDirectory"/temp if [[ "${Packages[0]}" =~ "AppImage" ]]; then chmod +x "${Packages[0]}" cd "$InstallDirectory"/temp || exit "${Packages[0]}" --appimage-extract mv "$InstallDirectory"/temp/squashfs-root/usr/bin/waterfox-"$lowerChosenPackageType" "$InstallDirectory"/temp/squashfs-root/usr/bin/waterfox mv "$InstallDirectory"/temp/squashfs-root/usr/bin/* "$InstallDirectory"/temp rm -rf "$InstallDirectory"/temp/squashfs-root/ mkdir -p "$InstallDirectory"/waterfox-"$lowerChosenPackageType" else tar xjfv "${Packages[0]}" -C "$InstallDirectory"/temp fi mv "$InstallDirectory"/temp/* "$InstallDirectory"/waterfox-"$lowerChosenPackageType" rm -rf "$InstallDirectory"/temp # Install a wrapper to avoid confusion about binary path echo "Creating desktop entry (Root priveleges are required)..." sudo install -Dm755 /dev/stdin "/usr/bin/waterfox-$lowerChosenPackageType" <