summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrnmst/Franco Masotti2016-10-23 16:03:33 +0200
committerfrnmst/Franco Masotti2016-10-23 16:03:33 +0200
commit3ea834723db30a2bbd1d3706b2434a69b3cb19a5 (patch)
tree58c4c366e3ae075cfa50e6df2fdf1e4697d67a7f
downloadaur-3ea834723db30a2bbd1d3706b2434a69b3cb19a5.tar.gz
First commit.
-rw-r--r--.SRCINFO18
-rw-r--r--.install12
-rw-r--r--PKGBUILD44
-rw-r--r--run.pl45
-rwxr-xr-xrun.sh151
-rw-r--r--swish.service40
6 files changed, 310 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 00000000000..2f13de9350f
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,18 @@
+pkgbase = swish
+ pkgdesc = SWI-Prolog for SHaring: a SWI-Prolog web IDE
+ pkgver = r1124.071295b
+ pkgrel = 1
+ url = https://github.com/SWI-Prolog/swish
+ install = .install
+ arch = x86_64
+ license = BSD
+ makedepends = git
+ makedepends = bower
+ makedepends = sed
+ depends = swi-prolog-devel
+ conflicts = swish-cplint
+ source = git+https://github.com/SWI-Prolog/swish#branch=master
+ md5sums = SKIP
+
+pkgname = swish
+
diff --git a/.install b/.install
new file mode 100644
index 00000000000..5e53d53b0b4
--- /dev/null
+++ b/.install
@@ -0,0 +1,12 @@
+post_install() {
+ # Add swish user and group.
+ getent group swish &>/dev/null || groupadd -r swish >/dev/null
+ getent passwd swish &>/dev/null || useradd -m -d /home/swish \
+-r -g swish swish >/dev/null
+
+ chown -R swish:swish /usr/share/swish
+
+ printf "\n\nYou can start and enable \
+swish.service to run the server.\n\n"
+}
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 00000000000..5f9391b760c
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,44 @@
+# Maintainer: Franco Masotti <franco dot masotti at student dot unife dot it>
+# Contributor: Franco Masotti <franco dot masotti at student dot unife dot it>
+pkgname=swish
+pkgver=r1124.071295b
+pkgrel=1
+pkgdesc="SWI-Prolog for SHaring: a SWI-Prolog web IDE"
+arch=('x86_64')
+url="https://github.com/SWI-Prolog/swish"
+license=('BSD')
+depends=('swi-prolog-devel')
+makedepends=('git'
+ 'bower'
+ 'sed')
+conflicts=('swish-cplint')
+install=.install
+source=('git+https://github.com/SWI-Prolog/swish#branch=master')
+md5sums=('SKIP')
+
+build() {
+ cd ${srcdir}/swish
+ bower --allow-root install
+ make src
+ # Patch
+ cp ../../run.pl .
+ cp ../../run.sh .
+}
+
+pkgver () {
+ cd ${srcdir}/swish
+ ( set -o pipefail
+ git describe --long 2>/dev/null | sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
+ printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
+ )
+}
+
+package() {
+ cd ${srcdir}
+ install -d "${pkgdir}"/usr/share/"${pkgname}"
+ install -d "${pkgdir}"/usr/bin
+ cp -r swish/* "${pkgdir}"/usr/share/"${pkgname}"
+ install -D -m644 swish/LICENSE "${pkgdir}"/usr/share/licenses/"${pkgname}"/LICENSE
+ install -D -m644 ../"${pkgname}".service ${pkgdir}/usr/lib/systemd/system/"${pkgname}".service
+ ln -s /usr/share/"${pkgname}"/run.sh "${pkgdir}"/usr/bin/"${pkgname}"
+}
diff --git a/run.pl b/run.pl
new file mode 100644
index 00000000000..990b58d934f
--- /dev/null
+++ b/run.pl
@@ -0,0 +1,45 @@
+/*
+ *
+ * run.pl
+ *
+ * Copyright (C) 2016 frnmst (Franco Masotti) <franco.masotti@student.unife.it>
+ *
+ * This file is part of swish-installer.
+ *
+ * swish-installer is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * swish-installer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with swish-installer. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+/* Patch to run the server in backround. This file should replace the one
+ * provided in the repository.
+ */
+
+:- use_module(server).
+:- use_module(lib/r_swish).
+:- use_module(library(r/r_sandbox)).
+
+% Using `localhost:3050`, we only bind to localhost interface!
+% Use plain `3050` (or any port number you like) to make the server
+% accessible from all network interfaces.
+
+%:- initialization server(localhost:3050).
+:- initialization main.
+
+main:-
+ server(3050),
+ wait.
+
+wait:-
+ thread_get_message(_),
+ halt.
diff --git a/run.sh b/run.sh
new file mode 100755
index 00000000000..a4721e3bc48
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,151 @@
+#!/usr/bin/env sh
+
+#
+# run.sh
+#
+# Copyright (C) 2016 frnmst (Franco Masotti) <franco.masotti@student.unife.it>
+#
+# This file is part of swish-installer.
+#
+# swish-installer is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# swish-installer is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with swish-installer. If not, see <http://www.gnu.org/licenses/>.
+#
+#
+
+# This is the file called from the /usr/bin/swish symlink
+
+pkg_dir="/usr/share/swish"
+pid_file="/run/swish/swish.pid"
+user="swish"
+group="swish"
+
+help()
+{
+ cat<<-EOF
+swish [OPTION]
+SWI-Prolog for SHaring: a SWI-Prolog web IDE integrated with the cplint suite
+
+Only a single option is permitted.
+ -h print this help
+ -k kill swish-cplint
+ -s start swish-cplint
+
+Exit status:
+ 0 if OK,
+ 1 some error occurred.
+
+Full documentation at: <https://https://github.com/SWI-Prolog/swish>
+EOF
+}
+
+killd()
+{
+ # kill action only if process exists.
+ if [ -f "$pid_file" ]; then
+ pid=$(cat "$pid_file")
+ ps -q $pid > /dev/null
+ if [ $? -eq 0 ]; then
+ kill -s TERM $pid
+ fi
+ fi
+}
+
+startd()
+{
+ local pid=""
+
+ {
+ ( exec swipl --quiet -f "$pkg_dir"/run.pl ) &
+ pid="$!"
+ } 1>/dev/null 2>/dev/null
+
+ write_pid_file "$pid"
+}
+
+#
+# shared_functions.sh
+#
+# Copyright (C) 2016 frnmst (Franco Masotti) <franco.masotti@student.unife.it>
+#
+# This file is part of swish-installer.
+#
+# swish-installer is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# swish-installer is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with swish-installer. If not, see <http://www.gnu.org/licenses/>.
+#
+#
+
+# This file is used by the various run.sh.
+
+check_running_user_and_group()
+{
+ if [ "$(id -un)" = "$user" ] && [ "$(id -gn)" = "$group" ]; then
+ :
+ else
+ printf "User must be "$user"\n"
+ printf "Group must be "$group"\n"
+ return 1
+ fi
+}
+
+write_pid_file()
+{
+ local pid="$1"
+
+ if [ -n "$pid" ]; then
+ printf "Server running with pid $pid\n"
+ printf "$pid\n" > "$pid_file"
+ else
+ printf "Server error\n"
+ return 1
+ fi
+}
+
+killd()
+{
+ # kill action only if process exists.
+ if [ -f "$pid_file" ]; then
+ pid=$(cat "$pid_file")
+ ps -q $pid > /dev/null
+ if [ $? -eq 0 ]; then
+ kill -s TERM $pid
+ fi
+ fi
+}
+
+option_parser()
+{
+ getopts ":hks" opt "$@"
+ case "$opt" in
+ h) help ;;
+ k) killd ;;
+ s) startd ;;
+ ?) help; return 1 ;;
+ esac
+}
+
+main()
+{
+ check_running_user_and_group && option_parser "$@"
+}
+
+main "$@"
diff --git a/swish.service b/swish.service
new file mode 100644
index 00000000000..c1505987037
--- /dev/null
+++ b/swish.service
@@ -0,0 +1,40 @@
+#
+# swish.service
+#
+# Copyright (C) 2016 frnmst (Franco Masotti) <franco.masotti@student.unife.it>
+#
+# This file is part of swish-installer.
+#
+# swish-installer is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# swish-installer is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with swish-installer. If not, see <http://www.gnu.org/licenses/>.
+#
+#
+
+# To be placed in /usr/lib/systemd/system/swish.service
+
+[Unit]
+Description=SWISH
+Documentation=https://github.com/SWI-Prolog/swish
+
+[Service]
+ExecStart=/usr/bin/swish -s
+ExecStop=/usr/bin/swish -k
+Type=forking
+PIDFile=/run/swish/swish.pid
+User=swish
+Group=swish
+RuntimeDirectory=swish
+
+[Install]
+WantedBy=default.target
+