-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·174 lines (139 loc) · 4.11 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
172
173
174
#!/bin/bash
#
# Install, enable and run the smax-scripts.service with systemd
#
# This installer should be run as root/with sudo permissions
#
# Paul Grimes
# 04/18/2023
#
# Attila Kovacs
# 09/26/2024
#
set -e
if [[ $1 =~ ^(help|--help|-h|-\?)$ ]] ; then
echo
echo " Syntax: sudo ./install.sh [mode]"
echo
echo " Option [mode]:"
echo
echo " auto Automatic installation, and start-up"
echo " sma Automatic installation for use at the SMA"
echo " help this help screen"
echo
echo " Environment:"
echo
echo " DESTDIR Deployment root (default: '/usr')"
echo " PREFIX Staging prefix (no start-up if not empty)"
echo
exit 0
fi
if [ $EUID -ne 0 ] ; then
echo "Please run as root"
exit 1
fi
# Deployment root
if [ "$DESTDIR" == "" ] ; then
DESTDIR="/usr"
fi
# Staging root
if [ "$PREFIX" == "" ] ; then
STAGE=$DESTDIR
else
STAGE=$PREFIX/$DESTDIR
fi
# Create /usr/share/smax and its lua/ sub-directory
SMAX="$STAGE/share/smax"
SYSTEMD="$PREFIX/etc/systemd/system"
# ============================================================================
# Part 1: copying things in place
# Copy LUA script over to /usr/share/smax
echo ". Creating $SMAX/lua directory"
mkdir -p $SMAX/lua
echo ". Copying LUA scripts to $SMAX/lua"
install -m 644 -D lua/* $SMAX/lua/
# install script loader and systemd unit file
echo ". Copying script loader to $STAGE/bin"
install -m 755 smax-init.sh $STAGE/bin/
echo ". Setting DESTDIR in script loader"
sed -i "s:/usr:$DESTDIR:g" $STAGE/bin/smax-init.sh
echo ". Copying systemd sevice unit to $SYSTEMD"
install -m 644 smax-scripts.service $SYSTEMD/
echo ". Setting DESTDIR in systemd service unit"
sed -i "s:/usr:$DESTDIR:g" $SYSTEMD/smax-scripts.service
if [[ ! $1 =~ ^(sma|SMA)$ ]] ; then
echo ". Removing SMA-specific sections from scripts"
sed -i '/^.*BEGIN SMA.*/,/^.*END SMA.*/d' $SMAX/lua/*.lua
fi
# Register smax-scripts with systemd
echo ". Reloading systemd daemon"
systemctl daemon-reload
if [ "$PREFIX" != "" ] ; then
echo "PREFIX is set, staging only."
echo "Done."
exit 0
fi
# ============================================================================
# Part 2: starting things up
# Checking for systemd...
echo "Checking for systemctl..."
which systemctl >> /dev/null 2>&1
# Don't exit on error return while we check variants
set +e
# On some distros the service is redis, on others is redis-server...
for name in 'redis-server' 'redis' 'valkey-server' 'valkey' ; do
systemctl status $name > /dev/null 2>&1;
if [ $? -eq 0 ] ; then
REDIS=$name;
break
fi
done
# Back to exit on error...
set -e
if [ "$REDIS" == "" ] ; then
echo "ERROR! You must install redis or valkey or equivalent..."
exit 2
fi
if [ "$REDIS" != "redis" ] ; then
echo "Updating systemd service name to $REDIS.service"
sed -i "s:redis.service:$REDIS.service:g" $SYSTEMD/smax-scripts.service
fi
START_SMAX=1
ENABLE_SMAX=1
# if you call the script with a single argument 'auto', then it will install
# a default without asking any questions. (Without the option, the installer
# will ask you to make some choices.)
if [[ $1 =~ ^(auto|sma|SMA)$ ]] ; then
# automatic installation
echo "Automatic installation..."
else
# prompt for choices
echo "Manual installation..."
read -p "Are you going to use SMA-X at the SMA? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]] ; then
echo ". Removing SMA-specific sections from scripts"
sed -i '/^.*BEGIN SMA.*/,/^.*END SMA.*$/d' *.lua
fi
read -p "start redis with SMA-X scripts at this time? " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]] ; then
START_SMAX=0
fi
read -p "Enable and start SMA-X at boot time? " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]] ; then
ENABLE_SMAX=0
fi
fi
if [ $START_SMAX -ne 0 ] ; then
echo ". Starting smax-scripts service"
systemctl restart smax-scripts
fi
if [ $ENABLE_SMAX -ne 0 ] ; then
echo ". Enabling Redis at boot"
systemctl enable $REDIS
echo ". Enabling SMA-X at boot"
systemctl enable smax-scripts
fi
echo "Done!"