-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstallsd.sh
More file actions
481 lines (463 loc) · 13.9 KB
/
installsd.sh
File metadata and controls
481 lines (463 loc) · 13.9 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
#!/bin/bash
# SD bash install script
# (c) 2023-2026 Donald Montaine and Mark Buller
# This software is released under the Blue Oak Model License
# a copy can be found on the web here: https://blueoakcouncil.org/license/1.0.0
#
# rev 2.0 Mar 15 2026 mab - echo -e to printf, allow install from local repository
# - prior history suppressed
#
# all important url of repository, change this to use your own fork
REPO_URL="https://github.com/stringdatabase/sdb64"
# define where we expect to find the package
dflt_git_folder=".sdb64tmp"
dflt_local_folder="sdb64"
#function to test git repo availability
repo_available() {
# Attempt to list remote references silently
git ls-remote -q "$REPO_URL" &>/dev/null
# Check the exit status of the previous command
if [ $? -eq 0 ]; then
echo "The Github repository at github.com is available."
echo "Creating temporary source code repository."
return 0
else
printf "%b\n" "$RED"
echo "Sdb64 repository is not available."
echo "Verify your internet connection and then try again."
printf "%b\n" "$NC"
exit
fi
}
if [[ $EUID -eq 0 ]]; then
echo "This script must NOT be run as root" 1>&2
exit
fi
if [ -f "/usr/local/sdsys/bin/sd" ]; then
echo "A version of sd is already installed."
echo "Uninstall it before running this script."
exit
fi
#
tgroup=sdusers
tuser=$USER
cwd=$(pwd)
sdsysdir="/usr/local/sdsys"
# Define color codes as variables
# note 90–97 Set bright foreground color aixterm (not in standard)
# 91 - bright RED
# 92 - bright GREEN
# 93 - bright YELLOW
# for now stick with standard
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
#
NC='\033[0m' # No Color (reset)
#
clear
printf "%bSD installer%b\n" "$RED" "$NC"
echo -----------------------
echo
printf "%bFor this install script to work you must have sudo installed\n" "$GREEN"
printf "and be a member of the sudo group. Also, systemd must be enabled.%b\n" "$NC"
echo
echo "Installer tested on Debian 13, Fedora 43, Manjaro 25 and Ubuntu 24.04."
echo
echo "This script will download the SD source code from the selected branch, compile and install SD."
printf "If a local repository is found in %s, an option to perform an installation from the local repository is provided.\n" "$dflt_local_folder"
echo
#
printf "%b\n" "$YELLOW"
read -p "Continue? (y/N) " yn
echo
case $yn in
[yY] ) echo;;
[nN] ) exit;;
* ) exit ;;
esac
#
# do we have a local repository?
#
if [ -d "$dflt_local_folder" ]; then
LOCAL_REPO=1
else
LOCAL_REPO=0
fi
#
printf "%b\n" "$GREEN"
echo "If requested, enter your account password:"
printf "%b\n" "$YELLOW"
#
sudo date &>/dev/null
clear
echo
rm -fr $cwd/$dflt_git_folder
printf "%b\n" "$NC"
#
# Ask for distribution type
is_arch=0
is_debian=0
is_fedora=0
is_suse=0
printf "%bChoose your distribution.\n" "$GREEN"
echo
echo " Enter <A> if you are installing on an Arch based distribution."
echo " Enter <D> if you are installing on a Debian or Ubuntu based distribution."
echo " Enter <F> if you are installing on a Fedora Based distribution."
echo " Enter <S> if you are installing on an openSuse Based distribution."
echo " Or press enter with no entry to exit the installer."
printf "%b\n" "$YELLOW"
read -p "Continue? (a/d/f/s) " adfs
printf "%b\n" "$NC"
case $adfs in
[aA] ) is_arch=1;;
[dD] ) is_debian=1;;
[fF] ) is_fedora=1;;
[sS] ) is_suse=1;;
* ) exit ;;
esac
#
# package installer is based on distro, clunky but easy to read
if [ $is_arch -eq 1 ]; then
sudo pacman -S git base-devel micro lynx libbsd libsodium openssh python
if [ $? -ne 0 ]; then
printf "%b\n" "$RED"
echo "Package installation using pacman failed. Exiting script."
echo "Verify your internet connection and then try again."
printf "%b\n" "$NC"
exit
else
sudo systemctl start sshd
sudo systemctl enable sshd
fi
fi
#
if [ $is_debian -eq 1 ]; then
sudo apt-get -y install git build-essential micro lynx libbsd-dev libsodium-dev openssh-server python3-dev
if [ $? -ne 0 ]; then
printf "%b\n" "$RED"
echo "Package installation using apt-get failed. Exiting script."
echo "Verify your internet connection and then try again."
printf "%b\n" "$NC"
exit
fi
fi
#
if [ $is_fedora -eq 1 ]; then
sudo dnf -y install git make automake gcc gcc-c++ kernel-devel micro lynx libbsd-devel libsodium-devel openssh-server python3-devel
if [ $? -ne 0 ]; then
printf "%b\n" "$RED"
echo "Package installation using dnf failed. Exiting script."
echo "Verify your internet connection and then try again."
printf "%b\n" "$NC"
exit
fi
fi
#
if [ $is_suse -eq 1 ]; then
sudo zypper --non-interactive install git make automake gcc gcc-c++ kernel-default-devel micro-editor lynx libbsd-devel libsodium-devel openssh python3-devel
if [ $? -ne 0 ]; then
printf "%b\n" "$RED"
echo "Package installation using zypper failed. Exiting script."
echo "Verify your internet connection and then try again."
printf "%b\n" "$NC"
exit
fi
fi
echo
printf "%bInstalling from GitHub repository $REPO_URL\n" "$YELLOW"
echo "Select: "
echo " <M>ain branch."
echo " <D>evelopment branch."
if [ $LOCAL_REPO -eq 1 ]; then
echo " <L>ocal repository."
read -p "Select repository? (M/D/L) " mdl
else
read -p "Select repository? (M/D) " mdl
fi
printf "%b\n" "$NC"
#
# check that sdb64 repository is accessible
case $mdl in
[mM] ) echo "Installing the main version at: $REPO_URL"
inst_folder=$dflt_git_folder
repo_available
git clone -b main $REPO_URL $inst_folder
;;
[dD] ) echo "Installing the development version at: $REPO_URL"
inst_folder=$dflt_git_folder
repo_available
git clone -b dev $REPO_URL $inst_folder
;;
[lL] ) echo "Installing local repository found in $dflt_local_folder"
inst_folder=$dflt_local_folder
;;
* ) echo "No matching selection, exit."
exit;;
esac
if [ -d "$inst_folder/sd64" ]; then
echo "Installing from $inst_folder."
else
echo "$inst_folder not found or not an sd install repo, aborting"
exit
fi
#
cd $cwd/$inst_folder
#
# rev 0.9.0 need python dev to build, did we get it?
python3 --version
if [ $? -eq 0 ]; then
# got it, what version and where are the include files?
PY_HDRS=$(python3-config --includes)
# remove the first "-I"
# and get the first path (for some reason its output twice?
HDRS_STR="${PY_HDRS%% *}"
HDRS_STR="${HDRS_STR#-I}"
#
echo "path to include file: " $HDRS_STR
# now create the include file we will use
echo "#include <"$HDRS_STR"/Python.h>" > sd64/gplsrc/sdext_python_inc.h
else
printf "%bPython missing, Cannot build!%b\n" "$RED" "$NC"
exit
fi
#
cd $cwd/$inst_folder/sd64
#
sudo make
# rev 0.9.0 if make fails, abort install
if [ $? -eq 0 ]; then
echo "Successful Build."
else
printf "%b\n" "$RED"
echo "Could not build SD. Install terminated!"
printf "%b\n" "$NC"
exit
fi
#
# Create sd system user and group
echo "Creating group: sdusers."
sudo groupadd --system sdusers
sudo usermod -a -G sdusers root
#
echo "Creating user: sdsys."
sudo useradd --system sdsys -G sdusers
echo "Setting user: sdsys default group to sdusers."
sudo usermod -g sdusers sdsys
#
sudo cp -R sdsys /usr/local
# Fool sd's vm into thinking gcat is populated
sudo touch /usr/local/sdsys/gcat/\$CPROC
# create errlog
sudo touch /usr/local/sdsys/errlog
#
# install TAPE and RESTORE system?
printf "%b\n" "$YELLOW"
read -p "Install TAPE and RESTORE subsystem? (y/N) " yn
printf "%b\n" "$NC"
case $yn in
[yY] ) echo "Copying TAPE and RESTORE programs to GPL.BP."
sudo cp tape/GPL.BP/* /usr/local/sdsys/GPL.BP
echo "Copying TAPE and RESTORE verbs to VOC."
sudo cp -R tape/VOC/* /usr/local/sdsys/VOC_TEMPLATE
echo ;;
esac
#
# copy install template
sudo cp -R bin $sdsysdir
sudo cp -R gplsrc $sdsysdir
sudo cp -R gplobj $sdsysdir
sudo mkdir $sdsysdir/gplbld
sudo cp -R gplbld/FILES_DICTS $sdsysdir/gplbld/FILES_DICTS
sudo cp -R terminfo $sdsysdir
#
# build program objects for bootstrap install
sudo python3 gplbld/bbcmp.py $sdsysdir GPL.BP/BBPROC GPL.BP.OUT/BBPROC
sudo python3 gplbld/bbcmp.py $sdsysdir GPL.BP/BCOMP GPL.BP.OUT/BCOMP
sudo python3 gplbld/bbcmp.py $sdsysdir GPL.BP/PATHTKN GPL.BP.OUT/PATHTKN
sudo python3 gplbld/pcode_bld.py
sudo cp Makefile $sdsysdir
sudo cp gpl.src $sdsysdir
sudo cp terminfo.src $sdsysdir
#
sudo chown -R sdsys:sdusers $sdsysdir
sudo chown root:root $sdsysdir/ACCOUNTS/SDSYS
sudo chmod 654 $sdsysdir/ACCOUNTS/SDSYS
sudo chown -R sdsys:sdusers $sdsysdir/terminfo
sudo cp sd.conf /etc/sd.conf
sudo chmod 644 /etc/sd.conf
sudo chmod -R 755 $sdsysdir
sudo chmod 775 $sdsysdir/errlog
sudo chmod -R 775 $sdsysdir/prt
#
# Add $tuser to sdusers group
sudo usermod -aG sdusers $tuser
#
# directories for sd accounts
ACCT_PATH=/home/sd
if [ ! -d "$ACCT_PATH" ]; then
sudo mkdir -p "$ACCT_PATH"/user_accounts
sudo mkdir "$ACCT_PATH"/group_accounts
fi
#
# rev 0.9.3 always set ownership (these could get messed up if sdsys and sdusers group gets deleted during deletesd.sh script
sudo chown sdsys:sdusers "$ACCT_PATH"
sudo chmod 775 "$ACCT_PATH"
sudo chown sdsys:sdusers "$ACCT_PATH"/group_accounts
sudo chmod 775 "$ACCT_PATH"/group_accounts
sudo chown sdsys:sdusers "$ACCT_PATH"/user_accounts
sudo chmod 775 "$ACCT_PATH"/user_accounts
#
sudo ln -s $sdsysdir/bin/sd /usr/local/bin/sd
#
# Install sd service for systemd
SYSTEMDPATH=/usr/lib/systemd/system
#
if [ -d "$SYSTEMDPATH" ]; then
if [ -f "$SYSTEMDPATH/sd.service" ]; then
echo "SD systemd service is already installed."
else
echo "Installing sd.service for systemd."
sudo cp usr/lib/systemd/system/* $SYSTEMDPATH
sudo chown root:root $SYSTEMDPATH/sd.service
sudo chown root:root $SYSTEMDPATH/sdclient.socket
sudo chown root:root $SYSTEMDPATH/sdclient@.service
sudo chmod 644 $SYSTEMDPATH/sd.service
sudo chmod 644 $SYSTEMDPATH/sdclient.socket
sudo chmod 644 $SYSTEMDPATH/sdclient@.service
fi
fi
#
# Copy saved directories if they exist
if [ -d /home/sd/ACCOUNTS ]; then
sudo rm -fr $sdsysdir/ACCOUNTS
sudo mv /home/sd/ACCOUNTS $sdsysdir
echo Restored ACCOUNTS directory
else
echo No ACCOUNTS backup directory exists
fi
#
# Copy saved sd.conf file if it exists
if [ -f /home/sd/sd.conf ]; then
sudo rm /etc/sd.conf
sudo mv /home/sd/sd.conf /etc
echo Restored sd.conf file
else
echo No sd.conf backup file exists
fi
#
# Start SD server
echo "Starting SD server."
sudo $sdsysdir/bin/sd -start
echo
echo "Bootstap pass 1."
sudo $sdsysdir/bin/sd -i
#
# files added in pass1 need perm and owner setup
sudo chmod -R 755 $sdsysdir/\$HOLD.DIC
sudo chmod -R 775 $sdsysdir/\$IPC
sudo chmod -R 755 $sdsysdir/\$MAP
sudo chmod -R 755 $sdsysdir/\$MAP.DIC
sudo chmod -R 755 $sdsysdir/VOC
sudo chmod -R 755 $sdsysdir/ACCOUNTS.DIC
sudo chmod -R 755 $sdsysdir/DICT.DIC
sudo chmod -R 755 $sdsysdir/DIR_DICT
sudo chmod -R 755 $sdsysdir/VOC.DIC
#
sudo chown -R sdsys:sdusers $sdsysdir/\$HOLD.DIC
sudo chown -R sdsys:sdusers $sdsysdir/\$IPC
sudo chown -R sdsys:sdusers $sdsysdir/\$MAP
sudo chown -R sdsys:sdusers $sdsysdir/\$MAP.DIC
sudo chown -R sdsys:sdusers $sdsysdir/VOC
sudo chown -R sdsys:sdusers $sdsysdir/ACCOUNTS.DIC
sudo chown -R sdsys:sdusers $sdsysdir/DICT.DIC
sudo chown -R sdsys:sdusers $sdsysdir/DIR_DICT
sudo chown -R sdsys:sdusers $sdsysdir/VOC.DIC
#
echo "Bootstap pass 2."
sudo $sdsysdir/bin/sd -internal SECOND.COMPILE
#
echo "Bootstap pass 3."
sudo $sdsysdir/bin/sd RUN GPL.BP WRITE_INSTALL_DICTS NO.PAGE
#
echo "Compiling C and I type dictionaries."
sudo $sdsysdir/bin/sd THIRD.COMPILE
#
echo "Compiling CPROC without IS_INSTALL defined."
sudo bash -c 'echo "*comment out * $define IS_INSTALL" > /usr/local/sdsys/GPL.BP/define_install.h'
sudo bin/sd -internal BASIC GPL.BP CPROC
sudo chmod -R 755 $sdsysdir/gcat
#
# create a user account for the current user
echo
echo
if [ ! -d /home/sd/user_accounts/$tuser ]; then
echo "Creating a user account for" $tuser "."
sudo bin/sd create-account USER $tuser no.query
fi
#
echo
echo Stopping sd
sudo $sdsysdir/bin/sd -stop
sleep 1
#
echo
echo Enabling services
sudo systemctl start sd.service
sudo systemctl start sdclient.socket
sudo systemctl enable sd.service
sudo systemctl enable sdclient.socket
#
sleep 1
sudo $sdsysdir/bin/sd -stop
sleep 1
sudo $sdsysdir/bin/sd -start
sleep 1
sudo $sdsysdir/bin/sd -stop
#
echo
echo Compiling terminfo database
sudo $cwd/$inst_folder/sd64/bin/sdtic -v $cwd/$inst_folder/sd64/terminfo.src
echo Terminfo compilation complete
sudo cp $cwd/$inst_folder/sd64/terminfo.src $sdsysdir
echo
if [ -d "$cwd/$dflt_git_folder" ]; then
echo "Remove $cwd/$dflt_git_folder"
rm -fr $cwd/$dflt_git_folder
fi
cd $cwd
#
# display end of script message
echo
echo ---------------------------------------------------------------
printf "%bThe SD server is installed.%b\n" "$RED" "$YELLOW"
echo "---------------------------"
echo
printf "%bThe temporary source code directory used during the install\n" "$GREEN"
echo "has been deleted."
echo
echo "The /home/sd directory has been created."
echo "User directories are created under /home/sd/user_accounts."
echo "Group directories are created under /home/sd/group_accounts."
echo "Accounts are only created using CREATE-ACCOUNT in SD."
echo
echo "Reboot to assure that group memberships are updated"
echo "and the APIsrvr Service is enabled."
echo "Note: In rare cases it requires two reboots for sd to autostart"
#
echo
echo "After rebooting, open a terminal and enter \'sd\' "
echo "to connect to your sd home directory."
echo
printf "%b----------------------------------------------------------------\n" "$NC"
printf "%b\n" "$YELLOW"
read -p "Restart Computer? (y/N) " yn
printf "%b\n" "$NC"
case $yn in
[yY] ) sudo reboot;;
[nN] ) echo;;
* ) echo ;;
esac
exit