-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·120 lines (99 loc) · 4.1 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·120 lines (99 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env bash
#
# Snap2Link Linux installer
# Usage: curl -fsSL https://raw.githubusercontent.com/amys94fr/Snap2Link/main/scripts/install.sh | bash
#
# Detects your distro, downloads the latest release from GitHub, and installs it.
# Falls back to the portable AppImage if no native package fits your system.
set -euo pipefail
REPO="amys94fr/Snap2Link"
APP_NAME="Snap2Link"
GITHUB_API="https://api.github.com/repos/${REPO}/releases/latest"
# ---------- pretty output ----------
if [[ -t 1 ]]; then
BOLD=$'\033[1m'; GREEN=$'\033[32m'; YELLOW=$'\033[33m'; RED=$'\033[31m'; RESET=$'\033[0m'
else
BOLD=""; GREEN=""; YELLOW=""; RED=""; RESET=""
fi
info() { echo "${BOLD}==>${RESET} $*"; }
warn() { echo "${YELLOW}${BOLD}!${RESET} $*" >&2; }
fail() { echo "${RED}${BOLD}✗${RESET} $*" >&2; exit 1; }
ok() { echo "${GREEN}${BOLD}✓${RESET} $*"; }
# ---------- preflight ----------
[[ "$(uname -s)" == "Linux" ]] || fail "This script is for Linux. See README for macOS/Windows."
ARCH="$(uname -m)"
[[ "$ARCH" == "x86_64" ]] || fail "Unsupported architecture: $ARCH (only x86_64 is built today)."
for cmd in curl grep sed; do
command -v "$cmd" >/dev/null 2>&1 || fail "Required command not found: $cmd"
done
# ---------- detect package manager ----------
PKG_KIND=""
if command -v apt-get >/dev/null 2>&1; then PKG_KIND="deb"
elif command -v dnf >/dev/null 2>&1; then PKG_KIND="rpm"
elif command -v zypper >/dev/null 2>&1; then PKG_KIND="rpm"
else PKG_KIND="appimage"
fi
info "Detected package format: ${BOLD}${PKG_KIND}${RESET}"
# ---------- pick the right asset ----------
case "$PKG_KIND" in
deb) ASSET_PATTERN='_amd64\.deb$' ;;
rpm) ASSET_PATTERN='\.x86_64\.rpm$' ;;
appimage) ASSET_PATTERN='_amd64\.AppImage$' ;;
esac
info "Fetching latest release info from GitHub…"
RELEASE_JSON="$(curl -fsSL "$GITHUB_API")" || fail "Could not reach GitHub API."
ASSET_URL="$(echo "$RELEASE_JSON" \
| grep -oE '"browser_download_url": *"[^"]+"' \
| sed -E 's/.*"(https[^"]+)".*/\1/' \
| grep -E "$ASSET_PATTERN" \
| head -n 1)"
[[ -n "${ASSET_URL:-}" ]] || fail "No matching asset found for pattern: $ASSET_PATTERN"
ASSET_NAME="$(basename "$ASSET_URL")"
VERSION="$(echo "$RELEASE_JSON" | grep -oE '"tag_name": *"[^"]+"' | sed -E 's/.*"([^"]+)".*/\1/')"
ok "Found ${BOLD}${APP_NAME} ${VERSION}${RESET} → ${ASSET_NAME}"
# ---------- download ----------
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
info "Downloading…"
curl -fL --progress-bar -o "${TMP_DIR}/${ASSET_NAME}" "$ASSET_URL"
ok "Downloaded to ${TMP_DIR}/${ASSET_NAME}"
# ---------- install ----------
need_sudo() {
if [[ "$EUID" -eq 0 ]]; then echo ""; else echo "sudo"; fi
}
case "$PKG_KIND" in
deb)
SUDO="$(need_sudo)"
info "Installing with apt (will resolve dependencies automatically)…"
$SUDO apt-get update -qq || warn "apt-get update failed, continuing anyway"
$SUDO apt-get install -y "${TMP_DIR}/${ASSET_NAME}"
ok "Installed. Launch with: ${BOLD}snap2link${RESET} (or find it in your app menu)"
;;
rpm)
SUDO="$(need_sudo)"
if command -v dnf >/dev/null 2>&1; then
info "Installing with dnf…"
$SUDO dnf install -y "${TMP_DIR}/${ASSET_NAME}"
else
info "Installing with zypper…"
$SUDO zypper --non-interactive install --allow-unsigned-rpm "${TMP_DIR}/${ASSET_NAME}"
fi
ok "Installed. Launch with: ${BOLD}snap2link${RESET} (or find it in your app menu)"
;;
appimage)
INSTALL_DIR="${HOME}/.local/bin"
mkdir -p "$INSTALL_DIR"
DEST="${INSTALL_DIR}/snap2link.AppImage"
mv "${TMP_DIR}/${ASSET_NAME}" "$DEST"
chmod +x "$DEST"
ok "Installed to ${BOLD}${DEST}${RESET}"
if ! echo ":$PATH:" | grep -q ":${INSTALL_DIR}:"; then
warn "${INSTALL_DIR} is not in your PATH. Add this to your shell rc file:"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
echo " Launch with: ${BOLD}snap2link.AppImage${RESET}"
warn "Tray icon needs libayatana-appindicator3-1 — install it via your package manager if missing."
;;
esac
echo
ok "Done. First launch will prompt you to connect Google Drive."