Dash:
[t2.git] / misc / tools-source / install_wrapper.sh
blob6f831e8d8ddf7f3795ec10833cc59a2d9099c4c8
1 #!/bin/bash
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # T2 SDE: misc/tools-source/install_wrapper.sh
4 # Copyright (C) 2004 - 2022 The T2 SDE Project
5 #
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2.
11 # --- T2-COPYRIGHT-NOTE-END ---
13 PATH="${PATH/:$INSTALL_WRAPPER_MYPATH:/:}"
14 PATH="${PATH#$INSTALL_WRAPPER_MYPATH:}"
15 PATH="${PATH%:$INSTALL_WRAPPER_MYPATH}"
17 filter="${INSTALL_WRAPPER_FILTER:+|} $INSTALL_WRAPPER_FILTER"
19 if [ "$INSTALL_WRAPPER_NOLOOP" = 1 ]; then
20 echo "--"
21 echo "Found loop in install_wrapper: $0 $*" >&2
22 echo "INSTALL_WRAPPER_MYPATH=$INSTALL_WRAPPER_MYPATH"
23 echo "PATH=$PATH"
24 echo "--"
25 exit 1
27 export INSTALL_WRAPPER_NOLOOP=1
29 logfile="${INSTALL_WRAPPER_LOGFILE:-/dev/null}"
30 [ -z "${logfile##*/*}" -a ! -d "${logfile%/*}" ] && logfile=/dev/null
32 command="${0##*/}"
33 destination=""
34 declare -a sources
35 newcommand="$command"
36 sources_counter=0
37 error=0
39 echo "" >> $logfile
40 echo "$PWD:" >> $logfile
41 echo "* ${INSTALL_WRAPPER_FILTER:-No Filter.}" >> $logfile
42 echo "- $command $*" >> $logfile
44 if [ "${*/--target-directory//}" != "$*" ]; then
45 echo "= $command $*" >> $logfile
46 $command "$@"; exit $?
49 while [ $# -gt 0 ]; do
50 case "$1" in
51 -g|-m|-o|-S|--group|--mode|--owner|--suffix)
52 newcommand="$newcommand $1 $2"
53 shift 1
55 -s|--strip)
56 if [[ $command != *install ]]; then
57 newcommand="$newcommand $1"
60 -t)
61 : # skip -t for now, as we generate target filenames
63 -*)
64 newcommand="$newcommand $1"
67 if [ -n "$destination" ]; then
68 sources[sources_counter++]="$destination"
70 destination="$1"
72 esac
73 shift 1
74 done
76 [ -z "${destination##/*}" ] || destination="$PWD/$destination"
78 if [ "$filter" != " " ]; then
79 destination="$( eval "echo \"$destination\" | tr -s '/' $filter" )"
82 if [ -z "$destination" -o $sources_counter -eq 0 ]; then
83 echo "+ $newcommand $destination" >> $logfile
84 $newcommand "$destination" || error=$?
85 elif [ -d "$destination" ]; then
86 for source in "${sources[@]}"; do
87 thisdest="${destination}"
88 [ ! -d "${source//\/\///}" ] && thisdest="$thisdest/${source##*/}"
89 thisdest="${thisdest//\/\///}"
90 [ "$filter" != " " ] && thisdest="$( eval "echo \"$thisdest\" $filter" )"
91 if [ ! -z "$thisdest" ]; then
92 echo "+ $newcommand $source $thisdest" >> $logfile
93 $newcommand "$source" "$thisdest" || error=$?
95 done
96 else
97 echo "+ $newcommand ${sources[*]} $destination" >> $logfile
98 $newcommand "${sources[@]}" "$destination" || error=$?
101 echo "===> Returncode: $error" >> $logfile
102 exit $error