summaryrefslogtreecommitdiff
path: root/rvs/wrapper
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2015-06-29 00:43:52 -0600
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-06-29 00:43:52 -0600
commit9beb9331c055cf30e114d99810b8837ce5c7b182 (patch)
tree90e8d916c272b242f1dd74000e57fbbdfd625215 /rvs/wrapper
parent206e003ca6f5b2500976f04a0dbb0b8a167fb3bf (diff)
Start re-jiggering RVS.HEADmaster
Diffstat (limited to 'rvs/wrapper')
-rw-r--r--rvs/wrapper/.gitignore2
-rw-r--r--rvs/wrapper/Makefile32
-rw-r--r--rvs/wrapper/Makefile.in90
-rw-r--r--rvs/wrapper/inner.sh145
-rw-r--r--rvs/wrapper/main.mk.in66
-rw-r--r--rvs/wrapper/outer.c63
-rw-r--r--rvs/wrapper/runcom.mk.in12
-rw-r--r--rvs/wrapper/rvs.sh165
8 files changed, 242 insertions, 333 deletions
diff --git a/rvs/wrapper/.gitignore b/rvs/wrapper/.gitignore
new file mode 100644
index 0000000..6141a28
--- /dev/null
+++ b/rvs/wrapper/.gitignore
@@ -0,0 +1,2 @@
+/outer
+/inner \ No newline at end of file
diff --git a/rvs/wrapper/Makefile b/rvs/wrapper/Makefile
new file mode 100644
index 0000000..f316cc0
--- /dev/null
+++ b/rvs/wrapper/Makefile
@@ -0,0 +1,32 @@
+#!/usr/bin/make -f
+# Copyright (C) 2009, 2015 Luke Shumaker
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+include $(dir $(lastword $(MAKEFILE_LIST)))/../config.mk
+include $(topsrcdir)/common.top.mk
+
+src_files += Makefile outer.c inner.sh
+obj_files += outer inner
+install_files += $(bindir)/$(PACKAGE) $(pkglibexecdir)/$(PACKAGE)
+
+$(objdir)/outer.o: $(topobjdir)/config.h
+$(objdir)/inner: $(topobjdir)/config.sh
+
+$(DESTDIR)$(bindir)/$(PACKAGE) : $(objdir)/outer | $(DESTDIR)$(bindir)
+ $(INSTALL_PROGRAM) $< $@
+$(DESTDIR)$(pkglibexecdir)/$(PACKAGE) : $(objdir)/inner | $(DESTDIR)$(bindir)
+ $(INSTALL_PROGRAM) $< $@
+
+include $(topsrcdir)/common.bottom.mk
diff --git a/rvs/wrapper/Makefile.in b/rvs/wrapper/Makefile.in
deleted file mode 100644
index cfe9772..0000000
--- a/rvs/wrapper/Makefile.in
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/make -f
-#name = Luke's Makefile
-#ver = 1.0
-# Copyright (C) 2009 Luke Shumaker
-#
-# This program 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 2 of the
-# License, or (at your option) any later version.
-#
-# This program 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 this program; see the file COPYING.
-# If not, see <http://www.gnu.org/licenses>.
-
-# Directories ########################################################
-DESTDIR = @DESTDIR@
-prefix = @prefix@
-exec_prefix = @exec_prefix@
-bindir = @bindir@
-sbindir = @sbindir@
-libexecdir = @libexecdir@
-dirs = $(DESTDIR) $(prefix) $(exec_prefix) $(bindir) $(sbindir) $(libexecdir)
-srcdir = @srcdir@
-VPATH = $(srcdir)
-
-# Programs ###########################################################
-SHELL = /bin/sh
-CC = gcc
-INSTALL = install
-INSTALL_PROGRAM = $(INSTALL)
-INSTALL_DATA = $(INSTALL) -m 644
-MKDIR = $(INSTALL) -d #mkdir -p
-RM = rm -f
-SED = sed
-
-include main.mk
-
-# dist ###############################################################
-d = $(name)-$(ver)
-.PHONY : dist
-dist : $(d).tar.gz
-
-$(d).tar.gz : $(d) $(addprefix $(d)/,$(filelist))
- tar -czf $@ $<
-
-$(d) :
- $(INSTALL) -m 777 -d $@
-
-$(d)/% : $(srcdir)/% $(d)
- $(INSTALL) -m 777 -d $(dir $@)
- cp $< $@
-
-# implicit rules #####################################################
-$(addprefix $(DESTDIR),$(dirs)) :
- $(MKDIR) $@
-
-% : %.sh
- $(SED) 's/@VER@/$(ver)/g' < $< > $@
-
-$(DESTDIR)$(bindir)/% : % $(DESTDIR)$(bindir)
- $(INSTALL_PROGRAM) $< $@
-
-.PHONY : dist Makefiles
-
-csources = $(filter %.c,$(filelist))
-Makefiles : $(shell find '$(srcdir)' -type f -name Makefile.in) \
- $(shell find '$(srcdir)' -type f -name Makefile.in) \
- $(csources:.c=.d)
-
-%Makefile %.mk : $(srcdir)/configure
- $< @CONFIG@
-
-# This is taken straight from the GNU `make' manual.
-# That makes it GFDL, which is incompatible with the GPL
-# I claim `fair-use'
-%.d: %.c
- @set -e; rm -f $@; \
- $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
- sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
- rm -f $@.$$$$
-
-ifneq ($(shell ls -d $(csources:.c=.d) 2>/dev/null),)
- include $(csources:.c=.d)
-endif
-
diff --git a/rvs/wrapper/inner.sh b/rvs/wrapper/inner.sh
new file mode 100644
index 0000000..b1dc718
--- /dev/null
+++ b/rvs/wrapper/inner.sh
@@ -0,0 +1,145 @@
+#!/usr/bin/env bash
+# rvs inner.sh - The main RVS program
+# Copyright (C) 2009-2010, 2015 Luke Shumaker
+#
+# This file is part of rvs.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+set -u
+
+m4_include(config.sh)
+
+declare -r varname_REPO="${PACKAGE^^}_REPO"
+declare -r varname_EXEC_PATH="${PACKAGE^^}_EXEC_PATH"
+
+declare -r program_name="$1"; shift
+
+
+
+_() {
+ if type gettext &>/dev/null; then
+ TEXTDOMAINDIR=$localedir gettext "$pkgtextdomain" "$1";
+ else
+ echo "$1";
+ fi
+}
+
+sighandler_exit() {
+ local signal=$1; shift
+ echo
+ error 0 "$@"
+ trap -- "$signal"
+ kill -"$signal" "$$"
+}
+
+install_sighandlers() {
+ set -E
+ for signal in TERM HUP QUIT; do
+ trap "signalhandler_exit $signal '%s signal cought. Exiting...'" $signal
+ done
+ trap 'signalhandler_exit INT "Aborted by user. Exiting..."' INT
+ trap 'kill -USR1 "$$"' ERR
+}
+
+# Like GLibC's error(3), but call gettext on the format string
+error() {
+ >&2 printf "%s: $(_ "$2")\n" "$RVS" "${@:3}"
+ [[ $1 -eq 0 ]] || exit $1
+}
+
+_runcmd() {
+ [[ $# -ge 1 ]] || error 1 'Usage: %s <command> [<args>]' "$program_name"
+ local cmd=$1
+
+ local exec_path="${!varname_EXEC_PATH:-$pkglibexecdir}"
+
+ if [ ! -e "$exec_path/$cmd" ] || [ "$cmd" = "${PACKAGE}" ]; then
+ error 127 '%s: Not a %s command' "$cmd" "$PACKAGE"
+ else
+ trap '[ -z "${TMPDIR:-}" ] || rm -rf -- "$TMPDIR"' EXIT
+ export TMPDIR="$(mktemp -dt "${PACKAGE}.XXXXXXXXXX")"
+
+ repo="$(_repo)"
+ export "$varname_REPO=$repo"
+
+ set -o pipefail
+
+ if [ -f "$exec_path/$cmd" ]; then
+ "$exec_path/$cmd" "$@" | tee -- "$TMPDIR/$cmd"
+ elif [ -d "$exec_path/$cmd" ]; then
+ mkdir -p -- "$TMPDIR/$cmd"
+ local file
+ for file in "$exec_path/$command"/*; do
+ "$file" "$@" | tee -- "$TMPDIR/$command/${file##*/}" ||
+ error 127 'Aborting: error encountered while running: %s' "$file"
+ done
+ else
+ error 127 '%s: Could not execute' "$exec_path/$cmd"
+ fi
+ fi
+}
+
+_repo() {
+ [[ $# -ne 0 ]] || error 1 'Usage: %s repo' "$program_name"
+ if [ -z "${!varname_REPO:-}" ]; then # we aren't getting a value from then env
+ local repo=".${PACKAGE,,}"
+
+ # [------can ascend-----] && ! [-not found repo--]
+ while [ "$PWD" != "$OLDPWD" ] && ! [ -d "$PWD/$repo" ]; do
+ cd ..
+ done
+
+ if [ -d "$PWD/$repo" ]; then
+ # we found a repository
+ printf '%s\n' "$PWD/$repo"
+ else
+ # we didn't find a repository
+ error 128 "No %s repository found" "$PACKAGE"
+ fi
+ else
+ printf '%s\n' "${!varname_REPO}"
+ fi
+}
+
+_init() {
+ [[ $# -gt 1 ]] || error 1 'Usage: %s init [directory]' "$program_name"
+ local dir="${1:-$PWD}"
+ mkdir -p -- "$dir"
+ cd "$dir"
+ repo="$(_repo 2> /dev/null)" || true
+ if [ -n "${repo:-}" ]; then
+ _error 129 "Repository already exists at \`%s'" "$repo"
+ fi
+ export "$varname_REPO=$PWD/.${PACKAGE,,}"
+ mkdir "${!varname_REPO}"
+ _runcmd init "$dir"
+}
+
+main() {
+ install_sighandlers
+ [[ $# -ge 1 ]] || error 'No command specified';;
+ export "${PACKAGE^^}=$program_name"
+
+ local cmd=$1; shift
+ case "$cmd" in
+ repo) _repo "$@";;
+ init) _init "$@";;
+ *) _runcmd "$cmd" "$@";;
+ esac
+}
+
+main "$@"
+
+# Copy/Paste Virus 1.3c Please copy and paste this text anywhere. Track
+# its progress by searching for this MD5#f7eac285ebfe21c4587bfebb9582f90d
diff --git a/rvs/wrapper/main.mk.in b/rvs/wrapper/main.mk.in
deleted file mode 100644
index 0ba00d7..0000000
--- a/rvs/wrapper/main.mk.in
+++ /dev/null
@@ -1,66 +0,0 @@
-#!/usr/bin/make -f
-name = @name@
-ver = 0.9
-# Copyright (C) 2009 Luke Shumaker
-#
-# This program 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 2 of the
-# License, or (at your option) any later version.
-#
-# This program 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 this program; see the file COPYING.
-# If not, see <http://www.gnu.org/licenses>.
-
-sysconfdir = @sysconfdir@
-BINDIR = @BINDIR@
-TMPDIR = @TMPDIR@
-LIBDIR = @LIBDIR@
-ETCDIR = @ETCDIR@
-dirs += $(sysconfdir) $(BINDIR) $(TMPDIR) $(LIBDIR) $(ETCDIR)
-
-rvs = @rvs@
-RVS = @RVS@
-
-# phony targets ####################################################
-.PHONY : all
-all : Makefiles rvs
-filelist=$(patsubst $(srcdir)/%,%,$(shell find $(srcdir)/* -type f))
-
-# most everything ##################################################
-
-# the installed wrapper
-$(RVS) : rvs $(dir $(RVS))
- $(INSTALL_PROGRAM) $< $@
-
-# build the wrapper
-b := @
-rvs : rvs.sh
- $(INSTALL_PROGRAM) $< $@
- $(SED) -i \
- -e 's/$bSHELL@/$(subst /,\/,$(SHELL))/g' \
- -e 's/$bname@/$(subst /,\/,$(rvs))/g' \
- -e 's/$bBINDIR@/$(subst /,\/,$(BINDIR))/' \
- -e 's/$bTMPDIR@/$(subst /,\/,$(TMPDIR))/' \
- -e 's/$bLIBDIR@/$(subst /,\/,$(LIBDIR))/' \
- -e 's/$bETCDIR@/$(subst /,\/,$(ETCDIR))/' \
- $@
-
-# standard targes ####################################################
-.PHONY : install uninstall clean distclean
-install : $(RVS)
-
-uninstall :
- $(RM) $(RVS)
-
-clean :
-
-distclean : clean
- $(RM) rvs
- $(RM) Makefile *.mk
-
diff --git a/rvs/wrapper/outer.c b/rvs/wrapper/outer.c
new file mode 100644
index 0000000..4bc2d2f
--- /dev/null
+++ b/rvs/wrapper/outer.c
@@ -0,0 +1,63 @@
+/* RVS outer.c - A wrapper for $(bindir) to call the main RVS program
+ * Copyright (C) 2015 Luke Shumaker
+ *
+ * This file is part of rvs.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#include <errno.h> /* for errno */
+#include <error.h> /* for error(3) */
+#include <libintl.h> /* for dgettext(3) */
+#include <locale.h> /* for bindtextdomain(3) and textdomain(3) */
+#include <stdio.h> /* for asprintf(3) */
+#include <stdlib.h> /* for getenv(3), calloc(3) */
+#include <string.h> /* for mempcy(3) */
+#include <unistd.h> /* for execv(3) */
+
+#include "config.h"
+#define _ gettext
+
+#define EXIT_FAILURE_OOM 126
+#define EXIT_FAILURE_EXEC 127
+
+int
+main(int argc, char *argv[]) {
+ bindtextdomain(pkgtextdomain, localedir);
+ textdomain(pkgtextdomain);
+
+ unsetenv("ENV");
+ unsetenv("BASH_ENV");
+
+ const char *varname = PACKAGE_UPPER "_EXEC_PATH";
+
+ char *exec_path = getenv(varname);
+ if (!exec_path)
+ exec_path = pkglibexecdir;
+
+ char *exec_file = NULL;
+ if (asprintf(&exec_file, "%s/" PACKAGE, exec_path) < 0)
+ error(EXIT_FAILURE_OOM, errno,
+ _("Could not allocate memory for string"));
+
+ char **args = calloc(argc+2, sizeof(char*));
+ if (!args)
+ error(EXIT_FAILURE_OOM, errno,
+ _("Could not allocate cleared memory"));
+ args[0] = exec_file;
+ memcpy(&args[1], argv, sizeof(char*) * argc);
+
+ execv(exec_file, args);
+ error(EXIT_FAILURE_EXEC, errno, _("Could not execute: %s"), exec_file);
+ return EXIT_FAILURE_EXEC;
+}
diff --git a/rvs/wrapper/runcom.mk.in b/rvs/wrapper/runcom.mk.in
deleted file mode 100644
index 55782f0..0000000
--- a/rvs/wrapper/runcom.mk.in
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/make -f
-
-FIND = $(patsubst $(1)/%,%,$(wildcard $(2)/*))
-
-COMMANDS = $(call FIND,$(BINDIR),$(BINDIR))
-$(COMMANDS): % : $(call FIND,$(BINDIR),$(BINDIR)/%)
-
-% ::
- "$(BINDIR)/$@" $(ARGS)
-
-include $(wildcard $(DEPDIR)/*)
-
diff --git a/rvs/wrapper/rvs.sh b/rvs/wrapper/rvs.sh
deleted file mode 100644
index 19a8188..0000000
--- a/rvs/wrapper/rvs.sh
+++ /dev/null
@@ -1,165 +0,0 @@
-#!/bin/sh
-name='@name@'
-ver='0.9'
-# Copyright (C) 2009-2010 Luke Shumaker
-#
-# This file is part of rvs.
-#
-# rvs 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 2, or (at your option) any later version.
-#
-# rvs 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 this program; see the file COPYING.
-# If not, see <http://www.gnu.org/licenses>.
-
-export RVS="$0" #RVS='@RVS@'
- BINDIR='@BINDIR@'
- DEPDIR='@DEPDIR@'
- baseTMPDIR='@TMPDIR@'
-export LIBDIR='@LIBDIR@'
-export ETCDIR='@ETCDIR@'
-
-################################################################################
-# Internal use #
-################################################################################
-
-# General ############################################################
-
-_error() {
- echo "$RVS: $1" >> /dev/stderr
- exit ${2-1}
-}
-
-# Repository #########################################################
-
-_repo() {
- if [ -z "$REPO" ]; then # we aren't getting a value from then env
- repo=".$name"
- owd="`pwd`" # old working directory
-
- # [----can ascend-----] && [-haven't found repo-]
- while [ "$pwd" != "`pwd`" ] && [ ! -e "`pwd`/$repo" ]; do
- pwd=`pwd`
- cd ..
- done
-
- if [ -e "`pwd`/$repo" ]; then
- # we found a repository
- echo "`pwd`/$repo"
- else
- # we didn't find a repository
- _error "no $name repository found"
- fi
- cd "$owd"
- else
- echo "$REPO"
- fi
-}
-
-# Modules ############################################################
-
-_runcom() {
- # exit states
- # 0 - fine
- # 1 - could not find command
- # 2 - could not run command
- usage="usage: $RVS runcom COMMAND"
- command=${1?"$usage"}; shift
-
- if [ ! -e "$BINDIR/$command" ]; then
- exit 1
- else
- mkdir -p "$baseTMPDIR"
- export TMPDIR="`mktemp -d --tmpdir="$baseTMPDIR"`"
-
- if [ -z "$RVS_LEVEL" ]; then
- export RVS_LEVEL=0;
- else
- export RVS_LEVEL=`expr $RVS_LEVEL + 1`
- fi
-
- if [ -f "$BINDIR/$command" ]; then
- exec "$BINDIR/$command" $@ | tee "$TMPDIR/$command"
- elif [ -d "$BINDIR/$command" ]; then
- mkdir -p "$TMPDIR/$command"
- for file in "$BINDIR/$command"/*; do
- id="`basename "$file" | sed 's/^[0-9]*-//'`"
- "$file" $@ | tee "$TMPDIR/$command/$id"
- done
- else
- exit 2
- fi
- rm -rf "$TMPDIR"
- fi
-}
-
-_nextpriority() {
- usage="usage: $RVS nextpriority COMMAND"
- command=${1?"$usage"}
- for file in "$BINDIR/$command"/*; do
- echo "$file" | sed 's/^\([0-9]*\)-.*/\1/'
- done | sort -n | tail -n1 | xargs expr 1 +
-}
-
-################################################################################
-# Builtin commands #
-################################################################################
-
-_init() {
- # exit states:
- # 0 - fine
- # 1 - repo already exists
- # 2 - error running init commands
- REPO="`_repo 2> /dev/null`"
- if [ -z "$REPO" ]; then
- export REPO="`pwd`/.$name"
- install -d "$REPO"
- _runcom init
- case "$?" in
- 0) exit 0;;
- 1) exit 0;;
- 2) _error 'error running init scripts' 2;;
- esac
- else
- _error "repository already exists at \`$REPO'" 1
- fi
-}
-
-################################################################################
-# Main #
-################################################################################
-
-# START OPTION HANDLING #
-com=$1;
-# END OPTION HANDLING #
-case "$com" in
- '') _error 'no command specified';;
- repo) _repo; exit $?;;
- 'init' ) shift; _init $@; exit $?;;
- 'install') shift; _install $@; exit $?;;
- 'uninstall') shift; _uninstall $@; exit $?;;
- *)
- REPO=`_repo`
- if [ "$?" = '0' ]; then
- export REPO
- _runcom $@
- case "$?" in
- 0) exit 0;;
- 1) _error "could not find command \`$1'" 1;;
- 2) _error "could not run command \`$1'" 2;;
- esac
- else
- exit 1
- fi
- :;;
-esac
-
-# Copy/Paste Virus 1.3c Please copy and paste this text anywhere. Track
-# its progress by searching for this MD5#f7eac285ebfe21c4587bfebb9582f90d
-