Annotation of embedaddon/strongswan/testing/scripts/build-strongswan, revision 1.1.1.2

1.1       misho       1: #!/bin/bash
                      2: 
                      3: DIR=$(dirname `readlink -f $0`)
                      4: . $DIR/../testing.conf
                      5: . $DIR/function.sh
                      6: 
                      7: [ `id -u` -eq 0 ] || die "You must be root to run $0"
                      8: [ -f "$BASEIMG" ] || die "Base image $BASEIMG not found"
                      9: running_any $STRONGSWANHOSTS && die "Please stop test environment before running $0"
                     10: 
                     11: SRCUID=${SUDO_UID:-$(id -u)}
                     12: SRCGID=${SUDO_GID:-$(id -g)}
                     13: 
1.1.1.2 ! misho      14: check_commands partprobe qemu-img qemu-nbd
1.1       misho      15: 
                     16: load_qemu_nbd
                     17: 
                     18: mkdir -p $LOOPDIR
                     19: mkdir -p $IMGDIR
                     20: 
1.1.1.2 ! misho      21: usage() {
        !            22: cat << EOF
        !            23: Usage:
        !            24:   ${0##*/} [--all] [--guest NAME|--no-guests] [--replace] [--clean] [SRCDIR]
        !            25:   ${0##*/} [--all] [--guest NAME|--no-guests] [--replace] [--tarball VERSION]
        !            26:     --help            (-h)  show usage information
        !            27:     --all             (-a)  build/install all software, not only strongSwan
        !            28:     --clean           (-c)  use a new strongSwan build directory
        !            29:     --guest NAME      (-g)  only install in a specific guest image
        !            30:     --no-guests       (-n)  don't build any guest images after the root image
        !            31:     --replace         (-r)  replace the root image (implies --all)
        !            32:     --tarball         (-t)  build strongSwan from a release tarball
        !            33: EOF
        !            34: }
        !            35: 
        !            36: ALL_RECIPES=
        !            37: CLEAN=
        !            38: GUEST=
        !            39: NO_GUESTS=
        !            40: REPLACE=
        !            41: TARBALL=
        !            42: 
        !            43: while :; do
        !            44:        case $1 in
        !            45:        -h|--help)
        !            46:                usage
        !            47:                exit
        !            48:                ;;
        !            49:        -a|--all)
        !            50:                ALL_RECIPES=1
        !            51:                ;;
        !            52:        -c|--clean)
        !            53:                CLEAN=1
        !            54:                ;;
        !            55:        -g|--guest)
        !            56:                if [ "$2" ]; then
        !            57:                        GUEST=$2
        !            58:                        shift
        !            59:                else
        !            60:                        die "Guest name missing"
        !            61:                fi
        !            62:                ;;
        !            63:        -n|--no-guests)
        !            64:                NO_GUESTS=1
        !            65:                ;;
        !            66:        -r|--replace)
        !            67:                REPLACE=1
        !            68:                ;;
        !            69:        -t|--tarball)
        !            70:                if [ "$2" ]; then
        !            71:                        TARBALL=$2
        !            72:                        shift
        !            73:                else
        !            74:                        die "Release version missing"
        !            75:                fi
        !            76:                ;;
        !            77:        *)
        !            78:                break
        !            79:        esac
        !            80: 
        !            81:        shift
        !            82: done
        !            83: 
        !            84: SWANDIR=
        !            85: 
        !            86: if [ -z "$TARBALL" ]; then
        !            87:        check_commands bindfs
        !            88: 
        !            89:        SWANDIR=${1:+$(readlink -f $1)}
        !            90:        : ${SWANDIR:=$(readlink -f $DIR/../..)}
        !            91: 
        !            92:        [ -f $SWANDIR/src/libstrongswan/asn1/oid.txt ] || die "strongSwan not found in $SWANDIR"
        !            93: fi
        !            94: 
        !            95: case "$GUEST" in
1.1       misho      96: "")
1.1.1.2 ! misho      97:        if [ ! -f "$ROOTIMG" -o "$REPLACE" ]; then
        !            98:                log_action "Creating root image $ROOTIMG"
        !            99:                execute "qemu-img create -b $BASEIMG -f $IMGEXT -F $IMGEXT $ROOTIMG"
        !           100:                ALL_RECIPES=1
        !           101:        fi
1.1       misho     102:        log_action "Connecting root image to NBD device $NBDEV"
1.1.1.2 ! misho     103:        [ -f "$ROOTIMG" ] || die "Root image $ROOTIMG not found"
1.1       misho     104:        execute "qemu-nbd -c $NBDEV $ROOTIMG"
                    105:        ;;
                    106: *)
1.1.1.2 ! misho     107:        echo $STRONGSWANHOSTS | grep -q "\b$GUEST\b" || die "Guest $GUEST not found"
        !           108:        GUESTIMG="$IMGDIR/$GUEST.$IMGEXT"
