#!/bin/sh

if [ "$(id -u)" != "0" ]; then
    echo "You must be root"
    exit 1
fi

create_backup() {
    directory=$1
    filename=$2
    mksquashfs $directory $filename
}

restore_backup() {
    filename=$1
    directory=$2
    unsquashfs -f -d $directory $filename
}

print_help() {
    printf "usage:\n\t$0 (create|restore)\nexample:\n\t$0 create (folder|directory) (filename)\n\t$0 restore (filename) (folder|directory)\n"
}

case "$1" in
    "create")
        if [[ "$2" == "" || "$3" == "" ]]; then
            print_help
            exit 1
        fi
        create_backup $2 $3
        ;;
    "restore")
        if [[ "$2" == "" || "$3" == "" ]]; then
            print_help
            exit 1
        fi
        restore_backup $2 $3
        ;;
    *)
        print_help
        ;;
esac
