#!/bin/sh
#
# run after all services have shut down and
# remaining processes have been terminated
#

export PATH=/sbin:/bin:/usr/sbin:/usr/bin

# assume proper directory
cd /usr/lib/dinit.d/early/..

if [ ! -e /run/dinit/container ]; then
    echo "Disabling swap..."
    ./early/scripts/swap.sh stop
    echo "Unmounting network filesystems..."
    umount -l -a -t nfs,nfs4,smbfs,cifs
    umount -l -a -O netdev
    echo "Unmounting filesystems..."
    ./early/scripts/fs-fstab.sh stop
    echo "Remounting root read-only..."
    ./early/helpers/mnt rmnt / ro
fi

sync

if [ ! -e /run/dinit/container ]; then
    export DM_DISABLE_UDEV=1
    echo "Deactivating cryptdisks..."
    ./early/scripts/cryptdisks.sh remaining stop
    echo "Deactivating volume groups..."
    ./early/scripts/lvm.sh stop
    echo "Deactivating remaining cryptdisks..."
    ./early/scripts/cryptdisks.sh early stop
fi
