summarylogtreecommitdiffstats
path: root/netinstall.sh
diff options
context:
space:
mode:
Diffstat (limited to 'netinstall.sh')
-rw-r--r--netinstall.sh74
1 files changed, 74 insertions, 0 deletions
diff --git a/netinstall.sh b/netinstall.sh
new file mode 100644
index 000000000000..06cb03c6a4ff
--- /dev/null
+++ b/netinstall.sh
@@ -0,0 +1,74 @@
+#!/bin/bash
+
+set -e
+
+INTERFACE=
+PACKAGES=()
+OPTIONS=()
+
+function help() {
+ echo "usage: ${0} [OPTIONS]"
+ echo
+ echo "where OPTIONS are:"
+ echo " -h show this help"
+ echo " -i INTERFACE install via INTERFACE"
+ echo " -k KEYFILE use KEYFILE"
+ echo " -p PACKAGE install PACKAGE"
+ echo " -r reset configuration"
+ echo " -s SCRIPT run script"
+}
+
+while getopts "hi:k:p:rs:" opt; do
+ case ${opt} in
+ h)
+ help
+ exit 0
+ ;;
+ i)
+ if ! ip addr show dev "${OPTARG}" >/dev/null 2>/dev/null; then
+ echo "Interface '${OPTARG}' does not exist." >&2
+ exit 1
+ fi
+ INTERFACE="${OPTARG}"
+ ;;
+ k)
+ OPTIONS+=(-k "${OPTARG}")
+ ;;
+ p)
+ if [ ! -s "${OPTARG}" ]; then
+ echo "Package '${OPTARG}' does not exist." >&2
+ exit 1
+ fi
+ PACKAGES+=("${OPTARG}")
+ ;;
+ r)
+ OPTIONS+=(-r)
+ ;;
+ s)
+ OPTIONS+=(-s "${OPTARG}")
+ ;;
+ esac
+done
+
+if [ -z "${PACKAGES}" ]; then
+ echo "No package given for installation." >&2
+ exit 1
+fi
+
+if [ -z "${INTERFACE}" ]; then
+ echo "No interface given for installation." >&2
+ exit 1
+fi
+
+if [ "${UID}" -gt 0 ]; then
+ exec sudo -p "This must be run as root. Please enter the password for %u to continue: " -- /bin/bash -- "${0}" $@
+fi
+
+ip netns add netinstall
+trap 'ip netns delete netinstall' EXIT INT QUIT TERM HUP
+
+ip link set dev "${INTERFACE}" netns netinstall
+ip netns exec netinstall ip addr add 192.168.88.2/24 dev "${INTERFACE}"
+ip netns exec netinstall ip link set dev "${INTERFACE}" up
+ip netns exec netinstall ip route add default dev "${INTERFACE}"
+ip netns exec netinstall /usr/lib/netinstall/netinstall "${OPTIONS[@]}" -a 192.168.88.1 "${PACKAGES[@]}"