-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·90 lines (65 loc) · 1.96 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
ZDSM_HOME="/var/srv/zdsm"
ZDSM_USER="zdsm-user"
info() {
echo -e "\x1b[38;2;57;62;65m[$(date +"%T")]\x1b[0m \x1b[38;2;86;164;255mINFO\x1b[0m \t-- $*"
}
error() {
echo -e "\x1b[38;2;57;62;65m[$(date +"%T")]\x1b[0m \x1b[38;2;246;96;96mERROR\x1b[0m \t-- $*"
exit 1
}
warn() {
echo -e "\x1b[38;2;57;62;65m[$(date +"%T")]\x1b[0m \x1b[38;2;255;237;129mWARN\x1b[0m \t-- $*"
}
success() {
echo -e "\x1b[38;2;179;255;114m✓\x1b[0m Sucessfully installed.\n"
}
checkIfRoot() {
if [ "$EUID" -eq 0 ]; then
error This script cannot be ran as root ! You\'ll ve prompted for sudo when needed.
fi
}
checkIfCurlInstalled() {
if ! command -v curl >/dev/null 2>&1; then
error "Curl wasn't found on this system, please make sure it is installed correctly and retry."
fi
}
installSystemService() {
if ! command -v systemctl >/dev/null 2>&1; then
warn "Looks like you are not using systemD, you will have to create your system service by yourself !"
info "Here's some helpfull informations:"
info "User: ${ZDSM_USER}"
info "Home: ${ZDSM_HOME}"
info "Executable: ${ZDSM_HOME}/zdsm"
info "Config file: ${ZDSM_HOME}/.env"
else
info "Creating service file"
echo "[Unit]
Description=ZDSM unit service
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=1
User=${ZDSM_USER}
ExecStart=${ZDSM_HOME}/zdsm
WorkingDirectory=${ZDSM_HOME}
[Install]
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/zdsm.service
fi
}
main() {
checkIfRoot
checkIfCurlInstalled
info "Adding user ${ZDSM_USER}"
sudo mkdir -p ${ZDSM_HOME}
sudo useradd -rUb ${ZDSM_HOME} ${ZDSM_USER}
info "Downloading ZDSM@latest"
curl -L https://github.com/0x454d505459/ZDSM/releases/latest/download/zdsm --output /tmp/zdsm
sudo mv /tmp/zdsm ${ZDSM_HOME}
sudo chown -R ${ZDSM_USER}:${ZDSM_USER} ${ZDSM_HOME}
sudo chmod 755 ${ZDSM_USER}:${ZDSM_USER} ${ZDSM_HOME}
installSystemService
success
}
main