[BACK]Return to ldom-load CVS log [TXT][DIR] Up to [local] / openbsd / ldom

Annotation of openbsd/ldom/ldom-load, Revision 1.3

1.1       afresh1     1: #!/bin/sh
1.3     ! afresh1     2: # $AFresh1: ldom-load,v 1.2 2020/06/05 22:46:35 afresh1 Exp $
1.1       afresh1     3: set -e
                      4: conf=$1
                      5:
                      6: factory_default_tgz=/var/backups/ldom-factory-default.tar.gz
                      7:
                      8: # Copyright (c) 2020 Andrew Hewus Fresh <andrew@afresh1.com>
                      9: #
                     10: # Permission to use, copy, modify, and distribute this software for any
                     11: # purpose with or without fee is hereby granted, provided that the above
                     12: # copyright notice and this permission notice appear in all copies.
                     13: #
                     14: # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     15: # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     16: # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     17: # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     18: # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     19: # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     20: # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     21:
                     22: if [ -z "$conf" ]; then
                     23:        echo "Usage: $0 ldom.conf" >&2
                     24:        exit 1
                     25: fi
                     26:
                     27: if [ ! -e "$conf" ]; then
                     28:        echo "Config '$conf' not found!" >&2
                     29:        exit 2
                     30: fi
                     31:
                     32: if [ "${conf%.conf}" = "$conf" ]; then
                     33:        echo "Config file '$conf' should end in '.conf'" >&2
                     34:        exit 3
                     35: fi
                     36:
                     37: conf=$( readlink -f $conf )
                     38: domain=$( basename "$conf" .conf )
                     39: [ "$domain" = ldom ] && domain=openbsd
                     40:
                     41: ldomctl init-system -n "$conf"
                     42:
                     43: OLDPWD="$PWD"
                     44: TMPDIR=''
                     45: cleanup() {
                     46:        cd "$OLDPWD"
                     47:        [ "$TMPDIR" -a -e "$TMPDIR" ] && rm -rf "$TMPDIR"
                     48: }
                     49: TMPDIR=$( mktemp -t -d ldom-load-XXXXXXXXX )
                     50: trap cleanup EXIT INT QUIT TERM
                     51:
                     52: cd $TMPDIR
                     53:
                     54: if [ ! -e "$factory_default_tgz" ]; then
1.3     ! afresh1    55:        current=$( ldomctl list | sed -ne 's/  *\[current\].*$//p' )
        !            56:        if [ "$current" != factory-default ]; then
        !            57:                echo "Current config is not factory-default!" >&2
        !            58:                echo "  Please create $factory_default_tgz" >&2
        !            59:                exit 4
        !            60:        fi
        !            61:
1.1       afresh1    62:        mkdir factory-default
                     63:
                     64:        cd factory-default
                     65:        ldomctl dump
                     66:        cd ..
                     67:
                     68:        tar czf "$factory_default_tgz" factory-default
                     69:
                     70:        echo "Backed up ldom dump to $factory_default_tgz"
                     71: fi
                     72:
                     73: tar -s "/^factory-default/$domain/" -xzpf "$factory_default_tgz"
                     74:
                     75: cd "$domain"
                     76: ldomctl init-system "$conf"
                     77: cd ..
                     78:
                     79: ldomctl list | grep -Fwq "$domain" && ldomctl delete "$domain"
                     80: ldomctl download "$domain"
                     81: ldomctl select   "$domain"
                     82: # ldomctl list
                     83:
                     84: echo "Loaded $domain, halt and reset the hardware to boot configuration"

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