forked from cesarcap49/releases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
171 lines (145 loc) · 4.42 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
if [[ $1 == "--uninstall" ]]; then
echo "Trying to remove autodarts"
sudo systemctl stop autodarts
sudo systemctl disable autodarts
sudo rm /etc/systemd/system/autodarts.service
sudo rm /etc/systemd/system/autodartsupdater.service
rm ~/.local/bin/autodarts
rm ~/.local/bin/update.sh
exit
fi
AUTOSTART="true"
AUTOUPDATE="true"
while getopts "nu" OPTION; do
case "${OPTION}" in
n)
AUTOSTART="false"
;;
u)
AUTOUPDATE="false"
;;
*)
AUTOSTART="true"
AUTOUPDATE="true"
;;
esac
done
shift "$(($OPTIND -1))"
PLATFORM=$(uname)
if [[ "$PLATFORM" = "Linux" ]]; then
PLATFORM="linux"
elif [[ "$PLATFORM" = "Darwin" ]]; then
PLATFORM="darwin"
else
echo "Platform is not 'linux', and hence is not supported by this script." && exit 1
fi
ARCH=$(uname -m)
case "${ARCH}" in
"x86_64"|"amd64") ARCH="amd64";;
"aarch64"|"arm64") ARCH="arm64";;
"armv7l") ARCH="armv7l";;
*) echo "Kernel architecture '${ARCH}' is not supported." && exit 1;;
esac
REQ_VERSION=$1
REQ_VERSION="${REQ_VERSION#v}"
if [[ "$REQ_VERSION" = "" ]]; then
VERSION=$(curl -sL https://api.github.com/repos/autodarts/releases/releases/latest | grep tag_name | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+')
echo "Installing latest version v${VERSION}."
else
VERSION=$(curl -sL https://api.github.com/repos/autodarts/releases/releases | grep tag_name | grep ${REQ_VERSION} | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+\(-\(beta\|rc\)[0-9]\+\)\?' | head -1)
if [[ "$VERSION" = "" ]]; then
echo "Requested version v${REQ_VERSION} not found." && exit 1
fi
echo "Installing requested version v${VERSION}."
fi
# Download autodarts binary and unpack to ~/.local/bin
mkdir -p ~/.local/bin
echo "Downloading and extracting 'autodarts${VERSION}.${PLATFORM}-${ARCH}.tar.gz' into '~/.local/bin'."
curl -sL https://github.com/autodarts/releases/releases/download/v${VERSION}/autodarts${VERSION}.${PLATFORM}-${ARCH}.tar.gz | tar -xz -C /usr/local/bin
echo "Making /usr/local/bin/autodarts executable."
chmod +x /usr/local/bin/autodarts
curl -sL https://raw.githubusercontent.com/autodarts/releases/main/updater.sh > /usr/local/bin/updater.sh
chmod +x /usr/local/bin/updater.sh
if [[ ${AUTOUPDATE} = "true" && "$PLATFORM" = "linux" ]]; then
# Create systemd service
echo "Creating systemd service for autodarts auto updater to run on system startup."
echo "We will need sudo access to do that."
if [[ ${USER} = "root" ]]; then
cat <<EOF | sudo tee /etc/systemd/system/autodartsupdater.service >/dev/null
# autodartsupdater.service
[Unit]
Description=Autodarts automatic updater.
Wants=network.target
After=network.target
[Service]
Type=simple
User=${USER}
ExecStart=/usr/local/bin/updater.sh
[Install]
WantedBy=multi-user.target
EOF
else
cat <<EOF | sudo tee /etc/systemd/system/autodartsupdater.service >/dev/null
# autodartsupdater.service
[Unit]
Description=Autodarts automatic updater.
Wants=network.target
After=network.target
[Service]
Type=simple
User=${USER}
ExecStart=/usr/local/bin/updater.sh
[Install]
WantedBy=multi-user.target
EOF
fi
echo "Enabling systemd service for automatic updates."
sudo systemctl enable autodartsupdater
fi
if [[ ${AUTOSTART} = "true" && "$PLATFORM" = "linux" ]]; then
# Create systemd service
echo "Creating systemd service for autodarts to start on system startup."
echo "We will need sudo access to do that."
if [[ ${USER} = "root" ]]; then
cat <<EOF | sudo tee /etc/systemd/system/autodarts.service >/dev/null
# autodarts.service
[Unit]
Description=Start/Stop Autodarts board service
Wants=network.target
After=network.target
[Service]
User=${USER}
ExecStart=/usr/local/bin/autodarts
Restart=on-failure
KillSignal=SIGINT
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF
else
cat <<EOF | sudo tee /etc/systemd/system/autodarts.service >/dev/null
# autodarts.service
[Unit]
Description=Start/Stop Autodarts board service
Wants=network.target
After=network.target
[Service]
User=${USER}
ExecStart=/usr/local/bin/autodarts
Restart=on-failure
KillSignal=SIGINT
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF
fi
echo "Adding the current user to the group video"
sudo usermod -aG ${USER} video
echo "Enabling systemd service."
sudo systemctl enable autodarts
echo "Starting autodarts."
sudo systemctl stop autodarts
sudo systemctl start autodarts
fi
echo "Done."