liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

update.sh (1170B)


      1 #!/usr/bin/env bash
      2 
      3 # this shell script is run on the build system to min-copy-closure the
      4 # system configuration onto the device and reboot/restart services as
      5 # requested
      6 
      7 die() {
      8     echo "$@"
      9     exit 1
     10 }
     11 
     12 
     13 PATH=@min_copy_closure@/bin:$PATH
     14 ssh_command=${SSH_COMMAND-ssh}
     15 
     16 reboot="reboot"
     17 case "$1" in
     18     "--no-reboot")
     19 	unset reboot
     20 	shift
     21 	;;
     22     "--fast")
     23 	reboot="soft"
     24 	shift
     25 	;;
     26 esac
     27 
     28 target_host=$1
     29 shift
     30 
     31 test -n "$target_host" || \
     32     die "Usage: $0 [--no-reboot] [--fast] target-host"
     33 
     34 toplevel=$(realpath @toplevel@)
     35 test -e $toplevel/etc/nix-store-paths || die "missing etc/nix-store-paths, is this really a system configuration?"
     36 echo installing from systemConfiguration $toplevel to host $target_host
     37 
     38 $ssh_command $target_host uname -a || die "Can't ssh to $target_host"
     39 min-copy-closure $target_host $toplevel
     40 ts=$(date +%Y%m%dT%H%M%S)
     41 $ssh_command $target_host "$toplevel/bin/install && ln -s $(realpath --relative-to / $toplevel) /persist/${ts}.configuration"
     42 case "$reboot" in
     43     reboot)
     44 	$ssh_command $target_host "sync; source /etc/profile; reboot"
     45 	;;
     46     soft)
     47 	$ssh_command $target_host $toplevel/bin/restart-services
     48 	;;
     49     *)
     50 	;;
     51 esac