#!/bin/bash proc usage_and_exit { echo "Usage: stage1_install_busybox.sh UUID" exit 1 } setglobal ARGC = $Argc if test $(ARGC) -lt 1 { usage_and_exit } while test $# -gt 0 { match $(1) { with --* usage_and_exit with * setglobal UUID = $(1) } shift } setglobal BUSYBOX = $(BUSYBOX_BINARY:-$(which busybox 2> /dev/null)) if test ! -x $(BUSYBOX) { echo "error: busybox binary is not executable: Install it or set BUSYBOX_BINARY env variable" exit 1 } setglobal IS_STATIC = $[file $(BUSYBOX) | grep static] if test -z $(IS_STATIC) { echo "error: busybox binary is not statically linked" exit 1 } setglobal RKT_RUN_DIR = '"/var/lib/rkt/pods/run'" setglobal POD_DIR = ""$(RKT_RUN_DIR)/$(UUID)"" setglobal BUSYBOX_LINKS = '"ls cp cat mount vi awk chmod chown mv df ps rm tar top tr wc which ping'" setglobal NSPAWN_PID = $[ps aux | grep "[u]uid=$UUID" | awk '{print $2}] sudo nsenter -m -t $(NSPAWN_PID) cp $(BUSYBOX) $(POD_DIR)/stage1/rootfs/bin sudo nsenter -m -t $(NSPAWN_PID) chmod +x "$(POD_DIR)/stage1/rootfs/bin/busybox" for link in [$(BUSYBOX_LINKS)] { sudo nsenter -m -t $(NSPAWN_PID) ln -sf busybox "$(POD_DIR)/stage1/rootfs/bin/$(link)" } echo "Busybox installed. Use the following command to enter pod's stage1:" setglobal SYSTEMD_PPID = $[sudo cat "$(RKT_RUN_DIR)/$(UUID)/ppid] setglobal SYSTEMD_PID = $[sudo cat /proc/$SYSTEMD_PPID/task/$SYSTEMD_PPID/children] echo sudo nsenter -m -u -i -p -t $(SYSTEMD_PID)