/usr/bin/samizdat-create-database is in samizdat 0.7.0-1.
This file is owned by root:root, with mode 0o755.
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 | #!/bin/bash
#
# Samizdat database generation script
#
# Copyright (c) 2002-2011 Dmitry Borodaenko <angdraug@debian.org>
#
# This program is free software.
# You can distribute/modify this program under the terms of
# the GNU General Public License version 3 or later.
#
print_usage()
{
echo "Usage: samizdat-create-database site [ driver ]"
echo
echo "Supported drivers:"
echo " pgsql (default)"
echo " sqlite3"
echo
echo "Requires root priviledges to run"
}
if [ -z "$1" ]; then
print_usage
exit 1
fi
SITE="$1"
DRIVER="$2"
[ -z "$DRIVER" ] && DRIVER="pgsql"
PACKAGE=samizdat
SQLDIR=/usr/share/$PACKAGE/database
DATADIR=/var/lib/$PACKAGE
SQL=`cat $SQLDIR/{create,triggers}-${DRIVER}.sql 2>/dev/null`
if [ -r "$SQLDIR/grant-${DRIVER}.sql" ]; then
SQL=$SQL`sed "s/samizdat/$SITE/g" $SQLDIR/grant-${DRIVER}.sql`
fi
case "$DRIVER" in
pgsql)
su -c "echo '' | psql -q '$SITE' 2>/dev/null" - postgres
if [ "$?" = "0" ]; then
echo "Error: database '$SITE' already exists."
exit 3
fi
echo "Creating database and user..."
su -c "createdb --encoding UNICODE '$SITE' && createuser -SDR '$SITE' && createlang plpgsql '$SITE'" - postgres
echo "Generating database schema..."
echo "$SQL" | su -c "psql -q '$SITE' 2>/dev/null" - postgres
echo
echo "Please configure IDENT access as described in install.txt, or provide"
echo "other means for Samizdat to log in to PostrgreSQL database '$SITE'."
echo
echo "Data source: 'DBI:Pg:${SITE}'"
;;
sqlite3)
SQLITE_DIR=$DATADIR/$SITE
SQLITE_FILE=$SQLITE_DIR/${SITE}-sqlite.db
if [ -e "$SQLITE_FILE" ]; then
echo "Error: SQLite3 database file for site '$SITE' already exists."
exit 3
fi
echo "Creating database..."
mkdir -p $SQLITE_DIR
sqlite3 $SQLITE_FILE "$SQL"
echo "Granting write access to the database to group 'www-data'..."
chgrp -R www-data $SQLITE_DIR
chmod 775 $SQLITE_DIR
chmod 664 $SQLITE_FILE
echo
echo "Data source: 'DBI:SQLite3:$SQLITE_FILE'"
echo "User: '$SITE'"
;;
*)
echo "Error: database '$DRIVER' is not supported."
exit 2
;;
esac
echo "Database generation completed."
|