aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.d/controller/modules/cchroot.sh2
-rw-r--r--config.d/controller/modules/cinit_pre-mount.sh73
-rw-r--r--config.d/controller/modules/cnetwork.sh4
-rw-r--r--config.d/controller/modules/net_script.sh58
4 files changed, 137 insertions, 0 deletions
diff --git a/config.d/controller/modules/cchroot.sh b/config.d/controller/modules/cchroot.sh
new file mode 100644
index 0000000..05a7907
--- /dev/null
+++ b/config.d/controller/modules/cchroot.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+
diff --git a/config.d/controller/modules/cinit_pre-mount.sh b/config.d/controller/modules/cinit_pre-mount.sh
new file mode 100644
index 0000000..41b1b60
--- /dev/null
+++ b/config.d/controller/modules/cinit_pre-mount.sh
@@ -0,0 +1,73 @@
+#!/bin/bash
+
+# EXPORT CONTROLLER CONFDIR
+CTCONFDIR=/config.d
+export CTCONFDIR
+
+# EXPORT LOCAL SCRIPTDIR
+CTSCRIPTS=/usr/local/controller
+export CTSCRIPTS
+
+# UPDATE PATH
+export "PATH=${PATH}:/usr/local/controller"
+
+# CONTROLLER FUNCTIONS
+source "${CTSCRIPTS}/cfunctions.sh"
+
+source "${CTSCRIPTS}/cnetwork.sh"
+
+if [[ "${_ctflag_net}" ]]; then
+ # SYNC CONF.D DIRECTORY FROM SERVER TO LOCAL
+ rsync -aAXhrq "${_M_SERVER}/config.d/controller/" "${CTCONFDIR}/confdir/"
+
+ # EXPORT NEW CONFIGS
+ _bsu_dfs
+
+ # COPY VERSION REGISTERED AS DEFAULT FROM THE SERVER
+ if rsync -aAXhq "${_M_SERVER}/local/version" "${CTCONFDIR}/version"; then
+ if mount -t "${SYSFS}" -o rw "${SYSDEV}" "/mnt/workdir"; then
+ _local_version="$(cat "/mnt/workdir/var/lib/version")"
+ _server_version="$(cat "${CTCONFDIR}/version")"
+ if [[ "${_local_version}" != "${_server_version}" ]]; then
+ if [[ -z "${_ctflag_nohuman}" ]]; then
+ echo "A new system version is present on the server"
+ echo "Do you wish to fetch the new system?"
+ while true; do
+ echo "Answer: Y/N "
+ read -rp "Input :: <= " ANS
+ case "${ANS}" in
+ [yY])
+ if umount "/mnt/workdir"; then
+ if [[ "${SYSFS}" == 'btrfs' ]]; then
+ eval "mkfs.${SYSFS}" -L ROOTFS -f "${SYSDEV}"
+ else
+ eval "mkfs.${SYSFS}" -L ROOTFS "${SYSDEV}"
+ fi
+ else
+ _rescue_shell "Could not umount ${SYSDEV} from /mnt/workdir"
+ fi
+
+ if mount -t "${SYSFS}" -o rw "${SYSDEV}" "/mnt/workdir"; then
+ if sync -aAXhq "${_M_SERVER}/dist.d/stage3-amd64-${_server_version}.tar.bz2" "${CTCONFDIR}/version"; then
+ echo "New system was fetched successfully"
+ else
+ echo "Fetching new system FAILED"
+ fi
+
+ else
+ _rescue_shell "Could not mount ${ROOTFS} to /mnt/workdir"
+fi
+
+# IF NETWORKING IS ESTABLISHED
+# CHECK IF THERE ARE ANY CHANGES IN THE CONFIG.D DIRECTORY
+# IF CHANGES EXIST
+# FETCH CONFIG.D DIRECTORY
+# EXPORT NEW CONFIG.D CONFIGURATIONS
+# ASK FOR VERSION
+
+# COMPARE LOCAL VERSION WITH THE FETCHED ONE
+# IF THEY DONT MATCH OR IF THE LOCAL ONE IS MISSING
+# PROMPT TO WIPE SYSFS
+# CREATE NEW SYSFS
+# FETCH NEW IMAGE FROM THE SERVER
+# EXPORT THE IMAGE
diff --git a/config.d/controller/modules/cnetwork.sh b/config.d/controller/modules/cnetwork.sh
new file mode 100644
index 0000000..84c6573
--- /dev/null
+++ b/config.d/controller/modules/cnetwork.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+ifconfig eth0 up
+udhcpc -t 5 -q -s "/bin/net_script.sh"
diff --git a/config.d/controller/modules/net_script.sh b/config.d/controller/modules/net_script.sh
new file mode 100644
index 0000000..ca4ff9a
--- /dev/null
+++ b/config.d/controller/modules/net_script.sh
@@ -0,0 +1,58 @@
+#!/bin/busybox sh
+# udhcpc script edited by Tim Riker <Tim@Rikers.org>
+
+RESOLV_CONF="/etc/resolv.conf"
+
+[ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }
+
+NETMASK=""
+[ -n "$subnet" ] && NETMASK="netmask $subnet"
+BROADCAST="broadcast +"
+[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
+
+case "$1" in
+ deconfig)
+ echo "Setting IP address 0.0.0.0 on $interface"
+ ifconfig $interface 0.0.0.0
+ ;;
+
+ renew|bound)
+ echo "Setting IP address $ip on $interface"
+ ifconfig $interface $ip $NETMASK $BROADCAST
+
+ if [ -n "$router" ] ; then
+ echo "Deleting routers"
+ while route del default gw 0.0.0.0 dev $interface ; do
+ :
+ done
+
+ metric=0
+ for i in $router ; do
+ echo "Adding router $i"
+ if [ "$subnet" = "255.255.255.255" ]; then
+ # special case for /32 subnets:
+ # /32 instructs kernel to always use routing for all outgoing packets
+ # (they can never be sent to local subnet - there is no local subnet for /32).
+ # Used in datacenters, avoids the need for private ip-addresses between two hops.
+ ip route add $i dev $interface
+ fi
+ route add default gw $i dev $interface metric $((metric++))
+ done
+ fi
+
+ echo "Recreating $RESOLV_CONF"
+ # If the file is a symlink somewhere (like /etc/resolv.conf
+ # pointing to /run/resolv.conf), make sure things work.
+ realconf=$(readlink -f "$RESOLV_CONF" 2>/dev/null || echo "$RESOLV_CONF")
+ tmpfile="$realconf-$$"
+ > "$tmpfile"
+ [ -n "$domain" ] && echo "search $domain" >> "$tmpfile"
+ for i in $dns ; do
+ echo " Adding DNS server $i"
+ echo "nameserver $i" >> "$tmpfile"
+ done
+ mv "$tmpfile" "$realconf"
+ ;;
+esac
+
+exit 0