Skip to content

Instantly share code, notes, and snippets.

@pkern
Last active December 29, 2016 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkern/79e5e2ec3224381df8525fbfdd60351d to your computer and use it in GitHub Desktop.
Save pkern/79e5e2ec3224381df8525fbfdd60351d to your computer and use it in GitHub Desktop.
Script to reinstall a z/VM instance with Debian
d-i debian-installer/locale string en_US
d-i debian-installer/country string US
d-i debian-installer/language string en
d-i time/zone Etc/UTC
d-i mirror/country manual
d-i mirror/http/mirror string deb.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
#!/bin/sh
HOST=host:port
HOSTNAME=userid
cat > parmfile.debian <<EOT
ro locale=C
s390-netdevice/choose_networktype=qeth s390-netdevice/qeth/layer2=true
s390-netdevice/qeth/choose=0.0.0340-0.0.0341-0.0.0342
netcfg/get_ipaddress=192.0.2.2 netcfg/get_netmask=255.255.255.0
netcfg/get_gateway=192.0.2.1 netcfg/get_nameservers=8.8.8.8
netcfg/confirm_static=true netcfg/get_hostname=$HOSTNAME
netcfg/get_domain=example.org
network-console/authorized_keys_url=https://github.com/username.keys
preseed/url=https://example.org/preseed-s390x.cfg
EOT
rm -f kernel.debian initrd.debian
./reinstall.sh $HOST $HOSTNAME password daily
#!/bin/bash
set -e
HOST="$1"
USERID="$2"
PASSWORD="$3"
TARGET_FILETYPE="DEBAUTO"
if [[ -z "$HOST" || -z "$USERID" || -z "$PASSWORD" ]]; then
echo "Usage: $0 <host:port> <userid> <password> [daily]"
exit 1
fi
BASEURL="https://deb.debian.org/debian/dists/stable/main/installer-s390x/current/images"
if [[ "$4" == "daily" ]]; then
BASEURL="https://d-i.debian.org/daily-images/s390x/daily"
fi
fetch() {
FILENAME="$1"
if [[ ! -f "$FILENAME" ]]; then
echo "Fetching $FILENAME ..."
curl -# -L -o "$FILENAME" "$BASEURL/generic/$FILENAME"
fi
}
fetch kernel.debian
fetch initrd.debian
fetch parmfile.debian
fetch debian.exec
cleanup() {
kill $pid
rm -f "$EXEC_TMP"
}
s3270 -scriptport 5000 &
pid=$!
trap cleanup EXIT
transfer_binary() {
SOURCE="$1"
TARGET="$2"
x3270if -t 5000 "Transfer(Direction=send,\"HostFile=$TARGET\",\"LocalFile=$SOURCE\",Host=vm,Mode=binary,Recfm=fixed,Lrecl=80,BufferSize=8192)"
wait_for 1,0,5 Ready
}
transfer_ascii() {
SOURCE="$1"
TARGET="$2"
x3270if -t 5000 "Transfer(Direction=send,\"HostFile=$TARGET\",\"LocalFile=$SOURCE\",Host=vm,Mode=ascii,Recfm=variable,Lrecl=80)"
wait_for 1,0,5 Ready
}
substring() {
COORDS="$1"
x3270if -t 5000 "Ascii('$COORDS')"
}
send_line() {
LINE="$1"
x3270if -t 5000 "String(\"$LINE\")"
x3270if -t 5000 "Enter()"
}
wait_for() {
LOCATION="$1"
STRING="$2"
while [ "$(substring $LOCATION)" != "$STRING" ]; do
sleep 2
done
}
sleep 1
x3270if -t 5000 "Connect($HOST)"
# Make sure we see a z/VM login prompt.
wait_for 1,1,4 z/VM
x3270if -t 5000 'Enter()'
send_line "LOGON $USERID $PASSWORD"
# TODO(pkern): Somehow determine if LOGON was successful.
echo "Connected."
# Disable pagination in the terminal.
send_line "#CP TERMINAL MORE 0 0"
# Don't kill the VM on disconnect.
send_line "#CP SET RUN ON"
send_line "#CP IPL CMS"
x3270if -t 5000 'Wait(2,Seconds)'
echo "Transfering parmfile ..."
transfer_ascii parmfile.debian "PARMFILE $TARGET_FILETYPE A"
echo "Transfering kernel ..."
transfer_binary kernel.debian "KERNEL $TARGET_FILETYPE a"
echo "Transfering initrd ..."
transfer_binary initrd.debian "INITRD $TARGET_FILETYPE a"
echo "Transfering CMS script ..."
EXEC_TMP="$(mktemp)"
sed -r -e "s/(PUNCH.*)DEBIAN(.*)/\1$TARGET_FILETYPE\2/g" < debian.exec > "$EXEC_TMP"
transfer_ascii "$EXEC_TMP" "$TARGET_FILETYPE exec a"
echo "Executing kernel ..."
send_line "DEBAUTO"
x3270if -t 5000 'Wait(10,Seconds)'
send_line "#CP DISC"
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment