Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 42 lines (34 sloc) 896 Bytes
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
SQUASH_ROOT=/squashed
if [[ -z $1 ]] || [[ ! -d ${SQUASH_ROOT}/$1 ]]; then
echo "Invalid target or none specified. Valid targets are: "
squashes=($(ls $SQUASH_ROOT))
echo -e "\n Used\tDir\n ---------------"
for dir in ${squashes[*]}; do
echo -e " $(du -sh ${SQUASH_ROOT}/${dir}/rw 2> /dev/null | cut -d\/ -f1)${dir}"
done
echo
exit 1
fi
if [[ $UID -ne 0 ]]; then
sudo $0 $*
exit
fi
stat_busy "Squashing /${1}"
mksquashfs /$1 ${SQUASH_ROOT}/${1}/${1}_tmp.sfs -b 65536 || exit 1
stat_done
stat_busy "Unmounting old UnionFS"
umount -l /${1}
umount -l -d ${SQUASH_ROOT}/${1}/ro
stat_done
stat_busy "Replacing with new SquashFS"
rm ${SQUASH_ROOT}/${1}/${1}.sfs
mv ${SQUASH_ROOT}/${1}/${1}{_tmp,}.sfs
rm -rf ${SQUASH_ROOT}/${1}/rw/*
stat_done
stat_busy "Mounting new /${1}"
mount ${SQUASH_ROOT}/${1}/ro
mount /${1}
stat_done