-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.sh.in
1094 lines (942 loc) · 30 KB
/
deploy.sh.in
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
#
# Copyright Rainer Wichmann (2005)
#
# License Information:
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#VERSION2.0
# -----------------------------------------------------------------------
# Be Bourne compatible
# -----------------------------------------------------------------------
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
emulate sh
NULLCMD=:
elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
set -o posix
fi
# -----------------------------------------------------------------------
# Make sure we support functions (from the autoconf manual)
# -----------------------------------------------------------------------
SHELL="${SHELL-/bin/sh}"
if test x"$1" = "x--re-executed"
then
shift
elif "$SHELL" -c 'foo () { (exit 0); exit 0; }; foo' 2>/dev/null
then
:
else
for cmd in sh bash ash bsh ksh zsh sh5; do
X="$PATH:/bin:/usr/bin:/usr/afsws/bin:/usr/ucb";
OLD_IFS=${IFS}
IFS=':'; export IFS
for dir in $X; do
shell="$dir/$cmd"
if (test -f "$shell" || test -f "$shell.exe")
then
if "$shell" -c 'foo () { (exit 0); exit 0; }; foo' 2>/dev/null
then
SHELL="$shell"; export SHELL
IFS=${OLD_IFS}; export IFS
exec "$shell" "$0" --re-executed ${1+"$@"}
fi
fi
done
IFS=${OLD_IFS}; export IFS
done
echo "-----------------------------------------------------------------"
echo "ERROR: Unable to locate a shell interpreter with function support" >&2
echo "-----------------------------------------------------------------"
{ (exit 1); exit 1; }
fi
# -----------------------------------------------------------------------
# Test for 'echo -n'
# -----------------------------------------------------------------------
case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
*c*,* ) ECHO_N=-n ECHO_C= ;;
*) ECHO_N= ECHO_C='\c' ;;
esac
as_cr_letters='abcdefghijklmnopqrstuvwxyz'
as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
as_cr_Letters=$as_cr_letters$as_cr_LETTERS
as_cr_digits='0123456789'
as_cr_alnum=$as_cr_Letters$as_cr_digits
#########################################################################
#
# Configuration section
#
#########################################################################
# -----------------------------------------------------------------------
# The following part will be cut and saved to ~/.deploy.conf
# -----------------------------------------------------------------------
#__BEGIN_CUT__
#########################################################################
#
# This file is sourced by a Bourne shell script.
# Thus you need to take care of proper shell syntax.
#
#########################################################################
# if you need, you can expand your PATH environment variable here
# just uncomment and replace /opt/contrib/bin with whatever you need
#
# PATH="/opt/contrib/bin:${PATH}"; export PATH
# the base directory of the deployment system
# CLI option: --basedir=...
#
defbasedir="@mydataroot@/profiles"
# the name of the database of installed clients
# no CLI option
#
defdatabase="yulerc.install.db"
# be quiet; 0 = false, 1 = true, 2 = very quiet
# CLI option: --quiet | --quiet=2
#
silent=0;
# assume yes as answer to all prompts and run non-interactively
# 0 = false, 1 = true
# CLI option: --yes
#
assumeyes=0;
# which 'dialog' to use (e.g. "Xdialog")
# "no" for plain text; empty ("") lets the program search for dialog
# CLI option: --dialog=...
#
prefdialog=""
# operating system; no default
# CLI option: --arch=...
#
arch=""
# Format for binary packages (run | deb | rpm | tbz2 | solaris-pkg | depot)
# CLI option: --format=...
#
format=""
# logfile; default is none
# CLI option: --logfile=...
#
logfile=""
# The path to the yule (samhain server) executable.
# CLI option: --yule_exec=...
#
yule_exec="@sbindir@/yule"
# The path to the yule (samhain server) configuration file.
# CLI option: --yule_conf=...
#
yule_conf="@sysconfdir@/yulerc"
# The path to the data directory of yule (samhain server).
# This is the directory where client configuration/database files
# are stored.
# CLI option: --yule_data=...
#
yule_data="@mydataroot@"
# The temporary directory to use. Default is '/tmp', but some
# sites may mount this 'noexec'.
#
temp_dir="/tmp"
#__END_CUT__
# -----------------------------------------------------------------------
# Write configuration file to user home directory/Read configuration file
# -----------------------------------------------------------------------
if test -f ~/.deploy.conf
then
. ~/.deploy.conf
else
#
# From the autoconf configure script - search ourselves
#
case $0 in
*[\\/]* ) as_myself=$0 ;;
*) old_IFS=$IFS; IFS=:
for as_dir in $PATH
do
IFS=$old_IFS
test -z "$as_dir" && as_dir=.
test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
done
;;
esac
# We did not find ourselves, most probably we were run as `sh COMMAND'
# in which case we are not to be found in the path.
if test "x$as_myself" = x; then
as_myself=$0
fi
if test ! -f "$as_myself"; then
{ echo "ERROR: cannot find myself; rerun with an absolute path" >&2
{ (exit 1); exit 1; }; }
fi
cat "$as_myself" | sed -n -e '/^#__BEGIN_CUT__/,/^#__END_CUT__/ p ' >~/.deploy.conf && {
echo
echo "-----------------------------------------------------"
echo " Configuration file ~/.deploy.conf created"
echo " You may want to edit it to adapt it to your needs"
echo "-----------------------------------------------------"
echo
}
fi
export silent
export assumeyes
export arch
export logfile
export format
export yule_exec
export yule_conf
export yule_data
export temp_dir
# dialog
#
DIALOG="${prefdialog}";
export DIALOG
# base directory
#
basedir="$defbasedir";
export basedir
# simulate only; 0 = false, 1 = true
#
simulate=0;
export simulate
# version
#
version=2.0;
export version
# host; no default
#
host=
export host
# hostgroup; empty default
#
hostgroup=
export hostgroup
# action; no default
#
action=
export action
# the 'log.lastrun' logfile
#
logOpen=0
export logOpen
# source version; default = current
#
src_version=""
export src_version
# checksrc; do you want to delete if PGP signature check fails ?
#
cs_delete=0
export cs_delete
# build; do you want to pack the executable ?
#
bd_packed=''
export bd_packed
bd_user='root'
export bd_user
# addpath
#
bd_addpath=""
export bd_addpath
# Install; do you want to initialize the database ?
#
is_init=y
export is_init
# Install; do you want to replace the rc.host file ?
#
is_rcfile=y
export is_rcfile
# Install; do you want to start the client ?
#
is_startup=y
export is_startup
# Install; optional local command ?
#
local_command=""; export local_command
# Info on packages ?
#
showpkg=n
export showpkg
#########################################################################
#
# Help Subroutines
#
#########################################################################
# -----------------------------------------------------------------------
# We cannot source these, because we don't know yet the base directory
# -----------------------------------------------------------------------
showUNINSTALL() {
echo "deploy.sh $version"
echo "USAGE: deploy.sh [options] uninstall"
echo
echo "Uninstall the samhain client from the specified host. Can only be"
echo "used if the client has been installed with deploy.sh version 2."
echo
echo "Options:"
echo
echo " --host=<hostname> The host where you want to uninstall."
echo " --tmpdir=<path> Temporary directory to use on the this host."
echo
{ (exit 0); exit 0; }
}
showINFO() {
echo "deploy.sh $version"
echo "USAGE: deploy.sh [options] info"
echo
echo "Show info for hosts in client database (default), or for available"
echo "binary installer packages."
echo
echo "Options:"
echo
echo " --packages Show info on packages."
echo
{ (exit 0); exit 0; }
}
showCLEAN() {
echo "deploy.sh $version"
echo "USAGE: deploy.sh [options] clean"
echo
echo "Remove all files that are no longer needed:"
echo " - Source tarballs in ${basedir}/source"
echo " - Unused installer packages in ${basedir}/archpkg"
echo
{ (exit 0); exit 0; }
}
showCHECKSRC() {
echo "deploy.sh $version"
echo "USAGE: deploy.sh [options] checksrc"
echo
echo "Check PGP signatures of source tarballs in the source/ subdirectory"
echo "of the deploy system."
echo "You must have gpg (GnuPG) in your PATH, and you should have imported"
echo "the samhain release PGP key (Key ID 0F571F6C, Rainer Wichmann)."
echo "To import the key, simply execute the command"
echo "\"gpg --keyserver blackhole.pca.dfn.de --recv-keys 0F571F6C\""
echo
echo "Options:"
echo
echo " --delete Delete source tarballs if PGP signature"
echo " cannot be verified."
echo
{ (exit 0); exit 0; }
}
showDOWNLOAD() {
echo "deploy.sh $version"
echo "USAGE: deploy.sh [options] download"
echo
echo "Download a samhain source tarball from http://www.la-samhna.de,"
echo "check its PGP signature, and install it into the source/ subdirectory"
echo "of the deploy system."
echo "You must have gpg (GnuPG) in your PATH, and you should have imported"
echo "the samhain release PGP key (Key ID 0F571F6C, Rainer Wichmann)."
echo "To import the key, simply execute the command"
echo "\"gpg --keyserver blackhole.pca.dfn.de --recv-keys 0F571F6C\""
echo
echo "Options:"
echo
echo " --version=<version> Version of samhain to download. The"
echo " default is \"current\" to download the current version."
echo
{ (exit 0); exit 0; }
}
showBUILD() {
echo "deploy.sh $version"
echo "USAGE: deploy.sh [options] build"
echo
echo "Copy a source tarball to a build machine, build a binary package, and fetch"
echo "the package. Will bail out if not running under ssh-agent. If you are sure"
echo "that you don't need ssh-agent, set the environment variable SSH_AGENT_PID"
echo "to some arbitrary string before launching the deploy.sh command."
echo
echo "Options:"
echo
echo " --host=<hostname> The build host."
echo " --arch=<arch> The architecture/operating system to build for."
echo " This is used to get the \"./configure\" options from the file"
echo " \${basedir}/configs/\${arch}.configure."
echo " --version=<version> The version of samhain you want to build."
echo " --format=<run|rpm|deb|tbz2|solaris-pkg|depot>"
echo " The format of the package. \"run\" is a portable tar"
echo " package, \"deb\" is for Debian, \"tbz2\" for Gentoo,"
echo " \"rpm\" for any RPM-based Linux, \"solaris-pkg\""
echo " for Sun Solaris, and \"depot\" for HP-UX"
echo " --packed=<password> The client password, if you want to"
echo " create a packed executable. Defaults to empty (don't pack)"
echo " --user=<username> Login as <username> to the build host (root)."
echo " --add-path=<path> Append 'path' to the PATH variable on the build host."
echo " --tmpdir=<path> Temporary directory to use on the build host."
{ (exit 0); exit 0; }
}
showINSTALL() {
echo "deploy.sh $version"
echo "USAGE: deploy.sh [options] install"
echo
echo "Copy a pre-built binary installer package to a remote host, stop the client"
echo "running there (if any), install the (new) client, optionally initialize"
echo "the file signature database and fetch it from the remote host, update"
echo "the server configuration file and reload the server."
echo
echo "Options:"
echo
echo " --host=<FQDN> The host where you want to install."
echo " --group=<group> Optional group the host belongs to."
echo " --arch=<arch> The architecture/operating system of this host."
echo " This is used to get the correct binary package."
echo " --version=<version> The version of samhain you want to install."
echo " --format=<run|rpm|deb|tbz2|solaris-pkg|depot>"
echo " The format of the binary package."
echo " --yule_exec=<path> The path to the 'yule' executable."
echo " --yule_conf=<path> The path to the 'yule' configuration file."
echo " --yule_data=<path> The path to the 'yule' data directory."
echo " --no-init Do not initialize the file signature database."
echo " --no-rcfile Do not replace the rc.host file on server."
echo " --no-start Do not start the client after installation."
echo " --local=<path> Local command (executed twice: "
echo " after config installation and before client startup)."
echo " --tmpdir=<path> Temporary directory to use on the this host."
{ (exit 0); exit 0; }
}
showUSAGE() {
echo "deploy.sh $version"
echo "USAGE: deploy.sh [options] command"
echo
echo "Commands: info | clean | download | checksrc | build | install | uninstall"
echo
echo "Options:"
echo " -h | --help Print general usage information."
echo " -h | --help <command> Print usage information for \"command\"."
echo " --basedir=<directory> Set the basedir for the deployment system."
echo " The default is ${defbasedir}."
echo " -q | --quiet Produce output suitable for logging."
echo " You can also use -q=# to set the quiet level up to"
echo " a maximum of 2. Note that -q=2 implies --yes (see below)."
echo " -s | --simulate Perform a simulation of events that"
echo " would occur but do not actually change the system."
echo " -y | --yes Assume "yes" as answer to"
echo " all prompts and run non-interactively."
echo " -o <file> | --logfile=<file>"
echo " Specify an output file for messages that would go to stdout"
echo " otherwise. Has no effect on stderr (error messages)."
echo " -d <dialog> | --dialog=<dialog> Specify your preferred \"dialog\""
echo " clone (e.g. Xdialog). Use \"no\" to force plain text."
if test x"$1" = x
then
{ (exit 0); exit 0; }
else
{ (exit $1); exit $1; }
fi
}
#########################################################################
#
# Command line
#
#########################################################################
for option
do
# If the previous option needs an argument, assign it.
#
if test -n "$opt_prev"; then
eval "$opt_prev=\$option"
eval export "$opt_prev"
opt_prev=
continue
fi
case "$option" in
-*=*) optarg=`echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
case "$option" in
# Info
--packages | -packages)
showpkg=y; export showpkg;
;;
# Install
--yule_exec | -yule_exec | --yule-exec | -yule-exec)
opt_prev=yule_exec
;;
--yule_exec=* | -yule_exec=* | --yule-exec=* | -yule-exec=*)
yule_exec="$optarg"; export yule_exec
;;
--yule_conf | -yule_conf | --yule-conf | -yule-conf)
opt_prev=yule_conf
;;
--yule_conf=* | -yule_conf=* | --yule-conf=* | -yule-conf=*)
yule_conf="$optarg"; export yule_conf
;;
--yule_data | -yule_data | --yule-data | -yule-data)
opt_prev=yule_data
;;
--yule_data=* | -yule_data=* | --yule-data=* | -yule-data=*)
yule_data="$optarg"; export yule_data
;;
--no-init | -no-init)
is_init=n; export is_init
;;
--no-rcfile | -no-rcfile)
is_rcfile=n; export is_rcfile
;;
--no-start | -no-start)
is_startup=n; export is_startup
;;
--local | -local)
opt_prev=local_command
;;
--local=* | -local=*)
local_command="$optarg"; export local_command
;;
--group | -group)
opt_prev=hostgroup
;;
--group=* | -group=*)
hostgroup="$optarg"; export hostgroup
;;
# Build
--format | -format)
opt_prev=format
;;
--format=* | -format=*)
format="$optarg"; export format
;;
--packed | --pack | -packed | -pack)
opt_prev=bd_packed
;;
--packed=* | -packed=*)
bd_packed="$optarg"; export bd_packed
;;
--user | -user)
opt_prev=bd_user
;;
--user=* | -user=*)
bd_user="$optarg"; export bd_user
;;
--add-path | -add-path | --addpath | -addpath)
opt_prev=bd_addpath
;;
--add-path=* | -add-path=* | --addpath=* | -addpath=*)
bd_addpath="$optarg"; export bd_addpath
;;
# Checksource
--delete | -delete)
cs_delete=1; export cs_delete
;;
# Download
--version | -version)
opt_prev=src_version
;;
--version=* | -version=*)
src_version="$optarg"; export src_version
;;
# Generic
--basedir | -basedir)
opt_prev=basedir
;;
--basedir=* | -basedir=*)
basedir="$optarg"; export basedir
;;
--host | -host)
opt_prev=host
;;
--host=* | -host=*)
host="$optarg"; export host
;;
--arch | -arch)
opt_prev=arch
;;
--arch=* | -arch=*)
arch="$optarg"; export arch
;;
--tmpdir | -tmpdir)
opt_prev=temp_dir
;;
--tmpdir=* | -tmpdir=*)
temp_dir="$optarg"; export temp_dir
;;
-o | --logfile | -logfile)
opt_prev=logfile
;;
-o=* | --logfile=* | -logfile=*)
logfile="$optarg"; export logfile
;;
-h | --h | --help | -help | help)
if test $# -gt 1
then
if test x"$2" = xdownload
then
showDOWNLOAD
elif test x"$2" = xinfo
then
showINFO
elif test x"$2" = xchecksrc
then
showCHECKSRC
elif test x"$2" = xclean
then
showCLEAN
elif test x"$2" = xbuild
then
showBUILD
elif test x"$2" = xinstall
then
showINSTALL
elif test x"$2" = xuninstall
then
showUNINSTALL
else
showUSAGE 1
fi
fi
showUSAGE
;;
-q | --quiet | -quiet | --silent | -silent)
if test x"$silent" = x0
then
silent=1; export silent
else
silent=2; export silent
fi
;;
-q=* | --quiet=* | --silent=* | -silent=*)
silent="$optarg"; export silent
;;
-s | --simulate | -simulate | --dry-run | -dry-run | --recon | -recon | --just-print | -just-print | --no-act | -no-act)
simulate=1; export simulate
;;
-y | --yes | -yes)
assumeyes=1; export assumeyes
;;
-d | --dialog | -dialog)
opt_prev=DIALOG
;;
-d=* | --dialog=* | -dialog=*)
DIALOG="$optarg"; export DIALOG
;;
-*)
showUSAGE 1
;;
clean | download | checksrc | build | install | info | uninstall)
action="$option"; export action
break ;;
esac
done
#########################################################################
#
# Subroutines
#
#########################################################################
# -----------------------------------------------------------------------
# Printing/logging Subroutines
# -----------------------------------------------------------------------
. ${basedir}/libexec/funcPRINT
# -----------------------------------------------------------------------
# Interaction Subroutines
# -----------------------------------------------------------------------
. ${basedir}/libexec/funcDIALOG
# -----------------------------------------------------------------------
# Setup test Subroutines
# -----------------------------------------------------------------------
. ${basedir}/libexec/funcSETUP
# -----------------------------------------------------------------------
# Subroutines for determining existence of / path to executables
# -----------------------------------------------------------------------
. ${basedir}/libexec/funcEXE
# -----------------------------------------------------------------------
# Subroutines for building
# -----------------------------------------------------------------------
. ${basedir}/libexec/funcBUILD
# -----------------------------------------------------------------------
# Subroutines for installing
# -----------------------------------------------------------------------
. ${basedir}/libexec/funcINSTALL
# -----------------------------------------------------------------------
# Subroutines for client database
# -----------------------------------------------------------------------
. ${basedir}/libexec/funcDB
# -----------------------------------------------------------------------
# Subroutine for the 'download' command
# -----------------------------------------------------------------------
. ${basedir}/libexec/comDOWNLOAD
# -----------------------------------------------------------------------
# Subroutine for the 'checksrc' command
# -----------------------------------------------------------------------
. ${basedir}/libexec/comCHECKSRC
# -----------------------------------------------------------------------
# Subroutine for the 'clean' command
# -----------------------------------------------------------------------
. ${basedir}/libexec/comCLEAN
# -----------------------------------------------------------------------
# Subroutine for the 'build' command
# -----------------------------------------------------------------------
. ${basedir}/libexec/comBUILD
# -----------------------------------------------------------------------
# Subroutine for the 'install' command
# -----------------------------------------------------------------------
. ${basedir}/libexec/comINSTALL
# -----------------------------------------------------------------------
# Subroutine for the 'install' command
# -----------------------------------------------------------------------
. ${basedir}/libexec/comUNINSTALL
#########################################################################
#
# Main
#
#########################################################################
main_exit_status=0
tmpdir=
# Find a dialog clone
#
findDIALOG
# Check for basedir and tmpdir
#
testSETUP1
# Logfile setup
#
exec 5>${basedir}/tmp/logfile.lastrun
now=`date`
echo "$now: $0 " ${1+"$@"} >&5
lastlog="${basedir}/tmp/logfile.lastrun"; export lastlog
logOpen=1
# Temporary directory/file setup
#
tmpD="$tmpdir/build.gui.$$"
mkdir "$tmpD" || printFATAL "Cannot create temporary directory $tmpD"
export tmpD
tmpF="$tmpD/tmpF.$$"
touch $tmpF || printFATAL "Cannot create temporary file $tmpF"
export tmpF
tmpERR="$tmpD/tmpERR.$$"
echo '0' > $tmpERR || printFATAL "Cannot create temporary file $tmpERR"
export tmpERR
# Trap exit and cleanup
#
trap "exit_status=$?; rm -rf $tmpD; exit ${exit_status};" 0
trap "(exit 1); exit 1;" 1 2 13 15
# Check for action to perform, and host, if required
#
testSETUP2
if test x"$action" = xdownload
then
if test x"$src_version" = x
then
src_version="current"; export src_version
fi
#---------------------------------------------------------------------
# Vodoo code to tee both stdout and stderr, but keep them seperate.
#---------------------------------------------------------------------
if test x"$DIALOG" = x
then
((commandDOWNLOAD | tee -a "$lastlog") 6>&1 1>&2 2>&6 | \
tee -a "$lastlog") 6>&1 1>&2 2>&6
else
commandDOWNLOAD 2>&1 | tee -a "$lastlog" >/dev/null | $DIALOG \
--title "deploy.sh $version DOWNLOAD logfile" \
--backtitle "Logfile: $lastlog" \
--tailbox "$lastlog" 19 75
fi
elif test x"$action" = xinfo
then
if test x"${showpkg}" = xn
then
if test x"$DIALOG" = x
then
((dbSHOWHOSTS "${host}" | tee -a "$lastlog") 6>&1 1>&2 2>&6 | \
tee -a "$lastlog") 6>&1 1>&2 2>&6
else
dbSHOWHOSTS "${host}" 2>&1 | tee -a "$lastlog" >/dev/null | $DIALOG \
--title "deploy.sh $version INFO logfile" \
--backtitle "Logfile: $lastlog" \
--tailbox "$lastlog" 19 75
fi
else
if test x"$DIALOG" = x
then
((dbSHOWPKG show | tee -a "$lastlog") 6>&1 1>&2 2>&6 | \
tee -a "$lastlog") 6>&1 1>&2 2>&6
else
dbSHOWPKG show 2>&1 | tee -a "$lastlog" >/dev/null | $DIALOG \
--title "deploy.sh $version INFO logfile" \
--backtitle "Logfile: $lastlog" \
--tailbox "$lastlog" 19 75
fi
fi
elif test x"$action" = xchecksrc
then
if test x"$DIALOG" = x
then
((commandCHECKSRC | tee -a "$lastlog") 6>&1 1>&2 2>&6 | \
tee -a "$lastlog") 6>&1 1>&2 2>&6
else
commandCHECKSRC 2>&1 | tee -a "$lastlog" >/dev/null | $DIALOG \
--title "deploy.sh $version CHECKSRC logfile" \
--backtitle "Logfile: $lastlog" \
--tailbox "$lastlog" 19 75
fi
elif test x"$action" = xclean
then
if test x"$DIALOG" = x
then
((commandCLEAN | tee -a "$lastlog") 6>&1 1>&2 2>&6 | \
tee -a "$lastlog") 6>&1 1>&2 2>&6
else
commandCLEAN 2>&1 | tee -a "$lastlog" >/dev/null | $DIALOG \
--title "deploy.sh $version CLEAN logfile" \
--backtitle "Logfile: $lastlog" \
--tailbox "$lastlog" 19 75
fi
elif test x"$action" = xbuild
then
#---------------------------------------------------------------------
# Make sure we are running under ssh-agent.
#---------------------------------------------------------------------
if test x"$SSH_AGENT_PID" = x
then
if test x"$assumeyes" = x1
then
printFATAL "Not running under ssh-agent, and not running interactive: cannot continue."
else
promptYESNO "Not running under ssh-agent, continue anyway" "no"
test "x$YESNO" = xn && { (exit 0; ); exit 0; }
fi
fi
#---------------------------------------------------------------------
# Setup.
#---------------------------------------------------------------------
selBVERSION
selBARCH
selBFORMAT
if test x"$DIALOG" = x
then
((commandBUILD | tee -a "$lastlog") 6>&1 1>&2 2>&6 | \
tee -a "$lastlog") 6>&1 1>&2 2>&6
else
commandBUILD 2>&1 | tee -a "$lastlog" >/dev/null | $DIALOG \
--title "deploy.sh $version BUILD logfile" \
--backtitle "Logfile: $lastlog" \
--tailbox "$lastlog" 19 75
fi
elif test x"$action" = xinstall
then
needEXE ssh scp ssh-agent
#---------------------------------------------------------------------
# Make sure we are running under ssh-agent.
#---------------------------------------------------------------------
if test x"$SSH_AGENT_PID" = x
then
if test x"$assumeyes" = x1
then
printFATAL "Not running under ssh-agent, and not running interactive: cannot continue."
else
promptYESNO "Not running under ssh-agent, continue anyway" "no"
test "x$YESNO" = xn && { (exit 0; ); exit 0; }
fi
fi
#---------------------------------------------------------------------
# Setup.
#---------------------------------------------------------------------
is_root=`id -u 2>/dev/null`
if test "x$?" = x0 && test "x${is_root}" != x0
then
promptYESNO "You are not root, continue anyway" "no"
test "x$YESNO" = xn && { (exit 0; ); exit 0; }
else
is_root=0
fi
pathYULE
pathYDATA
selbinARCH
selbinVERSION
if test "x${is_init}" = xy
then
promptYESNO "Initialize database" "yes"
is_init=$YESNO
fi
if test "x${is_rcfile}" = xy
then
promptYESNO "Replace rc.host file on server" "yes"