aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-11-05 15:28:18 +0100
committerDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-11-05 16:11:47 +0100
commit021fa432447bd7b447ca39738040698db39d751b (patch)
tree66c0e46dfd952ce6de6043916f3eb9e2d92e62e2 /scripts
Initial commitv1
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makemodule.am6
-rw-r--r--scripts/devfs.sh.in21
-rwxr-xr-xscripts/ifcfg.sh.in71
-rw-r--r--scripts/ifdown.sh8
-rwxr-xr-xscripts/ifrename.sh.in47
-rw-r--r--scripts/modules_load.sh.in21
-rwxr-xr-xscripts/overlay.sh21
-rwxr-xr-xscripts/setntpdate.sh49
-rw-r--r--scripts/trymount.sh7
9 files changed, 251 insertions, 0 deletions
diff --git a/scripts/Makemodule.am b/scripts/Makemodule.am
new file mode 100644
index 0000000..207b9d2
--- /dev/null
+++ b/scripts/Makemodule.am
@@ -0,0 +1,6 @@
+helper_SCRIPTS += scripts/devfs.sh scripts/trymount.sh scripts/ifrename.sh
+helper_SCRIPTS += scripts/ifcfg.sh scripts/ifdown.sh scripts/modules_load.sh
+helper_SCRIPTS += scripts/setntpdate.sh scripts/overlay.sh
+
+EXTRA_DIST += scripts/trymount.sh scripts/ifdown.sh scripts/setntpdate.sh
+EXTRA_DIST += scripts/overlay.sh
diff --git a/scripts/devfs.sh.in b/scripts/devfs.sh.in
new file mode 100644
index 0000000..af002f6
--- /dev/null
+++ b/scripts/devfs.sh.in
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+mount -t devtmpfs none /dev
+
+[ -c /dev/console ] || mknod -m 600 /dev/console c 5 1
+[ -c /dev/tty ] || mknod -m 666 /dev/tty c 5 0
+[ -c /dev/null ] || mknod -m 666 /dev/null c 1 3
+[ -c /dev/kmsg ] || mknod -m 660 /dev/kmsg c 1 11
+[ -e /dev/fd ] || ln -snf /proc/self/fd /dev/fd
+[ -e /dev/stdin ] || ln -snf /proc/self/fd/0 /dev/stdin
+[ -e /dev/stdout ] || ln -snf /proc/self/fd/1 /dev/stdout
+[ -e /dev/stderr ] || ln -snf /proc/self/fd/2 /dev/stderr
+[ -e /proc/kcore ] && ln -snf /proc/kcore /dev/core
+
+mkdir -p /dev/mqueue -m 1777
+mkdir -p /dev/pts -m 0755
+mkdir -p /dev/shm -m 1777
+
+@SCRIPTDIR@/trymount.sh "/dev/mqueue" "mqueue" "noexec,nosuid,nodev"
+@SCRIPTDIR@/trymount.sh "/dev/pts" "devpts" "noexec,nosuid,gid=5,mode=0620"
+@SCRIPTDIR@/trymount.sh "/dev/shm" "tmpfs" "noexec,nosuid,nodev,mode=1777"
diff --git a/scripts/ifcfg.sh.in b/scripts/ifcfg.sh.in
new file mode 100755
index 0000000..f8396c6
--- /dev/null
+++ b/scripts/ifcfg.sh.in
@@ -0,0 +1,71 @@
+#!/bin/sh
+CFGPATH="@ETCPATH@/netcfg"
+
+[ -d "$CFGPATH" ] || exit 0
+
+# configure interfaces
+for IFPATH in /sys/class/net/*; do
+ [ "$IFPATH" == "/sys/class/net/lo" ] && continue
+
+ IF=`basename $IFPATH`
+ CFGFILE="$CFGPATH/$IF"
+
+ [ -f "$CFGFILE" ] || continue
+
+ ip link set dev "$IF" down
+
+ while read LINE;
+ do
+ trimmed=`echo -- $LINE`
+ [ ! -z "$trimmed" ] || continue
+ set $trimmed
+
+ case "$1" in
+ address|addr|ip|ip6|ipv6)
+ shift
+ ip address add $@ dev "$IF"
+ ;;
+ arp|multicast|mtu)
+ ip link set dev "$IF" $@
+ ;;
+ offload)
+ shift
+ ethtool -K "$IF" $@
+ ;;
+ *)
+ ;;
+ esac
+ done < "$CFGFILE"
+done
+
+# configure static routs
+if [ -f "$CFGPATH/routes" ]; then
+ while read LINE;
+ do
+ trimmed=`echo -- $LINE`
+ [ ! -z "$trimmed" ] || continue
+ set $trimmed
+
+ case "$1" in
+ route)
+ shift
+ ip route add $@
+ ;;
+ rule)
+ shift
+ ip rule add $@
+ ;;
+ *)
+ ;;
+ esac
+ done < "$CFGFILE"
+fi
+
+# activate interfaces
+for IFPATH in /sys/class/net/*; do
+ [ "$IFPATH" == "/sys/class/net/lo" ] && continue
+
+ IF=`basename $IFPATH`
+
+ [ ! -f "$CFGPATH/$IF" ] || ip link set dev "$IF" up
+done
diff --git a/scripts/ifdown.sh b/scripts/ifdown.sh
new file mode 100644
index 0000000..e6f4500
--- /dev/null
+++ b/scripts/ifdown.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+for IFPATH in /sys/class/net/*; do
+ [ "$IFPATH" == "/sys/class/net/lo" ] && continue
+
+ IF=`basename $IFPATH`
+
+ ip link set dev "$IF" down
+done
diff --git a/scripts/ifrename.sh.in b/scripts/ifrename.sh.in
new file mode 100755
index 0000000..0820c94
--- /dev/null
+++ b/scripts/ifrename.sh.in
@@ -0,0 +1,47 @@
+#!/bin/sh
+NAMERULES="@ETCPATH@/netcfg/ifrename"
+TMPPATH="/tmp/ifrename"
+
+[ -f "$NAMERULES" ] || exit 0
+
+mkdir -p "$TMPPATH"
+
+for IFPATH in /sys/class/net/*; do
+ [ "$IFPATH" == "/sys/class/net/lo" ] && continue
+
+ IF=`basename $IFPATH`
+ MAC=`cat $IFPATH/address`
+
+ grep "^[^,]\+,[^,]\+,[a-zA-Z0-9]\+$" $NAMERULES | while read LINE;
+ do
+ NAMECMP=$(echo $LINE | cut -d',' -f1)
+ ADDRCMP=$(echo $LINE | cut -d',' -f2)
+ RULE=$(echo $LINE | cut -d',' -f3)
+
+ case $IF in ($NAMECMP) ;; *) continue;; esac
+ case $MAC in ($ADDRCMP) ;; *) continue;; esac
+
+ echo "$MAC,$IF" >> "$TMPPATH/$RULE"
+ break
+ done
+done
+
+for FNAME in $TMPPATH/*; do
+ [ ! -f "$FNAME" ] && break
+
+ IDX=0
+ PREFIX=$(basename $FNAME)
+
+ sort -t',' -k1 -u $FNAME | while read LINE;
+ do
+ OLDNAME=$(echo $LINE | cut -d',' -f2)
+ NEWNAME="$PREFIX$IDX"
+ IDX=`expr $IDX + 1`
+
+ ip link set "$OLDNAME" name "$NEWNAME"
+ done
+
+ rm "$FNAME"
+done
+
+rmdir "$TMPPATH"
diff --git a/scripts/modules_load.sh.in b/scripts/modules_load.sh.in
new file mode 100644
index 0000000..58bb2ab
--- /dev/null
+++ b/scripts/modules_load.sh.in
@@ -0,0 +1,21 @@
+#!/bin/sh
+MODLIST="@ETCPATH@/modules"
+
+if [ ! -f "$MODLIST" ]; then
+ exit 0
+fi
+
+while read LINE;
+do
+ trimmed=`echo -- $LINE`
+ [ ! -z "$trimmed" ] || continue
+ set $trimmed
+
+ case "$1" in
+ \#*)
+ ;;
+ *)
+ modprobe "$1"
+ ;;
+ esac
+done < "$MODLIST"
diff --git a/scripts/overlay.sh b/scripts/overlay.sh
new file mode 100755
index 0000000..090671c
--- /dev/null
+++ b/scripts/overlay.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+lower=/cfg/preserve/${1}
+upper=/cfg/overlay/${1}
+work=/cfg/overlay/${1}_work
+target=${2}
+
+if [ ! -d "$target" ]; then
+ exit
+fi
+
+if [ -d "$lower" ]; then
+ if [ -d "$upper" ]; then
+ mkdir -p "$work"
+ mount -t overlay overlay \
+ -olowerdir=${lower},upperdir=${upper},workdir=${work} \
+ ${target}
+ else
+ mount --bind "$lower" "$target"
+ fi
+fi
diff --git a/scripts/setntpdate.sh b/scripts/setntpdate.sh
new file mode 100755
index 0000000..bf0a753
--- /dev/null
+++ b/scripts/setntpdate.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+resolve() {
+ local domain="$1"
+ local server="$2"
+
+ if [ -x "$(command -v dig)" ]; then
+ if [ -z "$server" ]; then
+ dig +short "$domain"
+ else
+ dig +short "@$server" "$domain"
+ fi
+ return $?
+ fi
+
+ if [ -x "$(command -v drill)" ]; then
+ if [ -z "$server" ]; then
+ drill "$domain" | grep "^${domain}." | cut -d$'\t' -f5
+ else
+ drill "@$server" "$domain" | grep "^${domain}." |\
+ cut -d$'\t' -f5
+ fi
+ return $?
+ fi
+ exit 1
+}
+
+try_update() {
+ while read ip; do
+ if ntpdate -bu "$ip"; then
+ return 0
+ fi
+ done
+
+ return 1
+}
+
+pool="pool.ntp.org"
+dns="1.1.1.1"
+
+# try default DNS server first
+resolve "$pool" "" | try_update
+[ $? -eq 0 ] && exit 0
+
+# try fallback public dns server
+ping -q -c 1 "$dns" || exit 1
+
+resolve "$pool" "$dns" | try_update
+exit $?
diff --git a/scripts/trymount.sh b/scripts/trymount.sh
new file mode 100644
index 0000000..9be77f6
--- /dev/null
+++ b/scripts/trymount.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ -d "$1" ]; then
+ if grep -qsE "[[:space:]]+$2$" "/proc/filesystems"; then
+ mount -n -t "$2" -o "$3" "$2" "$1"
+ fi
+fi