From 6508c86dca5a3b401265b7a2cb4e71104a6a43ca Mon Sep 17 00:00:00 2001 From: Muko Date: Sat, 14 Sep 2024 17:38:51 +0700 Subject: [PATCH] Add in Version Dectection, Update, and Status --- appimageinstall.sh | 223 +++++++++++++++++++++++++++++++++------------ 1 file changed, 167 insertions(+), 56 deletions(-) diff --git a/appimageinstall.sh b/appimageinstall.sh index cd5725ac8..a9b0e97a7 100644 --- a/appimageinstall.sh +++ b/appimageinstall.sh @@ -1,12 +1,58 @@ #!/bin/bash +# Function to check if AVX2 is supported +check_avx2_support() { + if grep -q avx2 /proc/cpuinfo; then + return 0 # AVX2 supported + else + return 1 # AVX2 not supported + fi +} + +# Function to check if Zen Browser is installed +check_installation_status() { + if [ -f ~/.local/share/AppImage/ZenBrowser.AppImage ]; then + return 0 # Zen Browser installed + else + return 1 # Zen Browser not installed + fi +} + +# Function to check if zsync is installed +check_zsync_installed() { + if command -v zsync &> /dev/null; then + return 0 # zsync is installed + else + return 1 # zsync is not installed + fi +} + # Kawaii ASCII Art for the script kawaii_art() { - echo "╔════════════════════════════════════════════════╗" - echo "║ ║" - echo "║ (ノ◕ヮ◕)ノ*:・゚✧ Zen Browser Installer ✧゚・:* ║" - echo "║ ║" - echo "╚════════════════════════════════════════════════╝" + echo "╔════════════════════════════════════════════════════╗" + echo "║ ║" + echo "║ (ノ◕ヮ◕)ノ*:・゚✧ Zen Browser Installer ✧゚・:* ║" + echo "║ ║" + + if check_avx2_support; then + echo "║ CPU: AVX2 Supported (Optimized Version) ║" + else + echo "║ CPU: AVX2 Not Supported (Generic Version) ║" + fi + + if check_installation_status; then + echo "║ Status: Zen Browser Installed ║" + else + echo "║ Status: Zen Browser Not Installed ║" + fi + + if check_zsync_installed; then + echo "║ zsync: Installed (Needed for Updates) ║" + else + echo "║ zsync: Not Installed (Needed for Updates) ║" + fi + + echo "╚════════════════════════════════════════════════════╝" echo } @@ -14,19 +60,51 @@ kawaii_art() { download_until_success() { local url="$1" local output_path="$2" + local mode="$3" # New parameter to indicate the mode while true; do - echo "+------------------------------------------------+" - echo "| Downloading... |" - echo "+------------------------------------------------+" + echo "+----------------------------------------------------+" + case "$mode" in + "zsync") + echo "| Checking for Update... |" + ;; + "update") + echo "| Updating... |" + ;; + "install") + echo "| Installing... |" + ;; + esac + echo "+----------------------------------------------------+" if curl -# -L --connect-timeout 30 --max-time 600 "$url" -o "$output_path"; then - echo "+------------------------------------------------+" - echo "| Download completed successfully! |" - echo "+------------------------------------------------+" + echo "+----------------------------------------------------+" + case "$mode" in + "zsync") + echo "| Checking for Update successfully! |" + ;; + "update") + echo "| Update completed successfully! |" + ;; + "install") + echo "| Install completed successfully! |" + ;; + esac + echo "+----------------------------------------------------+" break else - echo "| (⌣_⌣” ) Download failed, retrying... |" - echo "+------------------------------------------------+" + echo "+----------------------------------------------------+" + case "$mode" in + "zsync") + echo "| (⌣_⌣” ) Checking for Update failed, retrying... |" + ;; + "update") + echo "| (⌣_⌣” ) Update failed, retrying... |" + ;; + "install") + echo "| (⌣_⌣” ) Install failed, retrying... |" + ;; + esac + echo "+----------------------------------------------------+" sleep 5 # Optional: wait a bit before retrying fi done @@ -57,8 +135,10 @@ process_appimage() { # Copy the icon to the icons directory cp "${icon_file}" ~/.local/share/icons/${app_name}.png - # Move AppImage to final location - mv "${appimage_path}" ~/.local/share/AppImage/ + # Move AppImage to final location, only if it's not already there + if [ "${appimage_path}" != "$HOME/.local/share/AppImage/${app_name}.AppImage" ]; then + mv "${appimage_path}" ~/.local/share/AppImage/ + fi # Edit .desktop file to update paths desktop_file=~/.local/share/applications/${app_name}.desktop @@ -98,60 +178,91 @@ uninstall_appimage() { echo "(︶︹︺) Uninstalled ${app_name}" } -choose_appimage_version() { - echo "(◕‿◕✿) Please choose the version to install:" - echo "+------------------------------------------------+" - echo "| 1) Optimized - Blazing fast and compatible |" - echo "| with modern devices |" - echo "+------------------------------------------------+" - echo "| 2) Generic - Slow but compatible with older |" - echo "| devices |" - echo "+------------------------------------------------+" - echo "| 3) Exit |" - echo "+------------------------------------------------+" - read -p "Enter your choice (1/2/3): " version_choice +check_for_updates() { + local zsync_url + local zsync_file + local appimage_url - case $version_choice in - 1) - url=$(curl -s https://api.github.com/repos/zen-browser/desktop/releases/latest | grep "browser_download_url.*zen-specific.AppImage\"" | cut -d '"' -f 4) - download_until_success "$url" ~/Downloads/ZenBrowser.AppImage - process_appimage ~/Downloads/ZenBrowser.AppImage ZenBrowser - ;; - 2) - url=$(curl -s https://api.github.com/repos/zen-browser/desktop/releases/latest | grep "browser_download_url.*zen-generic.AppImage\"" | cut -d '"' -f 4) - download_until_success "$url" ~/Downloads/ZenBrowser.AppImage - process_appimage ~/Downloads/ZenBrowser.AppImage ZenBrowser - ;; - 3) - echo "(⌒‿⌒) Exiting..." - exit 0 - ;; - *) - echo "(•ˋ _ ˊ•) Invalid choice. Exiting..." - exit 1 - ;; - esac + if check_avx2_support; then + zsync_url="https://github.com/zen-browser/desktop/releases/latest/download/zen-specific.AppImage.zsync" + appimage_url="https://github.com/zen-browser/desktop/releases/latest/download/zen-specific.AppImage" + else + zsync_url="https://github.com/zen-browser/desktop/releases/latest/download/zen-generic.AppImage.zsync" + appimage_url="https://github.com/zen-browser/desktop/releases/latest/download/zen-generic.AppImage" + fi + + zsync_file="${HOME}/Downloads/zen-browser.AppImage.zsync" + + if check_installation_status; then + echo "Checking for updates..." + if ! check_zsync_installed; then + echo "( ͡° ʖ̯ ͡°) zsync is not installed. Please install zsync to enable update functionality." + return 1 + fi + download_until_success "$zsync_url" "$zsync_file" "zsync" + update_output=$(zsync -i ~/.local/share/AppImage/ZenBrowser.AppImage -o ~/.local/share/AppImage/ZenBrowser.AppImage "$zsync_file" 2>&1) + if echo "$update_output" | grep -q "verifying download...checksum matches OK"; then + local version + version="1.0.0-a.39" + echo "(。♥‿♥。) Zen Browser is up-to-date! Version: $version" + else + echo "Updating Zen Browser..." + download_until_success "$appimage_url" ~/.local/share/AppImage/ZenBrowser.AppImage "update" + process_appimage ~/.local/share/AppImage/ZenBrowser.AppImage ZenBrowser + echo "(。♥‿♥。) Zen Browser updated to version: 1.0.0-a.39!" + fi + rm -f "$zsync_file" + else + echo "( ͡° ʖ̯ ͡°) Zen Browser is not installed." + main_menu + fi +} + +install_zen_browser() { + local appimage_url + + if check_avx2_support; then + appimage_url="https://github.com/zen-browser/desktop/releases/latest/download/zen-specific.AppImage" + else + appimage_url="https://github.com/zen-browser/desktop/releases/latest/download/zen-generic.AppImage" + fi + + download_until_success "$appimage_url" ~/Downloads/ZenBrowser.AppImage "install" + process_appimage ~/Downloads/ZenBrowser.AppImage ZenBrowser + echo "(。♥‿♥。) Zen Browser installed successfully!" } main_menu() { echo "(★^O^★) What would you like to do?" - echo "+------------------------------------------------+" - echo "| 1) Install |" - echo "+------------------------------------------------+" - echo "| 2) Uninstall |" - echo "+------------------------------------------------+" - echo "| 3) Exit |" - echo "+------------------------------------------------+" - read -p "Enter your choice (1/2/3): " main_choice + echo "+----------------------------------------------------+" + echo "| 1) Install |" + echo "+----------------------------------------------------+" + echo "| 2) Uninstall |" + echo "+----------------------------------------------------+" + if check_zsync_installed; then + echo "| 3) Check for Updates |" + echo "+----------------------------------------------------+" + fi + echo "| 0) Exit |" + echo "+----------------------------------------------------+" + read -p "Enter your choice (0-3): " main_choice case $main_choice in 1) - choose_appimage_version + install_zen_browser ;; 2) uninstall_appimage ZenBrowser ;; 3) + if check_zsync_installed; then + check_for_updates + else + echo "(•ˋ _ ˊ•) Invalid choice. Exiting..." + exit 1 + fi + ;; + 0) echo "(⌒‿⌒) Exiting..." exit 0 ;;