diff options
Diffstat (limited to 'libre/parabolaweb-utils')
-rw-r--r-- | libre/parabolaweb-utils/PKGBUILD | 55 | ||||
-rw-r--r-- | libre/parabolaweb-utils/helper.sh | 39 | ||||
-rw-r--r-- | libre/parabolaweb-utils/parabolaweb-download | 47 | ||||
-rw-r--r-- | libre/parabolaweb-utils/parabolaweb-fcgi | 12 | ||||
-rw-r--r-- | libre/parabolaweb-utils/parabolaweb-update | 80 | ||||
-rw-r--r-- | libre/parabolaweb-utils/parabolaweb.conf | 4 | ||||
-rw-r--r-- | libre/parabolaweb-utils/parabolaweb.rc | 44 | ||||
-rw-r--r-- | libre/parabolaweb-utils/parabolaweb.service | 13 |
8 files changed, 294 insertions, 0 deletions
diff --git a/libre/parabolaweb-utils/PKGBUILD b/libre/parabolaweb-utils/PKGBUILD new file mode 100644 index 000000000..e0b70ba1a --- /dev/null +++ b/libre/parabolaweb-utils/PKGBUILD @@ -0,0 +1,55 @@ +# Maintainer: Luke Shumaker <lukeshu@sbcglobal.net> + +. helper.sh +# provides: +# _get_pkgver +# _get_depends +# _get_depends_nover (no version requirements) + +pkgname=parabolaweb-utils +pkgver=`_get_pkgver` +pkgrel=5 +pkgdesc="Utils for the Parabola website" +arch=('any') +url="https://projects.parabolagnulinux.org/parabolaweb.git/" +license=('GPL2') +depends=( + 'python2' # duh + 'python2-flup' # for fcgi + 'postgresql' # for database + 'git' # used in parabolaweb-update + 'libretools' # used in parabolaweb-update + `_get_depends`) +backup=('etc/conf.d/parabolaweb') + +export pkgver + +source=(git://parabolagnulinux.org/parabolaweb.git + parabolaweb-download + parabolaweb-update + parabolaweb-fcgi + parabolaweb.rc + parabolaweb.service + parabolaweb.conf) + +build() { + : +} + +package() { + cd "${srcdir}" + install -Dm755 parabolaweb-download "${pkgdir}/usr/sbin/parabolaweb-download" + install -Dm755 parabolaweb-update "${pkgdir}/usr/sbin/parabolaweb-update" + install -Dm755 parabolaweb-fcgi "${pkgdir}/usr/sbin/parabolaweb-fcgi" + install -Dm755 parabolaweb.rc "${pkgdir}/etc/rc.d/parabolaweb" + install -Dm644 parabolaweb.service "${pkgdir}/usr/lib/systemd/system/parabolaweb.service" + install -Dm644 parabolaweb.conf "${pkgdir}/etc/conf.d/parabolaweb" +} + +md5sums=('SKIP' + '01bed679a4fd768e720bfd0f3c7d6694' + 'a73063b14746720b77fdbab851f5c161' + 'd5294495f42df29d29519ebd0a8f6093' + 'cc15e153f99fba82e7bb032896f655c2' + 'a468016a7155b5da46521dcfc6428384' + '9b565ef07e44d395bf7a0e484e3d19d1') diff --git a/libre/parabolaweb-utils/helper.sh b/libre/parabolaweb-utils/helper.sh new file mode 100644 index 000000000..5ce4182b3 --- /dev/null +++ b/libre/parabolaweb-utils/helper.sh @@ -0,0 +1,39 @@ +_mksource() { + if [[ -z _DO_NOT_RUN_MKSOURCE ]]; then + _DO_NOT_RUN_MKSOURCE=true makepkg -o + fi +} + +_get_pkgver() { + if [[ -n $pkgver ]] && [[ $pkgver != 0.bogus ]]; then + echo $pkgver + else + _mksource 1>&2 + if [[ -f "${srcdir:-src}/parabolaweb/requirements_prod.txt" ]]; then + pushd "${srcdir:-src}/parabolaweb" >/dev/null + # get the date requirements_prod.txt was last modified + gitdate="$(git log -n1 --date=iso --format=format:'%cd' ./requirements_prod.txt)" + date -u +%Y%m%d.%H%M -d "$gitdate" + popd >/dev/null + else + echo 0.bogus + fi + fi +} + +_get_depends() { + _mksource 1>&2 + if [[ -f "${srcdir:-src}/parabolaweb/requirements_prod.txt" ]]; then + pushd "${srcdir:-src}" >/dev/null + python2_packages='markdown|psycopg2|pyinotify|pytz|south' + < parabolaweb/requirements_prod.txt sed -r \ + -e 's/.*/\L&/' -e 's/==/=/' \ + -e 's/^python-memcached/python2-memcached/' \ + -e "s/^(${python2_packages})/python2-&/" + popd >/dev/null + fi +} + +_get_depends_nover() { + _get_depends | sed 's/[<>=].*//' +} diff --git a/libre/parabolaweb-utils/parabolaweb-download b/libre/parabolaweb-utils/parabolaweb-download new file mode 100644 index 000000000..823a18811 --- /dev/null +++ b/libre/parabolaweb-utils/parabolaweb-download @@ -0,0 +1,47 @@ +#!/bin/bash + +. /etc/conf.d/parabolaweb +. /usr/bin/libremessages + +dir=$WEBDIR +repo=git://parabolagnulinux.org/parabolaweb.git +ref=master + +cd_safe() { + if ! cd "$1"; then + error "$(gettext "Failed to change to directory %s")" "$1" + plain "$(gettext "Aborting...")" + exit 1 + fi +} + +download_git() { + if [[ ! -d "$dir/.git" ]] ; then + msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "git" + if ! git clone "$repo" "$dir"; then + error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "git" + plain "$(gettext "Aborting...")" + exit 1 + fi + else + cd_safe "$dir" + # Make sure we are fetching the right repo + # if [[ "$repo" != "$(git config --get remote.origin.url)" ]] ; then + # error "$(gettext "%s is not a clone of %s")" "$dir" "$repo" + # plain "$(gettext "Aborting...")" + # exit 1 + # fi + msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "git" + if ! git pull origin "$ref"; then + # only warn on failure to allow offline builds + warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "git" + fi + fi +} + +main() { + [[ -d "${dir%/*}" ]] || mkdir -p "${dir%/*}" + download_git +} + +main "$@" diff --git a/libre/parabolaweb-utils/parabolaweb-fcgi b/libre/parabolaweb-utils/parabolaweb-fcgi new file mode 100644 index 000000000..e42aec3cd --- /dev/null +++ b/libre/parabolaweb-utils/parabolaweb-fcgi @@ -0,0 +1,12 @@ +#!/bin/sh +set -e + +. /etc/conf.d/parabolaweb + +[[ -e ${WEBDIR}/manage.py ]] + +sudo -u "${WEBUSER:-$USER}" python2 "${WEBDIR}/manage.py" runfcgi \ + host=${HOST} \ + port=${PORT} \ + --settings=settings \ + "$@" diff --git a/libre/parabolaweb-utils/parabolaweb-update b/libre/parabolaweb-utils/parabolaweb-update new file mode 100644 index 000000000..45e17c4f2 --- /dev/null +++ b/libre/parabolaweb-utils/parabolaweb-update @@ -0,0 +1,80 @@ +#!/bin/bash +set -e + +. /etc/conf.d/parabolaweb +. /usr/bin/libremessages + +find_makefiles() { + pushd "$WEBDIR" > /dev/null + echo ./sitestatic + find . -name static -type d | while read dir; do + if [[ -e "$WEBDIR/$dir/Makefile" ]]; then + printf '%s\n' "$dir" + fi + done +} + +clean() { + msg "Purging old .pyc files...." + cd "$WEBDIR" + find . -name '*.pyc' -delete + for dir in `find_makefiles`; do + make -C "$WEBDIR/$dir" clean + done +} + +configure() { + msg "Checking configuration...." + cd "$WEBDIR" + if [[ ! -f local_settings.py ]]; then + msg2 "Configuration file missing, opening editor..." + cp local_settings.py.example local_settings.tmp.$$.py + if "$EDITOR" local_settings.tmp.$$.py; then + mv local_settings.tmp.$$.py local_settings.py + else + rm local_settings.tmp.$$.py + msg "Failed to configure, exiting" + exit 1 + fi + msg2 "Creating database...." + ./manage.py syncdb + else + msg2 "Current configuration checks out" + fi +} + +update-database() { + msg "Updating database...." + cd "$WEBDIR" + msg2 "Running migrations...." + ./manage.py migrate + msg2 "Loading fixtures...." + ./manage.py loaddata */fixtures/*.json +} + +update-filesystem() { + msg "Updating filesystem..." + for dir in `find_makefiles`; do + msg2 "Updating $dir with GNU Make..." + make -C "$WEBDIR/$dir" + done + cd "$WEBDIR" + msg2 "Collecting static files..." + echo yes | ./manage.py collectstatic -l +} + +main() { + if [[ -z "$EDITOR" ]]; then + error 'Please set the $EDITOR variable' + exit 1 + fi + + parabolaweb-download + clean + configure + clean + update-database + update-filesystem +} + +main "$@" diff --git a/libre/parabolaweb-utils/parabolaweb.conf b/libre/parabolaweb-utils/parabolaweb.conf new file mode 100644 index 000000000..467e62e2c --- /dev/null +++ b/libre/parabolaweb-utils/parabolaweb.conf @@ -0,0 +1,4 @@ +HOST=127.0.0.1 +PORT=8090 # 80 is nginx +WEBDIR=/srv/http/web +WEBUSER=nobody diff --git a/libre/parabolaweb-utils/parabolaweb.rc b/libre/parabolaweb-utils/parabolaweb.rc new file mode 100644 index 000000000..5e310b01d --- /dev/null +++ b/libre/parabolaweb-utils/parabolaweb.rc @@ -0,0 +1,44 @@ +#!/bin/bash + +. /etc/rc.conf +. /etc/rc.d/functions + +PIDFILE=/run/web/parabolaweb.pid + +case $1 in +start) + stat_busy "Starting ParabolaWeb" + install -dm777 ${PIDFILE%/*} + if parabolaweb-fcgi pidfile=${PIDFILE}; then + add_daemon parabolaweb + stat_done + exit 0 + else + stat_fail + exit 1 + fi + ;; + +stop) + stat_busy "Stopping ParabolaWeb" + if [[ -f ${PIDFILE} ]]; then + pid=$(cat ${PIDFILE}) + kill ${pid} + rm_daemon parabolaweb + stat_done + else + stat_fail + exit 1 + fi + ;; + +restart) + $0 stop + $0 start + ;; + +*) + echo "Usage: $0 {start|stop|restart}" >&2 + exit 1 + +esac diff --git a/libre/parabolaweb-utils/parabolaweb.service b/libre/parabolaweb-utils/parabolaweb.service new file mode 100644 index 000000000..a59d58512 --- /dev/null +++ b/libre/parabolaweb-utils/parabolaweb.service @@ -0,0 +1,13 @@ +[Unit] +Requires=postgresql.service +After=postgresql.service +Description=ParabolaWeb + +[Service] +Type=forking +PIDFile=/run/web/parabolaweb.pid +ExecStartPre=/usr/bin/install -dm777 /run/web +ExecStart=/usr/sbin/parabolaweb-fcgi pidfile=/run/web/parabolaweb.pid + +[Install] +WantedBy=multi-user.target |