33 lines
953 B
Bash
33 lines
953 B
Bash
|
#!/usr/bin/env bash
|
||
|
|
||
|
FILENAME="init-$(date -u '+%Y%m%d')_$(uuidgen |cut -d '-' -f 1).iso"
|
||
|
|
||
|
if [ $# -eq 1 ]; then
|
||
|
FILENAME="$1"
|
||
|
echo "Building image to ${FILENAME} ..."
|
||
|
elif [ $# -gt 1 ]; then
|
||
|
echo 'Usage: ./build.sh [filename]'
|
||
|
exit 1
|
||
|
else
|
||
|
echo "Building image to ${FILENAME} ..."
|
||
|
fi
|
||
|
|
||
|
SSH_KEY1=$(head -1 "SSH_KEY1")
|
||
|
SSH_KEY2=$(head -1 "SSH_KEY2")
|
||
|
SSH_KEY3=$(head -1 "SSH_KEY3")
|
||
|
|
||
|
cat user-data | ruby replace.rb "###SSH_KEY_1###" "${SSH_KEY1}" | ruby replace.rb "###SSH_KEY_2###" "${SSH_KEY2}" | ruby replace.rb "###SSH_KEY_3###" "${SSH_KEY3}" > user-data.in && \
|
||
|
cp -vf user-data.in user-data
|
||
|
|
||
|
cloud-init devel schema --config-file user-data
|
||
|
|
||
|
genisoimage -output ${FILENAME} -volid cidata -joliet -rock user-data meta-data
|
||
|
|
||
|
FILESIZE=$(stat -c %s ${FILENAME} 2>/dev/null)
|
||
|
if [[ "${FILESIZE}" -gt "0" ]]; then
|
||
|
printf '%s (%d bytes) ... done!\n' ${FILENAME} ${FILESIZE}
|
||
|
else
|
||
|
printf 'Something went wrong while trying to make %s\n' ${FILENAME}
|
||
|
fi
|
||
|
|