python312Packages.tencentcloud-sdk-python: 3.0.1291 -> 3.0.1292 (#369707)
[NixPkgs.git] / nixos / modules / system / boot / loader / init-script / init-script-builder.sh
blob755ea259c425dd694618a0aac3c0ced25e778001
1 #! @bash@/bin/sh -e
3 shopt -s nullglob
5 export PATH=/empty
6 for i in @path@; do PATH=$PATH:$i/bin; done
8 if test $# -ne 1; then
9 echo "Usage: init-script-builder.sh DEFAULT-CONFIG"
10 exit 1
13 defaultConfig="$1"
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"
23 target="/sbin/init"
24 targetOther="/boot/init-other-configurations-contents.txt"
26 tmp="$target.tmp"
27 tmpOther="$targetOther.tmp"
30 configurationCounter=0
31 numAlienEntries=`cat <<EOF | egrep '^[[:space:]]*title' | wc -l
32 @extraEntries@
33 EOF`
38 # Add an entry to $targetOther
39 addEntry() {
40 local name="$1"
41 local path="$2"
42 local shortSuffix="$3"
44 configurationCounter=$((configurationCounter + 1))
46 local stage2=$path/init
48 content="$(
49 echo "#!/bin/sh"
50 echo "# $name"
51 echo "# created by init-script-builder.sh"
52 echo "exec $stage2"
55 [ "$path" != "$defaultConfig" ] || {
56 echo "$content" > $tmp
57 echo "# older configurations: $targetOther" >> $tmp
58 chmod +x $tmp
61 echo -e "$content\n\n" >> $tmpOther
65 mkdir -p /boot /sbin
67 addEntry "@distroName@ - Default" $defaultConfig ""
69 # Add all generations of the system profile to the menu, in reverse
70 # (most recent to least recent) order.
71 for link in $((ls -d $defaultConfig/specialisation/* ) | sort -n); do
72 date=$(stat --printf="%y\n" $link | sed 's/\..*//')
73 addEntry "@distroName@ - variation" $link ""
74 done
76 for 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)"
88 addEntry "@distroName@ - Configuration $generation $suffix" $link "$generation ($date)"
89 done
91 mv $tmpOther $targetOther
92 mv $tmp $target