/usr/share/dbconfig-common/internal/sqlite is in dbconfig-common 2.0.9.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | # -*- mode: sh -*-
###
### sqlite bindings for dbconfig-common
###
### Author: Matt Brown <debian@mattb.net.nz>
###
### all variables and functions fall under the namespace "dbc_foo" and
### "_dbc_foo", depending on whether or not they are "external"
###
# get some common functions
. /usr/share/dbconfig-common/internal/common
check_basepath_permissions(){
local line
if dpkg-statoverride --list "$dbc_basepath" >/dev/null; then
line=$(dpkg-statoverride --list "$dbc_basepath")
c_owner=$(echo $line | cut -d' ' -f1,2 | tr ' ' ':')
c_perms=$(echo $line | cut -d' ' -f3)
fi
}
##
## execute a file with sqlite commands
##
dbc_sqlite_exec_file(){
local l_sqlfile l_retval l_dbfile
l_sqlfile=$1
l_dbfile="${dbc_basepath}/${dbc_dbname}"
if [ ! "$l_sqlfile" ]; then
dbc_error="no file supplied to execute"
return 1
fi
l_retval=0
$dbc_sqlite_cmd "$l_dbfile" < "$l_sqlfile" || l_retval=$?
return $l_retval
}
##
## execute a specific sqlite command
##
## note this is done without passing any info on the cmdline,
## including the command itself
##
dbc_sqlite_exec_command(){
local statement l_sqlfile l_retval
statement="$@"
l_retval=0
l_sqlfile=$(dbc_mktemp dbconfig-common_sqlfile.XXXXXX)
cat << EOF > $l_sqlfile
$statement
EOF
dbc_sqlite_exec_file "$l_sqlfile" || l_retval=$?
rm -f "$l_sqlfile"
return $l_retval
}
##
## check for the existance of a specified database
##
_dbc_sqlite_check_database(){
local dbc_dbname l_dbfile
dbc_dbname=$1
l_dbfile="${dbc_basepath}/${dbc_dbname}"
if test -f "$l_dbfile"; then
return 0
else
return 1
fi
}
##
## creates a new sqlite database file
##
##
dbc_sqlite_createdb(){
local ret l_dbfile l_owner l_perms
_dbc_sanity_check dbname $dbc_dbtype || return 1
l_dbfile="${dbc_basepath}/${dbc_dbname}"
# Default to root:root 0640 if the maintainer hasn't hinted otherwise
l_owner="root:root"
l_perms="0640"
if [ -n "$dbc_dbfile_owner" ]; then l_owner="$dbc_dbfile_owner"; fi
if [ -n "$dbc_dbfile_perms" ]; then l_perms="$dbc_dbfile_perms"; fi
dbc_logpart "creating database $dbc_dbname:"
if _dbc_sqlite_check_database "$dbc_dbname"; then
dbc_logline "already exists"
else
ret=0
if [ ! -d "${dbc_basepath}" ]; then
# Create the base directory
mkdir -p "${dbc_basepath}"
fi
# Setup permissions on the base directory to match dbfile
check_basepath_permissions
# Don't set permissions if admin has overriden them
if [ ! -n "$c_owner" ]; then
chown "$l_owner" "$dbc_basepath"
fi
if [ ! -n "$c_perms" ]; then
chmod "$l_perms" "$dbc_basepath"
# Always set execute bits on directories
chmod u+x,g+x "$dbc_basepath"
fi
# Create the database and setup permissions
dbc_sqlite_exec_command ".schema" && \
chown "$l_owner" "$l_dbfile" && \
chmod "$l_perms" "$l_dbfile" || ret=$?
if [ "$ret" = "0" ]; then
dbc_logline "success"
dbc_logpart "verifying database $dbc_dbname exists:"
if ! _dbc_sqlite_check_database "$dbc_dbname"; then
dbc_logline "failed"
dbc_error="Cannot find database after creation"
return 1
else
dbc_logline "success"
fi
else
dbc_logline "failed"
dbc_error="Failed to create database"
return 1
fi
fi
}
##
## drops the sqlite database file by removing it from the disk
##
##
dbc_sqlite_dropdb(){
_dbc_sanity_check dbname || return 1
dbc_logpart "dropping database $dbc_dbname:"
if _dbc_sqlite_check_database "$dbc_dbname"; then
if rm -f "${dbc_basepath}/${dbc_dbname}"; then
dbc_logline "success"
dbc_logpart "verifying database $dbc_dbname was dropped:"
if _dbc_sqlite_check_database "$dbc_dbname"; then
dbc_logline "failed"
dbc_error="Database still exists after rm command"
return 1
else
dbc_logline "success"
fi
if [ "${dbc_basepath}" = "${dbc_default_basepath}" ] ; then
# Make sure we clean up any empty directory as well
# see bug 775226
rmdir --parents --ignore-fail-on-non-empty "${dbc_basepath}"
fi
else
dbc_logline "failed"
dbc_error="Database removal failed"
return 1
fi
else
dbc_logline "database does not exist"
fi
}
##
## basic installation check
##
dbc_sqlite_db_installed(){
which sqlite >/dev/null 2>&1
}
dbc_sqlite3_db_installed(){
which sqlite3 >/dev/null 2>&1
}
##
## dump a sqlite database
##
dbc_sqlite_dump(){
local dumpfile ret old_umask
dumpfile=$1
old_umask=$(umask)
_dbc_sanity_check dbname $dbc_dbtype || return 1
if _dbc_sqlite_check_database "$dbc_dbname"; then
umask 0066
dbc_sqlite_exec_command ".dump" > "$dumpfile"
ret=$?
umask $old_umask
return $ret
else
dbc_logline "database does not exist"
return 0
fi
}
|