at master 2.0 kB view raw
1#! @bash@/bin/sh -e 2 3shopt -s nullglob 4 5export PATH=/empty:@path@ 6 7if test $# -ne 1; then 8 echo "Usage: init-script-builder.sh DEFAULT-CONFIG" 9 exit 1 10fi 11 12defaultConfig="$1" 13 14 15[ "$(stat -f -c '%i' /)" = "$(stat -f -c '%i' /boot)" ] || { 16 # see grub-menu-builder.sh 17 echo "WARNING: /boot being on a different filesystem not supported by init-script-builder.sh" 18} 19 20 21 22target="/sbin/init" 23targetOther="/boot/init-other-configurations-contents.txt" 24 25tmp="$target.tmp" 26tmpOther="$targetOther.tmp" 27 28 29configurationCounter=0 30 31 32 33 34# Add an entry to $targetOther 35addEntry() { 36 local name="$1" 37 local path="$2" 38 local shortSuffix="$3" 39 40 configurationCounter=$((configurationCounter + 1)) 41 42 local stage2=$path/init 43 44 content="$( 45 echo "#!/bin/sh" 46 echo "# $name" 47 echo "# created by init-script-builder.sh" 48 echo "exec $stage2" 49 )" 50 51 [ "$path" != "$defaultConfig" ] || { 52 echo "$content" > $tmp 53 echo "# older configurations: $targetOther" >> $tmp 54 chmod +x $tmp 55 } 56 57 echo -e "$content\n\n" >> $tmpOther 58} 59 60 61mkdir -p /boot /sbin 62 63addEntry "@distroName@ - Default" $defaultConfig "" 64 65# Add all generations of the system profile to the menu, in reverse 66# (most recent to least recent) order. 67for link in $((ls -d $defaultConfig/specialisation/* ) | sort -n); do 68 date=$(stat --printf="%y\n" $link | sed 's/\..*//') 69 addEntry "@distroName@ - variation" $link "" 70done 71 72for generation in $( 73 (cd /nix/var/nix/profiles && ls -d system-*-link) \ 74 | sed 's/system-\([0-9]\+\)-link/\1/' \ 75 | sort -n -r); do 76 link=/nix/var/nix/profiles/system-$generation-link 77 date=$(stat --printf="%y\n" $link | sed 's/\..*//') 78 if [ -d $link/kernel ]; then 79 kernelVersion=$(cd $(dirname $(readlink -f $link/kernel))/lib/modules && echo *) 80 suffix="($date - $kernelVersion)" 81 else 82 suffix="($date)" 83 fi 84 addEntry "@distroName@ - Configuration $generation $suffix" $link "$generation ($date)" 85done 86 87mv $tmpOther $targetOther 88mv $tmp $target