First commit.

This commit is contained in:
frnmst/Franco Masotti 2016-10-23 16:03:33 +02:00
commit 3ea834723d
6 changed files with 310 additions and 0 deletions

18
.SRCINFO Normal file
View File

@ -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

12
.install Normal file
View File

@ -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"
}

44
PKGBUILD Normal file
View File

@ -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}"
}

45
run.pl Normal file
View File

@ -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.

151
run.sh Executable file
View File

@ -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 "$@"

40
swish.service Normal file
View File

@ -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