1.1       misho     109:        [ -f "$GUESTIMG" ] || die "Guest image $GUESTIMG not found"
                    110:        log_action "Connecting guest image to NBD device $NBDEV"
                    111:        execute "qemu-nbd -c $NBDEV $GUESTIMG"
                    112:        ;;
                    113: esac
                    114: 
                    115: do_on_exit qemu-nbd -d $NBDEV
                    116: partprobe $NBDEV
                    117: 
                    118: log_action "Mounting $NBDPARTITION to $LOOPDIR"
                    119: execute "mount $NBDPARTITION $LOOPDIR"
                    120: do_on_exit umount $LOOPDIR
                    121: 
                    122: log_action "Mounting proc filesystem to $LOOPDIR/proc"
                    123: execute "mount -t proc none $LOOPDIR/proc"
                    124: do_on_exit umount $LOOPDIR/proc
                    125: 
                    126: mkdir -p $LOOPDIR/root/shared
                    127: log_action "Mounting $SHAREDDIR as /root/shared"
                    128: execute "mount -o bind $SHAREDDIR $LOOPDIR/root/shared"
                    129: do_on_exit umount $LOOPDIR/root/shared
                    130: 
                    131: log_action "Copy /etc/resolv.conf"
                    132: execute "cp /etc/resolv.conf $LOOPDIR/etc/resolv.conf"
                    133: do_on_exit rm $LOOPDIR/etc/resolv.conf
                    134: 
1.1.1.2 ! misho     135: log_action "Remove SWID tags of previous strongSwan versions"
1.1       misho     136: execute_chroot "find /usr/local/share -path '*strongswan*' -name *.swidtag -delete"
                    137: 
1.1.1.2 ! misho     138: if [ -z "$TARBALL" ]; then
        !           139:        mkdir -p $LOOPDIR/root/strongswan
        !           140:        log_action "Mounting $SWANDIR as /root/strongswan"
        !           141:        execute "bindfs -u $SRCUID -g $SRCGID --create-for-user=$SRCUID --create-for-group=$SRCGID $SWANDIR $LOOPDIR/root/strongswan"
        !           142:        do_on_exit umount $LOOPDIR/root/strongswan
        !           143: 
        !           144:        log_action "Determine strongSwan version"
        !           145:        desc=`git -C $SWANDIR describe --dirty`
        !           146:        if [ $? -eq 0 ]; then
        !           147:                version="$desc (`git -C $SWANDIR rev-parse --abbrev-ref HEAD`)"
        !           148:        else
        !           149:                version="`cat $SWANDIR/configure.ac | sed -n '/^AC_INIT/{ s/.*,\[\(.*\)\])$/\1/p }'`"
        !           150:        fi
        !           151:        echo "$version" > $SHAREDDIR/.strongswan-version
        !           152:        log_status 0
1.1       misho     153: 
1.1.1.2 ! misho     154:        log_action "Preparing source tree"
        !           155:        execute_chroot 'autoreconf -i /root/strongswan'
1.1       misho     156: fi
                    157: 
                    158: RECPDIR=$DIR/recipes
1.1.1.2 ! misho     159: if [ "$ALL_RECIPES" ]; then
        !           160:        echo "Building and installing strongSwan and all other software"
        !           161:        if [ -d "$RECPDIR/patches" ]
        !           162:        then
        !           163:                execute "cp -r $RECPDIR/patches $LOOPDIR/root/shared/compile" 0
        !           164:        fi
        !           165:        RECIPES=`ls $RECPDIR/*.mk | xargs -n1 basename`
        !           166: else
        !           167:        echo "Building and installing strongSwan"
        !           168:        RECIPES=`ls $RECPDIR/*strongswan.mk | xargs -n1 basename`
        !           169: fi
        !           170: 
        !           171: if [ "$CLEAN" ]; then
        !           172:        rm -rf $SHAREDDIR/build-strongswan
        !           173: fi
1.1       misho     174: mkdir -p $SHAREDDIR/build-strongswan
1.1.1.2 ! misho     175: mkdir -p $SHAREDDIR/compile
        !           176: 
        !           177: for r in $RECIPES
        !           178: do
        !           179:        log_action "Installing from recipe $r"
        !           180:        if [[ $r == *strongswan.mk && -z "$TARBALL" ]]; then
        !           181:                cp $RECPDIR/$r $SHAREDDIR/build-strongswan
        !           182:                execute_chroot "make SRCDIR=/root/strongswan BUILDDIR=/root/shared/build-strongswan -f /root/shared/build-strongswan/$r"
        !           183:        else
        !           184:                cp $RECPDIR/$r ${LOOPDIR}/root/shared/compile
        !           185:                execute_chroot "make SWANVERSION=$TARBALL -C /root/shared/compile -f $r"
        !           186:        fi
        !           187: done
1.1       misho     188: 
                    189: # rebuild the guest images after we modified the root image
1.1.1.2 ! misho     190: if [ -z "$GUEST" -a -z "$NO_GUESTS" ]; then
1.1       misho     191:        # cleanup before mounting guest images
                    192:        on_exit
                    193:        # building the guest images without certificates fails on winnetou
                    194:        if [ ! -f "$DIR/../hosts/winnetou/etc/ca/strongswanCert.pem" ]; then
                    195:                # this also re-builds the guest images
                    196:                $DIR/build-certs
                    197:        else
                    198:                $DIR/build-guestimages
                    199:        fi
                    200: fi

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>