diff --git a/cron-scripts/10-test.sh b/cron-scripts/10-test.sh index e1079f6..331409b 100755 --- a/cron-scripts/10-test.sh +++ b/cron-scripts/10-test.sh @@ -13,6 +13,15 @@ touch /tmp/cron-10-test.sh.lock set -x +mac=$(ip link show | awk '/link\/ether/{ print $2 }' | head -n1 | sed 's/://g') + +hostname=$(grep "^$mac" inventory | awk '{ print $2 }') + +if test -z "$hostname" +then + hostname=guix-template +fi + host_conf=$(hostname).scm cd /data/xhrpb-guix-config diff --git a/guix-test01.scm b/guix-test01.scm new file mode 100644 index 0000000..5083c53 --- /dev/null +++ b/guix-test01.scm @@ -0,0 +1,115 @@ +(use-modules (gnu) + (gnu system mapped-devices) + (gnu system nss) + (gnu packages linux) + (gnu packages tmux) + (gnu packages shells) + (gnu packages emacs) + (gnu packages vim) + (gnu packages certs) + (gnu packages admin) + (gnu packages version-control)) + +(use-service-modules networking ssh mcron) +(use-package-modules screen ssh) + +(define ssh-authorized-bjorn-pub (plain-file "bjornpub" " +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFAUQBM+p7ET8XRQE+UN6wa9DxQTMWlqErny7URZRtKE bjorn@regular +")) + +(let ((output-port (open-file "/data/cronjob.sh" "w"))) + (display "#!/usr/bin/env -S guix shell bash -- bash + +set -x + +export SSL_CERT_DIR=\"$HOME/.guix-profile/etc/ssl/certs\" +export SSL_CERT_FILE=\"$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt\" +export GIT_SSL_CAINFO=\"$SSL_CERT_FILE\" + +cd /data + +if test -d xhrpb-guix-config +then + cd xhrpb-guix-config + git pull --force +else + git clone https://src.xhrpb.com/human.equivalent/xhrpb-guix-config.git xhrpb-guix-config + cd xhrpb-guix-config +fi + +echo 'repo updated' + +cd cron-scripts + +find . -type f -executable | sort | while read script +do + echo running $script + $script +done +" output-port) + (newline output-port) + (close output-port)) + +(define ssh-authorized-bjorn-pub (plain-file "bjornpub" " +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFAUQBM+p7ET8XRQE+UN6wa9DxQTMWlqErny7URZRtKE bjorn@regular +")) + + +(define mcron-xhrpb-git + #~(job "* * * * *" + "bash /data/cronjob.sh")) + +(operating-system + (host-name "guix-test01") + (timezone "Europe/Stockholm") + (locale "en_US.utf8") + + (bootloader (bootloader-configuration + (bootloader grub-bootloader) + (targets '("/dev/sda")))) + + (kernel-arguments (list "console=ttyS0,115200")) + + (mapped-devices + (list (mapped-device + (source "sys") + (targets (list "sys-data")) + (type lvm-device-mapping)))) + + (file-systems (cons* (file-system + (device (file-system-label "root")) + (mount-point "/") + (type "ext4")) + (file-system + (device "/dev/mapper/sys-data") + (mount-point "/data") + (type "ext4") + (dependencies mapped-devices)) + %base-file-systems)) + + (users (cons (user-account + (name "bjorn") + (group "users") + (supplementary-groups '("wheel")) + (shell (file-append zsh "/bin/zsh"))) + %base-user-accounts)) + + ;; Globally-installed packages. + ;; orig: (packages (cons lvm2 tmux %base-packages)) + (packages (append (list + lvm2-static tmux zsh emacs-no-x neovim git nss-certs tcpdump) + %base-packages)) + + ;; Add services to the baseline: a DHCP client and + ;; an SSH server. + (services (append (list (service dhcp-client-service-type) + (simple-service 'my-cron-jobs + mcron-service-type + (list mcron-xhrpb-git)) + (service openssh-service-type + (openssh-configuration + (openssh openssh-sans-x) + (permit-root-login 'prohibit-password) + (authorized-keys `(("bjorn", ssh-authorized-bjorn-pub))) + (port-number 22)))) + %base-services))) diff --git a/inventory b/inventory new file mode 100644 index 0000000..3f04d45 --- /dev/null +++ b/inventory @@ -0,0 +1 @@ +525400f7130b guix-test01