-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·131 lines (115 loc) · 4.09 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·131 lines (115 loc) · 4.09 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
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env bash
# Cloud Drive Sync installer
# Usage: curl -fsSL https://raw.githubusercontent.com/ciberkids/cloud-drive-sync/main/install.sh | bash
set -euo pipefail
REPO="ciberkids/cloud-drive-sync"
INSTALL_DIR="$HOME/.local/bin"
SERVICE_DIR="$HOME/.config/systemd/user"
info() { printf '\033[1;34m[info]\033[0m %s\n' "$*"; }
warn() { printf '\033[1;33m[warn]\033[0m %s\n' "$*"; }
error() { printf '\033[1;31m[error]\033[0m %s\n' "$*" >&2; exit 1; }
# ---------- detect distro ----------
detect_distro() {
if [ -f /etc/os-release ]; then
. /etc/os-release
case "$ID" in
fedora|rhel|centos|rocky|alma) echo "rpm" ;;
ubuntu|debian|pop|linuxmint) echo "deb" ;;
*) echo "other" ;;
esac
else
echo "other"
fi
}
# ---------- fetch latest release tag ----------
latest_tag() {
curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" \
| grep '"tag_name"' \
| head -1 \
| sed -E 's/.*"tag_name":\s*"([^"]+)".*/\1/'
}
# ---------- download a release asset by pattern ----------
download_asset() {
local tag="$1" pattern="$2" dest="$3"
local assets_url="https://api.github.com/repos/$REPO/releases/tags/$tag"
local url
url=$(curl -fsSL "$assets_url" \
| grep '"browser_download_url"' \
| grep "$pattern" \
| head -1 \
| sed -E 's/.*"browser_download_url":\s*"([^"]+)".*/\1/')
[ -z "$url" ] && error "Could not find release asset matching '$pattern'"
info "Downloading $url"
curl -fsSL -o "$dest" "$url"
}
# ---------- install daemon ----------
install_daemon() {
local tag="$1"
mkdir -p "$INSTALL_DIR"
download_asset "$tag" "cloud-drive-sync-daemon" "$INSTALL_DIR/cloud-drive-sync-daemon"
chmod +x "$INSTALL_DIR/cloud-drive-sync-daemon"
info "Daemon installed to $INSTALL_DIR/cloud-drive-sync-daemon"
}
# ---------- install UI ----------
install_ui() {
local tag="$1" distro="$2"
local tmpdir
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT
case "$distro" in
deb)
download_asset "$tag" ".deb" "$tmpdir/cloud-drive-sync.deb"
info "Installing .deb package (requires sudo)"
sudo dpkg -i "$tmpdir/cloud-drive-sync.deb" || sudo apt-get install -f -y
;;
rpm)
download_asset "$tag" ".rpm" "$tmpdir/cloud-drive-sync.rpm"
info "Installing .rpm package (requires sudo)"
sudo rpm -U --force "$tmpdir/cloud-drive-sync.rpm"
;;
*)
download_asset "$tag" ".AppImage" "$INSTALL_DIR/cloud-drive-sync-ui.AppImage"
chmod +x "$INSTALL_DIR/cloud-drive-sync-ui.AppImage"
info "AppImage installed to $INSTALL_DIR/cloud-drive-sync-ui.AppImage"
;;
esac
}
# ---------- install systemd service ----------
install_service() {
local tag="$1"
mkdir -p "$SERVICE_DIR"
download_asset "$tag" "cloud-drive-sync-daemon.service" "$SERVICE_DIR/cloud-drive-sync-daemon.service"
systemctl --user daemon-reload
systemctl --user enable cloud-drive-sync-daemon
info "Systemd user service enabled (start with: systemctl --user start cloud-drive-sync-daemon)"
}
# ---------- ensure ~/.local/bin is on PATH ----------
ensure_path() {
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*)
warn "$INSTALL_DIR is not on your PATH"
warn "Add this to your shell profile: export PATH=\"\$HOME/.local/bin:\$PATH\""
;;
esac
}
# ---------- main ----------
main() {
info "Cloud Drive Sync installer"
local distro
distro=$(detect_distro)
info "Detected package format: $distro"
local tag
tag=$(latest_tag)
[ -z "$tag" ] && error "Could not determine latest release"
info "Latest release: $tag"
install_daemon "$tag"
install_ui "$tag" "$distro"
install_service "$tag"
ensure_path
echo
info "Installation complete!"
info "Start the daemon: systemctl --user start cloud-drive-sync-daemon"
info "Open the UI: cloud-drive-sync-ui (or launch from your app menu)"
}
main "$@"