| 1 |
#!/bin/sh |
| 2 |
# -------------------------------------------------------------------------- |
| 3 |
# |
| 4 |
# //===// //===== //===// // // //===// |
| 5 |
# // // // // // // // // // |
| 6 |
# //===// //===== //===// // // //===<< |
| 7 |
# // \\ // // // // // // |
| 8 |
# // \\ =====// // //===== // //===// Version III |
| 9 |
# |
| 10 |
# ------------- An Efficient RSerPool Prototype Implementation ------------- |
| 11 |
# |
| 12 |
# Copyright (C) 2002-2026 by Thomas Dreibholz |
| 13 |
# |
| 14 |
# This program is free software: you can redistribute it and/or modify |
| 15 |
# it under the terms of the GNU General Public License as published by |
| 16 |
# the Free Software Foundation, either version 3 of the License, or |
| 17 |
# (at your option) any later version. |
| 18 |
# |
| 19 |
# This program is distributed in the hope that it will be useful, |
| 20 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
# GNU General Public License for more details. |
| 23 |
# |
| 24 |
# You should have received a copy of the GNU General Public License |
| 25 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 26 |
# |
| 27 |
# Contact: [email protected] |
| 28 |
|
| 29 |
|
| 30 |
# ====== Warning message when no keyring is configured ====================== |
| 31 |
display_keyring_warning () |
| 32 |
{ |
| 33 |
echo "######################################################################" |
| 34 |
echo "WARNING: Skipping verification; you should better configure a keyring!" |
| 35 |
echo "######################################################################" |
| 36 |
} |
| 37 |
|
| 38 |
# ====== Preparation ======================================================== |
| 39 |
if [ $# -lt 1 ] ; then |
| 40 |
echo >2 "Usage: scriptingcontrol {check-environment [Directory] [Environment] [Keyring] [Trust DB]} {run [Directory] [Input] [Output] [Status] [Environment] [Keyring] [Trust DB]} {cleanup [Directory] [PID] {keeptempdirs}}" |
| 41 |
exit 1 |
| 42 |
fi |
| 43 |
MODE="$1" |
| 44 |
|
| 45 |
|
| 46 |
# ====== Environment check mode ============================================= |
| 47 |
if [ "$MODE" = "check-environment" ] ; then |
| 48 |
if [ $# -lt 5 ] ; then |
| 49 |
echo >2 "Usage: scriptingcontrol check-environment [Directory] [Environment] [Keyring] [Trust DB]" |
| 50 |
exit 1 |
| 51 |
fi |
| 52 |
DIRECTORY="$2" |
| 53 |
ENVIRONMENT_NAME="$3" |
| 54 |
KEYRING="$4" |
| 55 |
TRUSTDB="$5" |
| 56 |
|
| 57 |
cd $DIRECTORY || exit 1 |
| 58 |
|
| 59 |
# ====== Verify input ==================================================== |
| 60 |
if [ "$KEYRING" != "" -a "$TRUSTDB" != "" ] ; then |
| 61 |
cp -f "$KEYRING" keyring.gpg |
| 62 |
cp -f "$TRUSTDB" trustdb.gpg |
| 63 |
gpg -q --no-default-keyring --keyring ./keyring.gpg --trustdb-name ./trustdb.gpg --homedir . --verify $ENVIRONMENT_NAME || exit 1 |
| 64 |
else |
| 65 |
display_keyring_warning |
| 66 |
fi |
| 67 |
|
| 68 |
|
| 69 |
# ====== Work mode ========================================================== |
| 70 |
elif [ "$MODE" = "run" ] ; then |
| 71 |
if [ $# -lt 5 ] ; then |
| 72 |
echo >2 "Usage: scriptingcontrol run [Directory] [Input] [Output] [Status] [Environment] [Keyring] [Trust DB]" |
| 73 |
exit 1 |
| 74 |
fi |
| 75 |
DIRECTORY="$2" |
| 76 |
INPUT_NAME="$3" |
| 77 |
OUTPUT_NAME="$4" |
| 78 |
STATUS_NAME="$5" |
| 79 |
ENVIRONMENT_NAME="$6" |
| 80 |
KEYRING="$7" |
| 81 |
TRUSTDB="$8" |
| 82 |
|
| 83 |
cd $DIRECTORY || exit 1 |
| 84 |
|
| 85 |
# ====== Verify input ================================================= |
| 86 |
if [ "$KEYRING" != "" -a "$TRUSTDB" != "" ] ; then |
| 87 |
cp -f "$KEYRING" keyring.gpg |
| 88 |
cp -f "$TRUSTDB" trustdb.gpg |
| 89 |
gpg -q --no-default-keyring --keyring ./keyring.gpg --trustdb-name ./trustdb.gpg --homedir . --decrypt --output $INPUT_NAME.decrypt $INPUT_NAME || exit 1 |
| 90 |
mv $INPUT_NAME.decrypt $INPUT_NAME |
| 91 |
else |
| 92 |
display_keyring_warning |
| 93 |
fi |
| 94 |
|
| 95 |
# ====== Extract input =================================================== |
| 96 |
# Extract the input file: |
| 97 |
# - First, try plain Tar |
| 98 |
# - If it does not work, try Tar/GZip |
| 99 |
# - If it does not work, try Tar/BZip2 |
| 100 |
# - If it does not work, return an error |
| 101 |
tar xf $INPUT_NAME || tar xzf $INPUT_NAME || tar xjf $INPUT_NAME || exit 1 |
| 102 |
|
| 103 |
# ====== Do the actual work ============================================== |
| 104 |
chmod 700 ssrun && \ |
| 105 |
./ssrun $OUTPUT_NAME "$ENVIRONMENT_NAME" "$KEYRING" "$TRUSTDB" || exit 1 |
| 106 |
|
| 107 |
|
| 108 |
# ====== Clean up directory ================================================= |
| 109 |
elif [ "$MODE" = "cleanup" ] ; then |
| 110 |
if [ $# -lt 3 ] ; then |
| 111 |
echo >2 "Usage: scriptingcontrol cleanup [Directory] [PID] {keeptempdirs}" |
| 112 |
exit 1 |
| 113 |
fi |
| 114 |
DIRECTORY="$2" |
| 115 |
PID="$3" |
| 116 |
KEEPTEMPDIRS="$4" |
| 117 |
|
| 118 |
# ------ Send SIGKILL to worker process and all of its childs ------------ |
| 119 |
if [ $PID -ne 0 ] ; then |
| 120 |
CHILD_PIDS="" |
| 121 |
find_child_pids() { |
| 122 |
for pid in `pgrep -P $1` ; do |
| 123 |
CHILD_PIDS="$CHILD_PIDS $pid" |
| 124 |
find_child_pids $pid |
| 125 |
done |
| 126 |
} |
| 127 |
find_child_pids $PID |
| 128 |
|
| 129 |
echo "Terminating$CHILD_PIDS $PID ..." |
| 130 |
kill -KILL $CHILD_PIDS $PID |
| 131 |
fi |
| 132 |
|
| 133 |
# ------ Remove temporary directory -------------------------------------- |
| 134 |
if [ "$KEEPTEMPDIRS" != "keeptempdirs" ] ; then |
| 135 |
rm -rf "$DIRECTORY" |
| 136 |
fi |
| 137 |
|
| 138 |
|
| 139 |
# ====== Bad mode =========================================================== |
| 140 |
else |
| 141 |
echo "ERROR: Bad mode setting $MODE!" |
| 142 |
exit 1 |
| 143 |
fi |
| 144 |
|
| 145 |
exit 0 |