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

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

1.1       afresh1     1: #!/bin/sh
1.2     ! afresh1     2: # $AFresh1$
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
                     55:        mkdir factory-default
                     56:
                     57:        cd factory-default
                     58:        ldomctl dump
                     59:        cd ..
                     60:
                     61:        tar czf "$factory_default_tgz" factory-default
                     62:
                     63:        echo "Backed up ldom dump to $factory_default_tgz"
                     64: fi
                     65:
                     66: tar -s "/^factory-default/$domain/" -xzpf "$factory_default_tgz"
                     67:
                     68: cd "$domain"
                     69: ldomctl init-system "$conf"
                     70: cd ..
                     71:
                     72: ldomctl list | grep -Fwq "$domain" && ldomctl delete "$domain"
                     73: ldomctl download "$domain"
                     74: ldomctl select   "$domain"
                     75: # ldomctl list
                     76:
                     77: echo "Loaded $domain, halt and reset the hardware to boot configuration"

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