-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
executable file
·73 lines (63 loc) · 1.68 KB
/
install.sh
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
#!/usr/bin/env bash
# shellcheck disable=SC2016
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
echo "Installs CLN scripts."
echo "Usage: $(basename "$0")"
exit
fi
PREFIX="/opt/cln-scripts"
if [[ "$(whoami)" == "root" ]]; then
sudo=""
else
sudo="sudo"
fi
cd "$(dirname "$0")" || exit 1
$sudo mkdir -p "$PREFIX"
echo -n "Installing inc.common.sh..."
$sudo install -p -t "$PREFIX" -m 644 ./inc.common.sh
echo ""
SCRIPT_LIST="
amboss-ping
channelbalance
feereport
prune-protector
routing-summary
random-traffic-gen
walletbalance
"
for script in $SCRIPT_LIST; do
echo -n "Installing cln-$script..."
$sudo install -p -t "$PREFIX" "./cln-$script.sh"
$sudo ln -f -s "$PREFIX/cln-$script.sh" "/usr/local/bin/cln-$script"
echo ""
done
echo -n "Creating cln-uninstall..."
$sudo bash -c 'cat <<EOF > '"$PREFIX/cln-uninstall.sh"'
#!/usr/bin/env bash
if [[ "\$(whoami)" == "root" ]]; then
sudo=""
else
sudo="sudo"
fi
PREFIX="'"$PREFIX"'"
SCRIPT_LIST="'"$SCRIPT_LIST"'"
read -n 1 -p "This will uninstall cln-scripts from \$PREFIX. Are you sure? (y/N) "
echo ""
if [[ \${REPLY} =~ y|Y ]]; then
for script in \$SCRIPT_LIST; do
echo -n "Uninstalling cln-\$script..."
\$sudo unlink /usr/local/bin/cln-\$script
\$sudo rm -f "\$PREFIX/cln-\$script.sh"
echo ""
done
echo "Clean up rest..."
\$sudo rm -f "\$PREFIX/inc.common.sh"
\$sudo unlink /usr/local/sbin/cln-uninstall
\$sudo rm -f "\$PREFIX/cln-uninstall.sh"
\$sudo rmdir "\$PREFIX" 2> /dev/null
echo "Done."
fi
EOF'
$sudo chmod +x "$PREFIX/cln-uninstall.sh"
$sudo ln -f -s "$PREFIX/cln-uninstall.sh" /usr/local/sbin/cln-uninstall
echo "Done."