Skip to content
Snippets Groups Projects
Commit 1d0b9c5b authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

first commit

parents
No related branches found
No related tags found
No related merge requests found
config.mak
Main author:
Eric Vidal <eric@obarun.org>
Build Instructions
------------------
## Requirements
- GNU make version 3.81 or later
This software will install on any operating system that implements POSIX.1-2008, available at [opengroup](http://pubs.opengroup.org/onlinepubs/9699919799/).
## Standard usage
`./configure && make && sudo make install` will work for most users.
## Customization
You can customize paths via flags given to configure. See `./configure --help` for a list of all available configure options.
## Runtime dependencies
- execline version 2.6.0.2 or later: http://skarnet.org/software/execline/
- s6 version 2.9.1.0 or later: http://skarnet.org/software/s6/
- 66 version 0.4.0.0 or later https://framagit.org/Obarun/66/
- 66-tools version 0.0.4.0 or later https://framagit.org/Obarun/66-tools/
LICENSE 0 → 100644
Copyright (c) 2015-2020 Eric Vidal <eric@obarun.org>
All rights reserved.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Makefile 0 → 100644
#
# This Makefile requires GNU make.
#
# Do not make changes here.
# Use the included .mak files.
#
make_need := 3.81
ifeq "" "$(strip $(filter $(make_need), $(firstword $(sort $(make_need) $(MAKE_VERSION)))))"
fail := $(error Your make ($(MAKE_VERSION)) is too old. You need $(make_need) or newer)
endif
-include config.mak
include package/targets.mak
INSTALL := ./tools/install.sh
install: install-script install-service install-service-module install-service-instance-module install-configure
install-script: $(SCRIPT_TARGET:module/scandir@/configure/%=$(DESTDIR)$(module_directory)/scandir@/configure/%)
install-service: $(SERVICE_TARGET:service/%=$(DESTDIR)$(service_directory)/%)
install-service-module: $(MODULE_TARGET:module/scandir@/service/%=$(DESTDIR)$(module_directory)/scandir@/service/%)
install-service-instance-module: $(MODULE_INSTANCE_TARGET:module/scandir@/service@/%=$(DESTDIR)$(module_directory)/scandir@/service@/%)
install-configure: $(MODULE_CONFIGURE_TARGET:module/scandir@/configure/configure=$(DESTDIR)$(module_directory)/scandir@/configure/configure)
$(DESTDIR)$(module_directory)/scandir@/configure/%: module/scandir@/configure/%
exec $(INSTALL) -D -m 755 $< $@
sed -i -e 's,@BINDIR@,$(bindir),' $@
$(DESTDIR)$(module_directory)/scandir@/configure/configure: module/scandir@/configure/configure
exec $(INSTALL) -D -m 755 $< $@
sed -i -e 's,@BINDIR@,$(bindir),' $@
$(DESTDIR)$(module_directory)/scandir@/service/%: module/scandir@/service/%
exec $(INSTALL) -D -m 644 $< $@
$(DESTDIR)$(module_directory)/scandir@/service@/%: module/scandir@/service@/%
exec $(INSTALL) -D -m 644 $< $@
$(DESTDIR)$(service_directory)/%: service/%
exec $(INSTALL) -D -m 644 $< $@
sed -i -e 's,@VERSION@,$(version),' \
-e "s,@LIVEDIR@,$(livedir)," \
-e "s,@USER_CONF_DIR@,$(service_userconf)," \
-e "s,@LOGGER@,$(LOGGER)," \
-e "s,@USE_ENVIRONMENT@,$(USE_ENVIRONMENT)," \
-e "s,@VERBOSITY_LEVEL@,$(VERBOSITY_LEVEL)," \
-e "s,@NOTIFY@,$(NOTIFY)," $@
version:
@echo $(version)
.PHONY: install version
.DELETE_ON_ERROR:
# Changelog for scandir-66serv
---
# In 0.1.0
- first commit
configure 0 → 100755
#!/bin/sh
. package/info
usage () {
cat <<EOF
Usage: $0 [OPTION]... [TARGET]
Defaults for the options are specified in brackets.
Installation directories:
--prefix=PREFIX main installation prefix [/]
--exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
Fine tuning of the installation directories:
--bindir=BINDIR user executables [EPREFIX/bin]
--datarootdir=DATAROOTDIR read-only architecture-independent data root [PREFIX/share]
--with-system-service=DIR 66 service intallation directory [DATAROOTDIR/$package_macro_dir/service]
--with-system-module=DIR 66 module intallation directory [DATAROOTDIR/$package_macro_dir/module]
--livedir=DIR 66 default live directory [/run/66]
--with-user-service-conf=DIR 66 user service configuration directory [.66/conf]
Fine tunning of scandir configuration:
--LOGGER=BOOLEAN create an associated logger [!yes]
--USE_ENVIRONMENT=BOOLEAN Launch the scandir with a environment [!yes]
--NOTIFY=BOOLEAN use notification [!yes]
--VERBOSITY_LEVEL=BOOLEAN level of verbosity [!3]
Use yes or no with lowercase character to set BOOLEAN values.
Empty value is a commented one and not used at all.
An exclamation mark '!' at the begin of the value unexport the variable
for the environment after the use. This is avoid to poluate the environment
with tempory variables. You need to single-quote the options as
follow:
./configure --NOTIFY='!yes'
EOF
exit 0
}
# Helper functions
# If your system does not have printf, you can comment this, but it is
# generally not a good idea to use echo.
# See http://www.etalabs.net/sh_tricks.html
echo () {
IFS=" "
printf %s\\n "$*"
}
quote () {
tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
$1
EOF
echo "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#" -e "s|\*/|* /|g"
}
fail () {
echo "$*"
exit 1
}
fnmatch () {
eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac"
}
cmdexists () {
type "$1" >/dev/null 2>&1
}
stripdir () {
while eval "fnmatch '*/' \"\${$1}\"" ; do
eval "$1=\${$1%/}"
done
}
testval () {
if test -z ${1}; then
return 0 ;
else
return 1 ;
fi
}
# Actual script
prefix=
exec_prefix='$prefix'
bindir='$exec_prefix/bin'
datarootdir='$prefix/share'
service_directory='$datarootdir/$package_macro_dir/service'
module_directory='$datarootdir/$package_macro_dir/module'
livedir='/run/66'
service_userconf='.66/conf'
LOGGER='!yes'
USE_ENVIRONMENT='!yes'
NOTIFY='!yes'
VERBOSITY_LEVEL='!3'
for arg ; do
case "$arg" in
--help) usage ;;
--prefix=*) prefix=${arg#*=} ;;
--exec-prefix=*) exec_prefix=${arg#*=} ;;
--bindir=*) bindir=${arg#*=} ;;
--datarootdir=*) datarootdir=${arg#*=} ;;
--with-system-service=*) service_directory=${arg#*=} ;;
--with-system-module=*) module_directory=${arg#*=} ;;
--livedir=*) livedir=${arg#*=} ;;
--with-user-service-conf=*) service_userconf=${arg#*=} ;;
--LOGGER=*) LOGGER=${arg#*=} ;;
--USE_ENVIRONMENT=*) USE_ENVIRONMENT=${arg#*=} ;;
--NOTIFY=*) NOTIFY=${arg#*=} ;;
--VERBOSITY_LEVEL=*) VERBOSITY_LEVEL=${arg#*=} ;;
-* ) echo "$0: unknown option $arg" ;;
*=*) ;;
*) target=$arg ;;
esac
done
# Add /usr in the default case
if test -z "$prefix" ; then
if test "$datarootdir" = '$prefix/share'; then
datarootdir=/usr/share
fi
fi
# Expand installation directories
stripdir prefix
for i in exec_prefix bindir datarootdir \
livedir service_directory module_directory ; do
eval tmp=\${$i}
eval $i=$tmp
stripdir $i
done
stripdir datarootdir
for i in service_directory module_directory; do
eval tmp=\${$i}
eval $i=$tmp
stripdir $i
done
for i in LOGGER USE_ENVIRONMENT NOTIFY VERBOSITY_LEVEL; do
eval tmp=\${$i}
if testval $tmp; then
eval $i='${i}=\"\\#${i}=\"'
else
eval $i='$i=$i=$tmp'
fi
done
# Get usable temp filenames
i=0
set -C
while : ; do
i=$(($i+1))
tmpc="./tmp-configure-$$-$PPID-$i.c"
tmpe="./tmp-configure-$$-$PPID-$i.tmp"
2>|/dev/null > "$tmpc" && break
2>|/dev/null > "$tmpe" && break
test "$i" -gt 50 && fail "$0: cannot create temporary files"
done
set +C
trap 'rm -f "$tmpc" "$tmpe"' EXIT ABRT INT QUIT TERM HUP
echo "creating config.mak..."
cmdline=$(quote "$0")
for i ; do cmdline="$cmdline $(quote "$i")" ; done
exec 3>&1 1>config.mak
cat << EOF
# This file was generated by:
# $cmdline
# Any changes made here will be lost if configure is re-run.
version := $version
prefix := $prefix
exec_prefix := $exec_prefix
bindir := $bindir
datarootdir := $datarootdir
service_directory := $service_directory
module_directory := $module_directory
package_macro_dir := $package_macro_dir
livedir := $livedir
service_userconf := $service_userconf
$LOGGER
$USE_ENVIRONMENT
$NOTIFY
$VERBOSITY_LEVEL
EOF
exec 1>&3 3>&-
echo " ... done."
#!@BINDIR@/sh
## 66-yeller variable
export PROG="${MOD_NAME}"
export VERBOSITY="${MOD_VERBOSITY}"
export CLOCK_ENABLED=0
owner="${1}"
home_env=$(homeof "${owner}")
home_env="${home_env}/${MOD_SERVICE_USERCONFDIR}svscan@${owner}"
service_dir="${MOD_MODULE_DIR}/service@"
svscan="${service_dir}/svscan@"
die(){
66-yeller -f "${@}"
exit 111
}
check_empty_var(){
name="${1}" var_value="${2}"
if [ -z "${var_value}" ]; then
die invalid value for variable: "${name}"
fi
}
disable() {
name=${1}
66-yeller %rdisable%n service: "${name}"
sed -i "s:${name}:#${name}:g" "${svscan}" || die "unable to sed ${service_dir}/scandir@"
}
enable() {
name=${1}
66-yeller %benable%n service: "${name}"
touch "${MOD_MODULE_DIR}/service/${name}"
}
absolute_path(){
name="${1}" var="${2}"
if [ "$(66-yeller -i "${var}" | cut -c 1)" != "/" ]; then
die "${name}" must be an absolute path
fi
}
if execl-toc -X -V LIVE_DIRECTORY; then
check_empty_var "LIVE_DIRECTORY" "${LIVE_DIRECTORY}"
absolute_path "LIVE_DIRECTORY" "${LIVE_DIRECTORY}"
66-yeller set live directory to: %b"${LIVE_DIRECTORY}"%n
sed -i "s:@LIVE_DIR@:-l ${LIVE_DIRECTORY}:" "${svscan}" || die "unable to set the live directory to use"
else
66-yeller set live directory to: %b${MOD_LIVE}%n
sed -i "s:@LIVE_DIR@:-l ${MOD_LIVE}:" "${svscan}" || die "unable to set the live directory to use"
fi
if [ "${USE_ENVIRONMENT}" = yes ]; then
enable "setenv@${owner}"
sed -i "s:@USE_ENVIRONMENT@:-e ${home_env}:" "${svscan}" || die "unable to set environment directory to use"
sed -i "s:@PATH_ENVIRONMENT@:${home_env}:g" "${service_dir}/setenv@" || die "unable to set environment directory to use"
else
disable "setenv@@I"
sed -i "s:@USE_ENVIRONMENT@::" "${svscan}" || die "unable to set environment directory to use"
fi
if [ "${LOGGER}" != "yes" ]; then
66-yeller %rdisable%n logger options
sed -i "s:@options:#@options:" "${svscan}" || die "unable to disable log options"
else
66-yeller %benable%n logger options
fi
if [ "${NOTIFY}" != "yes" ]; then
66-yeller %rdisable%n notification
sed -i "s:@NOTIFY@::" "${svscan}" || die "unable to disable notification"
sed -i "s:@notify:#@notify:" "${svscan}" || die "unable to disable notification"
else
66-yeller %benable%n notification
sed -i "s:@NOTIFY@:-d3:" "${svscan}" || die "unable to enable notification"
fi
66-yeller set verbosity level to: %b"${VERBOSITY_LEVEL}"%n
sed -i "s:@VERBOSITY_LEVEL@:-v${VERBOSITY_LEVEL}:" "${svscan}" || die "unable to disable log options"
66-yeller "%bsuccessfully%n configured"
[main]
@type = oneshot
@version = @version@
@description = "Set well-know variables for @I user"
@user = ( root )
@options = ( log )
[start]
@runas = @I
@execute =
(
execl-subuidgid
backtick -n HOME { homeof @I }
importas -u HOME HOME
execl-toc -v3 -d @PATH_ENVIRONMENT@
redirfd -w 1 @PATH_ENVIRONMENT@/svscan@@I
## GENERAL VARIABLES
if { 66-echo HOME=${HOME} }
if { 66-echo LOGNAME=@I }
if { 66-echo USER=@I }
foreground {
importas PATH PATH
66-echo -- PATH=${PATH}
}
foreground {
backtick -D /usr/bin/sh -n shell {
pipeline { getent passwd ${UID} }
cut -d: -f7
}
importas -u shell shell
66-echo -- SHELL=${shell}
}
foreground
{
backtick -n x
{
sh -c "d=0 ; while true ; do \
if [ ! -e "/tmp/.X$d-lock" -o -S "/tmp/.X11-unix/X$d" ]; then \
66-echo -- $d ; \
break ; \
fi ; \
d=$(($d + 1)) ; \
done ;"
}
importas -u x x
66-echo -- DISPLAY=:${x}
}
## DBUS
if { 66-echo -- DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/${UID}/bus }
## XDG variables
if { 66-echo -- XDG_RUNTIME_DIR=/run/user/${UID} }
if { 66-echo -- XDG_CACHE_HOME=${HOME}/.cache }
if { 66-echo -- XDG_CONFIG_HOME=${HOME}/.config }
if { 66-echo -- XDG_DATA_HOME=${HOME}/.local/share }
if { 66-echo -- XDG_DATA_DIRS=${HOME}/.local/share:/usr/local/share:/usr/share }
66-echo -- XDG_SESSION_CLASS=user
)
[main]
@type = longrun
@version = @version@
@description = "Create and start a nested scandir for @I"
@user = ( root )
@options = ( log env )
@depends = ( setenv@@I )
@notify = 3
@timeout-up = 3000
[start]
@runas = @I
@execute =
(
s6-setsid -qb --
umask 022
execl-cmdline -s { 66-scandir ${cmd_args} -cu }
)
[environment]
cmd_args=!@VERBOSITY_LEVEL@ @NOTIFY@ @LIVE_DIR@ @USE_ENVIRONMENT@
package=scandir-66serv
version=0.1.0
package_macro_dir=66
configure 0755
SCRIPT_TARGET :=
SERVICE_TARGET := service/scandir@
MODULE_TARGET := $(shell find module/scandir@/service -type f)
MODULE_INSTANCE_TARGET := $(shell find module/scandir@/service@ -type f)
MODULE_CONFIGURE_TARGET := module/scandir@/configure/configure
[main]
@type = module
@version = @VERSION@
@description = "Create a nested scandir for @I"
@user = ( root )
@options = ( env )
[regex]
@configure="@I"
@files = ( @M=@I )
@infiles = ( ::@version@=@VERSION@ )
[environment]
## Run the scandir at LIVE_DIRECTORY.
## Need to be an absolute path.
## If commented the default is @LIVEDIR@
#LIVE_DIRECTORY=@LIVEDIR@
## Create an associated logger [yes|no]
@LOGGER@
## Launch the scandir with a environment [yes|no].
## The environment directory is: $HOME/@USER_CONF_DIR@/svscan@@I
@USE_ENVIRONMENT@
## Use notification [yes|no]
@NOTIFY@
## Level of verbosity [0-4]
@VERBOSITY_LEVEL@
#!/bin/sh
usage() {
echo "usage: $0 [-D] [-l] [-m mode] src dst" 1>&2
exit 1
}
mkdirp=false
symlink=false
mode=0755
while getopts Dlm: name ; do
case "$name" in
D) mkdirp=true ;;
l) symlink=true ;;
m) mode=$OPTARG ;;
?) usage ;;
esac
done
shift $(($OPTIND - 1))
test "$#" -eq 2 || usage
src=$1
dst=$2
tmp="$dst.tmp.$$"
case "$dst" in
*/) echo "$0: $dst ends in /" 1>&2 ; exit 1 ;;
esac
set -C
set -e
if $mkdirp ; then
umask 022
case "$2" in
*/*) mkdir -p "${dst%/*}" ;;
esac
fi
trap 'rm -f "$tmp"' EXIT INT QUIT TERM HUP
umask 077
if $symlink ; then
ln -s "$src" "$tmp"
else
cat < "$1" > "$tmp"
chmod "$mode" "$tmp"
fi
mv -f "$tmp" "$dst"
if test -d "$dst" ; then
rm -f "$dst/$(basename $tmp)"
if $symlink ; then
mkdir "$tmp"
ln -s "$src" "$tmp/$(basename $dst)"
mv -f "$tmp/$(basename $dst)" "${dst%/*}"
rmdir "$tmp"
else
echo "$0: $dst is a directory" 1>&2
exit 1
fi
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment