-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add scripts to start vm and install rpms
Add `./run_vm.sh` which starts a VM, from an image passed in as the first argument, with an authorized SSH keypair to access the VM. `./install_vm_rpms.sh` then adds the RPMs to the running VM. The VM can then be accessed using the generated SSH key id for manual testing/verification.
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
build/ | ||
vm/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/bash | ||
|
||
set -xeuo pipefail | ||
|
||
pkg=console-login-helper-messages | ||
vmdir=./vm | ||
sshkey_path="$vmdir/id_rsa" | ||
ssh_port=2226 | ||
|
||
rpms_paths=$(ls ./build/$pkg/rpms/noarch/${pkg}-*.noarch.rpm | tr '\n' ' ') | ||
ssh_opts="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" | ||
|
||
# Remove old RPMs in VM image. | ||
ssh $ssh_opts -i $sshkey_path -p $ssh_port root@localhost "pkgs=\$(rpm -qa | grep ${pkg}) ; if [ -n \"\$pkgs\" ]; then echo \"\$pkgs\" | xargs rpm -e; fi" | ||
ssh $ssh_opts -i $sshkey_path -p $ssh_port root@localhost "rm -f /root/${pkg}-*.noarch.rpm" | ||
|
||
# Copy new RPMs to VM image. | ||
scp $ssh_opts -i $sshkey_path -P $ssh_port $rpms_paths root@localhost:/root | ||
|
||
# Install new RPMs in VM. | ||
ssh $ssh_opts -i $sshkey_path -p $ssh_port root@localhost "rpm -i /root/${pkg}-*.noarch.rpm" | ||
|
||
# Enable applicable units, and reboot the VM so the services start as | ||
# if installed already. | ||
ssh $ssh_opts -i $sshkey_path -p $ssh_port root@localhost "systemctl enable console-login-helper-messages-issuegen.path" | ||
ssh $ssh_opts -i $sshkey_path -p $ssh_port root@localhost "systemctl enable console-login-helper-messages-motdgen.path" | ||
ssh $ssh_opts -i $sshkey_path -p $ssh_port root@localhost "systemctl reboot" | ||
|
||
echo SSH into the VM with: ssh -i $sshkey_path -p $ssh_port root@localhost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/bash | ||
|
||
set -xeuo pipefail | ||
|
||
vmdir=./vm | ||
ssh_port=2226 | ||
mkdir -p $vmdir | ||
|
||
image_path="$1" | ||
|
||
sshkey_path="$vmdir/id_rsa" | ||
ssh-keygen -t rsa -f "$sshkey_path" -q -N "" | ||
ssh_pubkey=$(cat "${sshkey_path}.pub") | ||
|
||
guestfish --rw -i -a "$image_path" <<EOF | ||
mkdir-p /root/.ssh/ | ||
chmod 0700 /root/.ssh/ | ||
copy-in "$sshkey_path" "${sshkey_path}.pub" /root/.ssh/ | ||
write /root/.ssh/authorized_keys "${ssh_pubkey}" | ||
chmod 0600 /root/.ssh/authorized_keys | ||
chmod 0600 /root/.ssh/id_rsa | ||
chmod 0644 /root/.ssh/id_rsa.pub | ||
write /etc/ssh/sshd_config.d/99-enable-root-login "PermitRootLogin without-password\n" | ||
write /etc/ssh/sshd_config.d/99-enable-pubkey "PubkeyAuthentication yes\n" | ||
selinux-relabel /etc/selinux/targeted/contexts/files/file_contexts /root/.ssh | ||
EOF | ||
|
||
qemu-kvm -m 2048 -cpu host -nographic -snapshot \ | ||
-drive if=virtio,file="${image_path}" \ | ||
-nic user,model=virtio,hostfwd=tcp::${ssh_port}-:22 |