summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoel Vilela2016-11-25 21:47:46 -0300
committerManoel Vilela2016-11-25 21:47:46 -0300
commitc536b8543ec045be8d7717c057a732c08ef46524 (patch)
tree319e81d32dac045fd35efa8a85df48f9d4f9c007
downloadaur-c536b8543ec045be8d7717c057a732c08ef46524.tar.gz
Add first version of emacs-openrc
Ported from gentoo using a simplified version without emacs bin wrapper. I need get some vars to put on defaults, like SHELL, HOME and USER. As the service start as root and the final user is not him, I need do some hacking here. Sorry for this shit :( BTW, in some way, this works.
-rw-r--r--.SRCINFO18
-rw-r--r--.gitignore4
-rw-r--r--CHANGELOG2
-rw-r--r--PKGBUILD27
-rwxr-xr-xemacs-daemon.rc66
-rw-r--r--emacs-openrc.install30
6 files changed, 147 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..629e6f5d4518
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,18 @@
+pkgbase = emacs-openrc
+ pkgdesc = Init script for emacs daemon for openrc
+ pkgver = 1.0
+ pkgrel = 1
+ install = emacs-openrc.install
+ changelog = CHANGELOG
+ arch = i686
+ arch = x86_64
+ license = GPL3
+ depends = emacs
+ depends = openrc
+ provides = openrc-emacs
+ conflicts = openrc-emacs
+ replaces = openrc-emacs
+ noextract = emacs-daemon.rc
+
+pkgname = emacs-openrc
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000000..d778e6b9e155
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.tar.xz
+*.tar.gz
+pkg/
+src/
diff --git a/CHANGELOG b/CHANGELOG
new file mode 100644
index 000000000000..a436d522d6ba
--- /dev/null
+++ b/CHANGELOG
@@ -0,0 +1,2 @@
+* v1.0
+ - The first version of emacs daemon openrc script ported from gentoo
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..43d02ccaf037
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,27 @@
+# Maintainer: Manoel Vilela <manoel_vilela@engineer.com>
+
+pkgname="emacs-openrc"
+pkgver="1.0"
+pkgrel=1
+pkgdesc="Init script for emacs daemon for openrc"
+arch=('i686' 'x86_64')
+license=('GPL3')
+groups=()
+depends=("emacs" "openrc")
+makedepends=()
+optdepends=()
+provides=('openrc-emacs')
+conflicts=('openrc-emacs')
+replaces=('openrc-emacs')
+backup=()
+options=()
+install="$pkgname.install"
+changelog="CHANGELOG"
+source=()
+noextract=("emacs-daemon.rc")
+
+package() {
+ # Creating need directories
+ install -dm755 "$pkgdir/etc/init.d"
+ install -Dm755 "emacs-daemon.rc" $pkgdir/etc/init.d/emacs
+}
diff --git a/emacs-daemon.rc b/emacs-daemon.rc
new file mode 100755
index 000000000000..1a72f733daa3
--- /dev/null
+++ b/emacs-daemon.rc
@@ -0,0 +1,66 @@
+#!/usr/bin/openrc-run
+# Copyright 2008-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2 or later
+
+USER=${RC_SVCNAME##*.}
+: ${EMACS:=/usr/bin/emacs}
+: ${EMACS_OPTS:=--daemon}
+: ${EMACS_TIMEOUT:=5}
+SKIP_ARGB_VISUALS=1
+
+description="Start an Emacs server running in the background"
+
+depend() {
+ need localmount
+ after bootmisc dbus
+}
+
+checkconfig() {
+ if [ "${RC_VERSION:-0}" = "0" ]; then
+ eerror "This script cannot be used for baselayout-1."
+ return 1
+ fi
+
+ if [ "${USER}" = "${RC_SVCNAME}" ]; then
+ eerror "You have to create an init script for each user:"
+ eerror "ln -s emacs /etc/init.d/emacs.<user>"
+ return 1
+ fi
+
+ if ! id -u "${USER}" >/dev/null; then
+ eerror "${USER}: No such user"
+ return 1
+ fi
+
+ local has_daemon=$(${EMACS} -batch -q --no-site-file \
+ --eval "(princ (fboundp 'daemonp))")
+ if [ "${has_daemon}" != t ]; then
+ eerror "${EMACS} does not support running as a daemon"
+ return 1
+ fi
+}
+
+
+start() {
+ local HOME
+ checkconfig || return 1
+
+ eval HOME="~${USER}"
+ ebegin "Starting Emacs daemon for user ${USER}"
+ start-stop-daemon --start \
+ --chdir ${HOME} \
+ --user ${USER} \
+ --exec ${EMACS} -- ${EMACS_OPTS}
+
+ eend $?
+}
+
+stop() {
+ ebegin "Stopping Emacs daemon for user ${USER}"
+ start-stop-daemon --stop \
+ --retry "TERM/${EMACS_TIMEOUT}/KILL/5" \
+ --user ${USER} \
+ --exec ${EMACS} -- ${EMACS_OPTS}
+
+ eend $?
+}
diff --git a/emacs-openrc.install b/emacs-openrc.install
new file mode 100644
index 000000000000..886b5b4b53e4
--- /dev/null
+++ b/emacs-openrc.install
@@ -0,0 +1,30 @@
+SERVICE_NAME=emacs
+SERVICE_NAME_USER=emacs.$SUDO_USER
+DEFAULT_CONF_PATH=/etc/conf.d/$SERVICE_NAME_USER
+EMACS_DAEMON_PATH=/etc/init.d/$SERVICE_NAME
+EMACS_DAEMON_USER_PATH=$EMACS_DAEMON_PATH.$SUDO_USER
+VARS_EXPORTED="SHELL\|USER\|HOME\|LANG"
+
+post_install() {
+ sudo ln -v -s -f $EMACS_DAEMON_PATH $EMACS_DAEMON_USER_PATH
+ echo ":: Installed daemon for $SUDO_USER."
+
+ echo ":: Getting useful vars from $SUDO_USER."
+ sudo -u $SUDO_USER env | grep $VARS_EXPORTED | sudo tee $DEFAULT_CONF_PATH
+ echo ":: Wrote default conf on $DEFAULT_CONF_PATH"
+
+ echo ":: Add init script on openrc."
+ sudo rc-update add $SERVICE_NAME_USER
+}
+
+post_upgrade() {
+ post_install
+ echo ":: We got a new version of emacs-openrc!"
+}
+
+post_remove() {
+ echo ":: Remove init script from openrc"
+ sudo rc-update del $SERVICE_NAME_USER
+ echo ":: Remove garbage files"
+ rm -fv $EMACS_DAEMON_USER_PATH $DEFAULT_CONF_PATH
+}