From 504d11ded8c1e9a0757332f2a10ed7d86dd5fc70 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 1 Jul 2015 23:22:00 -0600 Subject: A whole bunch of stuff --- wrapper/.gitignore | 3 +- wrapper/Makefile | 17 +++--- wrapper/inner.sh | 145 ------------------------------------------------- wrapper/inner.sh.m4 | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++ wrapper/runcmd.mk | 15 +++++ 5 files changed, 181 insertions(+), 153 deletions(-) delete mode 100644 wrapper/inner.sh create mode 100644 wrapper/inner.sh.m4 create mode 100644 wrapper/runcmd.mk (limited to 'wrapper') diff --git a/wrapper/.gitignore b/wrapper/.gitignore index 6141a28..0c3c90a 100644 --- a/wrapper/.gitignore +++ b/wrapper/.gitignore @@ -1,2 +1,3 @@ /outer -/inner \ No newline at end of file +/inner +/inner.sh diff --git a/wrapper/Makefile b/wrapper/Makefile index f316cc0..54047d2 100644 --- a/wrapper/Makefile +++ b/wrapper/Makefile @@ -17,16 +17,19 @@ 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) +src_files += Makefile outer.c inner.sh.m4 runcmd.mk +out_files += outer inner +clean_files += inner.sh +sys_files += $(bindir)/$(PACKAGE) $(pkglibexecdir)/$(PACKAGE) $(pkglibexecdir)/runcmd.mk -$(objdir)/outer.o: $(topobjdir)/config.h -$(objdir)/inner: $(topobjdir)/config.sh +$(outdir)/outer.o: $(topoutdir)/config.h +$(outdir)/inner: $(topoutdir)/config.sh -$(DESTDIR)$(bindir)/$(PACKAGE) : $(objdir)/outer | $(DESTDIR)$(bindir) +$(DESTDIR)$(bindir)/$(PACKAGE) : $(outdir)/outer | $(DESTDIR)$(bindir) $(INSTALL_PROGRAM) $< $@ -$(DESTDIR)$(pkglibexecdir)/$(PACKAGE) : $(objdir)/inner | $(DESTDIR)$(bindir) +$(DESTDIR)$(pkglibexecdir)/$(PACKAGE) : $(outdir)/inner | $(DESTDIR)$(pkglibexecdir) + $(INSTALL_PROGRAM) $< $@ +$(DESTDIR)$(pkglibexecdir)/runcmd.mk : $(srcdir)/runcmd.mk | $(DESTDIR)$(pkglibexecdir) $(INSTALL_PROGRAM) $< $@ include $(topsrcdir)/common.bottom.mk diff --git a/wrapper/inner.sh b/wrapper/inner.sh deleted file mode 100644 index b1dc718..0000000 --- a/wrapper/inner.sh +++ /dev/null @@ -1,145 +0,0 @@ -#!/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 . -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 []' "$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/wrapper/inner.sh.m4 b/wrapper/inner.sh.m4 new file mode 100644 index 0000000..8444bd6 --- /dev/null +++ b/wrapper/inner.sh.m4 @@ -0,0 +1,154 @@ +#!/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 . +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" "$program_name" "${@:3}" + [[ $1 -eq 0 ]] || exit $1 +} + +errusage() { + >&2 printf "$(_ "$2")\n" "$program_name" "${@:3}" + [[ $1 -eq 0 ]] || exit $1 +} + +_runcmd() { + [[ $# -ge 1 ]] || errusage 1 'Usage: %q []' + local cmd=$1; shift + local args_str='' + [[ $# -eq 0 ]] || printf -v args_str '%q ' "$@" + + local exec_path="${!varname_EXEC_PATH:-$pkglibexecdir}" + + shopt -s nullglob + local files=("${exec_path}"/modules/*/"$cmd") + if [[ ${#files[@]} -eq 0 ]]; then + error 127 '%s: Not a %s command' "$cmd" "$PACKAGE" + fi + files=("${files[@]#"${exec_path/modules/}"}") + + local output_dir + trap '[ -z "${output_dir:-}" ] || rm -rf -- "$TMPDIR"' EXIT + output_dir="$(mktemp -dt "${PACKAGE}.XXXXXXXXXX")" + + local repo + repo="$(_repo)" + export "${varname_REPO}=${repo}" + + local cwd + printf -v cwd '%q' "$PWD" + + make -j1 \ + -f "$exec_path/runcmd.mk" \ + -C "$output_dir" \ + ARGS="$args_str" \ + EXEC_PATH="$exec_path" \ + CWD="$cwd" \ + -- "${files[@]}" + exit $? +} + +_repo() { + [[ $# -ne 0 ]] || errusage 1 'Usage: %q repo' + 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 ]] || errusage 1 'Usage: %q init [directory]' + 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/wrapper/runcmd.mk b/wrapper/runcmd.mk new file mode 100644 index 0000000..7cadb43 --- /dev/null +++ b/wrapper/runcmd.mk @@ -0,0 +1,15 @@ +#!/usr/bin/make -f + +# Environment/command line variables: +# - ARGS +# - EXEC_DIR +# - CWD + +SHELL = bash -o pipefail + +export OUTPUT_DIR := $(realpath .) + +% : $(EXEC_PATH)/modules/% + cd $(CWD) && '$<' $(ARGS) | tee -- '$@' + +include $(wildcard $(EXEC_PATH)/modules/*.mk) -- cgit v1.2.3-2-g168b