add install script, fix perms
authorIan Kelling <ian@iankelling.org>
Tue, 14 Feb 2017 00:00:37 +0000 (16:00 -0800)
committerIan Kelling <ian@iankelling.org>
Tue, 14 Feb 2017 00:00:37 +0000 (16:00 -0800)
failmail [changed mode: 0644->0755]
logq-function [changed mode: 0755->0644]
setup [new file with mode: 0755]
sysd-mail-once

old mode 100644 (file)
new mode 100755 (executable)
old mode 100755 (executable)
new mode 100644 (file)
diff --git a/setup b/setup
new file mode 100755 (executable)
index 0000000..44ef3f5
--- /dev/null
+++ b/setup
@@ -0,0 +1,72 @@
+#!/bin/bash
+# Copyright (C) 2017 Ian Kelling
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+#     http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+
+[[ $EUID == 0 ]] || exec sudo "$BASH_SOURCE" "$@"
+
+usage() {
+    cat <<EOF
+Usage: ${0##*/} []
+Install or uninstall files to /usr/local/bin
+
+-n|--dry-run     Dry run
+-u|--uninstall   Uninstall. default is to install
+-h|--help         Print help and exit.
+
+Note: Uses GNU getopt options parsing style
+EOF
+    exit $1
+}
+dry=false
+uninstall=false # default
+temp=$(getopt -l help,uninstall,dry-run hun "$@") || usage 1
+eval set -- "$temp"
+while true; do
+    case $1 in
+        -n|--dry-run) dry=true; shift ;;
+        -u|--uninstall) uninstall=true; shift ;;
+        -h|--help) usage ;;
+        --) shift; break ;;
+        *) echo "$0: Internal error! unexpected args: $*" ; exit 1 ;;
+    esac
+done
+
+
+x="$(readlink -f "$BASH_SOURCE")"; cd ${x%/*} # directory of this file
+
+files=()
+for f in *; do
+    if [[ -x $f && ! -d $f && ! -L $f && $f != setup ]]; then
+        files+=($f)
+    fi
+done
+
+if $uninstall; then
+    if $dry; then
+        echo "setup dry run: cd /usr/local/bin"
+        echo "setup dry run: rm -fv ${files[*]}"
+    else
+        cd /usr/local/bin
+        rm -fv ${files[@]}
+    fi
+else
+    if $dry; then
+        echo "setup dry run: install -v ${files[*]} /usr/local/bin"
+    else
+        install -v ${files[@]} /usr/local/bin
+    fi
+fi
index a7840aad763463c93d5cb960b7c94092c00015f7..e4305aec3ce621764cf517f9d311c179106bc79b 100755 (executable)
@@ -61,7 +61,7 @@ if "$@"; then
             echo | mail -s "$HOSTNAME: $service success" $u@localhost
         fi
     fi
-else
+else # $@ failed
     if [[ $file ]]; then
         i=${file#$c}
         if (( i < errors )); then