2018-11-03 11:45:40 +01:00
_usage :
just -l
2018-12-17 13:10:06 +01:00
_get_nix_path versionsPath :
echo $( set -x; nix-build --no-link --show-trace { { invocation_directory( ) } } /nix/default.nix -A channelSources --argstr versionsPath { { versionsPath} } --argstr rebuildarg "dummy" )
2018-11-19 02:04:26 +01:00
_device recipe dir +moreargs="" :
2018-10-30 13:38:36 +01:00
#!/usr/bin/env bash
2018-11-03 11:45:40 +01:00
set -ex
2018-12-17 13:10:06 +01:00
source $( just -v _get_nix_path { { invocation_directory( ) } } /{ { dir} } /versions.nix)
2018-12-16 21:57:20 +01:00
$( set -x; nix-build --no-link --show-trace $( dirname { { dir} } ) /default.nix -A recipes.{ { recipe} } --argstr dir { { dir} } { { moreargs} } )
2018-10-30 13:38:36 +01:00
2018-11-10 19:49:25 +01:00
_render_templates :
2018-11-04 22:04:22 +01:00
#!/usr/bin/env bash
2018-11-10 19:49:25 +01:00
set -ex
2018-12-17 13:10:06 +01:00
source $( just -v _get_nix_path { { invocation_directory( ) } } /nix/variables/versions.nix)
2018-11-04 22:04:22 +01:00
nix/scripts/pre-eval-fixed.sh nix/home-manager/profiles/dotfiles/vcsh{ .tmpl,} .nix
2018-11-10 19:49:25 +01:00
_rebuild-device dir rebuildarg="dry-activate" +moreargs="" : _render_templates
#!/usr/bin/env bash
set -ex
2018-11-03 11:45:40 +01:00
just -v _device rebuild { { dir} } --argstr rebuildarg { { rebuildarg} } { { moreargs} }
2018-10-30 13:38:36 +01:00
2018-11-12 23:37:31 +01:00
rebuild-remote-device dir target rebuildarg="dry-activate" :
#!/usr/bin/env bash
set -ex
just -v _rebuild-device { { dir} } { { rebuildarg} } --argstr moreargs "'--target-host\ {{target}}'"
2018-11-03 11:03:03 +01:00
# Rebulid this device's NixOS
rebuild-this-device rebuildarg="dry-activate" :
2018-11-03 22:55:50 +01:00
#!/usr/bin/env bash
set -e
2018-10-30 13:38:36 +01:00
2018-11-03 22:55:50 +01:00
function parse_hm_rebuildarg( ) {
case $1 in
switch)
echo switch
; ;
*)
echo build
; ;
esac
}
2018-11-03 11:45:40 +01:00
2018-11-03 22:55:50 +01:00
export SYSREBUILD_LOG = .$( hostname -s) _sysrebuild.log
export HOMEREBUILD_LOG = .$( hostname -s) _homerebuild.log
2018-11-03 11:45:40 +01:00
2018-11-03 22:55:50 +01:00
echo Rebuilding system in { { rebuildarg} } -mode...
if just -v _rebuild-device nix/os/devices/$( hostname -s) { { rebuildarg} } > ${ SYSREBUILD_LOG } 2>& 1 ; then
echo System rebuild successful
2018-11-03 11:03:03 +01:00
else
2018-11-03 22:55:50 +01:00
cat ${ SYSREBUILD_LOG }
echo System rebuild failed
2018-11-03 11:03:03 +01:00
fi
if type home-manager > /dev/null 2>& 1; then
2018-11-03 22:55:50 +01:00
echo Rebuilding home in $( parse_hm_rebuildarg { { rebuildarg} } ) -mode...
2019-01-06 02:05:48 +01:00
source $( just -v _get_nix_path { { invocation_directory( ) } } /nix/os/devices/$( hostname -s) /versions.nix)
2018-11-03 22:55:50 +01:00
if home-manager -v $( parse_hm_rebuildarg { { rebuildarg} } ) > ${ HOMEREBUILD_LOG } 2>& 1 ; then
echo Home rebuild successful
2018-11-03 11:45:40 +01:00
else
2018-11-03 22:55:50 +01:00
cat ${ HOMEREBUILD_LOG }
echo Home rebuild failed
2018-11-03 11:03:03 +01:00
fi
fi
2018-11-03 22:55:50 +01:00
# This could be used to inject another channel
# --argstr moreargs "\'-I nixos-unstable=https://nixos.org/channels/nixos-unstable/nixexprs.tar.xz\'"
# Update nix-channels and switch to updated NixOS and home environments
update-this-device :
#!/usr/bin/env bash
set -e
export SYSREBUILD_LOG = .$( hostname -s) _sysrebuild.log
echo Updating system channels...
sudo nix-channel --update
just -v rebuild-this-device switch
2018-11-15 18:24:28 +01:00
# Iterate on a qtile config by running it inside Xephyr. (un-/grab the mouse with Ctrl + Shift-L)
2018-11-03 18:43:22 +01:00
hm-iterate-qtile :
#!/usr/bin/env bash
set -xe
2018-11-04 14:07:02 +01:00
home-manager switch || just -v rebuild-this-device switch
2018-11-03 18:43:22 +01:00
Xephyr -ac -br -resizeable :1 &
XEPHYR_PID = $!
echo ${ XEPHYR_PID }
DISPLAY = :1 $( grep qtile ~/.xsession) &
wait $!
kill ${ XEPHYR_PID }
2018-11-10 19:24:24 +01:00
# !!! DANGERIOUS !!! This wipes the disk which is configured for the given device.
disk-prepare dir :
just -v _device diskPrepare { { dir} } --argstr rebuildarg "dummy"
2018-11-03 11:03:03 +01:00
# Mount the target disk specified by device configuration directory. The 'dir' argument points to a device configuration, e.g. 'nix/os/devices/steveej-live-mmc-SL32G_0x259093f6'
disk-mount dir :
2018-11-04 23:56:36 +01:00
just -v _device diskMount { { dir} } --argstr rebuildarg "dummy"
2018-11-03 11:03:03 +01:00
# Unmount target disk, specified by device configuration directory
disk-umount dir :
2018-11-04 23:56:36 +01:00
just -v _device diskUmount { { dir} } --argstr rebuildarg "dummy"
2018-11-03 11:03:03 +01:00
2018-11-10 19:24:24 +01:00
# Perform an offline installation on the mounted target disk, specified by device configuration directory
2018-11-10 19:49:25 +01:00
disk-install dir : _render_templates
2018-11-04 23:56:36 +01:00
just -v _device diskInstall { { dir} } --argstr rebuildarg "dummy"
2018-11-19 18:25:06 +01:00
verify-vnc sshserver attempts="10" :
#!/usr/bin/env bash
set -e
2018-12-17 13:38:12 +01:00
: ${ VNCSOCK : ?VNCSOCK must be set }
: ${ VNCPW : ?VNCPW must be set }
2018-11-19 18:25:06 +01:00
export MAGICK_ARGS = "-filter Catrom -density 72 -resample 300 -contrast -normalize -despeckle -type grayscale -sharpen 1 -posterize 3 -negate -gamma 100 -blur 1x65535"
export TESS_ARGS = "-c debug_file=/dev/null --psm 4"
send_and_compare( ) {
local EXPECT = " $( pwgen -0 12) "
ssh -4 ${ SSHOPTS } root@{ { sshserver} } " echo -e '\0033\0143' ${ EXPECT } >> /dev/tty0 " 1>/dev/null 2>& 1
vncdo --server= ${ VNCSOCK } --password= ${ VNCPW } --disable-desktop-resizing --nocursor capture $PWD /screenshot.bmp
convert ${ MAGICK_ARGS } screenshot.bmp screenshot.tiff
tesseract ${ TESS_ARGS } screenshot.tiff screenshot
grep --quiet ${ EXPECT } screenshot.txt
}
trap " E= $? ; set +e; rm screenshot.*; echo Exiting...; exit $E " INT TERM HUP
for i in ` seq 1 { { attempts} } ` ; do
if send_and_compare; then
echo Verification succeeded at attempt $i . Unlocking remote drive...
2018-12-12 11:02:46 +01:00
if $GETPWD | head -n1 | ssh -4 ${ SSHOPTS } root@{ { sshserver} } "cryptsetup-askpass && exit 0" 1>/dev/null 2>& 1 > /dev/null; then
echo Unlock successful!
exit 0
fi
echo Unlock failed...
2018-11-19 18:25:06 +01:00
fi
done
echo Verification failed { { attempts} } times. Giving up...
exit 1
2018-12-17 13:38:12 +01:00
_get_pass_entry path key :
pass show { { path} } | grep -E "^{{key}}:" | awk '{ print $2 }'
# jq -sR 'split("\n") | map(split(":"))' <(pass show Infrastructure/VPS/CFB4ED74 | grep -E "^[A-Za-z_]+:")