-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
72 lines (60 loc) · 2.39 KB
/
setup.sh
File metadata and controls
72 lines (60 loc) · 2.39 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
#!/usr/bin/env bash
set -euo pipefail
is_termux() { [[ -n "${PREFIX:-}" && "$PREFIX" == */com.termux/* ]]; }
log(){ printf '%s\n' "$*" >&2; }
# --- Detect platform ---
if is_termux; then
PLATFORM="termux"
else
PLATFORM="ubuntu"
fi
# --- Install deps ---
if [[ "$PLATFORM" == "termux" ]]; then
pkg update -y
pkg install -y bash coreutils yt-dlp ffmpeg aria2 lynx pandoc nodejs xclip || true
termux-setup-storage || true
npm i -g readability-cli || true
else
sudo apt update -y
sudo apt install -y yt-dlp ffmpeg aria2 lynx pandoc xdg-user-dirs xclip wl-clipboard nodejs npm
sudo npm i -g readability-cli || true
xdg-user-dirs-update || true
fi
# --- Install helper ---
mkdir -p "$HOME/.scripts"
cat > "$HOME/.scripts/common.sh" <<"EOF"
#!/usr/bin/env bash
# Common helpers for Termux + Ubuntu
is_termux(){ [[ -n "${PREFIX:-}" && "$PREFIX" == */com.termux/* ]]; }
_xdg_dir(){
local key="$1"
if command -v xdg-user-dir >/dev/null 2>&1; then
xdg-user-dir "$key"
else
case "$key" in
DOCUMENTS) echo "$HOME/Documents" ;;
PICTURES) echo "$HOME/Pictures" ;;
MUSIC) echo "$HOME/Music" ;;
VIDEOS) echo "$HOME/Videos" ;;
DOWNLOAD) echo "$HOME/Downloads" ;;
*) echo "$HOME" ;;
esac
fi
}
documents_dir(){ if is_termux; then echo "$HOME/storage/shared/Documents"; else _xdg_dir DOCUMENTS; fi; }
pictures_dir(){ if is_termux; then echo "$HOME/storage/shared/Pictures"; else _xdg_dir PICTURES; fi; }
music_dir(){ if is_termux; then echo "$HOME/storage/shared/Music"; else _xdg_dir MUSIC; fi; }
videos_dir(){ if is_termux; then echo "$HOME/storage/shared/Movies"; else _xdg_dir VIDEOS; fi; }
downloads_dir(){ if is_termux; then echo "$HOME/storage/shared/Download"; else _xdg_dir DOWNLOAD; fi; }
ensure_dir(){ mkdir -p "$1"; }
clipboard_get(){
if command -v termux-clipboard-get >/dev/null 2>&1; then termux-clipboard-get; return; fi
if command -v wl-paste >/dev/null 2>&1; then wl-paste --no-newline; return; fi
if command -v xclip >/dev/null 2>&1; then xclip -selection clipboard -o 2>/dev/null; return; fi
if command -v xsel >/dev/null 2>&1; then xsel --clipboard --output 2>/dev/null; return; fi
return 1
}
media_scan(){ if command -v termux-media-scan >/dev/null 2>&1; then termux-media-scan "$@"; fi; }
sanitize_filename(){ printf '%s' "$1" | sed 's#[/:*?"<>|]#_#g; s/ \+/_/g'; }
EOF
chmod +x "$HOME/.scripts/common.sh"