-
Notifications
You must be signed in to change notification settings - Fork 0
/
rhcos-embed.sh
83 lines (75 loc) · 2.22 KB
/
rhcos-embed.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/env bash
set -eo pipefail
# Generate password hash
function generateHash () {
local hash="$(echo "test" | mkpasswd --method=SHA-512 --rounds=4096 -s)"
echo "$hash"
}
# Generate the FCC configuration file
function generateFCC () {
local hash="$1"
cat << EOF > fcos.fcc
variant: openshift
metadata:
name: config-openshift
labels:
machineconfiguration.openshift.io/role: master,worker
version: 4.8.0
passwd:
users:
- name: core
ssh_authorized_keys:
- your-key-here
storage:
files:
- path: /etc/hostname
overwrite: true
mode: 0644
contents:
inline: rhcos-server-test
- path: /etc/static-ip-config.json
overwrite: true
mode: 0644
contents:
local: hosts.json
verification: {}
- path: /etc/static-ip-setup
overwrite: true
mode: 0644
contents:
local: static-ip-setup
verification: {}
systemd:
units:
- name: static-ip-setup.service
enabled: true
contents: |
[Unit]
Description=Setup Static IP's from mappings
After=NetworkManager.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=sh /etc/static-ip-setup
[Install]
WantedBy=multi-user.target
EOF
}
# Create a snapshot of the image to not modify original image
rm rhcos.qcow2 &>/dev/null || true
qemu-img create -f qcow2 -b rhcos-orig.qcow2 rhcos.qcow2
# Generate the FCC configuration file
generateFCC "$(generateHash)"
cp -f hosts.json static-ip-setup /tmp/embed/
# Generate Ignition file from FCC configuration
podman run --privileged -i --rm -v /tmp/embed/:/tmp/ quay.io/coreos/fcct:latest --files-dir=/tmp --raw --pretty --strict < fcos.fcc > config.ign
# Inject configuration file into system image
fs_boot_path=$(virt-filesystems -a rhcos.qcow2 -l | grep boot | awk -F ' ' '{print $1}')
config_file_path=./config.ign
guestfish add rhcos.qcow2 : \
run : \
mount "$fs_boot_path" / : \
mkdir /ignition : \
copy-in "$config_file_path" /ignition/ : \
unmount-all : \
exit