-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.sh
executable file
·113 lines (99 loc) · 2.59 KB
/
config.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
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
#!/usr/bin/env bash
exe="changelogger"
install_dir="/usr/bin"
uninstall() {
sudo rm -rf "$install_dir/$exe"
echo "[INFO] Application uninstalled successfully."
}
install_exe() {
if ! sudo cp -f "$1" "$install_dir/$2"; then
echo "[ERRO] Failed to copy the executable to $install_dir"
exit 1
fi
echo "[INFO] $2 installed successfully."
}
install_clparse() {
curl -sLO https://github.com/marcaddeo/clparse/releases/download/0.9.1/clparse-0.9.1-x86_64-unknown-linux-musl.tar.gz
tar xzvf clparse-0.9.1-x86_64-unknown-linux-musl.tar.gz
sudo mv clparse /usr/bin/clparse
rm clparse-0.9.1-x86_64-unknown-linux-musl.tar.gz
}
install() {
echo "[WARN] Make sure you have the sqlite3.h, cjson.h, and yaml.h files in PATH (generally in /usr/include)."
if [ ! -f "/usr/bin/clparse" ]; then
install_clparse
fi
if [ -f "$exe" ]; then
install_exe "$exe" "$exe"
echo "[INFO] Installation completed successfully."
else
echo "[WARN] $exe is not built. Building..."
if make RELEASE=1; then
install_exe "$exe" "$exe"
echo "[INFO] Installation completed successfully."
else
echo "[ERRO] Failed to build $exe"
exit 1
fi
fi
if [ -d "$HOME/changelogger" ]; then
rm -rf "$HOME/changelogger"
fi
}
fetch() {
if [ -d "$HOME/changelogger" ]; then
echo "[ERRO] Directory $HOME/changelogger already exists."
echo "[INFO] Remove it or use 'update' to fetch the latest version."
exit 1
fi
git clone https://github.com/KDesp73/changelogger --depth=1 "$HOME/changelogger"
cd "$HOME/changelogger" || exit 1
}
update() {
cd "$HOME" || exit 1
rm -rf "$HOME/changelogger"
fetch
install
}
help() {
cat <<EOF
USAGE
config.sh <commands>...
COMMANDS
install Installs the executable
uninstall Uninstalls the executable
update Updates to the latest version
fetch Fetches the latest version
help Prints this message
EOF
}
if [ $# -eq 0 ]; then
echo "[ERRO] Specify at least one command" 1>&2
help
exit 1
fi
# Process all commands passed as arguments
for arg in "$@"; do
case "$arg" in
"uninstall")
uninstall
;;
"update")
update
;;
"fetch")
fetch
;;
"install")
install
;;
"help")
help
;;
*)
echo "[ERRO] Unknown command: $arg"
help
exit 1
;;
esac
done