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