summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorCem Keylan <cem@ckyln.com>2021-09-28 17:45:24 +0300
committerCem Keylan <cem@ckyln.com>2021-09-28 17:45:24 +0300
commit2e76c39765bf1172b1b53a7aef6cf95c1459fad5 (patch)
treec3021b5b5a33acedadad8f49d0ddf6b496151377 /tools
parent401452be4a1a0635a4187b277e79fcbffd43d047 (diff)
downloadlariza-2e76c39765bf1172b1b53a7aef6cf95c1459fad5.tar.gz
lariza: portability fixes on the build system
Diffstat (limited to 'tools')
-rwxr-xr-xtools/install.sh48
1 files changed, 48 insertions, 0 deletions
diff --git a/tools/install.sh b/tools/install.sh
new file mode 100755
index 0000000..4641973
--- /dev/null
+++ b/tools/install.sh
@@ -0,0 +1,48 @@
+#!/bin/sh -e
+# Portable install version that supports -D -m and -t
+# We have our own extension flag -s for running sed on the given files while
+# installing.
+die() { printf '%s\n' "$@" >&2; exit 1;}
+usage() {
+ die "usage: ${0##*/} [-D] [-m mode] [-s sedscript] source dest" \
+ " or: ${0##*/} [-D] [-m mode] [-s sedscript] [-t dir] [source...]"
+}
+
+sed=''
+mkdirp=''
+target=''
+mode=0755
+
+while getopts 'Dm:s:t:h' opt; do
+ case $opt in
+ D) mkdirp=1 ;;
+ s) sed=$OPTARG ;;
+ t) target=$OPTARG ;;
+ m) mode=$OPTARG ;;
+ *) usage
+ esac
+done
+
+shift "$((OPTIND - 1))"
+
+if [ "$target" ]; then
+ [ "$mkdirp" ] || [ -d "$target" ] || die "$target doesn't exist"
+ mkdir -p "$target"
+ for arg; do
+ [ -d "$target/${arg##*/}" ] && die "$target/${arg##*/} is a directory"
+ if [ "$sed" ]; then
+ sed "$sed" < "$arg" > "$target/${arg##*/}"
+ else
+ cp "$arg" "$target"
+ fi
+
+ chmod "$mode" "$target/${arg##*/}"
+ done
+else
+ case "$2" in */*) [ "$mkdirp" ] || [ -d "${2%/*}" ] || die "${2%/*} doesn't exist"
+ mkdir -p "${2%/*}"
+ esac
+ [ -d "$2" ] && die "$2 is a directory"
+ if [ "$sed" ]; then sed "$sed" < "$1" > "$2"; else cp "$1" "$2"; fi
+ chmod "$mode" "$2"
+fi