| 1 #!/bin/sh |
1 #!/bin/sh |
| 2 ## |
2 ## |
| 3 ## GNU shtool -- The GNU Portable Shell Tool |
3 ## GNU shtool -- The GNU Portable Shell Tool |
| 4 ## Copyright (c) 1994-2007 Ralf S. Engelschall <rse@engelschall.com> |
4 ## Copyright (c) 1994-2008 Ralf S. Engelschall <rse@engelschall.com> |
| 5 ## |
5 ## |
| 6 ## See http://www.gnu.org/software/shtool/ for more information. |
6 ## See http://www.gnu.org/software/shtool/ for more information. |
| 7 ## See ftp://ftp.gnu.org/gnu/shtool/ for latest version. |
7 ## See ftp://ftp.gnu.org/gnu/shtool/ for latest version. |
| 8 ## |
8 ## |
| 9 ## Version: 2.0.7 (19-May-2007) |
9 ## Version: 2.0.8 (18-Jul-2008) |
| 10 ## Contents: all available modules |
10 ## Contents: all available modules |
| 11 ## |
11 ## |
| 12 |
12 |
| 13 ## |
13 ## |
| 14 ## This program is free software; you can redistribute it and/or modify |
14 ## This program is free software; you can redistribute it and/or modify |
| 88 echo "$0:Error: invalid command line" 1>&2 |
88 echo "$0:Error: invalid command line" 1>&2 |
| 89 echo "$0:Hint: run \`$0 -h' for usage" 1>&2 |
89 echo "$0:Hint: run \`$0 -h' for usage" 1>&2 |
| 90 exit 1 |
90 exit 1 |
| 91 fi |
91 fi |
| 92 if [ ".$1" = ".-h" ] || [ ".$1" = ".--help" ]; then |
92 if [ ".$1" = ".-h" ] || [ ".$1" = ".--help" ]; then |
| 93 echo "This is GNU shtool, version 2.0.7 (19-May-2007)" |
93 echo "This is GNU shtool, version 2.0.8 (18-Jul-2008)" |
| 94 echo 'Copyright (c) 1994-2007 Ralf S. Engelschall <rse@engelschall.com>' |
94 echo 'Copyright (c) 1994-2008 Ralf S. Engelschall <rse@engelschall.com>' |
| 95 echo 'Report bugs to <bug-shtool@gnu.org>' |
95 echo 'Report bugs to <bug-shtool@gnu.org>' |
| 96 echo '' |
96 echo '' |
| 97 echo 'Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]' |
97 echo 'Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]' |
| 98 echo '' |
98 echo '' |
| 99 echo 'Available global <options>:' |
99 echo 'Available global <options>:' |
| 155 echo ' [-m|--magic] [-p|--path <path>] <str> [<str> ...]' |
155 echo ' [-m|--magic] [-p|--path <path>] <str> [<str> ...]' |
| 156 echo '' |
156 echo '' |
| 157 exit 0 |
157 exit 0 |
| 158 fi |
158 fi |
| 159 if [ ".$1" = ".-v" ] || [ ".$1" = ".--version" ]; then |
159 if [ ".$1" = ".-v" ] || [ ".$1" = ".--version" ]; then |
| 160 echo "GNU shtool 2.0.7 (19-May-2007)" |
160 echo "GNU shtool 2.0.8 (18-Jul-2008)" |
| 161 exit 0 |
161 exit 0 |
| 162 fi |
162 fi |
| 163 if [ ".$1" = ".-r" ] || [ ".$1" = ".--recreate" ]; then |
163 if [ ".$1" = ".-r" ] || [ ".$1" = ".--recreate" ]; then |
| 164 shtoolize -oshtool all |
164 shtoolize -oshtool all |
| 165 exit 0 |
165 exit 0 |
| 1287 ;; |
1287 ;; |
| 1288 |
1288 |
| 1289 install ) |
1289 install ) |
| 1290 ## |
1290 ## |
| 1291 ## install -- Install a program, script or datafile |
1291 ## install -- Install a program, script or datafile |
| 1292 ## Copyright (c) 1997-2007 Ralf S. Engelschall <rse@engelschall.com> |
1292 ## Copyright (c) 1997-2008 Ralf S. Engelschall <rse@engelschall.com> |
| 1293 ## |
1293 ## |
| 1294 |
1294 |
| 1295 # special case: "shtool install -d <dir> [...]" internally |
1295 # special case: "shtool install -d <dir> [...]" internally |
| 1296 # maps to "shtool mkdir -f -p -m 755 <dir> [...]" |
1296 # maps to "shtool mkdir -f -p -m 755 <dir> [...]" |
| 1297 if [ "$opt_d" = yes ]; then |
1297 if [ "$opt_d" = yes ]; then |
| 1626 prefix="$srcdir/" |
1626 prefix="$srcdir/" |
| 1627 srcdir="" |
1627 srcdir="" |
| 1628 dstdir="" |
1628 dstdir="" |
| 1629 else |
1629 else |
| 1630 while [ ".$srcdir" != . ] && [ ".$dstdir" != . ]; do |
1630 while [ ".$srcdir" != . ] && [ ".$dstdir" != . ]; do |
| 1631 presrc=`echo $srcdir | sed -e 's;^\([^/]*\)/.*;\1;'` |
1631 presrc=`echo $srcdir | sed -e 's;^\([^/][^/]*\)/.*;\1;'` |
| 1632 predst=`echo $dstdir | sed -e 's;^\([^/]*\)/.*;\1;'` |
1632 predst=`echo $dstdir | sed -e 's;^\([^/][^/]*\)/.*;\1;'` |
| 1633 if [ ".$presrc" != ".$predst" ]; then |
1633 if [ ".$presrc" != ".$predst" ]; then |
| 1634 break |
1634 break |
| 1635 fi |
1635 fi |
| 1636 prefix="$prefix$presrc/" |
1636 prefix="$prefix$presrc/" |
| 1637 srcdir=`echo $srcdir | sed -e 's;^[^/]*/*;;'` |
1637 srcdir=`echo $srcdir | sed -e 's;^[^/][^/]*/*;;'` |
| 1638 dstdir=`echo $dstdir | sed -e 's;^[^/]*/*;;'` |
1638 dstdir=`echo $dstdir | sed -e 's;^[^/][^/]*/*;;'` |
| 1639 done |
1639 done |
| 1640 fi |
1640 fi |
| 1641 |
1641 |
| 1642 # destination prefix is just the common prefix |
1642 # destination prefix is just the common prefix |
| 1643 dstpre="$prefix" |
1643 dstpre="$prefix" |
| 1646 # step-up corresponding to the destination directory |
1646 # step-up corresponding to the destination directory |
| 1647 srcpre="" |
1647 srcpre="" |
| 1648 allow_relative_srcpre=no |
1648 allow_relative_srcpre=no |
| 1649 if [ ".$prefix" != . ] && [ ".$prefix" != ./ ]; then |
1649 if [ ".$prefix" != . ] && [ ".$prefix" != ./ ]; then |
| 1650 allow_relative_srcpre=yes |
1650 allow_relative_srcpre=yes |
| 1651 fi |
1651 fi |
| 1652 if [ $oneisabs = 0 ]; then |
1652 if [ $oneisabs = 0 ]; then |
| 1653 allow_relative_srcpre=yes |
1653 allow_relative_srcpre=yes |
| 1654 fi |
1654 fi |
| 1655 if [ ".$opt_s" != .yes ]; then |
1655 if [ ".$opt_s" != .yes ]; then |
| 1656 allow_relative_srcpre=no |
1656 allow_relative_srcpre=no |
| 1657 fi |
1657 fi |
| 1658 if [ ".$allow_relative_srcpre" = .yes ]; then |
1658 if [ ".$allow_relative_srcpre" = .yes ]; then |
| 1659 pl="$dstdir/" |
1659 pl="$dstdir/" |
| 1660 OIFS="$IFS"; IFS='/' |
1660 OIFS="$IFS"; IFS='/' |
| 1661 for pe in $pl; do |
1661 for pe in $pl; do |
| 1662 [ ".$pe" = . ] && continue |
1662 [ ".$pe" = . ] && continue |
| 1677 else |
1677 else |
| 1678 dstbase=`echo "$prefix$srcdir" | sed -e 's;/*$;;' -e 's;.*/\([^/]*\)$;\1;'` |
1678 dstbase=`echo "$prefix$srcdir" | sed -e 's;/*$;;' -e 's;.*/\([^/]*\)$;\1;'` |
| 1679 fi |
1679 fi |
| 1680 fi |
1680 fi |
| 1681 |
1681 |
| |
1682 # special case (usually on "mkln -s /foo /foo/bar", etc) |
| |
1683 if [ ".$srcpre$srcdir$srcbase" = . ]; then |
| |
1684 srcdir="." |
| |
1685 fi |
| |
1686 |
| 1682 # now finalize source and destination directory paths |
1687 # now finalize source and destination directory paths |
| 1683 srcdir=`echo $srcdir | sed -e 's;\([^/]\)$;\1/;'` |
1688 srcdir=`echo $srcdir | sed -e 's;\([^/]\)$;\1/;'` |
| 1684 dstdir=`echo $dstdir | sed -e 's;\([^/]\)$;\1/;'` |
1689 dstdir=`echo $dstdir | sed -e 's;\([^/]\)$;\1/;'` |
| 1685 |
1690 |
| 1686 # run the final link command |
1691 # run the final link command |
| 1694 ;; |
1699 ;; |
| 1695 |
1700 |
| 1696 mkshadow ) |
1701 mkshadow ) |
| 1697 ## |
1702 ## |
| 1698 ## mkshadow -- Make a shadow tree through symbolic links |
1703 ## mkshadow -- Make a shadow tree through symbolic links |
| 1699 ## Copyright (c) 1998-2007 Ralf S. Engelschall <rse@engelschall.com> |
1704 ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com> |
| 1700 ## |
1705 ## |
| 1701 |
1706 |
| 1702 # source and destination directory |
1707 # source and destination directory |
| 1703 src=`echo "$1" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'` |
1708 src=`echo "$1" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'` |
| 1704 dst=`echo "$2" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'` |
1709 dst=`echo "$2" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'` |
| 1869 ;; |
1874 ;; |
| 1870 |
1875 |
| 1871 rotate ) |
1876 rotate ) |
| 1872 ## |
1877 ## |
| 1873 ## rotate -- Logfile rotation |
1878 ## rotate -- Logfile rotation |
| 1874 ## Copyright (c) 2001-2007 Ralf S. Engelschall <rse@engelschall.com> |
1879 ## Copyright (c) 2001-2008 Ralf S. Engelschall <rse@engelschall.com> |
| 1875 ## |
1880 ## |
| 1876 |
1881 |
| 1877 # make sure we have at least one file to rotate |
1882 # make sure we have at least one file to rotate |
| 1878 if [ ".$opt_n" = .0 ]; then |
1883 if [ ".$opt_n" = .0 ]; then |
| 1879 echo "$msgprefix:Error: invalid argument \`$opt_n' to option -n." 1>&2 |
1884 echo "$msgprefix:Error: invalid argument \`$opt_n' to option -n." 1>&2 |
| 2030 echo "rotating $ldir/$file" |
2035 echo "rotating $ldir/$file" |
| 2031 fi |
2036 fi |
| 2032 |
2037 |
| 2033 # execute prolog |
2038 # execute prolog |
| 2034 if [ ".$opt_P" != . ]; then |
2039 if [ ".$opt_P" != . ]; then |
| |
2040 # pass current log file name to prolog |
| |
2041 # prolog cannot be handed an argument as it may be |
| |
2042 # called as "prolog && something" |
| |
2043 SHTOOL_ROTATE_LOGFILE="$ldir/$file" |
| |
2044 export SHTOOL_ROTATE_LOGFILE |
| 2035 if [ ".$opt_t" = .yes ]; then |
2045 if [ ".$opt_t" = .yes ]; then |
| 2036 echo "$opt_P" |
2046 echo "$opt_P" |
| 2037 fi |
2047 fi |
| 2038 eval $opt_P |
2048 eval $opt_P |
| 2039 [ $? -ne 0 ] && shtool_exit $? |
2049 [ $? -ne 0 ] && shtool_exit $? |
| 2219 fi |
2229 fi |
| 2220 fi |
2230 fi |
| 2221 |
2231 |
| 2222 # execute epilog |
2232 # execute epilog |
| 2223 if [ ".$opt_E" != . ]; then |
2233 if [ ".$opt_E" != . ]; then |
| |
2234 # pass archive file name to epilog command |
| |
2235 # epilog cannot be handed an argument as it is often |
| |
2236 # called as "epilog && something" |
| |
2237 SHTOOL_ROTATE_LOGFILE="${adir}/${file}" |
| |
2238 export SHTOOL_ROTATE_LOGFILE |
| 2224 if [ ".$opt_t" = .yes ]; then |
2239 if [ ".$opt_t" = .yes ]; then |
| 2225 echo "$opt_E" |
2240 echo "$opt_E" |
| 2226 fi |
2241 fi |
| 2227 eval $opt_E |
2242 eval $opt_E |
| 2228 [ $? -ne 0 ] && shtool_exit $? |
2243 [ $? -ne 0 ] && shtool_exit $? |
| 2509 if [ ".$opt_n" = .no ]; then |
2524 if [ ".$opt_n" = .no ]; then |
| 2510 touch -r $file$orig $file |
2525 touch -r $file$orig $file |
| 2511 fi |
2526 fi |
| 2512 fi |
2527 fi |
| 2513 |
2528 |
| 2514 # optionally check whether any content change actually occurred |
2529 # optionally check whether any content change actually occurred |
| 2515 if [ ".$opt_q" = .no ]; then |
2530 if [ ".$opt_q" = .no ]; then |
| 2516 if cmp $file$orig $file >/dev/null 2>&1; then |
2531 if cmp $file$orig $file >/dev/null 2>&1; then |
| 2517 if [ ".$opt_w" = .yes ]; then |
2532 if [ ".$opt_w" = .yes ]; then |
| 2518 echo "$msgprefix:Warning: substitution resulted in no content change on file \"$file\"" 1>&2 |
2533 echo "$msgprefix:Warning: substitution resulted in no content change on file \"$file\"" 1>&2 |
| 2519 fi |
2534 fi |
| 2747 [ ".${tagfile}" = .x ] && continue |
2778 [ ".${tagfile}" = .x ] && continue |
| 2748 [ ! -f "/etc/${tagfile}" ] && continue |
2779 [ ! -f "/etc/${tagfile}" ] && continue |
| 2749 n=`echo ${tagfile} | sed -e 's/[_-]release$//' -e 's/[_-]version$//'` |
2780 n=`echo ${tagfile} | sed -e 's/[_-]release$//' -e 's/[_-]version$//'` |
| 2750 v=`(grep VERSION /etc/${tagfile}; cat /etc/${tagfile}) | grep '[0-9]' | sed -e 'q' |\ |
2781 v=`(grep VERSION /etc/${tagfile}; cat /etc/${tagfile}) | grep '[0-9]' | sed -e 'q' |\ |
| 2751 sed -e 's/^/#/' \ |
2782 sed -e 's/^/#/' \ |
| 2752 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \ |
2783 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\).*$/\1[\2]/' \ |
| 2753 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \ |
2784 -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \ |
| 2754 -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \ |
2785 -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \ |
| 2755 -e 's/^#.*$//'` |
2786 -e 's/^#.*$//'` |
| 2756 case "`util_lower ${n}`" in |
2787 case "`util_lower ${n}`" in |
| 2757 redhat ) |
2788 redhat ) |
| 2923 ;; |
2954 ;; |
| 2924 |
2955 |
| 2925 # IBM AIX |
2956 # IBM AIX |
| 2926 *:AIX:* ) |
2957 *:AIX:* ) |
| 2927 # determine architecture |
2958 # determine architecture |
| 2928 cpu_arch=rs6000 |
2959 cpu_arch=RS6000 |
| 2929 if [ -x /usr/sbin/lsdev -a -x /usr/sbin/lsattr ]; then |
2960 if [ -x /usr/sbin/lsdev -a -x /usr/sbin/lsattr ]; then |
| 2930 cpu_id=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` |
2961 cpu_id=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` |
| 2931 if [ ".`/usr/sbin/lsattr -El ${cpu_id} | grep -i powerpc`" != . ]; then |
2962 if [ ".`/usr/sbin/lsattr -El ${cpu_id} | grep -i powerpc`" != . ]; then |
| 2932 cpu_arch=powerpc |
2963 cpu_arch=PPC |
| 2933 fi |
2964 fi |
| 2934 elif [ -d /QOpenSys ]; then |
2965 elif [ -d /QOpenSys ]; then |
| 2935 # IBM i5/OS (aka OS/400) with PASE (Portable Application Solutions Environment) |
2966 # IBM i5/OS (aka OS/400) with PASE (Portable Application Solutions Environment) |
| 2936 cpu_arch=powerpc |
2967 cpu_arch=PPC |
| 2937 fi |
2968 fi |
| 2938 if [ -x /usr/bin/oslevel ]; then |
2969 if [ -x /usr/bin/oslevel ]; then |
| 2939 os_level=`/usr/bin/oslevel` |
2970 os_level=`/usr/bin/oslevel` |
| 2940 else |
2971 else |
| 2941 os_level="`uname -v`.`uname -r`" |
2972 os_level="`uname -v`.`uname -r`" |
| 2995 -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \ |
3026 -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \ |
| 2996 -e 's/^#.*$/v1="0"/'` |
3027 -e 's/^#.*$/v1="0"/'` |
| 2997 SP="[Apple ]Mac OS X ${v1}${v2+.$v2}${v3+[.$v3]}" |
3028 SP="[Apple ]Mac OS X ${v1}${v2+.$v2}${v3+[.$v3]}" |
| 2998 fi |
3029 fi |
| 2999 SC="4.4BSD/Mach3.0" |
3030 SC="4.4BSD/Mach3.0" |
| |
3031 ;; |
| |
3032 |
| |
3033 # Windows/Cygwin |
| |
3034 *:CYGWIN*:* ) |
| |
3035 # determine architecture |
| |
3036 AT="`uname -m`" |
| |
3037 AP="${AT}" |
| |
3038 case "${AP}" in |
| |
3039 i?86 ) AP="iX86" ;; |
| |
3040 esac |
| |
3041 AC="${AP}" |
| |
3042 # determine system |
| |
3043 unset v1; unset v2; unset v3 |
| |
3044 eval `echo "${UNAME_RELEASE}" |\ |
| |
3045 sed -e 's/^/#/' \ |
| |
3046 -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \ |
| |
3047 -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \ |
| |
3048 -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \ |
| |
3049 -e 's/^#.*$/v1="0"/'` |
| |
3050 ST="Cygwin ${v1}${v2+.$v2}${v3+[.$v3]}" |
| |
3051 SP="$ST" |
| |
3052 SC="Windows" |
| |
3053 v=`echo "${UNAME_SYSTEM}" | sed -e 's/^CYGWIN_NT-//' |\ |
| |
3054 sed -e 's/^/#/' -e 's/^#\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' -e 's/^#.*$//'` |
| |
3055 case "$v" in |
| |
3056 4.0 ) SC="$SC[ NT]" ;; |
| |
3057 5.0 ) SC="$SC[ 2000]" ;; |
| |
3058 5.1 ) SC="$SC[ XP]" ;; |
| |
3059 6.0 ) SC="$SC[ Vista]" ;; |
| |
3060 esac |
| 3000 ;; |
3061 ;; |
| 3001 |
3062 |
| 3002 # TODO ...ADD YOUR NEW PLATFORM CHECK HERE... TODO |
3063 # TODO ...ADD YOUR NEW PLATFORM CHECK HERE... TODO |
| 3003 # *:XXX:* ) |
3064 # *:XXX:* ) |
| 3004 # ... |
3065 # ... |