Skip to content

Commit

Permalink
[nixos] make autoinstall.sh retrieve the ssh public key
Browse files Browse the repository at this point in the history
  • Loading branch information
npf committed Mar 25, 2020
1 parent 223cb28 commit 585627c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions steps/bootstrap/nixos/prepare_autoinstall.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- insecure_ssh_key: $${kameleon_cwd}/insecure_ssh_key

- copy_autoinstall_script_to_http_directory:
- exec_local: mkdir -p $${http_directory}
- exec_local: cp $${autoinstall_script_path} $${http_directory}/autoinstall.sh
Expand All @@ -14,6 +16,10 @@
- exec_local: |
sed -i s'|export PASSWD=\(.*\)|export PASSWD=$${root_password}|'g $${http_directory}/autoinstall.sh
- paste_ssh_insecure_public_key:
- exec_local: |
cat $${insecure_ssh_key}.pub >> $${http_directory}/autoinstall.sh
#- write_boot_command:
# - write_local:
# - $${kameleon_cwd}/boot_command
Expand Down
12 changes: 10 additions & 2 deletions steps/data/nixos/autoinstall.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

set -x
set -e

export http_proxy=
Expand Down Expand Up @@ -27,6 +27,10 @@ mkdir -p $MNT/etc/nixos
cp /tmp/configuration.nix $MNT/etc/nixos
cp /tmp/hardware-configuration.nix $MNT/etc/nixos

install -d -o nixos -m 700 /home/nixos/.ssh
install -o nixos -m 700 /dev/null /home/nixos/.ssh/authorized_keys
sed -e '0,/^### Bulk data:/d' $0 >> /home/nixos/.ssh/authorized_keys

nixos-install --root $MNT

echo "Set root's passwd and populate system directories..."
Expand All @@ -38,4 +42,8 @@ sync
umount $MNT
sync

systemctl poweroff
systemctl start sshd

#systemctl poweroff
exit 0
### Bulk data: the SSH insecure public key should be pasted after this line ###
2 changes: 1 addition & 1 deletion steps/data/qemu-sendkeys/netinst-iso-nixos
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sudo -i<kp_enter>cd /etc/pam.d/<kp_enter>sed -i -e 's/^\(account.\+pam_unix\.so.\*\)$/\1 nullok/' sshd > sshd.new<kp_enter>rm sshd<kp_enter>mv sshd.new sshd<kp_enter>systemctl start sshd<kp_enter>
curl -sSL http://%LOCAL_IP%:%HTTP_PORT%/configuration.nix <gt> /tmp/configuration.nix<kp_enter>curl -sSL http://%LOCAL_IP%:%HTTP_PORT%/hardware-configuration.nix <gt> /tmp/hardware-configuration.nix<kp_enter>curl -sSL http://%LOCAL_IP%:%HTTP_PORT%/autoinstall.sh <gt> /tmp/autoinstall.sh<kp_enter>sudo bash /tmp/autoinstall.sh<kp_enter>

0 comments on commit 585627c

Please sign in to comment.