#!/bin/sh
# Hunter: Slow but most graceful nitro shutdown/reboot similar to sysvinit's.

# Recreate the /initrd if needed
if [ ! -d /initrd ]; then
    echo "Creating initrd directory\n" mkdir /initrd
fi
if [ -d /initrd -a ! -f /initrd/README.WARNING ]; then
    cat > /initrd/README.WARNING <<EOF
(mkinitrd) Don't remove this directory, it's needed at boot time,
in the initrd, to perform the pivot_root.
EOF
fi

if [ -d /boot/EFI ]; then umount /boot/EFI; fi
if [ -d /var/lock/subsys ]; then rm -f /var/lock/subsys/*; fi

# Save mixer settings, here for lack of a better place.
if [ -x /sbin/alsactl ]; then
  action "Saving mixer settings" /sbin/alsactl --ignore store
fi

# Save random seed
touch /var/lib/random-seed
chmod 600 /var/lib/random-seed
echo "Saving random seed:" && dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null

# Sync clock although nitro does not need a synced clock
[ -x /sbin/hwclock ] && echo "Syncing hardware clock to system time" && /sbin/hwclock --systohc

rm -f /.autofsck

# At this point I think we're safe.

# Sync devices
sync

exec $command
