source: trunk/deploy.sh.in @ 308

Last change on this file since 308 was 308, checked in by katerina, 10 years ago

Fix hardcoded temp directory in deployment scripts (ticket #230).

File size: 29.8 KB
Line 
1#! /bin/sh
2
3#
4# Copyright Rainer Wichmann (2005)
5#
6# License Information:
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20#
21
22#VERSION2.0
23
24# -----------------------------------------------------------------------
25# Be Bourne compatible
26# -----------------------------------------------------------------------
27
28if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
29  emulate sh
30  NULLCMD=:
31elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
32  set -o posix
33fi
34
35# -----------------------------------------------------------------------
36# Make sure we support functions (from the autoconf manual)
37# -----------------------------------------------------------------------
38
39SHELL="${SHELL-/bin/sh}"
40if test x"$1" = "x--re-executed"
41then
42    shift
43elif "$SHELL" -c 'foo () { (exit 0); exit 0; }; foo' 2>/dev/null
44then
45    :
46else
47    for cmd in sh bash ash bsh ksh zsh sh5; do
48        X="$PATH:/bin:/usr/bin:/usr/afsws/bin:/usr/ucb";
49        OLD_IFS=${IFS}
50        IFS=':'; export IFS
51        for dir in $X; do
52            shell="$dir/$cmd"
53            if (test -f "$shell" || test -f "$shell.exe")
54            then
55                if "$shell" -c  'foo () { (exit 0); exit 0; }; foo' 2>/dev/null
56                then
57                    SHELL="$shell"; export SHELL
58                    IFS=${OLD_IFS}; export IFS
59                    exec "$shell" "$0" --re-executed ${1+"$@"}
60                fi
61            fi
62        done
63        IFS=${OLD_IFS}; export IFS
64    done
65    echo "-----------------------------------------------------------------"
66    echo "ERROR: Unable to locate a shell interpreter with function support" >&2
67    echo "-----------------------------------------------------------------"
68    { (exit 1); exit 1; }
69fi
70
71# -----------------------------------------------------------------------
72# Test for 'echo -n'
73# -----------------------------------------------------------------------
74
75case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
76  *c*,*  ) ECHO_N=-n ECHO_C= ;;
77  *)       ECHO_N= ECHO_C='\c' ;;
78esac
79
80as_cr_letters='abcdefghijklmnopqrstuvwxyz'
81as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
82as_cr_Letters=$as_cr_letters$as_cr_LETTERS
83as_cr_digits='0123456789'
84as_cr_alnum=$as_cr_Letters$as_cr_digits
85
86
87#########################################################################
88#
89# Configuration section
90#
91#########################################################################
92
93# -----------------------------------------------------------------------
94# The following part will be cut and saved to ~/.deploy.conf
95# -----------------------------------------------------------------------
96
97#__BEGIN_CUT__
98
99#########################################################################
100#
101# This file is sourced by a Bourne shell script.
102# Thus you need to take care of proper shell syntax.
103#
104#########################################################################
105
106# if you need, you can expand your PATH environment variable here
107# just uncomment and replace /opt/contrib/bin with whatever you need
108#
109# PATH="/opt/contrib/bin:${PATH}"; export PATH
110
111# the base directory of the deployment system
112# CLI option: --basedir=...
113#
114defbasedir="@mydataroot@/profiles"
115
116# the name of the database of installed clients
117# no CLI option
118#
119defdatabase="yulerc.install.db"
120
121# be quiet; 0 = false, 1 = true, 2 = very quiet
122# CLI option: --quiet | --quiet=2
123#
124silent=0;
125
126# assume yes as answer to all prompts and run non-interactively
127# 0 = false, 1 = true
128# CLI option: --yes
129#
130assumeyes=0;
131
132# which 'dialog' to use (e.g. "Xdialog")
133# "no" for plain text; empty ("") lets the program search for dialog
134# CLI option: --dialog=...
135#
136prefdialog=""
137
138# operating system; no default
139# CLI option: --arch=...
140#
141arch=""
142
143# Format for binary packages (run | deb | rpm | tbz2 | solaris-pkg | depot)
144# CLI option: --format=...
145#
146format=""
147 
148# logfile; default is none
149# CLI option: --logfile=...
150#
151logfile=""
152
153# The path to the yule (samhain server) executable.
154# CLI option: --yule_exec=...
155#
156yule_exec="@sbindir@/yule"
157
158# The path to the yule (samhain server) configuration file.
159# CLI option: --yule_conf=...
160#
161yule_conf="@sysconfdir@/yulerc"
162
163# The path to the data directory of yule (samhain server).
164# This is the directory where client configuration/database files
165# are stored.
166# CLI option: --yule_data=...
167#
168yule_data="@mydataroot@"
169
170# The temporary directory to use. Default is '/tmp', but some
171# sites may mount this 'noexec'.
172#
173temp_dir="/tmp"
174
175#__END_CUT__
176
177# -----------------------------------------------------------------------
178# Write configuration file to user home directory/Read configuration file
179# -----------------------------------------------------------------------
180
181if test -f ~/.deploy.conf
182then
183    . ~/.deploy.conf
184else
185    #
186    # From the autoconf configure script - search ourselves
187    #
188    case $0 in
189        *[\\/]* ) as_myself=$0 ;;
190        *) old_IFS=$IFS; IFS=:
191        for as_dir in $PATH
192        do
193            IFS=$old_IFS
194            test -z "$as_dir" && as_dir=.
195            test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
196        done
197        ;;
198    esac
199    # We did not find ourselves, most probably we were run as `sh COMMAND'
200    # in which case we are not to be found in the path.
201    if test "x$as_myself" = x; then
202        as_myself=$0
203    fi
204    if test ! -f "$as_myself"; then
205        { echo "ERROR: cannot find myself; rerun with an absolute path" >&2
206    { (exit 1); exit 1; }; }
207    fi
208    cat "$as_myself" | sed  -n -e '/^#__BEGIN_CUT__/,/^#__END_CUT__/ p ' >~/.deploy.conf && {
209        echo
210        echo "-----------------------------------------------------"
211        echo " Configuration file ~/.deploy.conf created"
212        echo " You may want to edit it to adapt it to your needs"
213        echo "-----------------------------------------------------"
214        echo
215        }
216fi
217
218export silent
219export assumeyes
220export arch
221export logfile
222export format
223export yule_exec
224export yule_conf
225export yule_data
226export temp_dir
227
228# dialog
229#
230DIALOG="${prefdialog}";
231export DIALOG
232
233# base directory
234#
235basedir="$defbasedir";
236export basedir
237
238# simulate only; 0 = false, 1 = true
239#
240simulate=0;
241export simulate
242
243# version
244#
245version=2.0;
246export version
247
248# host; no default
249#
250host=
251export host
252
253# hostgroup; empty default
254#
255hostgroup=
256export hostgroup
257
258
259# action; no default
260#
261action=
262export action
263
264# the 'log.lastrun' logfile
265#
266logOpen=0
267export logOpen
268
269
270# source version; default = current
271#
272src_version=""
273export src_version
274
275# checksrc; do you want to delete if PGP signature check fails ?
276#
277cs_delete=0
278export cs_delete
279
280# build; do you want to pack the executable ?
281#
282bd_packed=''
283export bd_packed
284
285bd_user='root'
286export bd_user
287
288# addpath
289#
290bd_addpath=""
291export bd_addpath
292
293# Install; do you want to initialize the database ?
294#
295is_init=y
296export is_init
297
298# Install; do you want to replace the rc.host file ?
299#
300is_rcfile=y
301export is_rcfile
302
303# Install; do you want to start the client ?
304#
305is_startup=y
306export is_startup
307
308# Install; optional local command ?
309#
310local_command=""; export local_command
311
312# Info on packages ?
313#
314showpkg=n
315export showpkg
316
317#########################################################################
318#
319# Help Subroutines
320#
321#########################################################################
322
323# -----------------------------------------------------------------------
324# We cannot source these, because we don't know yet the base directory
325# -----------------------------------------------------------------------
326
327showUNINSTALL() {
328    echo "deploy.sh $version"
329    echo "USAGE: deploy.sh [options] uninstall"
330    echo
331    echo "Uninstall the samhain client from the specified host. Can only be"
332    echo "used if the client has been installed with deploy.sh version 2."
333    echo
334    echo "Options:"
335    echo
336    echo " --host=<hostname>      The host where you want to uninstall."
337    echo
338    { (exit 0); exit 0; }
339}
340
341showINFO() {
342    echo "deploy.sh $version"
343    echo "USAGE: deploy.sh [options] info"
344    echo
345    echo "Show info for hosts in client database (default), or for available"
346    echo "binary installer packages."
347    echo
348    echo "Options:"
349    echo
350    echo " --packages             Show info on packages."
351    echo
352    { (exit 0); exit 0; }
353}
354
355showCLEAN() {
356    echo "deploy.sh $version"
357    echo "USAGE: deploy.sh [options] clean"
358    echo
359    echo "Remove all files that are no longer needed:"
360    echo "  - Source tarballs in ${basedir}/source"
361    echo "  - Unused installer packages in ${basedir}/archpkg"
362    echo
363    { (exit 0); exit 0; }
364}
365
366showCHECKSRC() {
367    echo "deploy.sh $version"
368    echo "USAGE: deploy.sh [options] checksrc"
369    echo
370    echo "Check PGP signatures of source tarballs in the source/ subdirectory"
371    echo "of the deploy system."
372    echo "You must have gpg (GnuPG) in your PATH, and you should have imported"
373    echo "the samhain release PGP key (Key ID 0F571F6C, Rainer Wichmann)."
374    echo "To import the key, simply execute the command"
375    echo "\"gpg --keyserver blackhole.pca.dfn.de --recv-keys 0F571F6C\""
376    echo
377    echo "Options:"
378    echo
379    echo " --delete               Delete source tarballs if PGP signature"
380    echo "        cannot be verified."
381    echo
382    { (exit 0); exit 0; }
383}
384
385showDOWNLOAD() {
386    echo "deploy.sh $version"
387    echo "USAGE: deploy.sh [options] download"
388    echo
389    echo "Download a samhain source tarball from http://www.la-samhna.de,"
390    echo "check its PGP signature, and install it into the source/ subdirectory"
391    echo "of the deploy system."
392    echo "You must have gpg (GnuPG) in your PATH, and you should have imported"
393    echo "the samhain release PGP key (Key ID 0F571F6C, Rainer Wichmann)."
394    echo "To import the key, simply execute the command"
395    echo "\"gpg --keyserver blackhole.pca.dfn.de --recv-keys 0F571F6C\""
396    echo
397    echo "Options:"
398    echo
399    echo " --version=<version>    Version of samhain to download. The"
400    echo "        default is \"current\" to download the current version."
401    echo
402    { (exit 0); exit 0; }
403}
404
405showBUILD() {
406    echo "deploy.sh $version"
407    echo "USAGE: deploy.sh [options] build"
408    echo
409    echo "Copy a source tarball to a build machine, build a binary package, and fetch"
410    echo "the package. Will bail out if not running under ssh-agent. If you are sure"
411    echo "that you don't need ssh-agent, set the environment variable SSH_AGENT_PID"
412    echo "to some arbitrary string before launching the deploy.sh command."
413    echo
414    echo "Options:"
415    echo
416    echo " --host=<hostname>      The build host."
417    echo " --arch=<arch>          The architecture/operating system to build for."
418    echo "        This is used to get the \"./configure\" options from the file"
419    echo "        \${basedir}/configs/\${arch}.configure."
420    echo " --version=<version>    The version of samhain you want to build."
421    echo " --format=<run|rpm|deb|tbz2|solaris-pkg|depot>"
422    echo "        The format of the package. \"run\" is a portable tar"
423    echo "        package, \"deb\" is for Debian, \"tbz2\" for Gentoo,"
424    echo "        \"rpm\" for any RPM-based Linux, \"solaris-pkg\""
425    echo "        for Sun Solaris, and \"depot\" for HP-UX"
426    echo " --packed=<password>    The client password, if you want to"
427    echo "        create a packed executable. Defaults to empty (don't pack)"
428    echo " --user=<username>      Login as <username> to the build host (root)."
429    echo " --add-path=<path>      Append 'path' to the PATH variable on the build host."
430    { (exit 0); exit 0; }
431}
432
433showINSTALL() {
434    echo "deploy.sh $version"
435    echo "USAGE: deploy.sh [options] install"
436    echo
437    echo "Copy a pre-built binary installer package to a remote host, stop the client"
438    echo "running there (if any), install the (new) client, optionally initialize"
439    echo "the file signature database and fetch it from the remote host, update"
440    echo "the server configuration file and reload the server."
441    echo
442    echo "Options:"
443    echo
444    echo " --host=<FQDN>          The host where you want to install."
445    echo " --group=<group>        Optional group the host belongs to."
446    echo " --arch=<arch>          The architecture/operating system of this host."
447    echo "        This is used to get the correct binary package."
448    echo " --version=<version>    The version of samhain you want to install."
449    echo " --format=<run|rpm|deb|tbz2|solaris-pkg|depot>"
450    echo "        The format of the binary package."
451    echo " --yule_exec=<path>     The path to the 'yule' executable."
452    echo " --yule_conf=<path>     The path to the 'yule' configuration file."
453    echo " --yule_data=<path>     The path to the 'yule' data directory."
454    echo " --no-init              Do not initialize the file signature database."
455    echo " --no-rcfile            Do not replace the rc.host file on server."
456    echo " --no-start             Do not start the client after installation."
457    echo " --local=<path>         Local command (executed twice: "
458    echo "                        after config installation and before client startup)."
459    { (exit 0); exit 0; }
460}
461
462showUSAGE() {
463    echo "deploy.sh $version"
464    echo "USAGE: deploy.sh [options] command"
465    echo
466    echo "Commands: info | clean | download | checksrc | build | install | uninstall"
467    echo
468    echo "Options:"
469    echo " -h | --help            Print general usage information."
470    echo " -h | --help <command>  Print usage information for \"command\"."
471    echo " --basedir=<directory>  Set the basedir for the deployment system."
472    echo "                        The default is ${defbasedir}."
473    echo " -q | --quiet           Produce output suitable for logging."
474    echo "        You can also use -q=# to set the quiet level up to"
475    echo "        a maximum of 2. Note that -q=2 implies --yes (see below)."
476    echo " -s | --simulate        Perform  a  simulation  of events that"
477    echo "        would occur but do not actually change the  system."
478    echo " -y | --yes             Assume "yes" as answer to"
479    echo "        all prompts and run non-interactively."
480    echo " -o <file> | --logfile=<file>"
481    echo "        Specify an output file for messages that would go to stdout"
482    echo "        otherwise. Has no effect on stderr (error messages)."
483    echo " -d <dialog> | --dialog=<dialog>  Specify your preferred \"dialog\""
484    echo "        clone (e.g. Xdialog). Use \"no\" to force plain text."
485    if test x"$1" = x
486    then
487        { (exit 0); exit 0; }
488    else
489        { (exit $1); exit $1; }
490    fi
491}
492
493#########################################################################
494#
495# Command line
496#
497#########################################################################
498
499for option
500do
501
502  # If the previous option needs an argument, assign it.
503  #
504  if test -n "$opt_prev"; then
505    eval "$opt_prev=\$option"
506    eval export "$opt_prev"
507    opt_prev=
508    continue
509  fi
510
511  case "$option" in
512  -*=*) optarg=`echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
513  *) optarg= ;;
514  esac
515
516  case "$option" in
517
518  # Info
519
520  --packages | -packages)
521    showpkg=y; export showpkg;
522    ;;
523
524  # Install
525
526  --yule_exec | -yule_exec | --yule-exec | -yule-exec)
527    opt_prev=yule_exec
528    ;;
529
530  --yule_exec=* | -yule_exec=* | --yule-exec=* | -yule-exec=*)
531    yule_exec="$optarg"; export yule_exec
532    ;;
533
534  --yule_conf | -yule_conf | --yule-conf | -yule-conf)
535    opt_prev=yule_conf
536    ;;
537
538  --yule_conf=* | -yule_conf=* | --yule-conf=* | -yule-conf=*)
539    yule_conf="$optarg"; export yule_conf
540    ;;
541
542  --yule_data | -yule_data | --yule-data | -yule-data)
543    opt_prev=yule_data
544    ;;
545
546  --yule_data=* | -yule_data=* | --yule-data=* | -yule-data=*)
547    yule_data="$optarg"; export yule_data
548    ;;
549
550  --no-init | -no-init)
551    is_init=n; export is_init
552    ;;
553
554  --no-rcfile | -no-rcfile)
555    is_rcfile=n; export is_rcfile
556    ;;
557
558  --no-start | -no-start)
559    is_startup=n; export is_startup
560    ;;
561
562  --local | -local)
563    opt_prev=local_command
564    ;;
565
566  --local=* | -local=*)
567    local_command="$optarg"; export local_command
568    ;;
569
570  --group | -group)
571    opt_prev=hostgroup
572    ;;
573
574  --group=* | -group=*)
575    hostgroup="$optarg"; export hostgroup
576    ;;
577
578  # Build
579
580  --format | -format)
581    opt_prev=format
582    ;;
583
584  --format=* | -format=*)
585    format="$optarg"; export format
586    ;;
587
588  --packed | --pack | -packed | -pack)
589    opt_prev=bd_packed
590    ;;
591
592  --packed=* | -packed=*)
593    bd_packed="$optarg"; export bd_packed
594    ;;
595
596  --user | -user)
597    opt_prev=bd_user
598    ;;
599
600  --user=* | -user=*)
601    bd_user="$optarg"; export bd_user
602    ;;
603
604  --add-path | -add-path | --addpath | -addpath)
605    opt_prev=bd_addpath
606    ;;
607
608  --add-path=* | -add-path=* | --addpath=* | -addpath=*)
609    bd_addpath="$optarg"; export bd_addpath
610    ;;
611
612  # Checksource
613
614  --delete | -delete)
615    cs_delete=1; export cs_delete
616    ;;
617
618  # Download
619
620  --version | -version)
621    opt_prev=src_version
622    ;;
623  --version=* | -version=*)
624    src_version="$optarg"; export src_version
625    ;;
626
627  # Generic
628
629  --basedir | -basedir)
630    opt_prev=basedir
631    ;;
632  --basedir=* | -basedir=*)
633    basedir="$optarg"; export basedir
634    ;;
635
636  --host | -host)
637    opt_prev=host
638    ;;
639  --host=* | -host=*)
640    host="$optarg"; export host
641    ;;
642
643  --arch | -arch)
644    opt_prev=arch
645    ;;
646  --arch=* | -arch=*)
647    arch="$optarg"; export arch
648    ;;
649
650  --tmpdir | -tmpdir)
651    opt_prev=temp_dir
652    ;;
653  --tmpdir=* | -tmpdir=*)
654    temp_dir="$optarg"; export temp_dir
655    ;;
656
657  -o | --logfile | -logfile)
658    opt_prev=logfile
659    ;;
660  -o=* | --logfile=* | -logfile=*)
661    logfile="$optarg"; export logfile
662    ;;
663
664  -h | --h | --help | -help | help)
665    if test $# -gt 1
666    then
667        if test x"$2" = xdownload
668        then
669            showDOWNLOAD
670        elif test x"$2" = xinfo
671        then
672            showINFO
673        elif test x"$2" = xchecksrc
674        then
675            showCHECKSRC
676        elif test x"$2" = xclean
677        then
678            showCLEAN
679        elif test x"$2" = xbuild
680        then
681            showBUILD
682        elif test x"$2" = xinstall
683        then
684            showINSTALL
685        elif test x"$2" = xuninstall
686        then
687            showUNINSTALL
688        else
689            showUSAGE 1
690        fi
691    fi
692    showUSAGE
693    ;;
694
695  -q | --quiet | -quiet | --silent | -silent)
696    if test x"$silent" = x0
697    then
698        silent=1; export silent
699    else
700        silent=2; export silent
701    fi
702    ;;
703  -q=* | --quiet=* | --silent=* | -silent=*)
704    silent="$optarg"; export silent
705    ;;
706
707  -s | --simulate | -simulate | --dry-run | -dry-run | --recon | -recon | --just-print | -just-print | --no-act | -no-act)
708    simulate=1; export simulate
709    ;;
710
711  -y | --yes | -yes)
712    assumeyes=1; export assumeyes
713    ;;
714
715  -d | --dialog | -dialog)
716    opt_prev=DIALOG
717    ;;
718  -d=* | --dialog=* | -dialog=*)
719    DIALOG="$optarg"; export DIALOG
720    ;;
721
722  -*)
723    showUSAGE 1
724    ;;
725
726  clean | download | checksrc | build | install | info | uninstall)
727    action="$option"; export action
728    break ;;
729  esac
730
731done
732
733#########################################################################
734#
735# Subroutines
736#
737#########################################################################
738
739# -----------------------------------------------------------------------
740# Printing/logging Subroutines
741# -----------------------------------------------------------------------
742. ${basedir}/libexec/funcPRINT
743
744# -----------------------------------------------------------------------
745# Interaction Subroutines
746# -----------------------------------------------------------------------
747. ${basedir}/libexec/funcDIALOG
748
749# -----------------------------------------------------------------------
750# Setup test Subroutines
751# -----------------------------------------------------------------------
752. ${basedir}/libexec/funcSETUP
753
754# -----------------------------------------------------------------------
755# Subroutines for determining existence of / path to executables
756# -----------------------------------------------------------------------
757. ${basedir}/libexec/funcEXE
758
759# -----------------------------------------------------------------------
760# Subroutines for building
761# -----------------------------------------------------------------------
762. ${basedir}/libexec/funcBUILD
763
764# -----------------------------------------------------------------------
765# Subroutines for installing
766# -----------------------------------------------------------------------
767. ${basedir}/libexec/funcINSTALL
768
769# -----------------------------------------------------------------------
770# Subroutines for client database
771# -----------------------------------------------------------------------
772. ${basedir}/libexec/funcDB
773
774# -----------------------------------------------------------------------
775# Subroutine for the 'download' command
776# -----------------------------------------------------------------------
777. ${basedir}/libexec/comDOWNLOAD
778
779# -----------------------------------------------------------------------
780# Subroutine for the 'checksrc' command
781# -----------------------------------------------------------------------
782. ${basedir}/libexec/comCHECKSRC
783
784# -----------------------------------------------------------------------
785# Subroutine for the 'clean' command
786# -----------------------------------------------------------------------
787. ${basedir}/libexec/comCLEAN
788
789# -----------------------------------------------------------------------
790# Subroutine for the 'build' command
791# -----------------------------------------------------------------------
792. ${basedir}/libexec/comBUILD
793
794# -----------------------------------------------------------------------
795# Subroutine for the 'install' command
796# -----------------------------------------------------------------------
797. ${basedir}/libexec/comINSTALL
798
799# -----------------------------------------------------------------------
800# Subroutine for the 'install' command
801# -----------------------------------------------------------------------
802. ${basedir}/libexec/comUNINSTALL
803
804
805#########################################################################
806#
807# Main
808#
809#########################################################################
810
811main_exit_status=0
812
813tmpdir=
814
815# Find a dialog clone
816#
817findDIALOG
818
819# Check for basedir and tmpdir
820#
821testSETUP1
822
823# Logfile setup
824#
825exec 5>${basedir}/tmp/logfile.lastrun
826now=`date`
827echo "$now: $0 " ${1+"$@"} >&5
828lastlog="${basedir}/tmp/logfile.lastrun"; export lastlog
829logOpen=1
830
831# Temporary directory/file setup
832#
833tmpD="$tmpdir/build.gui.$$"
834mkdir "$tmpD" || printFATAL "Cannot create temporary directory $tmpD"
835export tmpD
836tmpF="$tmpD/tmpF.$$"
837touch $tmpF || printFATAL "Cannot create temporary file $tmpF"
838export tmpF
839tmpERR="$tmpD/tmpERR.$$"
840echo '0' > $tmpERR || printFATAL "Cannot create temporary file $tmpERR"
841export tmpERR
842
843# Trap exit and cleanup
844#
845trap "exit_status=$?; rm -rf $tmpD; exit ${exit_status};" 0
846trap "(exit 1); exit 1;" 1 2 13 15
847
848# Check for action to perform, and host, if required
849#
850testSETUP2
851
852if test x"$action" = xdownload
853then
854    if test x"$src_version" = x
855    then
856        src_version="current"; export src_version
857    fi
858    #---------------------------------------------------------------------
859    # Vodoo code to tee both stdout and stderr, but keep them seperate.
860    #---------------------------------------------------------------------
861    if test x"$DIALOG" = x
862    then
863        ((commandDOWNLOAD | tee -a "$lastlog") 6>&1 1>&2 2>&6 | \
864        tee -a "$lastlog") 6>&1 1>&2 2>&6
865    else
866        commandDOWNLOAD 2>&1 | tee -a "$lastlog" >/dev/null | $DIALOG \
867        --title "deploy.sh $version DOWNLOAD logfile" \
868        --backtitle "Logfile:  $lastlog" \
869        --tailbox "$lastlog" 19 75
870    fi
871elif test x"$action" = xinfo
872then
873    if test x"${showpkg}" = xn
874    then
875      if test x"$DIALOG" = x
876      then
877        ((dbSHOWHOSTS "${host}" | tee -a "$lastlog") 6>&1 1>&2 2>&6 | \
878        tee -a "$lastlog") 6>&1 1>&2 2>&6
879      else
880        dbSHOWHOSTS "${host}" 2>&1 | tee -a "$lastlog" >/dev/null | $DIALOG \
881        --title "deploy.sh $version INFO logfile" \
882        --backtitle "Logfile:  $lastlog" \
883        --tailbox "$lastlog" 19 75
884      fi
885    else
886      if test x"$DIALOG" = x
887      then
888        ((dbSHOWPKG show | tee -a "$lastlog") 6>&1 1>&2 2>&6 | \
889        tee -a "$lastlog") 6>&1 1>&2 2>&6
890      else
891        dbSHOWPKG show 2>&1 | tee -a "$lastlog" >/dev/null | $DIALOG \
892        --title "deploy.sh $version INFO logfile" \
893        --backtitle "Logfile:  $lastlog" \
894        --tailbox "$lastlog" 19 75
895      fi
896    fi
897elif test x"$action" = xchecksrc
898then
899    if test x"$DIALOG" = x
900    then
901        ((commandCHECKSRC | tee -a "$lastlog") 6>&1 1>&2 2>&6 | \
902        tee -a "$lastlog") 6>&1 1>&2 2>&6
903    else
904        commandCHECKSRC 2>&1 | tee -a "$lastlog" >/dev/null | $DIALOG \
905        --title "deploy.sh $version CHECKSRC logfile" \
906        --backtitle "Logfile:  $lastlog" \
907        --tailbox "$lastlog" 19 75
908    fi
909elif test x"$action" = xclean
910then
911    if test x"$DIALOG" = x
912    then
913        ((commandCLEAN | tee -a "$lastlog") 6>&1 1>&2 2>&6 | \
914        tee -a "$lastlog") 6>&1 1>&2 2>&6
915    else
916        commandCLEAN 2>&1 | tee -a "$lastlog" >/dev/null | $DIALOG \
917        --title "deploy.sh $version CLEAN logfile" \
918        --backtitle "Logfile:  $lastlog" \
919        --tailbox "$lastlog" 19 75
920    fi
921elif test x"$action" = xbuild
922then
923
924    #---------------------------------------------------------------------
925    # Make sure we are running under ssh-agent.
926    #---------------------------------------------------------------------
927    if test x"$SSH_AGENT_PID" = x
928    then
929        if test x"$assumeyes" = x1
930        then
931            printFATAL "Not running under ssh-agent, and not running interactive: cannot continue."
932        else
933            promptYESNO "Not running under ssh-agent, continue anyway" "no"
934            test "x$YESNO" = xn && { (exit 0; ); exit 0; }
935        fi
936    fi
937
938    #---------------------------------------------------------------------
939    # Setup.
940    #---------------------------------------------------------------------
941    selBVERSION
942    selBARCH
943    selBFORMAT
944
945    if test x"$DIALOG" = x
946    then
947        ((commandBUILD | tee -a "$lastlog") 6>&1 1>&2 2>&6 | \
948        tee -a "$lastlog") 6>&1 1>&2 2>&6
949    else
950        commandBUILD 2>&1 | tee -a "$lastlog" >/dev/null | $DIALOG \
951        --title "deploy.sh $version BUILD logfile" \
952        --backtitle "Logfile:  $lastlog" \
953        --tailbox "$lastlog" 19 75
954    fi
955
956elif test x"$action" = xinstall
957then
958
959    needEXE ssh scp ssh-agent
960
961    #---------------------------------------------------------------------
962    # Make sure we are running under ssh-agent.
963    #---------------------------------------------------------------------
964    if test x"$SSH_AGENT_PID" = x
965    then
966        if test x"$assumeyes" = x1
967        then
968            printFATAL "Not running under ssh-agent, and not running interactive: cannot continue."
969        else
970            promptYESNO "Not running under ssh-agent, continue anyway" "no"
971            test "x$YESNO" = xn && { (exit 0; ); exit 0; }
972        fi
973    fi
974
975    #---------------------------------------------------------------------
976    # Setup.
977    #---------------------------------------------------------------------
978    is_root=`id -u 2>/dev/null`
979    if test "x$?" = x0 && test "x${is_root}" != x0
980    then
981        promptYESNO "You are not root, continue anyway" "no"
982        test "x$YESNO" = xn && { (exit 0; ); exit 0; }
983    else
984        is_root=0
985    fi
986    pathYULE
987    pathYDATA
988    selbinARCH
989    selbinVERSION
990    if test "x${is_init}" = xy
991    then
992        promptYESNO "Initialize database" "yes"
993        is_init=$YESNO
994    fi
995    if test "x${is_rcfile}" = xy
996    then
997        promptYESNO "Replace rc.host file on server" "yes"
998        is_rcfile=$YESNO
999    fi
1000    if test "x${is_startup}" = xy
1001    then
1002        promptYESNO "Start client after installation" "yes"
1003        is_startup=$YESNO
1004    fi
1005    if test -f "${yule_conf}"
1006    then
1007        :
1008    else
1009        promptINPUT "Please enter the path to the yule configuration file"
1010        yule_conf="$INPUT"; export yule_conf
1011        if test -f "${yule_conf}"
1012        then
1013            :
1014        else
1015            printFATAL "Cannot find ${yule_conf}"
1016        fi
1017    fi
1018
1019    if test x"$DIALOG" = x
1020    then
1021        ((commandINSTALL | tee -a "$lastlog") 6>&1 1>&2 2>&6 | \
1022        tee -a "$lastlog") 6>&1 1>&2 2>&6
1023    else
1024        commandINSTALL 2>&1 | tee -a "$lastlog" >/dev/null | $DIALOG \
1025        --title "deploy.sh $version INSTALL logfile" \
1026        --backtitle "Logfile:  $lastlog" \
1027        --tailbox "$lastlog" 19 75
1028    fi
1029
1030elif test x"$action" = xuninstall
1031then
1032
1033    needEXE ssh scp ssh-agent
1034
1035    #---------------------------------------------------------------------
1036    # Make sure we are running under ssh-agent.
1037    #---------------------------------------------------------------------
1038    if test x"$SSH_AGENT_PID" = x
1039    then
1040        if test x"$assumeyes" = x1
1041        then
1042            printFATAL "Not running under ssh-agent, and not running interactive: cannot continue."
1043        else
1044            promptYESNO "Not running under ssh-agent, continue anyway" "no"
1045            test "x$YESNO" = xn && { (exit 0; ); exit 0; }
1046        fi
1047    fi
1048
1049    #---------------------------------------------------------------------
1050    # Setup.
1051    #---------------------------------------------------------------------
1052
1053    dbINFO "$host"
1054
1055    if test x"$?" = x0
1056    then
1057        if test x"${DB_status}" = "xD2_installed"
1058        then
1059            :
1060        else
1061            if test x"${DB_status}" = "xD2_removed"
1062            then
1063                promptYESNO "Already uninstalled on host $host, continue" "no"
1064                test "x$YESNO" = xn && { (exit 0; ); exit 0; }
1065            else
1066                printFATAL "No deploy version 2 installation on host $host: ${DB_status}"
1067            fi
1068        fi
1069    else
1070        printFATAL "Cannot uninstall on host $host"
1071    fi
1072
1073    if test x"$DIALOG" = x
1074    then
1075        ((commandUNINSTALL | tee -a "$lastlog") 6>&1 1>&2 2>&6 | \
1076        tee -a "$lastlog") 6>&1 1>&2 2>&6
1077    else
1078        commandUNINSTALL 2>&1 | tee -a "$lastlog" >/dev/null | $DIALOG \
1079        --title "deploy.sh $version UNINSTALL logfile" \
1080        --backtitle "Logfile:  $lastlog" \
1081        --tailbox "$lastlog" 19 75
1082    fi
1083
1084fi
1085
1086if test x"${main_exit_status}" = x0
1087then
1088    test -f "$tmpERR" && main_exit_status=`cat "$tmpERR" | tr -d '\n'`
1089fi
1090
1091(exit ${main_exit_status}); exit ${main_exit_status};
Note: See TracBrowser for help on using the repository browser.