From 00ee15236f7bbeea44f22e3a19b70c652f156481 Mon Sep 17 00:00:00 2001 From: Muko Date: Sat, 14 Sep 2024 12:08:05 +0700 Subject: [PATCH 1/5] Create appimageinstall.sh --- appimageinstall.sh | 174 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 appimageinstall.sh diff --git a/appimageinstall.sh b/appimageinstall.sh new file mode 100644 index 000000000..cd5725ac8 --- /dev/null +++ b/appimageinstall.sh @@ -0,0 +1,174 @@ +#!/bin/bash + +# Kawaii ASCII Art for the script +kawaii_art() { + echo "╔════════════════════════════════════════════════╗" + echo "║ ║" + echo "║ (ノ◕ヮ◕)ノ*:・゚✧ Zen Browser Installer ✧゚・:* ║" + echo "║ ║" + echo "╚════════════════════════════════════════════════╝" + echo +} + +# Function to download a file with unlimited retries +download_until_success() { + local url="$1" + local output_path="$2" + + while true; do + echo "+------------------------------------------------+" + echo "| Downloading... |" + echo "+------------------------------------------------+" + if curl -# -L --connect-timeout 30 --max-time 600 "$url" -o "$output_path"; then + echo "+------------------------------------------------+" + echo "| Download completed successfully! |" + echo "+------------------------------------------------+" + break + else + echo "| (⌣_⌣” ) Download failed, retrying... |" + echo "+------------------------------------------------+" + sleep 5 # Optional: wait a bit before retrying + fi + done +} + +process_appimage() { + local appimage_path="$1" + local app_name="$2" + + # Make AppImage executable + chmod +x "${appimage_path}" + + # Extract all files from AppImage + "${appimage_path}" --appimage-extract + + # Move .desktop file (from /squashfs-root only) + desktop_file=$(find squashfs-root -maxdepth 1 -name "*.desktop" | head -n 1) + mv "${desktop_file}" ~/.local/share/applications/${app_name}.desktop + + # Find PNG icon (from /squashfs-root only) + icon_file=$(find squashfs-root -maxdepth 1 -name "*.png" | head -n 1) + + # Resolve symlink if the icon is a symlink + if [ -L "${icon_file}" ]; then + icon_file=$(readlink -f "${icon_file}") + fi + + # 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/ + + # Edit .desktop file to update paths + desktop_file=~/.local/share/applications/${app_name}.desktop + awk -v home="$HOME" -v app_name="$app_name" ' + BEGIN { in_action = 0 } + /^\[Desktop Action/ { in_action = 1 } + /^Exec=/ { + if (in_action) { + split($0, parts, "=") + sub(/^[^ ]+/, "", parts[2]) # Remove the first word (original command) + print "Exec=" home "/.local/share/AppImage/" app_name ".AppImage" parts[2] + } else { + print "Exec=" home "/.local/share/AppImage/" app_name ".AppImage" + } + next + } + /^Icon=/ { print "Icon=" home "/.local/share/icons/" app_name ".png"; next } + { print } + ' "${desktop_file}" > "${desktop_file}.tmp" && mv "${desktop_file}.tmp" "${desktop_file}" + + # Clean up extracted files + rm -rf squashfs-root +} + +uninstall_appimage() { + local app_name="$1" + + # Remove AppImage + rm -f ~/.local/share/AppImage/${app_name}.AppImage + + # Remove .desktop file + rm -f ~/.local/share/applications/${app_name}.desktop + + # Remove icon + rm -f ~/.local/share/icons/${app_name}.png + + 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 + + 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 +} + +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 + + case $main_choice in + 1) + choose_appimage_version + ;; + 2) + uninstall_appimage ZenBrowser + ;; + 3) + echo "(⌒‿⌒) Exiting..." + exit 0 + ;; + *) + echo "(•ˋ _ ˊ•) Invalid choice. Exiting..." + exit 1 + ;; + esac +} + +# Create necessary directories +mkdir -p ~/.local/share/applications +mkdir -p ~/.local/share/icons +mkdir -p ~/.local/share/AppImage + +# Show kawaii ASCII art +kawaii_art + +# Execute the main menu +main_menu From f1c1169d42ed9a3ba19693e7b2d076e9d11c69e4 Mon Sep 17 00:00:00 2001 From: Muko Date: Sat, 14 Sep 2024 12:16:29 +0700 Subject: [PATCH 2/5] Update README.md --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 9bb3a8778..f3c5876ae 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,18 @@ You can also install Zen using Homebrew: brew install --cask zen-browser ``` +### Linux + +#### AppImage +``` +curl -sL https://github.com/Muko-Tabi/desktop/raw/main/appimageinstall.sh -o /tmp/appimageinstall.sh && bash /tmp/appimageinstall.sh && rm /tmp/appimageinstall.sh +``` + +#### Flatpak +``` +flatpak install flathub io.github.zen_browser.zen +``` + To upgrade the browser to a newer version, use the embedded update functionality in `About Zen`. # Core Components From cf6c72df08cc2dd14f9c83fe809417505e7b77fa Mon Sep 17 00:00:00 2001 From: Muko Date: Sat, 14 Sep 2024 12:51:17 +0700 Subject: [PATCH 3/5] Fix wrong link for AppImage script --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f3c5876ae..2ae27f270 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ brew install --cask zen-browser #### AppImage ``` -curl -sL https://github.com/Muko-Tabi/desktop/raw/main/appimageinstall.sh -o /tmp/appimageinstall.sh && bash /tmp/appimageinstall.sh && rm /tmp/appimageinstall.sh +curl -sL https://github.com/zen-browser/desktop/raw/main/appimageinstall.sh -o /tmp/appimageinstall.sh && bash /tmp/appimageinstall.sh && rm /tmp/appimageinstall.sh ``` #### Flatpak From 6508c86dca5a3b401265b7a2cb4e71104a6a43ca Mon Sep 17 00:00:00 2001 From: Muko Date: Sat, 14 Sep 2024 17:38:51 +0700 Subject: [PATCH 4/5] 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 ;; From b73f16f09a3c013a584bcfe91905bfcbdc2f56f7 Mon Sep 17 00:00:00 2001 From: Muko Date: Sat, 14 Sep 2024 17:40:13 +0700 Subject: [PATCH 5/5] Add in zsync requirement for Updating --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 2ae27f270..b448d28df 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,9 @@ brew install --cask zen-browser ### Linux #### AppImage + +- `zsync` is required for the Update feature of the script below + ``` curl -sL https://github.com/zen-browser/desktop/raw/main/appimageinstall.sh -o /tmp/appimageinstall.sh && bash /tmp/appimageinstall.sh && rm /tmp/appimageinstall.sh ```