2016-06-24 18:42:41 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-06-07 16:30:35 +02:00
|
|
|
if [ $# -ne 1 ] ; then
|
|
|
|
logger 'ckan-connector-fixer: at least one argument must be passed'
|
|
|
|
echo "at leas one argument must be passed, init or update"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
ARG=$1
|
2016-06-24 18:42:41 +02:00
|
|
|
CK_WEB_DIR={{ smartgears_instance_path }}/webapps/ckan-connector/WEB-INF
|
2016-07-22 10:44:57 +02:00
|
|
|
CK_WEB_XML=$CK_WEB_DIR/.web.xml.tpl
|
|
|
|
CK_WEB_XML_TMP=$CK_WEB_DIR/.web.xml.tmp
|
|
|
|
CK_WEB_XML_DEST=$CK_WEB_DIR/web.xml
|
2016-06-24 18:42:41 +02:00
|
|
|
CK_DB_NAME={{ ckan_db_name }}
|
|
|
|
CK_DB_USER={{ ckan_db_user }}
|
|
|
|
CK_DB_HOST={{ psql_db_host }}
|
|
|
|
CK_ADMIN={{ ckan_connector_user }}
|
|
|
|
CK_ADMIN_PWD={{ ckan_connector_user_pwd }}
|
|
|
|
CK_INI=/etc/ckan/default/production.ini
|
|
|
|
API_KEY=
|
|
|
|
CKAN_KEY=
|
|
|
|
SQL_FILE=$( mktemp /tmp/XXXXXX.sql )
|
2017-06-07 16:30:35 +02:00
|
|
|
CKAN_CREATE_USER={{ ckan_init_db_and_solr }}
|
|
|
|
|
|
|
|
trap "logger 'ckan-connector-fixer: trap intercepted, exiting.' ; cleanup" SIGHUP SIGINT SIGTERM
|
|
|
|
|
|
|
|
function cleanup() {
|
|
|
|
rm -f $SQL_FILE
|
|
|
|
rm -f $CK_WEB_XML_TMP
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if [ -f $CK_WEB_DIR/.web.xml.configured ] ; then
|
|
|
|
if [ "$ARG" != "update" ] ; then
|
|
|
|
logger 'ckan-connector-fixer: service already configured, doing nothing.'
|
|
|
|
echo "service already configured. Use 'update' as argument to force the execution"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
2016-06-24 18:42:41 +02:00
|
|
|
|
|
|
|
{% raw %}
|
|
|
|
|
|
|
|
# Set the CKAN python virtualenv
|
|
|
|
. /usr/lib/ckan/default/bin/activate
|
|
|
|
cd /usr/lib/ckan/default/src/ckan
|
2017-06-07 16:30:35 +02:00
|
|
|
|
|
|
|
if [ "$CKAN_CREATE_USER" == "True" ] ; then
|
2016-06-24 18:42:41 +02:00
|
|
|
# Create the admin user
|
2017-06-07 16:30:35 +02:00
|
|
|
paster sysadmin add $CK_ADMIN -c $CK_INI << EOF
|
|
|
|
|
2016-06-24 18:42:41 +02:00
|
|
|
y
|
|
|
|
$CK_ADMIN_PWD
|
|
|
|
$CK_ADMIN_PWD
|
2016-07-21 13:04:32 +02:00
|
|
|
|
2017-06-07 16:30:35 +02:00
|
|
|
|
2016-06-24 18:42:41 +02:00
|
|
|
EOF
|
|
|
|
|
2017-06-07 16:30:35 +02:00
|
|
|
fi
|
|
|
|
|
2016-06-24 18:42:41 +02:00
|
|
|
# Get the admin key
|
|
|
|
echo "update \"user\" set state = 'active' where name = '${CK_ADMIN}';" > $SQL_FILE
|
|
|
|
echo "select apikey from \"user\" where name = '${CK_ADMIN}' and state = 'active';" >> $SQL_FILE
|
|
|
|
API_KEY=$( psql -t -n -q -h $CK_DB_HOST -U $CK_DB_USER -w $CK_DB_NAME -f $SQL_FILE )
|
|
|
|
|
|
|
|
[ $? -ne 0 ] && exit 1
|
|
|
|
|
|
|
|
CKAN_KEY=$( grep ^beaker\.session\.secret $CK_INI | awk '{ print $3 }' )
|
|
|
|
|
|
|
|
[ $? -ne 0 ] && exit 1
|
|
|
|
|
2016-07-22 10:44:57 +02:00
|
|
|
cp $CK_WEB_XML $CK_WEB_XML_TMP
|
2016-06-24 18:42:41 +02:00
|
|
|
# Use the admin key on the connector web.xml
|
2016-07-21 13:04:32 +02:00
|
|
|
if [ ! -z $API_KEY ] ; then
|
2016-07-22 10:44:57 +02:00
|
|
|
sed -i -e "s#@CKAN_API_KEY@#${API_KEY}#g" $CK_WEB_XML_TMP
|
2016-07-21 13:04:32 +02:00
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-06-24 18:42:41 +02:00
|
|
|
|
|
|
|
# Use the ckan key on the connector web.xml
|
2016-07-21 13:04:32 +02:00
|
|
|
if [ ! -z $CKAN_KEY ] ; then
|
2016-07-22 10:44:57 +02:00
|
|
|
sed -i -e "s#@CKAN_SECRET@#${CKAN_KEY}#g" $CK_WEB_XML_TMP
|
2016-07-21 13:04:32 +02:00
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-07-22 10:44:57 +02:00
|
|
|
{% endraw %}
|
2016-06-24 18:42:41 +02:00
|
|
|
|
2016-07-22 10:44:57 +02:00
|
|
|
mv $CK_WEB_XML_TMP $CK_WEB_XML_DEST
|
|
|
|
chown {{ smartgears_user }}:{{ smartgears_user }} $CK_WEB_XML_DEST
|
|
|
|
chmod 440 $CK_WEB_XML_DEST
|
2016-06-24 18:42:41 +02:00
|
|
|
|
|
|
|
touch $CK_WEB_DIR/.web.xml.configured
|
|
|
|
|
2017-06-07 16:30:35 +02:00
|
|
|
trap cleanup EXIT
|
2016-06-24 18:42:41 +02:00
|
|
|
exit 0
|
|
|
|
|
|
|
|
|
|
|
|
|