Skip to content

Commit ae7deef

Browse files
author
KillerZ
committed
feat: installer
1 parent 3f88f88 commit ae7deef

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

installer/installer.sh

100644100755
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
#!/bin/bash
2+
33

44
if [ $(id -u) -ne 0 ]; then
55
echo -e "\e[31mERROR: Not root user\e[0m"
@@ -14,19 +14,20 @@ RAW_REPO="$RAW_PREFIX/$REPO"
1414
BASE_PATH=/opt/py-openbmclapi
1515
USERNAME=openbmclapi
1616
PY_MIRCO=3.10
17-
if ! PY_VERSION=$(python -V 2>&1|awk '{print $2}') ; then
17+
if ! PY_VERSION=$(python -V 2>&1|awk '{print $2}') && $(python -V 2>&1|awk '{print $2}'|awk -F '.' '{print $1}') -lt 3 ; then
1818
echo -e "\e[31mERROR: Failed to detect python version\e[0m"
1919
exit 1
2020
fi
21-
22-
different=$(echo 2>&1 | awk "{print $PY_VERSION-$PY_MIRCO}")
23-
compare=$(expr $different \> 0)
24-
if [[ $compare -eq 1 ]] ; then
21+
PY_VERSION=$(python -V 2>&1|awk '{print $2}'|awk -F '.' '{print $1}').$(python -V 2>&1|awk '{print $2}'|awk -F '.' '{print $2}')
22+
different=$(echo 2>&1 | awk "{print $PY_VERSION - $PY_MIRCO}")
23+
compare=$(expr "$different" \> 0)
24+
printf $compare
25+
if [[ $compare -eq 0 ]] ; then
2526
echo -e "\e[31mERROR: Python version not supported;need >=3.10\e[0m"
2627
exit 1
2728
fi
2829

29-
if ! systemd --version >/dev/null 2>&1 ; then
30+
if ! systemctl --version >/dev/null 2>&1 ; then
3031
echo -e "\e[31mERROR: Failed to test systemd\e[0m"
3132
exit 1
3233
fi
@@ -72,7 +73,7 @@ function fetchBlob(){
7273

7374
echo
7475

75-
if [ -f /usr/lib/systemd/system/go-openbmclapi.service ]; then
76+
if [ -f /usr/lib/systemd/system/py-openbmclapi.service ]; then
7677
echo -e "\e[33m==> WARN: py-openbmclapi.service is already installed, stopping\e[0m"
7778
systemctl disable --now py-openbmclapi.service
7879
fi
@@ -86,11 +87,11 @@ if [ ! -n "$TARGET_TAG" ]; then
8687
echo
8788
fi
8889

89-
fetchBlob service/py-openbmclapi.service /usr/lib/systemd/system/py-openbmclapi.service 0644 || exit $?
90+
fetchBlob installer/py-openbmclapi.service /usr/lib/systemd/system/py-openbmclapi.service 0644 || exit $?
9091

9192
[ -d "$BASE_PATH" ] || { mkdir -p "$BASE_PATH" && chmod 0755 "$BASE_PATH" && chown $USERNAME "$BASE_PATH"; } || exit $?
9293

93-
# fetchBlob service/start-server.sh "$BASE_PATH/start-server.sh" 0755 || exit $?
94+
fetchBlob installer/start.sh "$BASE_PATH/start.sh" 0755 || exit $?
9495
# fetchBlob service/stop-server.sh "$BASE_PATH/stop-server.sh" 0755 || exit $?
9596
# fetchBlob service/reload-server.sh "$BASE_PATH/reload-server.sh" 0755 || exit $?
9697

@@ -106,8 +107,8 @@ systemctl enable py-openbmclapi.service || exit $?
106107
echo -e "
107108
================================ Install successed ================================
108109
109-
Use 'systemctl start go-openbmclapi.service' to start openbmclapi server
110-
Use 'systemctl stop go-openbmclapi.service' to stop openbmclapi server
111-
Use 'systemctl reload go-openbmclapi.service' to reload openbmclapi server configs
112-
Use 'journalctl -f --output cat -u go-openbmclapi.service' to watch the openbmclapi logs
110+
Use 'systemctl start py-openbmclapi.service' to start openbmclapi server
111+
Use 'systemctl stop py-openbmclapi.service' to stop openbmclapi server
112+
Use 'systemctl reload py-openbmclapi.service' to reload openbmclapi server configs
113+
Use 'journalctl -f --output cat -u py-openbmclapi.service' to watch the openbmclapi logs
113114
"

installer/py-openbmclapi.service

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[Unit]
2+
Description=Py-OpenBmclAPI Service
3+
Documentation=https://github.com/TTB-Network/python-openbmclapi
4+
Wants=basic.target
5+
After=network.target
6+
7+
[Service]
8+
Type=simple
9+
User=openbmclapi
10+
WorkingDirectory=/opt/py-openbmclapi
11+
ExecStart=/opt/py-openbmclapi/start.sh
12+
ExecReload=kill -s HUP $MAINPID
13+
RestartSec=30
14+
Restart=on-failure
15+
TimeoutSec=30
16+
17+
[Install]
18+
WantedBy=multi-user.target

installer/start.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
python3 /opt/py-openbmclapi/main.py

0 commit comments

Comments
 (0)