X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=fai-redep;h=05414973ff69f9607fb7fec8f75897540cc5c2e4;hb=4acdd54dd395d63eef73778547fa8cc119ac6fca;hp=935e96c5af2b696ac375b70ab6ff00f4d8962250;hpb=146686eb0d97bab588a5912e1994835001e5b459;p=automated-distro-installer diff --git a/fai-redep b/fai-redep index 935e96c..0541497 100755 --- a/fai-redep +++ b/fai-redep @@ -1,36 +1,142 @@ -#!/bin/bash -lx +#!/bin/bash +# Copyright (C) 2019 Ian Kelling +# SPDX-License-Identifier: AGPL-3.0-or-later +set -eE -o pipefail +trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR + +readonly this_file="$(readlink -f -- "${BASH_SOURCE[0]}")"; cd "${this_file%/*}" + +usage() { + cat <&2; exit 1; } + +temp=$(getopt -l help hd:t: "$@") || usage 1 +eval set -- "$temp" +while true; do + case $1 in + -d) distro=$2; shift ;; + -t) target=$2; shift ;; + -h|--help) usage ;; + --) shift; break ;; + *) echo "$0: unexpected args: $*" >&2 ; usage 1 ;; + esac + shift +done +host=${1:-faiserver} + +readonly host distro target -# Deploy fai configuration to faiserver, -# then start a virtual machine to test the config. +##### end command line parsing ######## +# i use faiserver as a dns alias, but ssh key is associated with +# a canonical hostname and we will have ssh warning spam unless we +# use it, so look it up just to avoid the warning spam. +faiserver_host=$(chost $host) || faiserver_host=$host + +rsync -rlpt --delete --relative --exclude /fai/config/basefiles/ fai/config root@$faiserver_host:/srv + +sudo rsync -a /root/.ssh/home.pub \ + root@$faiserver_host:/srv/fai/config/files/root/.ssh/authorized_keys/STANDARD +# todo: automatically disable faiserver after a period so +# these files are not available. + +if [[ $target ]]; then + if sudo test -e /q/root/shadow/$target; then + shadowfile=shadow/$target # empty otherwise + fi + sudo rsync -lpt --files-from=- /q/root root@$faiserver_host:/srv/fai/config/distro-install-common </dev/null ||: # broken pipe + + +rsync -rplt --include '/*.gz' --exclude '/**' --delete-excluded $BASEFILE_DIR/ root@$faiserver_host:/srv/fai/config/basefiles/ +ssh root@$faiserver_host bash <<'EOF' set -eE -o pipefail -trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR - -ssh root@faiserver rm -rf /srv/fai/config/\* -scp -r /a/bin/fai/fai/config root@faiserver:/srv/fai -# fai example pass: fai -#ROOTPW='$1$kBnWcO.E$djxB128U7dMkrltJHPf6d1' - -# generating a hashed password: -# under debian, you can do -# echo "yoursecrectpassword" | mkpasswd -m sha-512 -s -# On arch, best seems to be copy your shadow file to a temp location, -# then passwd, get out the new pass, then copy the shadow file back. -ssh root@faiserver tee -a /srv/fai/config/class/DEFAULT.var </dev/null; then + changed=true + printf "%s\n" "$line" >>$f +fi + +if ! modprobe nfsd &>/dev/null; then + # no apt-cache on maru debian, because we are low on space already + sed -i '/^ *APTPROXY=/d' /srv/fai/config/class/DEBIAN.var + # maru debian doesn't have loopback devs created + if ! losetup -f; then + shopt -s nullglob + x=(/dev/loop*) + minor=0 + if (( ${#x[@]} )); then + minor=$(( ${x[-1]#/dev/loop} + 1 )) + fi + mknod -m660 /dev/loop$minor b 7 $minor + losetup -f + fi + # -B boo only iso, no nfsroot, no paritial miorr, no config space. + # -f = force, for overwriting + # -S = make squash image for http booting + # -d config space url, instead of putting it in the squash.img, + # this just makes it so that we don't have to regenerate the img + # when the config changes. + cd /srv/fai/config + tar czf /var/www/faiserver/html/config.tar.gz . + if $changed || [[ ! -e /var/www/faiserver/html/squash.img ]]; then + # note, on maru, selinux needs to be disabled in android before + # this will work. + mount + export debug=true + fai-cd -d http://faiserver:8080/config.tar.gz -f -M -S /var/www/faiserver/html/squash.img + mount + fi +fi EOF -scp ~/.ssh/id_rsa.pub \ - root@faiserver:/srv/fai/config/files/home/ian/.ssh/authorized_keys/GRUB_PC -s scp -r /q/root/luks root@faiserver:/srv/fai/config/distro-install-common -ssh root@faiserver chmod -R a+r /srv/fai/config/distro-install-common - -s virshrm demohost ||: -# this one doesn't need to be done every time -s qemu-img create -o preallocation=metadata -f qcow2 \ - /var/lib/libvirt/images/demohost 30G -s qemu-img create -o preallocation=metadata -f qcow2 \ - /var/lib/libvirt/images/demohostb 30G -# osinfo-query os | gr jessie -s virt-install --os-variant debian8 --cpu host -n demohost --pxe -r 2048 --vcpus 1 \ - --disk path=/var/lib/libvirt/images/demohost \ - --disk path=/var/lib/libvirt/images/demohostb -w bridge=br0,mac=52:54:00:9c:ef:ad