diff --git a/from_scratch/base.yaml b/from_scratch/base.yaml index 4bdc40bd..0d0647b0 100644 --- a/from_scratch/base.yaml +++ b/from_scratch/base.yaml @@ -63,6 +63,8 @@ global: qemu_append_cmdline: $${installer_cmdline} qemu_iso_path: $${kameleon_cwd}/qemu.iso + first_vm_boot_timeout: 5 + # rootfs options disk_device: /dev/vda rootfs: /rootfs @@ -105,15 +107,15 @@ bootstrap: - enable_checkpoint - download_installer - prepare_disk - - prepare_autoinstall + - prepare_ssh_to_out_context - start_http_server + - prepare_autoinstall - start_qemu: - force_vm_shutdown: false - shutdown_vm_immediately: true - vm_cleanup_section: bootstrap - vm_expected_service: - - boot_timeout: 5 - - prepare_ssh_to_out_context + - boot_timeout: $${first_vm_boot_timeout} - prepare_appliance - start_qemu: - force_vm_shutdown: true diff --git a/from_scratch/nixos-19.03.yaml b/from_scratch/nixos-19.03.yaml new file mode 100644 index 00000000..728b88b2 --- /dev/null +++ b/from_scratch/nixos-19.03.yaml @@ -0,0 +1,21 @@ +#============================================================================== +# vim: softtabstop=2 shiftwidth=2 expandtab fenc=utf-8 cc=81 tw=80 +#============================================================================== +# +# DESCRIPTION: NIXOS +# +#============================================================================== +--- +extend: nixos-base.yaml + +global: + release: 19.03 + +bootstrap: + - "@base" + +setup: + - "@base" + +export: + - "@base" diff --git a/from_scratch/nixos-19.09.yaml b/from_scratch/nixos-19.09.yaml new file mode 100644 index 00000000..5b3374ff --- /dev/null +++ b/from_scratch/nixos-19.09.yaml @@ -0,0 +1,21 @@ +#============================================================================== +# vim: softtabstop=2 shiftwidth=2 expandtab fenc=utf-8 cc=81 tw=80 +#============================================================================== +# +# DESCRIPTION: NIXOS +# +#============================================================================== +--- +extend: nixos-base.yaml + +global: + release: 19.09 + +bootstrap: + - "@base" + +setup: + - "@base" + +export: + - "@base" diff --git a/from_scratch/nixos-20.03.yaml b/from_scratch/nixos-20.03.yaml new file mode 100644 index 00000000..5e0598e4 --- /dev/null +++ b/from_scratch/nixos-20.03.yaml @@ -0,0 +1,21 @@ +#============================================================================== +# vim: softtabstop=2 shiftwidth=2 expandtab fenc=utf-8 cc=81 tw=80 +#============================================================================== +# +# DESCRIPTION: NIXOS +# +#============================================================================== +--- +extend: nixos-base.yaml + +global: + release: 20.03 + +bootstrap: + - "@base" + +setup: + - "@base" + +export: + - "@base" diff --git a/from_scratch/nixos-base.yaml b/from_scratch/nixos-base.yaml new file mode 100644 index 00000000..8795202d --- /dev/null +++ b/from_scratch/nixos-base.yaml @@ -0,0 +1,52 @@ +#============================================================================== +# vim: softtabstop=2 shiftwidth=2 expandtab fenc=utf-8 cc=81 tw=80 +#============================================================================== +# +# DESCRIPTION: NIXOS +# +#============================================================================== +--- +extend: base.yaml + +global: + distrib: nixos + release: 19.09 + + installer_iso_url: https://channels.nixos.org/$${distrib}-$${release}/latest-nixos-minimal-$${arch}-linux.iso + # To use a special build, comment the previous line and uncomment the build + # and installer_iso_url lines below. Builds can be found at http://releases.nixos.org/?prefix=nixos/19.09-small/ + #build: 2484.322fd893724 + #installer_iso_url: http://releases.nixos.org/$${distrib}/$${release}-small/$${distrib}-$${release}.$${build}/$${distrib}-minimal-$${release}.$${build}-$${arch}-linux.iso + + qemu_iso_path: $${kameleon_cwd}/$${distrib}.iso + + qemu_sendkeys_commands: $${kameleon_data_dir}/qemu-sendkeys/netinst-iso-$${distrib} + qemu_memory_size: 2048 + + first_vm_boot_timeout: 40 + use_virt_customize: false + + autoinstall_script_path: $${kameleon_data_dir}/$${distrib}/autoinstall.sh + + nix_hardware_configuration: $${kameleon_data_dir}/$${distrib}/hardware-configuration.nix + nix_configuration: $${kameleon_data_dir}/$${distrib}/configuration.nix + + out_context: + cmd: ssh -F $${ssh_config_file} $${kameleon_recipe_name} -t /run/current-system/sw/bin/bash + workdir: /root/kameleon_workdir + proxy_cache: $${local_ip} + + in_context: + cmd: ssh -F $${ssh_config_file} $${kameleon_recipe_name} -t /run/current-system/sw/bin/bash + workdir: /root/kameleon_workdir + proxy_cache: $${local_ip} + +bootstrap: + - "@base" + - breakpoint +setup: + - "@base" + - breakpoint + +export: + - "@base" diff --git a/steps/bootstrap/nixos/prepare_autoinstall.yaml b/steps/bootstrap/nixos/prepare_autoinstall.yaml index 56298876..54588e31 100644 --- a/steps/bootstrap/nixos/prepare_autoinstall.yaml +++ b/steps/bootstrap/nixos/prepare_autoinstall.yaml @@ -1,21 +1,24 @@ +- 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 - exec_local: cp $${nix_configuration} $${http_directory}/configuration.nix + - exec_local: cp $${nix_hardware_configuration} $${http_directory}/hardware-configuration.nix - configure_proxy: - exec_local: | - if [ ! "$${proxy_out}" = "" ]; then - sed -i s'|export http_proxy=\(.*\)|export http_proxy=http://$${proxy_out}|'g $${http_directory}/autoinstall.sh + if [ -n "$${proxy_out}" ]; then + sed -i -e "s|%HTTP_PROXY%|http://$${proxy_out}|g" $${http_directory}/autoinstall.sh + else + sed -i -e "s|%HTTP_PROXY%||g" $${http_directory}/autoinstall.sh fi - set_root_password: - exec_local: | - sed -i s'|export PASSWD=\(.*\)|export PASSWD=$${root_password}|'g $${http_directory}/autoinstall.sh - -- write_boot_command: - - write_local: - - $${kameleon_cwd}/boot_command - - > - curl -sSL http://$${local_ip}:$${http_port}/configuration.nix /tmp/configuration.nix - curl -sSL http://$${local_ip}:$${http_port}/autoinstall.sh | bash + INSECURE_SSH_KEY_PUB=$(< $${insecure_ssh_key}.pub) + sed -i -e "s|%PASSWORD%|$${root_password}|g" $${http_directory}/autoinstall.sh + sed -i -e "s|%LOCAL_IP%|$${local_ip}|g" $${http_directory}/autoinstall.sh + sed -i -e "s|%HTTP_PORT%|$HTTP_PORT|g" $${http_directory}/autoinstall.sh + sed -i -e "s|%PASSWORD%|$${root_password}|g" $${http_directory}/configuration.nix + sed -i -e "s|%SSH_PUBLIC_KEY%|$INSECURE_SSH_KEY_PUB|g" $${http_directory}/configuration.nix diff --git a/steps/bootstrap/prepare_appliance.yaml b/steps/bootstrap/prepare_appliance.yaml index 13c62bc8..2816de55 100644 --- a/steps/bootstrap/prepare_appliance.yaml +++ b/steps/bootstrap/prepare_appliance.yaml @@ -1,53 +1,33 @@ - insecure_ssh_key: $${kameleon_cwd}/insecure_ssh_key - enable_workaround_login_delay: false +- use_virt_customize: true -- generate_ssh_keys: - - check_cmd_local: ssh-keygen - - exec_local: echo -e 'y\n' | ssh-keygen -q -t rsa -b 4096 -f $${insecure_ssh_key} -N '' +- show_ssh_keys: - exec_local: cat $${insecure_ssh_key} + - exec_local: cat $${insecure_ssh_key}.pub - inject_ssh_private_key: - check_cmd_local: virt-customize - - exec_local: | - virt-customize \ - -a $${image_disk}.$${image_format} \ - --run-command 'mkdir -p /root/.ssh' \ - --upload $${insecure_ssh_key}.pub:/root/.ssh/.kameleon_authorized_keys \ - --run-command 'touch /root/.ssh/authorized_keys' \ - --run-command 'cp /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bak' \ - --run-command 'cat /root/.ssh/.kameleon_authorized_keys >> /root/.ssh/authorized_keys' \ - --run-command 'chmod 700 /root/.ssh' \ - --run-command 'chmod -R go-rw /root/.ssh' \ - --run-command 'chown -R root:root /root/.ssh' - - on_export_init: - - exec_local: | - virt-customize \ - -a $${image_disk}.$${image_format} \ - --run-command 'mv /root/.ssh/authorized_keys.bak /root/.ssh/authorized_keys' \ - --delete /root/.ssh/.kameleon_authorized_keys - -- add_insecure_key_to_ssh_config: - - on_checkpoint: redo - - exec_local: | - cat <> $${ssh_config_file} - IdentityFile $${insecure_ssh_key} - EOF - -- workaround_login_delay_due_to_ldap_and_dns: - test: - - exec_local: test "$${enable_workaround_login_delay}" = "true" + - exec_local: test "$${use_virt_customize}" = "true" - exec_local: | - virt-customize \ - -a $${image_disk}.$${image_format} \ - --run-command 'mv /etc/nslcd.conf /etc/nslcd.conf.orig-g5k' \ - --run-command 'sed -i.orig-g5k "s/ ldap//" /etc/nsswitch.conf' \ - --run-command 'echo > /etc/resolv.conf' - - exec_local: echo "Workaround is not enabled" - - on_setup_clean: - - test: - - exec_local: test "$${enable_workaround_login_delay}" = "true" - - exec_local: | virt-customize \ -a $${image_disk}.$${image_format} \ - --run-command 'mv /etc/nslcd.conf.orig-g5k /etc/nslcd.conf' \ - --run-command 'mv /etc/nsswitch.conf.orig-g5k /etc/nsswitch.conf' + --run-command 'mkdir -p /root/.ssh' \ + --upload $${insecure_ssh_key}.pub:/root/.ssh/.kameleon_authorized_keys \ + --run-command 'touch /root/.ssh/authorized_keys' \ + --run-command 'cp /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bak' \ + --run-command 'cat /root/.ssh/.kameleon_authorized_keys >> /root/.ssh/authorized_keys' \ + --run-command 'chmod 700 /root/.ssh' \ + --run-command 'chmod -R go-rw /root/.ssh' \ + --run-command 'chown -R root:root /root/.ssh' + - exec_local: echo "Do nothing (do not use virt-customize)" + - on_export_init: + - test: + - exec_local: test "$${use_virt_customize}" = "true" + - exec_local: | + virt-customize \ + -a $${image_disk}.$${image_format} \ + --run-command 'mv /root/.ssh/authorized_keys.bak /root/.ssh/authorized_keys' \ + --delete /root/.ssh/.kameleon_authorized_keys + - exec_local: echo "Do nothing (do not use virt-customize)" diff --git a/steps/bootstrap/prepare_ssh_to_out_context.yaml b/steps/bootstrap/prepare_ssh_to_out_context.yaml index 172f7a42..5c2e3dbe 100644 --- a/steps/bootstrap/prepare_ssh_to_out_context.yaml +++ b/steps/bootstrap/prepare_ssh_to_out_context.yaml @@ -1,9 +1,17 @@ +- insecure_ssh_key: $${kameleon_cwd}/insecure_ssh_key + - select_empty_port: - on_checkpoint: redo - exec_local: | # Find empty SSH forwarding port SSH_FWD_PORT=$(__find_free_port 50000 60000) echo "SSH forwarding port: $SSH_FWD_PORT" + +- generate_ssh_keys: + - check_cmd_local: ssh-keygen + - exec_local: echo -e 'y\n' | ssh-keygen -q -t rsa -b 4096 -f $${insecure_ssh_key} -N '' + - exec_local: cat $${insecure_ssh_key} + - prepare_ssh_config: - on_checkpoint: redo - write_local: @@ -21,3 +29,5 @@ ForwardAgent yes Compression yes Protocol 2 + IdentityFile $${insecure_ssh_key} + diff --git a/steps/bootstrap/start_http_server.yaml b/steps/bootstrap/start_http_server.yaml index 59184c3b..d6a4f66f 100644 --- a/steps/bootstrap/start_http_server.yaml +++ b/steps/bootstrap/start_http_server.yaml @@ -1,6 +1,7 @@ - http_script: $${kameleon_data_dir}/helpers/simple_http_server.py - run_http_server: + - exec_local: mkdir -p $${http_directory} - exec_local: | HTTP_PORT=$(__find_free_port 8000 8100) echo "HTTP port: $HTTP_PORT" diff --git a/steps/bootstrap/start_qemu.yaml b/steps/bootstrap/start_qemu.yaml index 4536f5b3..38c59620 100644 --- a/steps/bootstrap/start_qemu.yaml +++ b/steps/bootstrap/start_qemu.yaml @@ -17,6 +17,7 @@ - no_reboot: true - socat_monitor: socat - UNIX-CONNECT:$${qemu_monitor_socket} - qemu_sendkeys_script: $${kameleon_data_dir}/qemu-sendkeys.rb +- qemu_sendkeys_opts: - qemu_sendkeys_commands: - vm_expected_service: ssh - vm_cleanup_section: setup @@ -207,7 +208,7 @@ - exec_local: | echo "Sending keyboard commands to the VM: $${qemu_sendkeys_commands}" echo "(Local httpd server url: http://$${local_ip}:$HTTP_PORT)" - ruby $${qemu_sendkeys_script} -d 0.05 "$(sed -e s/%LOCAL_IP%/$${local_ip}/g -e s/%HTTP_PORT%/$HTTP_PORT/g $${qemu_sendkeys_commands})" | $${socat_monitor} > /dev/null + ruby $${qemu_sendkeys_script} $${qemu_sendkeys_opts} "$(sed -e s/%LOCAL_IP%/$${local_ip}/g -e s/%HTTP_PORT%/$HTTP_PORT/g $${qemu_sendkeys_commands})" | $${socat_monitor} > /dev/null - exec_local: echo "No keyboard commands to send" - shutdown_vm: diff --git a/steps/data/configuration.nix b/steps/data/configuration.nix deleted file mode 100644 index 8808e679..00000000 --- a/steps/data/configuration.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ config, pkgs, ...} : -{ - boot.loader.grub.device = "/dev/sda"; - - # Enable virtualbox guest additions - virtualisation.virtualbox.guest.enable = true; - - # Enable the sshd daemon so you can ssh - # into it - services.openssh.enable = true; - - fileSystems = [ - { mountPoint = "/"; - label = "nixos"; - } - ]; - - users.users.root.initialHashedPassword = ""; - -} diff --git a/steps/data/nixos-autoinstall.sh b/steps/data/nixos-autoinstall.sh deleted file mode 100644 index 37a04665..00000000 --- a/steps/data/nixos-autoinstall.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -set -e - -export http_proxy= -export https_proxy="$http_proxy" -export PASSWD= - -DISK=/dev/sda -MNT=/mnt - -# Format partition -echo "Partitioning disk..." -parted -s $DISK mklabel msdos -parted -s -a none $DISK mkpart primary 64s 100% -parted -s $DISK set 1 boot on - -mkfs.ext4 ${DISK}1 -L nixos -mkdir -p $MNT -mount ${DISK}1 $MNT - -echo "install nixos..." -mkdir -p $MNT/etc/nixos -cp /tmp/configuration.nix $MNT/etc/nixos -nixos-install --root $MNT < $MNT/etc/nixos/configuration.nix +curl -sSL http://%LOCAL_IP%:%HTTP_PORT%/hardware-configuration.nix > $MNT/etc/nixos/hardware-configuration.nix + +nixos-install --root $MNT + +echo "Set root's passwd and populate system directories..." +#NOTE: nixos-enter implies creation and settlement of system directories if they are missing +nixos-enter --root $MNT -- /run/current-system/sw/bin/mkdir -p /tmp +#The following only set the root password in the installer. +nixos-enter --root $MNT -- echo -n "root:%PASSWORD%" | /run/current-system/sw/bin/chpasswd + +sync +umount $MNT + +systemctl poweroff diff --git a/steps/data/nixos/configuration.nix b/steps/data/nixos/configuration.nix new file mode 100644 index 00000000..0ac2b6d1 --- /dev/null +++ b/steps/data/nixos/configuration.nix @@ -0,0 +1,68 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page +# and in the NixOS manual (accessible by running ‘nixos-help’). + +{ config, pkgs, ... }: + +{ + imports = + [ # Include the results of the hardware scan. + ./hardware-configuration.nix + ]; + + # List packages installed in system profile. To search, run: + # $ nix search wget + environment.systemPackages = with pkgs; [ + wget + vim + ]; + + # Use the GRUB 2 boot loader. + boot.loader.grub.enable = true; + boot.loader.grub.version = 2; + boot.loader.grub.device = "/dev/vda"; + boot.loader.grub.forceInstall = true; + + boot.initrd.preFailCommands = "/bin/sh"; + + #boot.kernelParams = ["console=tty0 console=ttyS0,38400n8 modprobe.blacklist=myri10ge"]; + #boot.loader.grub.extraConfig = '' + # serial --speed=38400 --unit=0 --word=8 --parity=no --stop=1; + # terminal_input serial; + # terminal_output serial + #''; + #systemd.services."serial-getty@ttyS0".enable = true; + + networking.hostName = ""; # Dhcp will set hostname + networking.firewall.enable = false; + # Set your time zone. + time.timeZone = "Europe/Paris"; + + services.openssh = { + enable = true; + startWhenNeeded = true; + permitRootLogin = "yes"; + passwordAuthentication = true; + }; + + users.users.root = { + password = "%PASSWORD%"; + openssh.authorizedKeys.keys = [ "%SSH_PUBLIC_KEY%" ]; + }; + + #users.users.kameleon = { + # isNormalUser = true; + # home = "/home/kameleon"; + # description = "kameleon builder"; + # extraGroups = [ "wheel" ]; + # password = "%PASSWORD%"; + # openssh.authorizedKeys.keys = [ "%SSH_PUBLIC_KEY%" ]; + #}; + + # This value determines the NixOS release with which your system is to be + # compatible, in order to avoid breaking some software such as database + # servers. You should change this only after NixOS release notes say you + # should. + # + system.stateVersion = "19.09"; # Did you read the comment? +} diff --git a/steps/data/nixos/hardware-configuration.nix b/steps/data/nixos/hardware-configuration.nix new file mode 100644 index 00000000..c6ece664 --- /dev/null +++ b/steps/data/nixos/hardware-configuration.nix @@ -0,0 +1,22 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, ... }: + +{ + imports = + [ + ]; + + boot.initrd.availableKernelModules = [ "ahci" "ehci_pci" "sd_mod" "virtio_pci" "virtio_blk" "virtio_net" ]; + + fileSystems."/" = + { label = "System"; + fsType = "ext4"; + }; + + swapDevices = [ ]; + + nix.maxJobs = lib.mkDefault 32; + powerManagement.cpuFreqGovernor = lib.mkDefault "powersave"; +} diff --git a/steps/data/qemu-sendkeys.README b/steps/data/qemu-sendkeys.README new file mode 100644 index 00000000..12c07963 --- /dev/null +++ b/steps/data/qemu-sendkeys.README @@ -0,0 +1 @@ +The qemu-sendkeys.rb script comes from https://github.com/mvidner/sendkeys diff --git a/steps/data/qemu-sendkeys.rb b/steps/data/qemu-sendkeys.rb index d1bcb0fd..4cc59dbf 100755 --- a/steps/data/qemu-sendkeys.rb +++ b/steps/data/qemu-sendkeys.rb @@ -5,7 +5,9 @@ # https://en.wikibooks.org/wiki/QEMU/Monitor#sendkey_keys # sendkey keys # -# You can emulate keyboard events through sendkey command. The syntax is: sendkey keys. To get a list of keys, type sendkey [tab]. Examples: +# You can emulate keyboard events through sendkey command. +# The syntax is: sendkey keys. To get a list of keys, type sendkey [tab]. +# Examples: # # sendkey a # sendkey shift-a @@ -13,86 +15,99 @@ # sendkey ctrl-alt-f1 # # As of QEMU 0.12.5 there are: -# shift shift_r alt alt_r altgr altgr_r -# ctrl ctrl_r menu esc 1 2 -# 3 4 5 6 7 8 -# 9 0 minus equal backspace tab -# q w e r t y -# u i o p ret a -# s d f g h j -# k l z x c v -# b n m comma dot slash -# asterisk spc caps_lock f1 f2 f3 -# f4 f5 f6 f7 f8 f9 -# f10 num_lock scroll_lock kp_divide kp_multiply kp_subtract -# kp_add kp_enter kp_decimal sysrq kp_0 kp_1 -# kp_2 kp_3 kp_4 kp_5 kp_6 kp_7 -# kp_8 kp_9 < f11 f12 print -# home pgup pgdn end left up -# down right insert delete +# shift shift_r alt alt_r altgr altgr_r +# ctrl ctrl_r menu esc 1 2 +# 3 4 5 6 7 8 +# 9 0 minus equal backspace tab +# q w e r t y +# u i o p ret a +# s d f g h j +# k l z x c v +# b n m comma dot slash +# asterisk spc caps_lock f1 f2 f3 +# f4 f5 f6 f7 f8 f9 +# f10 num_lock scroll_lock kp_divide kp_multiply kp_subtract +# kp_add kp_enter kp_decimal sysrq kp_0 kp_1 +# kp_2 kp_3 kp_4 kp_5 kp_6 kp_7 +# kp_8 kp_9 < f11 f12 print +# home pgup pgdn end left up +# down right insert delete require "optparse" -# incomplete! only what I need now. +UPCASE_PAIRS = ("A".."Z").map do |i| + [i, "shift-#{i.downcase}"] +end + KEYS = { - "%" => "shift-5", - "/" => "slash", - ":" => "shift-semicolon", - "=" => "equal", - "." => "dot", - " " => "spc", - "-" => "minus", - "_" => "shift-minus", - "*" => "asterisk", - "," => "comma", - "+" => "shift-equal", - "|" => "shift-backslash", + # ASCII-sorted + " " => "spc", + "!" => "shift-1", + '"' => "shift-apostrophe", + "#" => "shift-3", + "$" => "shift-4", + "%" => "shift-5", + "&" => "shift-7", + "'" => "apostrophe", + "(" => "shift-9", + ")" => "shift-0", + "*" => "shift-8", + "+" => "shift-equal", + "," => "comma", + "-" => "minus", + "." => "dot", + "/" => "slash", + # 0..9 work as literals + ":" => "shift-semicolon", + ";" => "semicolon", + "<" => "shift-comma", + "=" => "equal", + ">" => "shift-dot", + "?" => "shift-slash", + "@" => "shift-2", + # A..Z via UPCASE_PAIRS + "[" => "bracket_left", "\\" => "backslash", -} + "]" => "bracket_right", + "^" => "shift-6", + "_" => "shift-minus", + "`" => "grave_accent", + # a..z work as literals + "{" => "shift-bracket_left", + "|" => "shift-backslash", + "}" => "shift-bracket_right", + "~" => "shift-grave_accent" +}.merge Hash[UPCASE_PAIRS] class Main attr_accessor :command - attr_accessor :delay_s attr_accessor :keystring def initialize self.command = nil - self.delay_s = 0.1 OptionParser.new do |opts| - opts.banner = "Usage: sendkeys [-c command_to_pipe_to] STRING\n" + - "Where STRING can be 'lsls/dev/null'" + opts.banner = "Usage: sendkeys [-c command_to_pipe_to] STRING\n" \ + "Where STRING can be 'lsls/dev/null'\n" \ + "and a delays 1s instead of sending a key" opts.on("-c", "--command COMMAND", - "Pipe sendkeys to this commands, individually") do |v| + "Pipe sendkeys to this commands, individually") do |v| self.command = v end - opts.on("-d", "--delay SECONDS", Float, - "Delay SECONDS after each key (default: 0.1)") do |v| - self.delay_s = v - end end.parse! - self.keystring = ARGV[0] + self.keystring = ARGV[0] || "" end def sendkey(qemu_key_name) - if qemu_key_name == "wait" - sleep 1 + qemu_cmd = "sendkey #{qemu_key_name}" + if command + system "echo '#{qemu_cmd}' | #{command}" else - if qemu_key_name =~ /[A-Za-z]/ && qemu_key_name == qemu_key_name.upcase - key = "shift-#{qemu_key_name.downcase}" - else - key = qemu_key_name - end - qemu_cmd = "sendkey #{key}" - if command - system "echo '#{qemu_cmd}' | #{command}" - else - puts qemu_cmd - $stdout.flush # important when we are piped - end - sleep delay_s + puts qemu_cmd + $stdout.flush # important when we are piped end + sleep 0.1 end PATTERN = / @@ -106,6 +121,12 @@ def run keystring.scan(PATTERN) do |match| if match[0] == "<" key_name = match.slice(1..-2) + + if key_name == "delay" + sleep 1 + next + end + sendkey case key_name when "lt" then "shift-comma" when "gt" then "shift-dot" diff --git a/steps/data/qemu-sendkeys/netinst-iso-nixos b/steps/data/qemu-sendkeys/netinst-iso-nixos new file mode 100644 index 00000000..9a9b67ef --- /dev/null +++ b/steps/data/qemu-sendkeys/netinst-iso-nixos @@ -0,0 +1 @@ +curl -sSL http://%LOCAL_IP%:%HTTP_PORT%/autoinstall.sh | sudo bash diff --git a/steps/setup/nixos/clean_system.yaml b/steps/setup/nixos/clean_system.yaml new file mode 100644 index 00000000..1ecafb18 --- /dev/null +++ b/steps/setup/nixos/clean_system.yaml @@ -0,0 +1,5 @@ +- clean_user: + +- clean_network: + +- clean_udev: diff --git a/steps/setup/nixos/minimal_install.yaml b/steps/setup/nixos/minimal_install.yaml new file mode 100644 index 00000000..8b26e26a --- /dev/null +++ b/steps/setup/nixos/minimal_install.yaml @@ -0,0 +1,4 @@ + +- set_root_password: + +- upgrade_system: