-
Notifications
You must be signed in to change notification settings - Fork 217
/
change-iso-password.sh
executable file
·54 lines (43 loc) · 1.75 KB
/
change-iso-password.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
#!/bin/bash
set -euo pipefail
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <path to discovery .iso>"
exit 1
fi
if [[ ! -f $1 ]]; then
echo "ERROR: Discovery ISO not found at $1"
exit 1
fi
DISCOVERY_ISO_HOST_PATH="$1"
DISCOVERY_ISO_HOST_DIR=$(dirname "$DISCOVERY_ISO_HOST_PATH")
function COREOS_INSTALLER() {
podman run -v "$DISCOVERY_ISO_HOST_DIR":/data:Z --rm quay.io/coreos/coreos-installer:release "$@"
}
ISO_NAME=$(basename "$DISCOVERY_ISO_HOST_PATH" .iso)
# Container paths
DISCOVERY_ISO_PATH=/data/${ISO_NAME}.iso
DISCOVERY_ISO_WITH_PASSWORD=/data/${ISO_NAME}_with_password.iso
# Host output path
DISCOVERY_ISO_WITH_PASSWORD_HOST=$(dirname "$DISCOVERY_ISO_HOST_PATH")/$(basename "$DISCOVERY_ISO_WITH_PASSWORD")
# Prompt
read -rsp 'Please enter the password to be used by the "core" user: ' pw
echo ''
USER_PASSWORD=$(openssl passwd -6 --stdin <<<"$pw")
unset pw
# Transform original ignition
TRANSFORMED_IGNITION_PATH=$(mktemp --tmpdir="$DISCOVERY_ISO_HOST_DIR")
TRANSFORMED_IGNITION_NAME=$(basename "$TRANSFORMED_IGNITION_PATH")
COREOS_INSTALLER iso ignition show "$DISCOVERY_ISO_PATH" | jq --arg pass "$USER_PASSWORD" '.passwd.users[0].passwordHash = $pass' >"$TRANSFORMED_IGNITION_PATH"
if [[ -f "$DISCOVERY_ISO_WITH_PASSWORD_HOST" ]]; then
echo "ERROR: $DISCOVERY_ISO_WITH_PASSWORD_HOST already exists"
echo "Would you like to overwrite it? [y/N]"
read -r SHOULD_OVERWRITE
if [[ "$SHOULD_OVERWRITE" != "y" ]]; then
echo "Exiting"
exit 1
fi
fi
# Generate new ISO
rm -f "$DISCOVERY_ISO_WITH_PASSWORD_HOST"
COREOS_INSTALLER iso customize --output "$DISCOVERY_ISO_WITH_PASSWORD" --force "$DISCOVERY_ISO_PATH" --live-ignition /data/"$TRANSFORMED_IGNITION_NAME"
echo 'Created ISO with your password in "'"$DISCOVERY_ISO_WITH_PASSWORD_HOST"'", the login username is "core"'