Synced with trunk @ 15505

svn path=/nixos/branches/modular-nixos/; revision=15640
This commit is contained in:
Marc Weber 2009-05-18 12:01:31 +00:00
parent 1d0c0a4291
commit 81d6032c43
2 changed files with 69 additions and 38 deletions

View File

@ -15,6 +15,9 @@ bootMount="@bootMount@"
if test -z "$bootMount"; then bootMount=/boot; fi if test -z "$bootMount"; then bootMount=/boot; fi
echo "updating the Grub menu..."
target=/boot/grub/menu.lst target=/boot/grub/menu.lst
tmp=$target.tmp tmp=$target.tmp
@ -27,14 +30,13 @@ GRUBEND
if test -n "@grubSplashImage@"; then if test -n "@grubSplashImage@"; then
splashLocation=@grubSplashImage@ splashLocation=@grubSplashImage@
# !!! image in /nix/store doesn't seem to work # Splash images in /nix/store don't seem to work, so copy them.
#if test -n "@copyKernels@"; then
cp -f $splashLocation /boot/background.xpm.gz cp -f $splashLocation /boot/background.xpm.gz
splashLocation="$bootMount/background.xpm.gz" splashLocation="$bootMount/background.xpm.gz"
#fi
echo "splashimage $splashLocation" >> $tmp echo "splashimage $splashLocation" >> $tmp
fi fi
configurationCounter=0 configurationCounter=0
configurationLimit="@configurationLimit@" configurationLimit="@configurationLimit@"
numAlienEntries=`cat <<EOF | egrep '^[[:space:]]*title' | wc -l numAlienEntries=`cat <<EOF | egrep '^[[:space:]]*title' | wc -l
@ -45,6 +47,36 @@ if test $((configurationLimit+numAlienEntries)) -gt 190; then
configurationLimit=$((190-numAlienEntries)); configurationLimit=$((190-numAlienEntries));
fi fi
# Convert a path to a file in the Nix store such as
# /nix/store/<hash>-<name>/file to <hash>-<name>-<file>.
cleanName() {
local path="$1"
echo "$path" | sed 's|^/nix/store/||' | sed 's|/|-|g'
}
# Copy a file from the Nix store to /boot/kernels.
declare -A filesCopied
copyToKernelsDir() {
local src="$1"
local dst="/boot/kernels/$(cleanName $src)"
# Don't copy the file if $dst already exists. This means that we
# have to create $dst atomically to prevent partially copied
# kernels or initrd if this script is ever interrupted.
if ! test -e $dst; then
local dstTmp=$dst.tmp.$$
cp $src $dstTmp
mv $dstTmp $dst
fi
filesCopied[$dst]=1
result=$dst
}
# Add an entry for a configuration to the Grub menu, and if
# appropriate, copy its kernel and initrd to /boot/kernels.
addEntry() { addEntry() {
local name="$1" local name="$1"
local path="$2" local path="$2"
@ -53,7 +85,7 @@ addEntry() {
configurationCounter=$((configurationCounter + 1)) configurationCounter=$((configurationCounter + 1))
if test $configurationCounter -gt @configurationLimit@; then if test $configurationCounter -gt @configurationLimit@; then
return return
fi; fi
if ! test -e $path/kernel -a -e $path/initrd; then if ! test -e $path/kernel -a -e $path/initrd; then
return return
@ -74,30 +106,21 @@ EOF
fi fi
if test -n "@copyKernels@"; then if test -n "@copyKernels@"; then
local kernel2=/boot/kernels/$(echo $kernel | sed 's^/^-^g') copyToKernelsDir $kernel; kernel=$result
if ! test -e $kernel2; then copyToKernelsDir $initrd; initrd=$result
cp $kernel $kernel2
fi fi
kernel=$kernel2
local initrd2=/boot/kernels/$(echo $initrd | sed 's^/^-^g')
if ! test -e $initrd2; then
cp $initrd $initrd2
fi
initrd=$initrd2
if test -n "$bootMount"; then if test -n "$bootMount"; then
kernel=$(echo $kernel2 | sed -e "s^/boot^$bootMount^") kernel=$(echo $kernel | sed -e "s^/boot^$bootMount^")
initrd=$(echo $initrd2 | sed -e "s^/boot^$bootMount^") initrd=$(echo $initrd | sed -e "s^/boot^$bootMount^")
fi
fi fi
local confName=$(if test -e $path/configuration-name; then local confName=$(if test -e $path/configuration-name; then
cat $path/configuration-name; cat $path/configuration-name;
fi); fi)
if test -n "$confName"; then if test -n "$confName"; then
name="$confName $3"; name="$confName $3"
fi; fi
cat >> $tmp << GRUBEND cat >> $tmp << GRUBEND
@ -108,11 +131,11 @@ GRUBEND
} }
rm -rf /boot/kernels
if test -n "@copyKernels@"; then if test -n "@copyKernels@"; then
mkdir -p /boot/kernels mkdir -p /boot/kernels
fi fi
# Additional entries specified verbatim by the configuration. # Additional entries specified verbatim by the configuration.
extraGrubEntries=`cat <<EOF extraGrubEntries=`cat <<EOF
@extraGrubEntries@ @extraGrubEntries@
@ -135,11 +158,11 @@ for link in $((ls -d $default/fine-tune/* ) | sort -n); do
date=$(stat --printf="%y\n" $link | sed 's/\..*//') date=$(stat --printf="%y\n" $link | sed 's/\..*//')
addEntry "NixOS - variation" $link "" addEntry "NixOS - variation" $link ""
done done
for generation in $( for generation in $(
(cd /nix/var/nix/profiles && ls -d system-*-link) \ (cd /nix/var/nix/profiles && ls -d system-*-link) \
| sed 's/system-\([0-9]\+\)-link/\1/' \ | sed 's/system-\([0-9]\+\)-link/\1/' \
| sort -n -r); do | sort -n -r); do
echo $generation
link=/nix/var/nix/profiles/system-$generation-link link=/nix/var/nix/profiles/system-$generation-link
date=$(stat --printf="%y\n" $link | sed 's/\..*//') date=$(stat --printf="%y\n" $link | sed 's/\..*//')
kernelVersion=$(cd $(dirname $(readlink -f $link/kernel))/lib/modules && echo *) kernelVersion=$(cd $(dirname $(readlink -f $link/kernel))/lib/modules && echo *)
@ -150,3 +173,11 @@ done
# Atomically update /boot/grub/menu.lst. !!! should do an fsync() # Atomically update /boot/grub/menu.lst. !!! should do an fsync()
# here on $tmp, especially on ext4. # here on $tmp, especially on ext4.
mv $tmp $target mv $tmp $target
# Remove obsolete files from /boot/kernels.
for fn in $(ls /boot/kernels/*); do
if ! test "${filesCopied[$fn]}" = 1; then
rm -vf -- "$fn"
fi
done

View File

@ -50,8 +50,8 @@ EOF
oldEvents=$(readlink -f /etc/event.d || true) oldEvents=$(readlink -f /etc/event.d || true)
newEvents=$(readlink -f @out@/etc/event.d) newEvents=$(readlink -f @out@/etc/event.d)
echo "old: $oldEvents" #echo "old: $oldEvents"
echo "new: $newEvents" #echo "new: $newEvents"
stopJob() { stopJob() {
local job=$1 local job=$1
@ -73,7 +73,7 @@ EOF
# Activate the new configuration (i.e., update /etc, make # Activate the new configuration (i.e., update /etc, make
# accounts, and so on). # accounts, and so on).
echo "Activating the configuration..." echo "activating the configuration..."
@out@/activate @out@ @out@/activate @out@
# Make Upstart reload its events. !!! Should wait until it has # Make Upstart reload its events. !!! Should wait until it has