-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·122 lines (100 loc) · 3.58 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·122 lines (100 loc) · 3.58 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
#!/usr/bin/env bash
# install.sh — download basyn into /opt/basyn and symlink into /usr/local/sbin
#
# Usage (one-liner):
# curl -fsSL https://raw.githubusercontent.com/stvorl/basyn/master/install.sh | sudo bash
#
# To update later:
# sudo /opt/basyn/install.sh
#
# Files to install are listed in install.lst. Add or remove entries there;
# this script stays untouched.
set -euo pipefail
# === Configuration ===
GH_USER="stvorl"
GH_REPO="basyn"
GH_BRANCH="master"
RAW="https://raw.githubusercontent.com/$GH_USER/$GH_REPO/$GH_BRANCH"
DEST="/opt/basyn"
BIN_DIR="/usr/local/sbin"
SELF="install.sh"
LIST="install.lst"
# === Pre-flight checks (run regardless of phase) ===
if [[ "$(id -u)" != "0" ]]; then
echo "ERROR: This script must be run as root (use sudo)."
exit 1
fi
if ! command -v python3 &>/dev/null; then
echo "ERROR: python3 is not installed."
echo "Install it with your package manager, e.g.:"
echo " apt install python3 (Debian/Ubuntu)"
echo " yum install python3 (RHEL/CentOS)"
echo " pacman -S python (Arch)"
exit 1
fi
echo "python3 found: $(python3 --version)"
if ! command -v curl &>/dev/null; then
echo "ERROR: curl is not installed."
echo "Install it with your package manager, e.g.:"
echo " apt install curl (Debian/Ubuntu)"
echo " yum install curl (RHEL/CentOS)"
echo " pacman -S curl (Arch)"
exit 1
fi
if [[ ! -d "$BIN_DIR" ]]; then
echo "Target directory $BIN_DIR does not exist, creating..."
mkdir -p "$BIN_DIR"
fi
# === Determine phase: are we already inside DEST? ===
# When piped via curl|bash there is no source file → definitely Phase 1.
if [[ -z "${BASH_SOURCE[0]:-}" ]]; then
SCRIPT_DIR=""
else
SCRIPT_PATH="$(realpath "${BASH_SOURCE[0]}")"
SCRIPT_DIR="$(dirname "$SCRIPT_PATH")"
fi
if [[ "$SCRIPT_DIR" != "$DEST" ]]; then
# ============================================================
# PHASE 1: we are NOT in DEST (first run, piped from curl)
# ============================================================
echo "==> Phase 1: bootstrapping into $DEST..."
mkdir -p "$DEST"
echo "==> Downloading $SELF into $DEST..."
curl -fsSL "$RAW/$SELF" -o "$DEST/$SELF"
chmod +x "$DEST/$SELF"
echo "==> Launching phase 2 from $DEST..."
exec "$DEST/$SELF"
# exec replaces the current process — code below never runs
fi
# ============================================================
# PHASE 2: we are already inside DEST
# ============================================================
echo "==> Phase 2: updating files in $DEST..."
# --- Download the file list ---
echo "==> Fetching $LIST..."
curl -fsSL "$RAW/$LIST" -o "$DEST/$LIST"
# --- Download / update every file from the list ---
while IFS= read -r line; do
# Skip empty lines and comments
[[ -z "$line" || "$line" == \#* ]] && continue
read -r mode filename <<< "$line"
[[ -z "$mode" || -z "$filename" ]] && continue
echo "==> Downloading $filename (mode $mode)..."
curl -fsSL "$RAW/$filename" -o "$DEST/$filename"
chmod "$mode" "$DEST/$filename"
# If the file has any executable bit, ensure a symlink in BIN_DIR
dst="$BIN_DIR/$filename"
if (( mode & 0111 )); then
if [[ ! -L "$dst" ]] || [[ "$(readlink "$dst")" != "$DEST/$filename" ]]; then
echo "==> Symlink: $dst -> $DEST/$filename"
rm -f "$dst"
ln -s "$DEST/$filename" "$dst"
else
echo " Symlink OK: $dst"
fi
fi
done < "$DEST/$LIST"
echo ""
echo "==> Installation complete."
echo " Files in $DEST:"
ls -la "$DEST"