]> git.datanom.net - webcal.git/blob - install/upgrade.sh
Initial upload
[webcal.git] / install / upgrade.sh
1 #!/bin/sh
2
3 PATH=/usr/bin:/usr/sbin:/bin:/sbin
4 DIR=/tmp
5 USR=user.sql
6 CAL=calendar.sql
7 USR_DUMP=".mode insert user\n.output user.sql"
8 CAL_DUMP=".mode insert calendar\n.output calendar.sql"
9
10 function export_db() {
11 echo -n 'Please enter name of database to export from: '
12 read DB
13 if [ ! -e "$DB" ]; then
14 echo $DB: File does not exist
15 exit 1
16 fi
17
18 echo -e $USR_DUMP > "$DIR/$USR"
19 sqlite3 -init "$DIR/$USR" "$DB" 'select * from user where id <> 1'
20 rm -f "$DIR/$USR"
21
22 echo -e $CAL_DUMP > "$DIR/$CAL"
23 sqlite3 -init "$DIR/$CAL" "$DB" 'select * from calendar'
24 rm -f "$DIR/$CAL"
25 }
26
27 function import_db() {
28 echo -n 'Please enter name of database to import into: '
29 read DB
30 if [ ! -e "$DB" ]; then
31 echo $DB: File does not exist
32 exit 1
33 fi
34 if [ ! -e "./$USR" ]; then
35 echo $USR: File does not exist
36 exit 1
37 fi
38 if [ ! -e "./$CAL" ]; then
39 echo $CAL: File does not exist
40 exit 1
41 fi
42
43 sqlite3 "$DB" < "./$USR"
44 sqlite3 "$DB" < "./$CAL"
45
46 echo -n "Delete files containing backup [y/N]: "
47 read DEL
48 if [ ! -z "$DEL" ]; then
49 if [ "$DEL" = "y" -o "$DEL" = "Y" ]; then
50 rm -f "./$USR"
51 rm -f "./$CAL"
52 fi
53 fi
54 }
55
56 if [ $UID -ne '0' ]; then
57 echo You must run this script as root
58 exit 1
59 fi
60
61 case "$1" in
62 export)
63 export_db
64 echo Database was succesfully exported
65 echo You should now perform standard install
66 echo and run this script with command import
67 exit 0
68 ;;
69 import)
70 import_db
71 echo Database was succesfully imported
72 exit 0
73 ;;
74 *)
75 echo -e "usage: $0 CMD\n
76 CMD is:
77 \texport\texport data from a database
78 \timport\timport data to a database"
79 exit 0
80 ;;
81 esac
This page took 0.075769 seconds and 6 git commands to generate.