Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Merge #360 (Linux updater) into g-waylnd

KnifeLemon57b516a56eef
diff --cc installer/linux/install.sh
index 0d3cef7e,cdfefacf..b678fe53
mode 100644,100755..100755
--- a/installer/linux/install.sh
+++ b/installer/linux/install.sh
@@@ -6,64 -29,198 +29,237 @@@ data_dir=${XDG_DATA_HOME:-"$HOME/.local
install_dir="$data_dir/filee/application"
bin_dir="$HOME/.local/bin"
desktop_file="$data_dir/applications/com.filee.app.desktop"
+gnome_extension_id="[email protected]"
+gnome_extension_source="$source_dir/gnome/$gnome_extension_id"
+gnome_extension_dir="$data_dir/gnome-shell/extensions/$gnome_extension_id"
- if [ -e "$install_dir" ] || [ -L "$install_dir" ]; then
- printf '%s\n' "An installation already exists at $install_dir. Run its uninstall.sh first."
- exit 1
- fi
- if [ -e "$bin_dir/filee" ] || [ -L "$bin_dir/filee" ]; then
- printf '%s\n' "$bin_dir/filee already exists. Remove or rename it before installing Filee."
- exit 1
- fi
- if [ -e "$desktop_file" ] || [ -L "$desktop_file" ]; then
- printf '%s\n' "$desktop_file already exists. Remove or rename it before installing Filee."
- exit 1
- fi
+is_gnome=false
+if printf '%s' "${XDG_CURRENT_DESKTOP:-}" | tr ':' '\n' | grep -qi '^GNOME$'; then
+ is_gnome=true
+fi
- if [ "$is_gnome" = true ] && [ -d "$gnome_extension_source" ] && { [ -e "$gnome_extension_dir" ] || [ -L "$gnome_extension_dir" ]; }; then
- printf '%s\n' "A GNOME extension already exists at $gnome_extension_dir. Remove or rename it before installing Filee."
+
+ # Validate required tools and incoming payload files before doing anything.
+ command -v python3 >/dev/null 2>&1 || {
+ printf '%s\n' "Python 3 is required to install Filee." >&2
+ exit 1
+ }
+
+
+ if [ ! -f "$source_dir/Filee" ] || [ ! -x "$source_dir/Filee" ]; then
+ printf '%s\n' "Payload validation failed: $source_dir/Filee is missing or not executable." >&2
exit 1
fi
- command -v python3 >/dev/null
- test -x "$source_dir/Filee"
- test -x "$source_dir/filee-cli"
- mkdir -p "$data_dir/filee" "$bin_dir" "$data_dir/applications"
- cp -R "$source_dir" "$install_dir"
- printf '%s\n' 'com.filee.app' > "$install_dir/.filee-package"
- ln -s "$install_dir/filee-cli" "$bin_dir/filee"
- if [ "$is_gnome" = true ] && [ -d "$gnome_extension_source" ]; then
- mkdir -p "$(dirname "$gnome_extension_dir")"
- cp -R "$install_dir/gnome/$gnome_extension_id" "$gnome_extension_dir"
- printf '%s\n' 'com.filee.app' > "$gnome_extension_dir/.filee-package"
- if command -v gsettings >/dev/null 2>&1; then
- enabled=$(gsettings get org.gnome.shell enabled-extensions 2>/dev/null || true)
- if [ -n "$enabled" ]; then
- updated=$(python3 - "$enabled" "$gnome_extension_id" <<'PY'
+
+ if [ ! -f "$source_dir/filee-cli" ] || [ ! -x "$source_dir/filee-cli" ]; then
+ printf '%s\n' "Payload validation failed: $source_dir/filee-cli is missing or not executable." >&2
+ exit 1
+ fi
+
+ if [ "$upgrade" -eq 0 ]; then
+ # First-time installation: refuse to overwrite an existing installation or files.
+ if [ -e "$install_dir" ] || [ -L "$install_dir" ]; then
+ printf '%s\n' "An installation already exists at $install_dir. Run its uninstall.sh first."
+ exit 1
+ fi
+ if [ -e "$bin_dir/filee" ] || [ -L "$bin_dir/filee" ]; then
+ printf '%s\n' "$bin_dir/filee already exists. Remove or rename it before installing Filee."
+ exit 1
+ fi
+ if [ -e "$desktop_file" ] || [ -L "$desktop_file" ]; then
+ printf '%s\n' "$desktop_file already exists. Remove or rename it before installing Filee."
+ exit 1
+ fi
++ if [ "$is_gnome" = true ] && [ -d "$gnome_extension_source" ] && { [ -e "$gnome_extension_dir" ] || [ -L "$gnome_extension_dir" ]; }; then
++ printf '%s\n' "A GNOME extension already exists at $gnome_extension_dir. Remove or rename it before installing Filee."
++ exit 1
++ fi
+
+ mkdir -p "$data_dir/filee" "$bin_dir" "$data_dir/applications"
+ cp -R "$source_dir" "$install_dir"
+ printf '%s\n' 'com.filee.app' > "$install_dir/.filee-package"
+ rm -f "$install_dir/.filee-upgrade-token"
+ ln -s "$install_dir/filee-cli" "$bin_dir/filee"
++ if [ "$is_gnome" = true ] && [ -d "$gnome_extension_source" ]; then
++ mkdir -p "$(dirname "$gnome_extension_dir")"
++ cp -R "$install_dir/gnome/$gnome_extension_id" "$gnome_extension_dir"
++ printf '%s\n' 'com.filee.app' > "$gnome_extension_dir/.filee-package"
++ if command -v gsettings >/dev/null 2>&1; then
++ enabled=$(gsettings get org.gnome.shell enabled-extensions 2>/dev/null || true)
++ if [ -n "$enabled" ]; then
++ updated=$(python3 - "$enabled" "$gnome_extension_id" <<'PY'
+import ast
+import sys
+
+try:
+ extensions = ast.literal_eval(sys.argv[1].removeprefix("@as "))
+except (SyntaxError, ValueError):
+ raise SystemExit(0)
+if not isinstance(extensions, list) or not all(isinstance(item, str) for item in extensions):
+ raise SystemExit(0)
+if sys.argv[2] not in extensions:
+ extensions.append(sys.argv[2])
+print("[" + ", ".join("'" + item.replace("'", "\\'") + "'" for item in extensions) + "]")
+PY
- )
- if [ -n "$updated" ]; then
- gsettings set org.gnome.shell enabled-extensions "$updated" >/dev/null 2>&1 || true
++ )
++ if [ -n "$updated" ]; then
++ gsettings set org.gnome.shell enabled-extensions "$updated" >/dev/null 2>&1 || true
++ fi
++ fi
++ fi
++ fi
+ else
+ # Upgrade existing installation: verify it is genuine and safely swap in place.
+ if [ ! -d "$install_dir" ] || [ -L "$install_dir" ]; then
+ printf '%s\n' "No existing installation found at $install_dir to upgrade." >&2
+ exit 1
+ fi
+
+ marker_file="$install_dir/.filee-package"
+ if [ ! -f "$marker_file" ]; then
+ printf '%s\n' "Cannot upgrade: $install_dir is missing the .filee-package marker." >&2
+ exit 1
+ fi
+
+ marker=$(tr -d '\r\n' < "$marker_file" 2>/dev/null || true)
+ if [ "$marker" != "com.filee.app" ]; then
+ printf '%s\n' "Cannot upgrade: $install_dir was not installed by Filee." >&2
+ exit 1
+ fi
+
+ # Tell running instance to save and exit cleanly before touching files.
+ if [ -x "$install_dir/Filee" ]; then
+ if ! "$install_dir/Filee" --quit; then
+ printf '%s\n' "Could not gracefully shut down the running Filee instance. Please exit Filee and try again." >&2
+ exit 1
+ fi
+ fi
+
+ # Generate a unique transaction ID for this upgrade session using PID and random bytes.
+ # This prevents collisions with any concurrent installer or pre-existing backup artifacts.
+ token_rand=$(od -vN 8 -An -tx1 /dev/urandom 2>/dev/null | tr -d ' \n' || true)
+ tx_id="$$-${token_rand:-$(date +%s)}"
+ staging_dir="$data_dir/filee/.staging-$tx_id"
+ backup_dir="$data_dir/filee/.backup-$tx_id"
+ failed_dir="$data_dir/filee/.failed-$tx_id"
+ upgrade_token="filee-upgrade-$tx_id"
+ activated=0
+
+ # Ensure transaction paths are completely distinct and do not collide with pre-existing files.
+ if [ -e "$staging_dir" ] || [ -e "$backup_dir" ] || [ -e "$failed_dir" ]; then
+ printf '%s\n' "Transaction path conflict detected at $data_dir/filee. Please retry." >&2
+ exit 1
+ fi
+
+ mkdir -p "$data_dir/filee" "$bin_dir" "$data_dir/applications"
+ mkdir "$staging_dir"
+
+ # Copy incoming payload into staging (preserves source_dir without moving/deleting it).
+ cp -R "$source_dir/." "$staging_dir/"
+ printf '%s\n' 'com.filee.app' > "$staging_dir/.filee-package"
+ printf '%s\n' "$upgrade_token" > "$staging_dir/.filee-upgrade-token"
+ chmod +x "$staging_dir/Filee" "$staging_dir/filee-cli"
+
+ # Validate the staged files before moving the existing installation aside.
+ if [ ! -x "$staging_dir/Filee" ] || [ ! -x "$staging_dir/filee-cli" ]; then
+ rm -rf "$staging_dir"
+ printf '%s\n' "Staged payload validation failed." >&2
+ exit 1
+ fi
+
+ # Rollback trap: handles catchable signals and script aborts.
+ # Ensures $backup_dir is restored if anything fails during replacement.
+ rollback_and_cleanup() {
+ exit_code=$?
+ if [ -d "$backup_dir" ]; then
+ # If new files were activated into $install_dir, verify that $install_dir
+ # actually contains this run's upgrade token before moving it aside.
+ # This prevents another process or symlink swap from causing cleanup
+ # to remove anything other than this process's failed payload.
+ if [ "$activated" -eq 1 ] && [ -d "$install_dir" ] && [ ! -L "$install_dir" ]; then
+ token_file="$install_dir/.filee-upgrade-token"
+ if [ -f "$token_file" ] && [ ! -L "$token_file" ]; then
+ token=$(tr -d '\r\n' < "$token_file" 2>/dev/null || true)
+ if [ "$token" = "$upgrade_token" ]; then
+ # Token verified: safely move the failed payload aside to quarantine.
+ # Ensure $failed_dir does not already exist so mv performs a clean rename,
+ # and never fall back to recursive deletion if quarantine move fails.
+ if [ ! -e "$failed_dir" ] && mv "$install_dir" "$failed_dir" 2>/dev/null; then
+ # Re-verify token inside quarantined directory before deletion (TOCTOU mitigation).
+ # If ownership, symlink checks, or token match fail, keep $failed_dir intact.
+ q_token_file="$failed_dir/.filee-upgrade-token"
+ if [ -d "$failed_dir" ] && [ ! -L "$failed_dir" ] && [ -f "$q_token_file" ] && [ ! -L "$q_token_file" ]; then
+ q_token=$(tr -d '\r\n' < "$q_token_file" 2>/dev/null || true)
+ if [ "$q_token" = "$upgrade_token" ]; then
+ rm -rf "$failed_dir" 2>/dev/null || true
+ fi
+ fi
+ fi
+ fi
+ fi
+ fi
+
+ if [ ! -d "$install_dir" ] && mv "$backup_dir" "$install_dir" 2>/dev/null; then
+ printf '%s\n' "Update failed. Restored the previous Filee installation." >&2
+ if [ -d "$failed_dir" ]; then
+ printf '%s\n' "Quarantined failed update files preserved at: $failed_dir" >&2
+ fi
+ else
+ printf '%s\n' "CRITICAL: Update failed and automatic rollback could not complete." >&2
+ printf '%s\n' "Your previous installation is preserved at: $backup_dir" >&2
+ if [ -d "$install_dir" ]; then
+ printf '%s\n' "A partial or invalid directory exists at: $install_dir" >&2
+ printf '%s\n' "To restore manually, inspect and remove or rename '$install_dir', then run:" >&2
+ printf '%s\n' " mv '$backup_dir' '$install_dir'" >&2
+ else
+ printf '%s\n' "To restore manually, run: mv '$backup_dir' '$install_dir'" >&2
+ fi
+ if [ -d "$failed_dir" ]; then
+ printf '%s\n' "Quarantined failed update files preserved at: $failed_dir" >&2
+ fi
fi
fi
+ rm -rf "$staging_dir" 2>/dev/null || true
+ exit "$exit_code"
+ }
+ trap rollback_and_cleanup EXIT INT TERM HUP
+
+ # Note on atomicity and crash recovery:
+ # Individual filesystem renames (rename syscall) are atomic in POSIX.
+ # However, replacing a non-empty directory on Linux requires two renames:
+ # 1. mv "$install_dir" "$backup_dir"
+ # 2. mv "$staging_dir" "$install_dir"
+ # The two-step sequence as a whole is not a single atomic transaction.
+ # There is a brief window between step 1 and step 2 where $install_dir does
+ # not exist. Catchable signals (SIGINT, SIGTERM, SIGHUP) and script errors
+ # are handled by the rollback trap above, which immediately restores $backup_dir.
+ # If uncatchable termination (SIGKILL) or sudden hardware power loss occurs
+ # during this brief window, automatic traps cannot run; the previous installation
+ # remains safe in $backup_dir and can be restored manually.
+
+ # Move active installation to backup.
+ mv "$install_dir" "$backup_dir"
+
+ # Activate new installation from staging.
+ if ! mv "$staging_dir" "$install_dir"; then
+ exit 1
+ fi
+ activated=1
+
+ # Post-swap validation: ensure new installation is active and healthy.
+ if [ ! -x "$install_dir/Filee" ] || [ ! -x "$install_dir/filee-cli" ] || [ ! -f "$install_dir/.filee-package" ]; then
+ printf '%s\n' "Activated installation failed post-swap validation. Rolling back..." >&2
+ exit 1
fi
+
+ # Success: disarm the rollback trap before removing the old version backup.
+ trap - EXIT INT TERM HUP
+ rm -rf "$backup_dir"
+ rm -f "$install_dir/.filee-upgrade-token"
+
+ # Refresh launcher symlink (using -f to overwrite existing link atomically).
+ ln -sf "$install_dir/filee-cli" "$bin_dir/filee"
fi
+
+ # Update desktop launcher.
python3 - "$install_dir" "$desktop_file" <<'PY'
import pathlib
import sys
@@@ -85,11 -242,13 +281,17 @@@ desktop.write_text
f'Icon={desktop_value(app / "filee.png")}\n'
'Terminal=false\nCategories=Utility;\nX-Filee-Managed=true\n', encoding='utf-8')
PY
+
if command -v update-desktop-database >/dev/null 2>&1; then
- update-desktop-database "$data_dir/applications"
+ update-desktop-database "$data_dir/applications" 2>/dev/null || true
+ fi
+
+ if [ "$upgrade" -eq 1 ]; then
+ printf '%s\n' "Upgraded Filee at $install_dir."
+ else
+ printf '%s\n' "Installed Filee at $install_dir" "CLI: $bin_dir/filee (add $bin_dir to PATH if needed)."
fi
- printf '%s\n' "Installed Filee at $install_dir" "CLI: $bin_dir/filee (add $bin_dir to PATH if needed)."
+
- if [ "$is_gnome" = true ] && [ -d "$gnome_extension_source" ]; then
++if [ "$upgrade" -eq 0 ] && [ "$is_gnome" = true ] && [ -d "$gnome_extension_source" ]; then
+ printf '%s\n' 'GNOME Wayland: enable "Filee donut at the cursor" in Extensions.' 'Sign out and sign in if the extension is not listed yet. Then hold Ctrl and drag a file in Files.' 'No administrator access or input group is required. See GNOME-WAYLAND.md.'
+fi