diff --git a/README.md b/README.md index 0e31b28..050e7d0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,15 @@ # freeze-thaw -Freeze/Thaw scripts. Or, poor-man's DeepFreeze + +## Freeze/Thaw scripts. Or, poor-man's DeepFreeze + +A long time ago I was working with a Windows machine that had DeepFreeze installed. Deep Freeze will take a snapshot of +system upon demand and can revert to that snapshot after every boot. We used it in an assisted-living library to +prevent the residents from over-riding system settings, changing the language, setting the wallpaper to porn or deleting +the C:/Windows directory (all of which happened at one point or another) + +There are certainly more robust or professional solutions but this was quick, easy to understand and effective. + +I then converted these machines to Linux (since the browser was the application used 98% of the time) and I wanted to +emulate Deep Freeze. I stumbled across these scripts, tweaked them and held onto them since they worked so well. + + diff --git a/freeze.sh b/freeze.sh new file mode 100755 index 0000000..dc3f01c --- /dev/null +++ b/freeze.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +#=============================================================================== +# +# FILE: freeze.sh +# +# USAGE: sudo ./freeze.sh +# +# DESCRIPTION: Part of the Freeze/Thaw set of scripts. This script creates a +# tarball of the users home directory +# +# OPTIONS: --- +# REQUIREMENTS: Root privileges. You must be logged in as a 'root' user +# You cannot be logged in as the user to be 'frozen' +# BUGS: --- +# NOTES: Inspired by +# http://www.linuxquestions.org/linux/answers/Applications_GUI_Multimedia/Deepfreeze_for_Linux +# AUTHOR: C Hawley +# COMPANY: +# VERSION: 1.0 +# CREATED: 02/24/2011 12:18:55 PM EST +# REVISION: Mon 09 Oct 2017 05:15:49 PM EDT +#=============================================================================== + +set -o nounset # Treat unset variables as an error + +# Check for empty argument +if [ -z "${1:-}" ]; then + arg="undefined" + echo "You must specify the username and archive location" + exit 1 +fi + +frozenuser="${1}" +frozenarchive="${2}/${frozenuser}.frozen.tgz" + +# If Previously frozen file exists - remove it. +if [ -f "${frozenarchive}" ]; then + rm -f "${frozenarchive}" +fi + +# create new frozen file +# tar options: +# -p extract all protection information +# -P don't strip leading '/'s from file names +tar -cpPf "${frozenarchive}" /home/"${frozenuser}" diff --git a/thaw.sh b/thaw.sh new file mode 100755 index 0000000..afaf384 --- /dev/null +++ b/thaw.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +#=============================================================================== +# +# FILE: thaw.sh +# +# USAGE: sudo ./thaw.sh +# +# DESCRIPTION: Part of the Freeze/Thaw set of scripts. This script extracts a +# tarball of the users home directory +# +# OPTIONS: --- +# REQUIREMENTS: Must be run at boot: +# Save this script in the /etc/init.d/ directory. +# Make it executable (chmod 755 /ect/init.d/thaw.sh) +# Then run 'update-rc.d thaw.sh defaults' (no quotes) +# BUGS: --- +# NOTES: Inspired by: +# http://www.linuxquestions.org/linux/answers/Applications_GUI_Multimedia/Deepfreeze_for_Linux +# Runlevel info: +# http://embraceubuntu.com/2005/09/07/adding-a-startup-script-to-be-run-at-bootup/ +# AUTHOR: C Hawley +# COMPANY: +# VERSION: 1.0 +# CREATED: 02/24/2011 12:18:55 PM EST +# REVISION: Mon 09 Oct 2017 05:16:19 PM EDT +#=============================================================================== + +set -o nounset # Treat unset variables as an error + +# Check for empty argument +if [ -z "${1:-}" ]; then + arg="undefined" + echo "You must specify the username and archive location" + exit 1 +fi + +frozenuser="${1}" +frozenarchive="${2}/${frozenuser}.frozen.tgz" + +# remove existing user directory +rm -rf /home/"${frozenuser}" + +# extract user tarball +# tar options: +# -p extract all protection information +# -P don't strip leading '/'s from file names +tar -xpPf "${frozenarchive}" -C /