File: convert_sqlite3.sh

package info (click to toggle)
krecipes 2.0~beta2-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 15,880 kB
  • ctags: 3,917
  • sloc: cpp: 39,833; sql: 168; perl: 134; sh: 43; xml: 43; makefile: 11
file content (58 lines) | stat: -rwxr-xr-x 1,394 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
#
# This script will convert an SQLite 2.x database file to SQLite 3.
#
# Calling it without any parameters, it will convert the file specified in the
# Krecipes configuration
#
# If Krecipes can't find the database file, you need to manually give
# it on the command-line, e.g.:
#
#   $./convert_sqlite.sh /path/to/database.file
#

file=$1
if test -z $1; then
  file=`kreadconfig --file krecipesrc --group Server --key DBFile`
  if test "$?" -ne "0"; then
    echo "Unable to find database file using 'kreadconfig'"
    echo "You need to manually specify where the SQLite 2 database file is, e.g.:"
    echo "  $./convert_sqlite3.sh /path/to/database.file"
    exit 1
  fi
fi

if test -e $file; then

sqlite $file .dump > /dev/null

if test "$?" -ne "0"; then
  echo "Conversion failed"
  exit 1
fi

sqlite $file .dump | sqlite3 $file.new

if test "$?" -ne "0"; then
  echo "Conversion failed"
  exit 1
fi

mv $file $file.sqlite2
if test "$?" -ne "0"; then
  echo "Unable to backup old SQLite 2 file... aborting"
  exit 1
fi

mv $file.new $file
if test "$?" -ne "0"; then
  echo "Created SQLite 3 database, '$file.new', but unable to copy it to $file"
else
  echo "Conversion successful!"
fi

else
  echo "Database file '$file' doesn't exist"
  echo "You need to manually specify where the SQLite 2 database file is, e.g.:"
  echo "  $./convert_sqlite3.sh /path/to/database.file"
fi