Apache/2.4.7 (Ubuntu) Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) safemode : OFF MySQL: ON | Perl: ON | cURL: OFF | WGet: ON > / usr / share / dbconfig-common / internal / | server ip : 172.67.156.115 your ip : 172.69.214.234 H O M E |
Filename | /usr/share/dbconfig-common/internal/sqlite |
Size | 4.23 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 27-Apr-2025 10:12 |
Last modified | 01-May-2012 03:18 |
Last accessed | 06-Jul-2025 18:38 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
###
### sqlite bindings for dbconfig-common
###
### Author: Matt Brown <[email protected]>
###
### 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"
dbc_log="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
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
umask 0066
dbc_sqlite_exec_command ".dump" > "$dumpfile"
ret=$?
umask $old_umask
return $ret
}
### sqlite bindings for dbconfig-common
###
### Author: Matt Brown <[email protected]>
###
### 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"
dbc_log="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
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
umask 0066
dbc_sqlite_exec_command ".dump" > "$dumpfile"
ret=$?
umask $old_umask
return $ret
}