#!/bin/sh PATH=/usr/bin:/usr/sbin:/bin:/sbin DIR=/tmp USR=user.sql CAL=calendar.sql USR_DUMP=".mode insert user\n.output user.sql" CAL_DUMP=".mode insert calendar\n.output calendar.sql" function export_db() { echo -n 'Please enter name of database to export from: ' read DB if [ ! -e "$DB" ]; then echo $DB: File does not exist exit 1 fi echo -e $USR_DUMP > "$DIR/$USR" sqlite3 -init "$DIR/$USR" "$DB" 'select * from user where id <> 1' rm -f "$DIR/$USR" echo -e $CAL_DUMP > "$DIR/$CAL" sqlite3 -init "$DIR/$CAL" "$DB" 'select * from calendar' rm -f "$DIR/$CAL" } function import_db() { echo -n 'Please enter name of database to import into: ' read DB if [ ! -e "$DB" ]; then echo $DB: File does not exist exit 1 fi if [ ! -e "./$USR" ]; then echo $USR: File does not exist exit 1 fi if [ ! -e "./$CAL" ]; then echo $CAL: File does not exist exit 1 fi sqlite3 "$DB" < "./$USR" sqlite3 "$DB" < "./$CAL" echo -n "Delete files containing backup [y/N]: " read DEL if [ ! -z "$DEL" ]; then if [ "$DEL" = "y" -o "$DEL" = "Y" ]; then rm -f "./$USR" rm -f "./$CAL" fi fi } if [ $UID -ne '0' ]; then echo You must run this script as root exit 1 fi case "$1" in export) export_db echo Database was succesfully exported echo You should now perform standard install echo and run this script with command import exit 0 ;; import) import_db echo Database was succesfully imported exit 0 ;; *) echo -e "usage: $0 CMD\n CMD is: \texport\texport data from a database \timport\timport data to a database" exit 0 ;; esac