-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbastille-init
1484 lines (1366 loc) · 48.7 KB
/
bastille-init
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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# bastille-init
# Bastille Extension for XigmaNAS x64 12.x and later.
# Bastille Extension Forum: https://www.xigmanas.com/forums/viewtopic.php?f=71&t=14848
# Bastille Extension GitHub: https://github.com/JRGTH/xigmanas-bastille-extension
# Bastille Homepage: http://bastillebsd.org/
# Bastille GitHub: https://github.com/BastilleBSD/bastille
#
# Debug script
#set -x
# Copyright (c) 2019-2024, José Rivera ([email protected]).
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the developer nor the names of contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# Set environment.
PATH=${PATH}:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
# Determine full working directory.
CWDIR=$(dirname $(realpath $0))
# Global variables.
CWDIR_TRIM=""
BASTILLE_ZFS_ZPOOL_MOUNTPOINT=""
BASTILLE_ZFS_ZPOOL_MOUNTPOINT_TRIM=""
REQUIRED_UPDATE=""
PLATFORM=$(uname -m)
PRODUCT=$(uname -i)
PRDVERSION=$(uname -r | cut -d '-' -f1 | tr -d '.')
HOSTVERSION=$(freebsd-version | cut -d '-' -f1)
PRDPLATFORM=$(cat /etc/platform)
PRDPRODUCT=$(cat /etc/prd.name)
SCRIPTNAME=$(basename $0)
CONFIG="/cf/conf/config.xml"
PRDNAME="Bastille"
APPNAME="bastille"
EXTLOGFILE="${CWDIR}/log/bastille_ext.log"
FULLAPPNAME="${APPNAME}-dist"
WWWPATH="/usr/local/www"
PKGCACHE="/var/cache/pkg"
USRLOCAL="/usr/local"
VARLOG="/var/log"
EXTCONF="/conf/${APPNAME}_config"
EXTCONFLINK="/var/etc/${APPNAME}_conf"
BASTILLERCD="/usr/local/etc/rc.d/${APPNAME}"
BASTILLEPATH="${USRLOCAL}/bin"
BASTILLECONF="${USRLOCAL}/etc/${APPNAME}/${APPNAME}.conf"
BASTILLECONFFILE="/conf/bastille_config"
BASTILLECONFLINK="/var/etc/bastille_conf"
BASTILLECONF_EXT="${CWDIR}/conf/bastille.conf.ext"
INCLUDE_PATH="${CWDIR}/conf/system"
FREEBSD_UPDATE="${INCLUDE_PATH}/freebsd-update/${HOSTVERSION}"
SYSTEM_INCLUDE="${INCLUDE_PATH}/include/${HOSTVERSION}"
INSTALLPATH="${CWDIR}/${FULLAPPNAME}"
BRANCH="master"
BASTILLE_URL="https://github.com/BastilleBSD/${APPNAME}/archive/${BRANCH}.zip" # Official Bastille Repository)
BASTILLE_ALT="https://github.com/JRGTH/${APPNAME}/archive/${BRANCH}.zip" # Alternate Bastille Repository, early updates)
BASTILLE_VERSION="https://raw.githubusercontent.com/BastilleBSD/${APPNAME}/${BRANCH}/usr/local/bin/${APPNAME}"
GITURL="https://github.com/JRGTH/xigmanas-${APPNAME}-extension/archive/${BRANCH}.zip"
VERFILE="https://raw.githubusercontent.com/JRGTH/xigmanas-${APPNAME}-extension/${BRANCH}/version"
URL_FREEBSD="http://ftp.freebsd.org/pub/FreeBSD/releases/"
URL_HARDENEDBSD="https://installers.hardenedbsd.org/pub/"
URL_MIDNIGHTBSD="https://www.midnightbsd.org/ftp/MidnightBSD/releases/"
OPT="${1}"
# Bastille required
if [ -f "${BASTILLECONF}" ]; then
. /${BASTILLECONF}
if [ "${bastille_zfs_enable}" = "YES" -o "${bastille_zfs_enable}" = "yes" ]; then
if [ -n "${bastille_zfs_prefix}" ] && [ -n "${bastille_zfs_zpool}" ]; then
# Always enforce ZFS activation below "/mnt/" from the extension.
if echo "${CWDIR}" | grep -q '/mnt/'; then
CWDIR_TRIM=$(echo "${CWDIR}" | sed "s|/mnt/||;s|/${bastille_zfs_prefix}||")
fi
BASTILLE_ZFS_ZPOOL_MOUNTPOINT=$(zfs get -H -o value mountpoint "${bastille_zfs_zpool}")
BASTILLE_ZFS_ZPOOL_MOUNTPOINT_TRIM=""
if echo "${BASTILLE_ZFS_ZPOOL_MOUNTPOINT}" | grep -q '/mnt/'; then
BASTILLE_ZFS_ZPOOL_MOUNTPOINT_TRIM=$(echo "${BASTILLE_ZFS_ZPOOL_MOUNTPOINT}" | sed "s|/mnt/||;s|/${bastille_zfs_prefix}||")
fi
fi
fi
fi
error_notify()
{
# Log/notify message on error and exit.
MSG="$*"
logger -t "${SCRIPTNAME}" "${MSG}"
echo -e "$*" >&2; exit 1
}
runtime_config()
{
# Run-time configuration and checks.
if [ -f "${INSTALLPATH}/${BASTILLECONF}" ]; then
if ! sysrc -f ${BASTILLECONF} -qn bastille_prefix | grep -q "${CWDIR}"; then
sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_prefix="${CWDIR}" >/dev/null 2>&1
fi
fi
# Check for required directories and files.
if [ ! -d "${CWDIR}/backups" ]; then
mkdir -p ${CWDIR}/backups
fi
if [ ! -d "${CWDIR}/conf" ]; then
mkdir -p ${CWDIR}/conf
fi
if [ ! -d "${CWDIR}/log" ]; then
mkdir -p ${CWDIR}/log
fi
if [ ! -d "${CWDIR}/locale-bastille" ]; then
mkdir -p ${CWDIR}/locale-bastille
fi
if [ ! -d "${CWDIR}/freebsd-update" ]; then
mkdir ${CWDIR}/freebsd-update
fi
if [ ! -f "${CWDIR}${BASTILLECONFFILE}" ]; then
touch ${CWDIR}${BASTILLECONFFILE}
fi
if [ ! -d "${CWDIR}/system" ]; then
mkdir -p ${CWDIR}/system
fi
# Check for permissions.
if [ -f "${FREEBSD_UPDATE}/freebsd-update" ]; then
FREEBSD_UPDATE_PERMS=$(stat -f "%Op" ${FREEBSD_UPDATE}/freebsd-update)
if [ "${FREEBSD_UPDATE_PERMS}" != 100555 ]; then
chmod 0555 ${FREEBSD_UPDATE}/freebsd-update
fi
fi
# Workaround to check for host /tmp sane permissions.
# This is because after working with Linux jails, this may be changed to 0777 but XigmaNAS wants 1777.
if grep -qw '\"chmod\ 777\ /tmp\"' ${INSTALLPATH}/usr/local/share/bastille/create.sh; then
sed -i '' 's|\"chmod\ 777\ /tmp\"|\"chmod\ 1777\ /tmp\"|g' ${INSTALLPATH}/usr/local/share/bastille/create.sh
else
if [ -d "/tmp" ]; then
TMP_PERMS=$(stat -f "%Op" "/tmp")
if [ "${TMP_PERMS}" != "41777" ]; then
chmod 1777 /tmp
fi
fi
fi
# Check and append new config parameters.
update_config
}
bastille_initial_download()
{
# Check if bastille already exist.
if [ -n "${REQUIRED_UPDATE}" ] || [ ! -f "${CWDIR}/${FULLAPPNAME}${BASTILLEPATH}/${APPNAME}" ]; then
# Fetch latest bastille package.
echo "Fetching ${APPNAME} files..."
fetch -ao ${CWDIR}/${BRANCH}.zip --no-verify-peer --timeout=30 ${BASTILLE_URL} || \
error_notify "Error: A problem has occurred while fetching ${APPNAME}."
bastille_pkg_extract
fi
}
bastille_pkg_extract()
{
# Extract bastille files from package.
if [ -n "${REQUIRED_UPDATE}" ] || [ -f "${CWDIR}/${BRANCH}.zip" ]; then
if [ -n "${REQUIRED_UPDATE}" ] || [ ! -f "${CWDIR}/${FULLAPPNAME}${BASTILLEPATH}/${APPNAME}" ]; then
echo "Extracting ${APPNAME}..."
tar -xf ${CWDIR}/${BRANCH}.zip --exclude='.git*' --exclude='docs' --exclude='bastille.conf' --strip-components 1 -C ${CWDIR}/${FULLAPPNAME} || \
error_notify "Error: A problem has occurred while extractig ${APPNAME} files."
chmod 555 ${CWDIR}/${FULLAPPNAME}${BASTILLEPATH}/${APPNAME}
chmod 555 ${CWDIR}/${FULLAPPNAME}${BASTILLERCD}
rm -f ${CWDIR}/${BRANCH}.zip
echo "Done!"
fi
fi
}
bastille_upgrade()
{
# Perform an online bastille upgrade.
DATE=$(date +"%a %b %d %T %Y")
echo "Looking for new ${APPNAME} package!"
mkdir -p ${CWDIR}/update
fetch -ao ${CWDIR}/update --no-verify-peer --timeout=30 ${BASTILLE_VERSION} || \
error_notify "Error: A problem has occurred while fetching version file."
# Compare version files and fetch latest package if available.
if [ -f "${CWDIR}/update/${APPNAME}" ]; then
UPDATEVER=$(cat ${CWDIR}/update/${APPNAME} | grep BASTILLE_VERSION= | egrep -o "([0-9]{1,}\.)+[0-9]{1,}" | tr -d '.')
CURRENTVER=$(cat ${BASTILLEPATH}/${APPNAME} | grep BASTILLE_VERSION= | egrep -o "([0-9]{1,}\.)+[0-9]{1,}" | tr -d '.')
if [ "${UPDATEVER}" -gt "${CURRENTVER}" ]; then
echo "New ${APPNAME} package found, performing upgrade..."
fetch -ao ${CWDIR}/update --no-verify-peer --timeout=30 ${BASTILLE_URL} || \
error_notify "Error: A problem has occurred while fetching ${APPNAME} package."
tar -xf ${CWDIR}/update/${BRANCH}.zip --exclude='.git*' --exclude='docs' --exclude='bastille.conf' --strip-components 1 -C ${CWDIR}/update
rm -f ${CWDIR}/update/${BRANCH}.zip
rm -f ${CWDIR}/update/${APPNAME}
chmod 555 ${CWDIR}/update/${BASTILLEPATH}/${APPNAME}
chmod 555 ${CWDIR}/${FULLAPPNAME}${BASTILLERCD}
cp -Rf ${CWDIR}/update/* ${CWDIR}/${FULLAPPNAME}/
rm -R ${CWDIR}/update
# Logging the update event.
UPDATEVERSION=$(cat ${BASTILLEPATH}/${APPNAME} | grep BASTILLE_VERSION= | cut -d"=" -f2 | tr -d '."')
echo "${DATE}: ${APPNAME} upgraded to ${UPDATEVERSION}" >> ${EXTLOGFILE}
echo "${APPNAME} upgraded to version ${UPDATEVERSION}"
echo "${APPNAME} package upgrade completed!"
else
echo "${APPNAME} is on the latest version!"
rm -R ${CWDIR}/update
fi
# Workaround to update legacy config.
if [ "${UPDATEVER}" -gt "0620200202" ]; then
update_config
fi
fi
}
bastille_core_update()
{
# Check if bastille already exist.
if [ -f "${CWDIR}/${FULLAPPNAME}${BASTILLEPATH}/${APPNAME}" ]; then
# Fetch latest bastille package.
echo "Fetching ${APPNAME} files..."
fetch -ao ${CWDIR}/${BRANCH}.zip --no-verify-peer --timeout=30 ${BASTILLE_URL} || \
error_notify "Error: A problem has occurred while fetching ${APPNAME}."
bastille_pkg_extract
fi
if [ -f "${CWDIR}/${BRANCH}.zip" ] && [ -f "${CWDIR}/${FULLAPPNAME}${BASTILLEPATH}/${APPNAME}" ]; then
echo "Extracting ${APPNAME}..."
tar -xf ${CWDIR}/${BRANCH}.zip --exclude='.git*' --exclude='docs' --exclude='bastille.conf' --strip-components 1 -C ${CWDIR}/${FULLAPPNAME} || \
error_notify "Error: A problem has occurred while extractig ${APPNAME} files."
chmod 555 ${CWDIR}/${FULLAPPNAME}${BASTILLEPATH}/${APPNAME}
chmod 555 ${CWDIR}/${FULLAPPNAME}${BASTILLERCD}
rm -f ${CWDIR}/${BRANCH}.zip
echo "Done!"
fi
echo "${PRDNAME} core package update completed!"
exit 0
}
ext_initial_download()
{
# Always ensure the version file is present, otherwise update the extension files on startup.
if [ ! -f "${CWDIR}/version" ]; then
echo "Fetching and extracting extension files..."
mkdir -p ${CWDIR}/update
fetch -ao ${CWDIR}/update --no-verify-peer --timeout=30 ${GITURL} || \
error_notify "Error: A problem has occurred while fetching extension package."
tar -xf ${CWDIR}/update/${BRANCH}.zip --exclude='.git*' --strip-components 1 -C ${CWDIR}/update
chmod +x ${CWDIR}/update/${SCRIPTNAME}
rm -f ${CWDIR}/update/${BRANCH}.zip
cp -Rf ${CWDIR}/update/* ${CWDIR}/
rm -R ${CWDIR}/update
echo "Done!"
fi
}
extension_upgrade()
{
# Perform an online extension upgrade.
DATE=$(date +"%a %b %d %T %Y")
echo "Looking for new Extension package!"
mkdir -p ${CWDIR}/update
fetch -ao ${CWDIR}/update --no-verify-peer --timeout=30 ${VERFILE} || \
error_notify "Error: A problem has occurred while fetching version file."
# Compare version files and fetch latest package if available.
if [ -f "${CWDIR}/update/version" ]; then
UPDATEVER=$(cat ${CWDIR}/update/version | tr -d .)
CURRENTVER=$(cat ${CWDIR}/version | tr -d .)
if [ "${UPDATEVER}" -gt "${CURRENTVER}" ]; then
echo "New Extension package found, performing upgrade..."
fetch -ao ${CWDIR}/update --no-verify-peer --timeout=30 ${GITURL} || \
error_notify "Error: A problem has occurred while fetching extension package."
tar -xf ${CWDIR}/update/${BRANCH}.zip --exclude='.git*' --strip-components 1 -C ${CWDIR}/update
chmod +x ${CWDIR}/update/${SCRIPTNAME}
rm -f ${CWDIR}/update/${BRANCH}.zip
cp -Rf ${CWDIR}/update/* ${CWDIR}/
rm -R ${CWDIR}/update
# Logging the update event.
UPDATEVERSION=$(cat ${CWDIR}/version)
echo "${DATE}: Extension upgraded to ${UPDATEVERSION}" >> ${EXTLOGFILE}
echo "Extension upgraded to version ${UPDATEVERSION}"
echo "Extension package upgrade completed!"
else
echo "Extension is on the latest version!"
rm -R ${CWDIR}/update
fi
fi
}
create_addon_env()
{
# Set bastille dir required permissions.
chmod 0750 ${CWDIR}
# Create required directories.
if [ ! -d "${CWDIR}/backups" ]; then
mkdir -p ${CWDIR}/backups
fi
if [ ! -d "${CWDIR}/log" ]; then
mkdir -p ${CWDIR}/log
fi
if [ ! -d "${CWDIR}/${FULLAPPNAME}" ]; then
mkdir -p ${CWDIR}/${FULLAPPNAME}
fi
if [ ! -d "${CWDIR}/${FULLAPPNAME}${BASTILLEPATH}" ]; then
mkdir -p ${CWDIR}/${FULLAPPNAME}${BASTILLEPATH}
fi
if [ ! -d "${CWDIR}/freebsd-update" ]; then
mkdir ${CWDIR}/freebsd-update
fi
# Link bastille-init to /usr/local/sbin.
if [ ! -f "${USRLOCAL}/sbin/${SCRIPTNAME}" ]; then
ln -fs ${CWDIR}/${SCRIPTNAME} ${USRLOCAL}/sbin/${SCRIPTNAME}
fi
}
platform_check()
{
# Check for working platform.
if [ "${PRDPLATFORM}" = "x64-embedded" ]; then
create_addon_env
ext_initial_download
bastille_initial_download
sys_symlinkdir
include_files
elif [ "${PRDPLATFORM}" = "x64-full" ]; then
create_addon_env
ext_initial_download
bastille_initial_download
sys_symlinkdir
include_files
fi
}
bin_symlinks()
{
# Main bastille symlinks.
if [ -d "${INSTALLPATH}/${BASTILLEPATH}" ]; then
cd ${INSTALLPATH}/${BASTILLEPATH}
for file in *
do
ln -fhs ${INSTALLPATH}/${BASTILLEPATH}/${file} ${USRLOCAL}/bin/${file}
done
fi
}
sys_symlinkdir()
{
# Check and create/relink required symlinks/dirs for bastille.
# This environment will be checked each time the script is started for consistency.
# Link required binaries.
bin_symlinks
# Required directories for bastille.
if [ ! -d "${USRLOCAL}/share/licenses" ]; then
mkdir -p ${USRLOCAL}/share/licenses
fi
# Required symlinks for bastille.
if [ -d "${INSTALLPATH}${USRLOCAL}/share/licenses" ]; then
cd ${INSTALLPATH}${USRLOCAL}/share/licenses
for file in *
do
ln -fhs ${INSTALLPATH}${USRLOCAL}/share/licenses/${file} ${USRLOCAL}/share/licenses/${file}
done
fi
# Link bastille config file directory.
if [ -d "${INSTALLPATH}${USRLOCAL}/etc/${APPNAME}" ]; then
ln -fhs ${INSTALLPATH}${USRLOCAL}/etc/${APPNAME} ${USRLOCAL}/etc/${APPNAME}
fi
# Link bastille config file.
#if [ -f "${INSTALLPATH}${USRLOCAL}/etc/${APPNAME}/${APPNAME}.conf.sample" ]; then
# cd ${INSTALLPATH}${USRLOCAL}/etc/${APPNAME}
# if [ ! -f "${APPNAME}.conf" ]; then
# cp ${APPNAME}.conf.sample ${APPNAME}.conf
# fi
#else
if [ -f "${BASTILLECONF_EXT}" ]; then
if [ ! -f "${INSTALLPATH}${USRLOCAL}/etc/${APPNAME}/${APPNAME}.conf" ]; then
cp ${BASTILLECONF_EXT} ${INSTALLPATH}${USRLOCAL}/etc/${APPNAME}/${APPNAME}.conf
fi
fi
#fi
# Copy bastille shared.
if [ -d "${INSTALLPATH}${USRLOCAL}/share/${APPNAME}" ]; then
ln -fhs ${INSTALLPATH}${USRLOCAL}/share/${APPNAME} ${USRLOCAL}/share/${APPNAME}
fi
# Copy bastille rc.
if [ -f "${INSTALLPATH}${USRLOCAL}/etc/rc.d/${APPNAME}" ]; then
cp ${INSTALLPATH}${USRLOCAL}/etc/rc.d/${APPNAME} ${USRLOCAL}/etc/rc.d/${APPNAME}
fi
}
include_files()
{
if [ "$(freebsd-version | cut -d '.' -f1)" -ge 12 ]; then
sysrc -f ${CWDIR}${EXTCONF} VNET_ENABLE="YES" >/dev/null 2>&1
# Include missing system files.
if [ ! -f "/usr/bin/ar" ]; then
if [ -f "${SYSTEM_INCLUDE}/ar" ]; then
install -m 0555 ${SYSTEM_INCLUDE}/ar /usr/bin/ar
fi
fi
if [ ! -f "/usr/local/bin/jib" ]; then
if [ -f "${SYSTEM_INCLUDE}/jib" ]; then
install -m 0544 ${SYSTEM_INCLUDE}/jib /usr/local/bin/jib
fi
fi
if [ ! -f "/usr/sbin/setfib" ]; then
if [ -f "${SYSTEM_INCLUDE}/setfib" ]; then
install -m 0555 ${SYSTEM_INCLUDE}/setfib /usr/sbin/setfib
fi
fi
if [ ! -f "/usr/bin/sum" ]; then
if [ -f "${SYSTEM_INCLUDE}/sum" ]; then
install -m 0555 ${SYSTEM_INCLUDE}/sum /usr/bin/sum
fi
fi
if [ ! -f "/usr/bin/diff3" ]; then
if [ -f "${SYSTEM_INCLUDE}/diff3" ]; then
install -m 0555 ${SYSTEM_INCLUDE}/diff3 /usr/bin/diff3
fi
fi
if [ ! -f "/usr/bin/makewhatis" ]; then
if [ -f "${SYSTEM_INCLUDE}/makewhatis" ]; then
install -m 0555 ${SYSTEM_INCLUDE}/makewhatis /usr/bin/makewhatis
fi
fi
else
sysrc -f ${CWDIR}${EXTCONF} VNET_ENABLE="NO" >/dev/null 2>&1
fi
if [ "$(freebsd-version | cut -d '.' -f1)" -ge 12 ]; then
# Include missing pf(packet filter) files.
PF_FILES="/pfctl /pfilctl /pflogd /pf.os"
for _file in ${PF_FILES}; do
if [ ! -f "/sbin/${_file}" ]; then
if [ "${_file}" = "/pf.os" ]; then
if [ ! -f "/etc/${_file}" ]; then
if [ -f "${SYSTEM_INCLUDE}/${_file}" ]; then
install -m 0644 ${SYSTEM_INCLUDE}/${_file} /etc/${_file}
fi
fi
else
if [ -f "${SYSTEM_INCLUDE}/${_file}" ]; then
install -m 0555 ${SYSTEM_INCLUDE}/${_file} /sbin/${_file}
fi
fi
fi
done
fi
}
required_updates()
{
# Check for critical and/or required updates and bug fixes and apply them.
# This is because not always the bastille version is increased on updates and/or bug fixes.
if [ -f "${INSTALLPATH}${USRLOCAL}/share/${APPNAME}/rename.sh" ]; then
if ! grep -qw '{ZFS_DATASET_ORIGIN}.*{ZFS_DATASET_TARGET}' ${INSTALLPATH}${USRLOCAL}/share/${APPNAME}/rename.sh; then
echo "Required update found, performing update..."
echo "${DATE}: ${APPNAME} required update has been applied" >> ${EXTLOGFILE}
REQUIRED_UPDATE="1"
bastille_initial_download
fi
fi
# Check for a critical bug that prevents VNET jail creation.
if grep -q '\\"vnet host interface for Bastille jail ${NAME}"' ${INSTALLPATH}${USRLOCAL}/share/${APPNAME}/create.sh; then
sed -i '' 's|\\"vnet host interface for Bastille jail ${NAME}"|\\"vnet host interface for Bastille jail ${NAME}\\"|g' ${INSTALLPATH}${USRLOCAL}/share/${APPNAME}/create.sh
fi
}
postinit_cmd()
{
# Check and generate temporary php script for postinit command.
if ! grep -qw ${CWDIR}/${SCRIPTNAME} ${CONFIG}; then
touch ${CWDIR}/postinit || error_notify "Error: A problem has occurred while creating the postinit file."
chmod +x ${CWDIR}/postinit
if [ "${PRDVERSION}" -ge "110" ]; then
# Generate php script for start/stop commands.
cat << EOF > ${CWDIR}/postinit
<?php
require_once("config.inc");
require_once("functions.inc");
\$cmd = dirname(__FILE__)."/${SCRIPTNAME}";
\$cmd2 = dirname(__FILE__)."/${SCRIPTNAME} -p";
\$name = "${PRDNAME} Extension";
\$comment = "Start ${PRDNAME} Container Manager";
\$comment2 = "Stop ${PRDNAME} Container Manager";
\$rc = &array_make_branch(\$config,'rc','param');
if(false === array_search_ex(\$cmd,\$rc,'cmd')):
\$rc_param = [];
\$rc_param['uuid'] = uuid();
\$rc_param['name'] = \$name;
\$rc_param['value'] = \$cmd;
\$rc_param['comment'] = \$comment;
\$rc_param['typeid'] = '2';
\$rc_param['enable'] = true;
\$rc[] = \$rc_param;
write_config();
endif;
unset(\$rc);
\$rc = &array_make_branch(\$config,'rc','param');
if(false === array_search_ex(\$cmd2,\$rc,'cmd2')):
\$rc_param = [];
\$rc_param['uuid'] = uuid();
\$rc_param['name'] = \$name;
\$rc_param['value'] = \$cmd2;
\$rc_param['comment'] = \$comment2;
\$rc_param['typeid'] = '3';
\$rc_param['enable'] = true;
\$rc[] = \$rc_param;
write_config();
endif;
unset(\$rc);
?>
EOF
fi
# Execute temporary php script.
if [ "${OBI_INSTALL}" != "ON" ]; then
echo "Creating postinit command..."
php-cgi -f ${CWDIR}/postinit && rm ${CWDIR}/postinit || \
error_notify "Error: A problem has occurred while executing postinit file."
echo "Done!"
fi
# Set extension to enable by default.
sysrc -f ${CWDIR}${EXTCONF} GUI_ENABLE=YES INSTALL_DIR=${CWDIR} >/dev/null 2>&1
fi
}
gui_start()
{
# Initialize the extension gui.
if [ -d "${CWDIR}/gui" ]; then
# Always ensure the config directory/file exist.
if [ ! -f "${CWDIR}${EXTCONF}" ]; then
# Try to restore default configuration.
runtime_config
# Set default config.
sysrc -f ${CWDIR}${EXTCONF} GUI_ENABLE=YES INSTALL_DIR=${CWDIR} >/dev/null 2>&1
fi
GUI_STATUS=$(sysrc -f ${CWDIR}${EXTCONF} -qn GUI_ENABLE)
if [ "${GUI_STATUS}" = "YES" ]; then
# Store the installation path and link conf.
if ! sysrc -f ${CWDIR}${EXTCONF} -n INSTALL_DIR | grep -q "${CWDIR}"; then
sysrc -f ${CWDIR}${EXTCONF} INSTALL_DIR=${CWDIR} >/dev/null 2>&1
fi
mkdir -p ${BASTILLECONFLINK}
ln -fhs ${CWDIR}/conf ${BASTILLECONFLINK}/conf
# Link the gui files.
if [ ! -d "${WWWPATH}/ext" ]; then
mkdir -p ${WWWPATH}/ext
fi
ln -fhs ${CWDIR}/gui/ext/bastille ${WWWPATH}/ext/ || error_notify "Error: A problem has occurred while copying extension gui files."
ln -fhs ${CWDIR}/gui/images ${WWWPATH}/ext/bastille/ || error_notify "Error: A problem has occurred while copying extension gui files."
ln -fhs ${CWDIR}/gui/bastille_manager_*.php ${WWWPATH}/ || error_notify "Error: A problem has occurred while linking extension gui files."
fi
fi
}
gui_enable()
{
# Relink conf and gui files.
if [ -d "${CWDIR}/gui" ]; then
mkdir -p ${BASTILLECONFLINK}
ln -fhs ${CWDIR}/conf ${BASTILLECONFLINK}/conf
sysrc -f ${CWDIR}${EXTCONF} GUI_ENABLE=YES >/dev/null 2>&1
if [ ! -d "${WWWPATH}/ext" ]; then
mkdir -p ${WWWPATH}/ext
fi
ln -fhs ${CWDIR}/gui/ext/bastille ${WWWPATH}/ext/ || error_notify "Error: A problem has occurred while copying extension gui files."
ln -fhs ${CWDIR}/gui/images ${WWWPATH}/ext/bastille/ || error_notify "Error: A problem has occurred while copying extension gui files."
ln -fhs ${CWDIR}/gui/bastille_manager_*.php ${WWWPATH}/ || error_notify "Error: A problem has occurred while copying extension gui files."
exit 0
else
error_notify "Error: Extension gui files not found."
fi
}
gui_disable()
{
# Disable gui if -t option specified.
if [ -d "${CWDIR}/gui" ]; then
rm -f ${WWWPATH}bastille_manager_*.php
rm -rf ${WWWPATH}/ext/bastille
rm -rf ${WWWPATH}/ext/bastille/images
rm -rf ${LOCALSHAREPATH}/locale-bastille
rm -rf ${BASTILLECONFLINK}
sysrc -f ${CWDIR}${EXTCONF} GUI_ENABLE=NO >/dev/null 2>&1 || error_notify "Error: A problem while removing extension gui files."
exit 0
else
error_notify "Error: Extension gui files not found."
fi
# Remove empty ext folder to prevent empty "Extensions" tab.
if [ -d "${WWWPATH}/ext" ]; then
if [ ! "$(ls -A ${WWWPATH}/ext)" ]; then
rm -r ${WWWPATH}/ext
fi
fi
}
jail_update()
{
# Workaround since XigmaNAS does not ship with freebsd-update command.
if [ "${PRDPRODUCT}" = "XigmaNAS" -o "${PRDPRODUCT}" = "NAS4Free" ]; then
if [ ! -d "${FREEBSD_UPDATE}" ]; then
echo "Not supported on ${PRDPRODUCT} platform."
exit 1
fi
else
echo "Unsupported platform!"; exit 1
fi
if [ ! -z "$(freebsd-version | grep -i HBSD)" ]; then
echo "Not supported on HardenedBSD."
exit 1
fi
if [ -d "${bastille_jailsdir}/${TARGET}" ]; then
if ! cat "${bastille_jailsdir}/${TARGET}/fstab" 2>/dev/null | grep -w "${TARGET}" | grep -qw "/.*/.bastille"; then
if [ -f "${bastille_jailsdir}/${TARGET}/root/COPYRIGHT" ]; then
if [ "$(jls name | grep -w "${TARGET}")" ]; then
# Update a thick container.
CURRENT_VERSION=$(jexec -l ${TARGET} freebsd-version)
if [ -z "${CURRENT_VERSION}" ]; then
echo "Can't determine '${TARGET}' version."
exit 1
else
env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \
-d ${CWDIR}/freebsd-update -b "${bastille_jailsdir}/${TARGET}/root" fetch --currently-running "${CURRENT_VERSION}"
${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \
-d ${CWDIR}/freebsd-update -b "${bastille_jailsdir}/${TARGET}/root" install --currently-running "${CURRENT_VERSION}"
fi
else
echo "Container not running."
echo "See 'bastille start ${TARGET}'."
exit 1
fi
else
echo "${TARGET} state is unknown."
exit 1
fi
else
echo "${TARGET} is not a thick container."
exit 1
fi
else
if [ -d "${bastille_releasesdir}/${TARGET}" ]; then
# Update container base(affects base child containers).
env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \
-d ${CWDIR}/freebsd-update -b "${bastille_releasesdir}/${TARGET}" fetch --currently-running "${TARGET}"
${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \
-d ${CWDIR}/freebsd-update -b "${bastille_releasesdir}/${TARGET}" install --currently-running "${TARGET}"
else
echo "${TARGET} not found. See bootstrap."
exit 1
fi
fi
exit 0
}
release_upgrade()
{
if [ -d "${bastille_releasesdir}/${TARGET}" ]; then
if [ -f "${bastille_releasesdir}/${TARGET}/COPYRIGHT" ]; then
if [ "${TARGET}" = "${RELEASE}" ]; then
echo "Specified releases name match."
exit 0
fi
# Upgrade a release base.
echo "=> Run the command below several times when asked to finish installing updates."
echo "bastille-init install ${TARGET}"
echo
env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \
-d ${CWDIR}/freebsd-update -b "${bastille_releasesdir}/${TARGET}" --currently-running "${TARGET}" -r ${RELEASE} upgrade
echo
echo "=> Please run: 'bastille-init install ${TARGET}' to finish installing updates."
else
echo "Unknown ${RELEASE}. See bootstrap."; exit 1
fi
else
echo "${TARGET} not found. See bootstrap."; exit 1
fi
exit 0
}
release_install()
{
if [ -d "${bastille_releasesdir}/${TARGET}" ]; then
if [ -f "${bastille_releasesdir}/${TARGET}/COPYRIGHT" ]; then
# Finish installing upgrade on a thick container.
env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \
-d ${CWDIR}/freebsd-update -b "${bastille_releasesdir}/${TARGET}" install
else
echo "${TARGET} state is unknown."
exit 1
fi
else
echo "${TARGET} not found. See bootstrap."; exit 1
fi
exit 0
}
release_change()
{
if [ ! -z "$(freebsd-version | grep -i HBSD)" ]; then
echo "Not supported on HardenedBSD."
exit 1
fi
# Verify for user input and handle some errors.
if [ -d "${bastille_jailsdir}/${TARGET}" ]; then
if [ -d "${bastille_releasesdir}/${RELEASE}" ]; then
if [ -f "${bastille_releasesdir}/${RELEASE}/COPYRIGHT" ]; then
# Check if the container is running.
if [ "$(jls name | grep -w "${TARGET}")" ]; then
echo "${TARGET} running."
echo "See 'bastille stop ${TARGET}'."
exit 1
elif [ "${RELEASE}" = "${NEWRELEASE}" ]; then
echo "Specified releases name match."
exit 0
fi
if [ -d "${bastille_releasesdir}/${NEWRELEASE}" ]; then
if [ -f "${bastille_releasesdir}/${NEWRELEASE}/COPYRIGHT" ]; then
if [ -f "${bastille_jailsdir}/${TARGET}/fstab" ]; then
# Check if is a thin container.
if cat "${bastille_jailsdir}/${TARGET}/fstab" | grep "${RELEASE}" | grep -qw "/.*/.bastille"; then
# If the previous conditions meets, proceed with the container base upgrade.
sed -i '' "s/${RELEASE}/${NEWRELEASE}/g" ${bastille_jailsdir}/${TARGET}/fstab
echo "${TARGET} release changed to ${NEWRELEASE}."
elif cat "${bastille_jailsdir}/${TARGET}/fstab" | grep "${NEWRELEASE}" | grep -qw "/.*/.bastille"; then
echo "${TARGET} already using ${NEWRELEASE}."
exit 0
else
if cat "${bastille_jailsdir}/${TARGET}/fstab" | grep -qw "/.*/.bastille"; then
echo "${TARGET} container does not use ${RELEASE}."; exit 1
else
echo "${TARGET} is not a thin container."; exit 1
fi
fi
else
echo "${TARGET} fstab not found."; exit 1
fi
else
echo "Unknown ${NEWRELEASE}. See bootstrap."; exit 1
fi
else
echo "${NEWRELEASE} not found, bootstrap starting...."
bastille bootstrap ${NEWRELEASE}
if [ ! $? -ne 0 ]; then
release_change
fi
fi
else
echo "Unknown ${RELEASE}. See bootstrap."; exit 1
fi
else
echo "${RELEASE} not found. See bootstrap."; exit 1
fi
else
echo "${TARGET} not found. See create."; exit 1
fi
exit 0
}
thickjail_upgrade()
{
# Workaround since XigmaNAS does not ship with freebsd-update command.
if [ "${PRDPRODUCT}" = "XigmaNAS" -o "${PRDPRODUCT}" = "NAS4Free" ]; then
if [ ! -d "${FREEBSD_UPDATE}" ]; then
echo "Not supported on ${PRDPRODUCT} platform."
exit 1
fi
else
echo "Unsupported platform!"; exit 1
fi
if [ ! -z "$(freebsd-version | grep -i HBSD)" ]; then
echo "Not supported on HardenedBSD."
exit 1
fi
# Verify for user input and handle some errors.
if [ -d "${bastille_jailsdir}/${TARGET}" ]; then
if ! cat "${bastille_jailsdir}/${TARGET}/fstab" 2>/dev/null | grep -w "${TARGET}" | grep -qw "/.*/.bastille"; then
if [ -f "${bastille_jailsdir}/${TARGET}/root/COPYRIGHT" ]; then
if [ "$(jls name | grep -w "${TARGET}")" ]; then
# Upgrade a thick container.
echo "=> Run the command below several times when asked to finish installing updates."
echo "bastille-init install ${TARGET}"
echo
CURRENT_VERSION=$(jexec -l ${TARGET} freebsd-version)
env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \
-d ${CWDIR}/freebsd-update -b "${bastille_jailsdir}/${TARGET}/root" --currently-running "${CURRENT_VERSION}" -r ${RELEASE} upgrade
echo
echo "=> Please run: 'bastille-init install ${TARGET}' to finish installing updates."
else
echo "Container not running."
echo "See 'bastille start ${TARGET}'."
exit 1
fi
else
echo "${TARGET} state is unknown."
exit 1
fi
else
echo "${TARGET} is not a thick container."
exit 1
fi
elif [ -d "${bastille_releasesdir}/${RELEASE}" ]; then
# Try to upgrade a release instead.
release_upgrade
fi
exit 0
}
thickjail_install()
{
# Workaround since XigmaNAS does not ship with freebsd-update command.
if [ "${PRDPRODUCT}" = "XigmaNAS" -o "${PRDPRODUCT}" = "NAS4Free" ]; then
if [ ! -d "${FREEBSD_UPDATE}" ]; then
echo "Not supported on ${PRDPRODUCT} platform."
exit 1
fi
else
echo "Unsupported platform!"; exit 1
fi
if [ ! -z "$(freebsd-version | grep -i HBSD)" ]; then
echo "Not supported on HardenedBSD."
exit 1
fi
if [ -d "${bastille_jailsdir}/${TARGET}" ]; then
if ! cat "${bastille_jailsdir}/${TARGET}/fstab" 2>/dev/null | grep -w "${TARGET}" | grep -qw "/.*/.bastille"; then
if [ -f "${bastille_jailsdir}/${TARGET}/root/COPYRIGHT" ]; then
if [ "$(jls name | grep -w "${TARGET}")" ]; then
# Finish installing upgrade on a thick container.
env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \
-d ${CWDIR}/freebsd-update -b "${bastille_jailsdir}/${TARGET}/root" install
else
echo "Container not running."
echo "See 'bastille start ${TARGET}'."
exit 1
fi
else
echo "${TARGET} state is unknown."
exit 1
fi
else
echo "${TARGET} is not a thick container."
exit 1
fi
elif [ -d "${bastille_releasesdir}/${RELEASE}" ]; then
# Try to upgrade a release instead.
release_install
fi
exit 0
}
zfs_activate()
{
# Check if ZFS is already configured.
# Always enforce ZFS activation below "/mnt/" from the extension.
if echo "${BASTILLE_ZFS_ZPOOL_MOUNTPOINT_TRIM}" | grep -qw "${CWDIR_TRIM}$"; then
BASTILLE_DIR=$(echo "${CWDIR}" | grep -o '[^/]*$')
if [ "${bastille_zfs_prefix}" != "${BASTILLE_DIR}" ]; then
error_notify "Invalid ZFS configuration."
fi
if zfs list "${bastille_zfs_zpool}/${BASTILLE_DIR}" > /dev/null 2>&1; then
echo "Bastille ZFS is already configured."
sysrc -f ${CWDIR}${EXTCONF} ZFS_ACTIVATED="YES" >/dev/null 2>&1
exit 0
else
BASTILLE_DIRS="cache jails logs releases templates"
for dir in ${BASTILLE_DIRS}; do
if [ -d "${CWDIR}/${dir}" ]; then
# Stop if any of the listed dirs already exist.
error_notify "Bastille has been bootstrapped already, aborting."
fi
done
fi
echo "Enabling ZFS on ${PRDNAME} Extension..."
# Confirm before conversion.
while :
do
read -p "Do you really wish to enable ZFS for ${PRDNAME} Extension? [y/N]:" yn
case ${yn} in
[Yy]) break;;
[Nn]) exit 0;;
esac
done
echo "Proceeding..."
if [ "${bastille_zfs_enable}" = "YES" ]; then
if [ ! -z "${bastille_zfs_zpool}" ]; then
if zfs list "${bastille_zfs_zpool}" > /dev/null 2>&1; then
if ! zfs list "${bastille_zfs_zpool}/${BASTILLE_DIR}" > /dev/null 2>&1; then
echo "Renaming existing '${BASTILLE_DIR}' directory"
mv ${CWDIR} ${CWDIR}.old
echo "Creating a new ZFS dataset for '${BASTILLE_DIR}'"
zfs create ${bastille_zfs_options} ${bastille_zfs_zpool}/${bastille_zfs_prefix}
if [ $? -ne 0 ]; then
MSG="Failed to enable ZFS, reverting changes."
echo "${MSG}"
mv ${CWDIR}.old ${CWDIR}
logger -t "${SCRIPTNAME}" "${MSG}"
error_notify "${MSG}"
else
echo "Synchronizing '${BASTILLE_DIR}' data on new dataset"
rsync -a ${CWDIR}.old/ ${CWDIR}/
fi
else
echo "Bastille ZFS is already configured."
fi
else
error_notify "ERROR: ${bastille_zfs_zpool} is not a ZFS pool/dataset."
fi
else
error_notify "Bastille ZPOOL is not set."
fi
echo "ZFS Enabled for ${PRDNAME} Extension successfully."
else
error_notify "Bastille ZFS option is not set."
fi
else
error_notify "Invalid ZFS configuration."
fi
sysrc -f ${CWDIR}${EXTCONF} ZFS_ACTIVATED="YES" >/dev/null 2>&1
exit 0
}
pkg_upgrade()
{
# Re-fetch bastille package and extract.
if [ -f "${CWDIR}/${FULLAPPNAME}${BASTILLEPATH}/${APPNAME}" ]; then
bastille_upgrade
else
bastille_initial_download
fi
# Check for extension updates.
extension_upgrade
}
reset_install()
{
# Reset the extension environment.
echo "Removing extension files..."
if [ -f "${CWDIR}/conf/bastille_config" ]; then
rm -rf ${CWDIR}/conf/bastille_config
fi