shtool 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814
  1. #!/bin/sh
  2. ##
  3. ## GNU shtool -- The GNU Portable Shell Tool
  4. ## Copyright (c) 1994-2008 Ralf S. Engelschall <rse@engelschall.com>
  5. ##
  6. ## See http://www.gnu.org/software/shtool/ for more information.
  7. ## See ftp://ftp.gnu.org/gnu/shtool/ for latest version.
  8. ##
  9. ## Version: 2.0.8 (18-Jul-2008)
  10. ## Contents: 5/19 available modules
  11. ##
  12. ##
  13. ## This program is free software; you can redistribute it and/or modify
  14. ## it under the terms of the GNU General Public License as published by
  15. ## the Free Software Foundation; either version 2 of the License, or
  16. ## (at your option) any later version.
  17. ##
  18. ## This program is distributed in the hope that it will be useful,
  19. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. ## General Public License for more details.
  22. ##
  23. ## You should have received a copy of the GNU General Public License
  24. ## along with this program; if not, write to the Free Software
  25. ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  26. ## USA, or contact Ralf S. Engelschall <rse@engelschall.com>.
  27. ##
  28. ## NOTICE: Given that you include this file verbatim into your own
  29. ## source tree, you are justified in saying that it remains separate
  30. ## from your package, and that this way you are simply just using GNU
  31. ## shtool. So, in this situation, there is no requirement that your
  32. ## package itself is licensed under the GNU General Public License in
  33. ## order to take advantage of GNU shtool.
  34. ##
  35. ##
  36. ## Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]
  37. ##
  38. ## Available commands:
  39. ## echo Print string with optional construct expansion
  40. ## install Install a program, script or datafile
  41. ## mkdir Make one or more directories
  42. ## platform Platform Identification Utility
  43. ## path Deal with program paths
  44. ##
  45. ## Not available commands (because module was not built-in):
  46. ## mdate Pretty-print modification time of a file or dir
  47. ## table Pretty-print a field-separated list as a table
  48. ## prop Display progress with a running propeller
  49. ## move Move files with simultaneous substitution
  50. ## mkln Make link with calculation of relative paths
  51. ## mkshadow Make a shadow tree through symbolic links
  52. ## fixperm Fix file permissions inside a source tree
  53. ## rotate Logfile rotation
  54. ## tarball Roll distribution tarballs
  55. ## subst Apply sed(1) substitution operations
  56. ## arx Extended archive command
  57. ## slo Separate linker options by library class
  58. ## scpp Sharing C Pre-Processor
  59. ## version Maintain a version information file
  60. ##
  61. # maximum Bourne-Shell compatibility
  62. if [ ".$ZSH_VERSION" != . ] && (emulate sh) >/dev/null 2>&1; then
  63. # reconfigure zsh(1)
  64. emulate sh
  65. NULLCMD=:
  66. alias -g '${1+"$@"}'='"$@"'
  67. elif [ ".$BASH_VERSION" != . ] && (set -o posix) >/dev/null 2>&1; then
  68. # reconfigure bash(1)
  69. set -o posix
  70. fi
  71. # maximum independence of NLS nuisances
  72. for var in \
  73. LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
  74. LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
  75. LC_TELEPHONE LC_TIME
  76. do
  77. if (set +x; test -z "`(eval $var=C; export $var) 2>&1`"); then
  78. eval $var=C; export $var
  79. else
  80. unset $var
  81. fi
  82. done
  83. # initial command line handling
  84. if [ $# -eq 0 ]; then
  85. echo "$0:Error: invalid command line" 1>&2
  86. echo "$0:Hint: run \`$0 -h' for usage" 1>&2
  87. exit 1
  88. fi
  89. if [ ".$1" = ".-h" ] || [ ".$1" = ".--help" ]; then
  90. echo "This is GNU shtool, version 2.0.8 (18-Jul-2008)"
  91. echo 'Copyright (c) 1994-2008 Ralf S. Engelschall <rse@engelschall.com>'
  92. echo 'Report bugs to <bug-shtool@gnu.org>'
  93. echo ''
  94. echo 'Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]'
  95. echo ''
  96. echo 'Available global <options>:'
  97. echo ' -v, --version display shtool version information'
  98. echo ' -h, --help display shtool usage help page (this one)'
  99. echo ' -d, --debug display shell trace information'
  100. echo ' -r, --recreate recreate this shtool script via shtoolize'
  101. echo ''
  102. echo 'Available <cmd-name> [<cmd-options>] [<cmd-args>]:'
  103. echo ' echo [-n|--newline] [-e|--expand] [<string> ...]'
  104. echo ' install [-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy]'
  105. echo ' [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>]'
  106. echo ' [-o|--owner <owner>] [-g|--group <group>] [-e|--exec'
  107. echo ' <sed-cmd>] <file> [<file> ...] <path>'
  108. echo ' mkdir [-t|--trace] [-f|--force] [-p|--parents] [-m|--mode'
  109. echo ' <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir>'
  110. echo ' [<dir> ...]'
  111. echo ' platform [-F|--format <format>] [-S|--sep <string>] [-C|--conc'
  112. echo ' <string>] [-L|--lower] [-U|--upper] [-v|--verbose]'
  113. echo ' [-c|--concise] [-n|--no-newline] [-t|--type <type>]'
  114. echo ' [-V|--version] [-h|--help]'
  115. echo ' path [-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename]'
  116. echo ' [-m|--magic] [-p|--path <path>] <str> [<str> ...]'
  117. echo ''
  118. echo 'Not available <cmd-name> (because module was not built-in):'
  119. echo ' mdate [-n|--newline] [-z|--zero] [-s|--shorten] [-d|--digits]'
  120. echo ' [-f|--field-sep <str>] [-o|--order <spec>] <path>'
  121. echo ' table [-F|--field-sep <sep>] [-w|--width <width>] [-c|--columns'
  122. echo ' <cols>] [-s|--strip <strip>] <str><sep><str>...'
  123. echo ' prop [-p|--prefix <str>]'
  124. echo ' move [-v|--verbose] [-t|--trace] [-e|--expand] [-p|--preserve]'
  125. echo ' <src-file> <dst-file>'
  126. echo ' mkln [-t|--trace] [-f|--force] [-s|--symbolic] <src-path>'
  127. echo ' [<src-path> ...] <dst-path>'
  128. echo ' mkshadow [-v|--verbose] [-t|--trace] [-a|--all] <src-dir> <dst-dir>'
  129. echo ' fixperm [-v|--verbose] [-t|--trace] <path> [<path> ...]'
  130. echo ' rotate [-v|--verbose] [-t|--trace] [-f|--force] [-n|--num-files'
  131. echo ' <count>] [-s|--size <size>] [-c|--copy] [-r|--remove]'
  132. echo ' [-a|--archive-dir <dir>] [-z|--compress [<tool>:]<level>]'
  133. echo ' [-b|--background] [-d|--delay] [-p|--pad <len>] [-m|--mode'
  134. echo ' <mode>] [-o|--owner <owner>] [-g|--group <group>] [-M|--migrate'
  135. echo ' <cmd>] [-P|--prolog <cmd>] [-E|--epilog <cmd>] <file> [...]'
  136. echo ' tarball [-t|--trace] [-v|--verbose] [-o|--output <tarball>]'
  137. echo ' [-c|--compress <prog>] [-d|--directory <dir>] [-u|--user'
  138. echo ' <user>] [-g|--group <group>] [-e|--exclude <pattern>]'
  139. echo ' <path> [<path> ...]'
  140. echo ' subst [-v|--verbose] [-t|--trace] [-n|--nop] [-w|--warning]'
  141. echo ' [-q|--quiet] [-s|--stealth] [-i|--interactive] [-b|--backup'
  142. echo ' <ext>] [-e|--exec <cmd>] [-f|--file <cmd-file>] [<file>]'
  143. echo ' [...]'
  144. echo ' arx [-t|--trace] [-C|--command <cmd>] <op> <archive> [<file>'
  145. echo ' ...]'
  146. echo ' slo [-p|--prefix <str>] -- -L<dir> -l<lib> [-L<dir> -l<lib>'
  147. echo ' ...]'
  148. echo ' scpp [-v|--verbose] [-p|--preserve] [-f|--filter <filter>]'
  149. echo ' [-o|--output <ofile>] [-t|--template <tfile>] [-M|--mark'
  150. echo ' <mark>] [-D|--define <dname>] [-C|--class <cname>]'
  151. echo ' <file> [<file> ...]'
  152. echo ' version [-l|--language <lang>] [-n|--name <name>] [-p|--prefix'
  153. echo ' <prefix>] [-s|--set <version>] [-e|--edit] [-i|--increase'
  154. echo ' <knob>] [-d|--display <type>] <file>'
  155. echo ''
  156. exit 0
  157. fi
  158. if [ ".$1" = ".-v" ] || [ ".$1" = ".--version" ]; then
  159. echo "GNU shtool 2.0.8 (18-Jul-2008)"
  160. exit 0
  161. fi
  162. if [ ".$1" = ".-r" ] || [ ".$1" = ".--recreate" ]; then
  163. shtoolize -obuild/shtool echo install mkdir platform path
  164. exit 0
  165. fi
  166. if [ ".$1" = ".-d" ] || [ ".$1" = ".--debug" ]; then
  167. shift
  168. set -x
  169. fi
  170. name=`echo "$0" | sed -e 's;.*/\([^/]*\)$;\1;' -e 's;-sh$;;' -e 's;\.sh$;;'`
  171. case "$name" in
  172. echo|install|mkdir|platform|path )
  173. # implicit tool command selection
  174. tool="$name"
  175. ;;
  176. * )
  177. # explicit tool command selection
  178. tool="$1"
  179. shift
  180. ;;
  181. esac
  182. arg_spec=""
  183. opt_spec=""
  184. gen_tmpfile=no
  185. ##
  186. ## DISPATCH INTO SCRIPT PROLOG
  187. ##
  188. case $tool in
  189. echo )
  190. str_tool="echo"
  191. str_usage="[-n|--newline] [-e|--expand] [<string> ...]"
  192. arg_spec="0+"
  193. opt_spec="n.e."
  194. opt_alias="n:newline,e:expand"
  195. opt_n=no
  196. opt_e=no
  197. ;;
  198. install )
  199. str_tool="install"
  200. str_usage="[-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy] [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] [-e|--exec <sed-cmd>] <file> [<file> ...] <path>"
  201. arg_spec="1+"
  202. opt_spec="v.t.d.c.C.s.m:o:g:e+"
  203. opt_alias="v:verbose,t:trace,d:mkdir,c:copy,C:compare-copy,s:strip,m:mode,o:owner,g:group,e:exec"
  204. opt_v=no
  205. opt_t=no
  206. opt_d=no
  207. opt_c=no
  208. opt_C=no
  209. opt_s=no
  210. opt_m="0755"
  211. opt_o=""
  212. opt_g=""
  213. opt_e=""
  214. ;;
  215. mkdir )
  216. str_tool="mkdir"
  217. str_usage="[-t|--trace] [-f|--force] [-p|--parents] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir> [<dir> ...]"
  218. arg_spec="1+"
  219. opt_spec="t.f.p.m:o:g:"
  220. opt_alias="t:trace,f:force,p:parents,m:mode,o:owner,g:group"
  221. opt_t=no
  222. opt_f=no
  223. opt_p=no
  224. opt_m=""
  225. opt_o=""
  226. opt_g=""
  227. ;;
  228. platform )
  229. str_tool="platform"
  230. str_usage="[-F|--format <format>] [-S|--sep <string>] [-C|--conc <string>] [-L|--lower] [-U|--upper] [-v|--verbose] [-c|--concise] [-n|--no-newline] [-t|--type <type>] [-V|--version] [-h|--help]"
  231. arg_spec="0="
  232. opt_spec="F:S:C:L.U.v.c.n.t:d.V.h."
  233. opt_alias="F:format,S:sep,C:conc,L:lower,U:upper,v:verbose,c:consise,t:type,n:no-newline,V:version,h:help"
  234. opt_F="%{sp} (%{ap})"
  235. opt_S=" "
  236. opt_C="/"
  237. opt_L=no
  238. opt_U=no
  239. opt_t=""
  240. opt_v=no
  241. opt_c=no
  242. opt_n=no
  243. opt_V=no
  244. opt_h=no
  245. ;;
  246. path )
  247. str_tool="path"
  248. str_usage="[-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename] [-m|--magic] [-p|--path <path>] <str> [<str> ...]"
  249. gen_tmpfile=yes
  250. arg_spec="1+"
  251. opt_spec="s.r.d.b.m.p:"
  252. opt_alias="s:suppress,r:reverse,d:dirname,b:basename,m:magic,p:path"
  253. opt_s=no
  254. opt_r=no
  255. opt_d=no
  256. opt_b=no
  257. opt_m=no
  258. opt_p="$PATH"
  259. ;;
  260. -* )
  261. echo "$0:Error: unknown option \`$tool'" 2>&1
  262. echo "$0:Hint: run \`$0 -h' for usage" 2>&1
  263. exit 1
  264. ;;
  265. * )
  266. echo "$0:Error: unknown command \`$tool'" 2>&1
  267. echo "$0:Hint: run \`$0 -h' for usage" 2>&1
  268. exit 1
  269. ;;
  270. esac
  271. ##
  272. ## COMMON UTILITY CODE
  273. ##
  274. # commonly used ASCII values
  275. ASC_TAB=" "
  276. ASC_NL="
  277. "
  278. # determine name of tool
  279. if [ ".$tool" != . ]; then
  280. # used inside shtool script
  281. toolcmd="$0 $tool"
  282. toolcmdhelp="shtool $tool"
  283. msgprefix="shtool:$tool"
  284. else
  285. # used as standalone script
  286. toolcmd="$0"
  287. toolcmdhelp="sh $0"
  288. msgprefix="$str_tool"
  289. fi
  290. # parse argument specification string
  291. eval `echo $arg_spec |\
  292. sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'`
  293. # parse option specification string
  294. eval `echo h.$opt_spec |\
  295. sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'`
  296. # parse option alias string
  297. eval `echo h:help,$opt_alias |\
  298. sed -e 's/-/_/g' -e 's/\([a-zA-Z0-9]\):\([^,]*\),*/opt_ALIAS_\2=\1;/g'`
  299. # interate over argument line
  300. opt_PREV=''
  301. while [ $# -gt 0 ]; do
  302. # special option stops processing
  303. if [ ".$1" = ".--" ]; then
  304. shift
  305. break
  306. fi
  307. # determine option and argument
  308. opt_ARG_OK=no
  309. if [ ".$opt_PREV" != . ]; then
  310. # merge previous seen option with argument
  311. opt_OPT="$opt_PREV"
  312. opt_ARG="$1"
  313. opt_ARG_OK=yes
  314. opt_PREV=''
  315. else
  316. # split argument into option and argument
  317. case "$1" in
  318. --[a-zA-Z0-9]*=*)
  319. eval `echo "x$1" |\
  320. sed -e 's/^x--\([a-zA-Z0-9-]*\)=\(.*\)$/opt_OPT="\1";opt_ARG="\2"/'`
  321. opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'`
  322. eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
  323. ;;
  324. --[a-zA-Z0-9]*)
  325. opt_OPT=`echo "x$1" | cut -c4-`
  326. opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'`
  327. eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
  328. opt_ARG=''
  329. ;;
  330. -[a-zA-Z0-9]*)
  331. eval `echo "x$1" |\
  332. sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \
  333. -e 's/";\(.*\)$/"; opt_ARG="\1"/'`
  334. ;;
  335. -[a-zA-Z0-9])
  336. opt_OPT=`echo "x$1" | cut -c3-`
  337. opt_ARG=''
  338. ;;
  339. *)
  340. break
  341. ;;
  342. esac
  343. fi
  344. # eat up option
  345. shift
  346. # determine whether option needs an argument
  347. eval "opt_MODE=\$opt_MODE_${opt_OPT}"
  348. if [ ".$opt_ARG" = . ] && [ ".$opt_ARG_OK" != .yes ]; then
  349. if [ ".$opt_MODE" = ".:" ] || [ ".$opt_MODE" = ".+" ]; then
  350. opt_PREV="$opt_OPT"
  351. continue
  352. fi
  353. fi
  354. # process option
  355. case $opt_MODE in
  356. '.' )
  357. # boolean option
  358. eval "opt_${opt_OPT}=yes"
  359. ;;
  360. ':' )
  361. # option with argument (multiple occurrences override)
  362. eval "opt_${opt_OPT}=\"\$opt_ARG\""
  363. ;;
  364. '+' )
  365. # option with argument (multiple occurrences append)
  366. eval "opt_${opt_OPT}=\"\$opt_${opt_OPT}\${ASC_NL}\$opt_ARG\""
  367. ;;
  368. * )
  369. echo "$msgprefix:Error: unknown option: \`$opt_OPT'" 1>&2
  370. echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
  371. exit 1
  372. ;;
  373. esac
  374. done
  375. if [ ".$opt_PREV" != . ]; then
  376. echo "$msgprefix:Error: missing argument to option \`$opt_PREV'" 1>&2
  377. echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
  378. exit 1
  379. fi
  380. # process help option
  381. if [ ".$opt_h" = .yes ]; then
  382. echo "Usage: $toolcmdhelp $str_usage"
  383. exit 0
  384. fi
  385. # complain about incorrect number of arguments
  386. case $arg_MODE in
  387. '=' )
  388. if [ $# -ne $arg_NUMS ]; then
  389. echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2
  390. echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
  391. exit 1
  392. fi
  393. ;;
  394. '+' )
  395. if [ $# -lt $arg_NUMS ]; then
  396. echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2
  397. echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
  398. exit 1
  399. fi
  400. ;;
  401. esac
  402. # establish a temporary file on request
  403. if [ ".$gen_tmpfile" = .yes ]; then
  404. # create (explicitly) secure temporary directory
  405. if [ ".$TMPDIR" != . ]; then
  406. tmpdir="$TMPDIR"
  407. elif [ ".$TEMPDIR" != . ]; then
  408. tmpdir="$TEMPDIR"
  409. else
  410. tmpdir="/tmp"
  411. fi
  412. tmpdir="$tmpdir/.shtool.$$"
  413. ( umask 077
  414. rm -rf "$tmpdir" >/dev/null 2>&1 || true
  415. mkdir "$tmpdir" >/dev/null 2>&1
  416. if [ $? -ne 0 ]; then
  417. echo "$msgprefix:Error: failed to create temporary directory \`$tmpdir'" 1>&2
  418. exit 1
  419. fi
  420. )
  421. # create (implicitly) secure temporary file
  422. tmpfile="$tmpdir/shtool.tmp"
  423. touch "$tmpfile"
  424. fi
  425. # utility function: map string to lower case
  426. util_lower () {
  427. echo "$1" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'
  428. }
  429. # utility function: map string to upper case
  430. util_upper () {
  431. echo "$1" | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  432. }
  433. # cleanup procedure
  434. shtool_exit () {
  435. rc="$1"
  436. if [ ".$gen_tmpfile" = .yes ]; then
  437. rm -rf "$tmpdir" >/dev/null 2>&1 || true
  438. fi
  439. exit $rc
  440. }
  441. ##
  442. ## DISPATCH INTO SCRIPT BODY
  443. ##
  444. case $tool in
  445. echo )
  446. ##
  447. ## echo -- Print string with optional construct expansion
  448. ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
  449. ##
  450. text="$*"
  451. # check for broken escape sequence expansion
  452. seo=''
  453. bytes=`echo '\1' | wc -c | awk '{ printf("%s", $1); }'`
  454. if [ ".$bytes" != .3 ]; then
  455. bytes=`echo -E '\1' | wc -c | awk '{ printf("%s", $1); }'`
  456. if [ ".$bytes" = .3 ]; then
  457. seo='-E'
  458. fi
  459. fi
  460. # check for existing -n option (to suppress newline)
  461. minusn=''
  462. bytes=`echo -n 123 2>/dev/null | wc -c | awk '{ printf("%s", $1); }'`
  463. if [ ".$bytes" = .3 ]; then
  464. minusn='-n'
  465. fi
  466. # determine terminal bold sequence
  467. term_bold=''
  468. term_norm=''
  469. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[Bb]'`" != . ]; then
  470. case $TERM in
  471. # for the most important terminal types we directly know the sequences
  472. xterm|xterm*|vt220|vt220*)
  473. term_bold=`awk 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }' </dev/null 2>/dev/null`
  474. term_norm=`awk 'BEGIN { printf("%c%c%c", 27, 91, 109); }' </dev/null 2>/dev/null`
  475. ;;
  476. vt100|vt100*|cygwin)
  477. term_bold=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }' </dev/null 2>/dev/null`
  478. term_norm=`awk 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }' </dev/null 2>/dev/null`
  479. ;;
  480. # for all others, we try to use a possibly existing `tput' or `tcout' utility
  481. * )
  482. paths=`echo $PATH | sed -e 's/:/ /g'`
  483. for tool in tput tcout; do
  484. for dir in $paths; do
  485. if [ -r "$dir/$tool" ]; then
  486. for seq in bold md smso; do # 'smso' is last
  487. bold="`$dir/$tool $seq 2>/dev/null`"
  488. if [ ".$bold" != . ]; then
  489. term_bold="$bold"
  490. break
  491. fi
  492. done
  493. if [ ".$term_bold" != . ]; then
  494. for seq in sgr0 me rmso init reset; do # 'reset' is last
  495. norm="`$dir/$tool $seq 2>/dev/null`"
  496. if [ ".$norm" != . ]; then
  497. term_norm="$norm"
  498. break
  499. fi
  500. done
  501. fi
  502. break
  503. fi
  504. done
  505. if [ ".$term_bold" != . ] && [ ".$term_norm" != . ]; then
  506. break;
  507. fi
  508. done
  509. ;;
  510. esac
  511. if [ ".$term_bold" = . ] || [ ".$term_norm" = . ]; then
  512. echo "$msgprefix:Warning: unable to determine terminal sequence for bold mode" 1>&2
  513. term_bold=''
  514. term_norm=''
  515. fi
  516. fi
  517. # determine user name
  518. username=''
  519. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[uUgG]'`" != . ]; then
  520. username="`(id -un) 2>/dev/null`"
  521. if [ ".$username" = . ]; then
  522. str="`(id) 2>/dev/null`"
  523. if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then
  524. username=`echo $str | sed -e 's/^uid[ ]*=[ ]*[0-9]*(//' -e 's/).*$//'`
  525. fi
  526. if [ ".$username" = . ]; then
  527. username="$LOGNAME"
  528. if [ ".$username" = . ]; then
  529. username="$USER"
  530. if [ ".$username" = . ]; then
  531. username="`(whoami) 2>/dev/null |\
  532. awk '{ printf("%s", $1); }'`"
  533. if [ ".$username" = . ]; then
  534. username="`(who am i) 2>/dev/null |\
  535. awk '{ printf("%s", $1); }'`"
  536. if [ ".$username" = . ]; then
  537. username='unknown'
  538. fi
  539. fi
  540. fi
  541. fi
  542. fi
  543. fi
  544. fi
  545. # determine user id
  546. userid=''
  547. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%U'`" != . ]; then
  548. userid="`(id -u) 2>/dev/null`"
  549. if [ ".$userid" = . ]; then
  550. userid="`(id -u ${username}) 2>/dev/null`"
  551. if [ ".$userid" = . ]; then
  552. str="`(id) 2>/dev/null`"
  553. if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then
  554. userid=`echo $str | sed -e 's/^uid[ ]*=[ ]*//' -e 's/(.*$//'`
  555. fi
  556. if [ ".$userid" = . ]; then
  557. userid=`(getent passwd ${username}) 2>/dev/null | \
  558. sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
  559. if [ ".$userid" = . ]; then
  560. userid=`grep "^${username}:" /etc/passwd 2>/dev/null | \
  561. sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
  562. if [ ".$userid" = . ]; then
  563. userid=`(ypmatch "${username}" passwd; nismatch "${username}" passwd) 2>/dev/null | \
  564. sed -e 'q' | sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
  565. if [ ".$userid" = . ]; then
  566. userid=`(nidump passwd . | grep "^${username}:") 2>/dev/null | \
  567. sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
  568. if [ ".$userid" = . ]; then
  569. userid='?'
  570. fi
  571. fi
  572. fi
  573. fi
  574. fi
  575. fi
  576. fi
  577. fi
  578. # determine (primary) group id
  579. groupid=''
  580. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[gG]'`" != . ]; then
  581. groupid="`(id -g ${username}) 2>/dev/null`"
  582. if [ ".$groupid" = . ]; then
  583. str="`(id) 2>/dev/null`"
  584. if [ ".`echo $str | grep 'gid[ ]*=[ ]*[0-9]*('`" != . ]; then
  585. groupid=`echo $str | sed -e 's/^.*gid[ ]*=[ ]*//' -e 's/(.*$//'`
  586. fi
  587. if [ ".$groupid" = . ]; then
  588. groupid=`(getent passwd ${username}) 2>/dev/null | \
  589. sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
  590. if [ ".$groupid" = . ]; then
  591. groupid=`grep "^${username}:" /etc/passwd 2>/dev/null | \
  592. sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
  593. if [ ".$groupid" = . ]; then
  594. groupid=`(ypmatch "${username}" passwd; nismatch "${username}" passwd) 2>/dev/null | \
  595. sed -e 'q' | sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
  596. if [ ".$groupid" = . ]; then
  597. groupid=`(nidump passwd . | grep "^${username}:") 2>/dev/null | \
  598. sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
  599. if [ ".$groupid" = . ]; then
  600. groupid='?'
  601. fi
  602. fi
  603. fi
  604. fi
  605. fi
  606. fi
  607. fi
  608. # determine (primary) group name
  609. groupname=''
  610. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%g'`" != . ]; then
  611. groupname="`(id -gn ${username}) 2>/dev/null`"
  612. if [ ".$groupname" = . ]; then
  613. str="`(id) 2>/dev/null`"
  614. if [ ".`echo $str | grep 'gid[ ]*=[ ]*[0-9]*('`" != . ]; then
  615. groupname=`echo $str | sed -e 's/^.*gid[ ]*=[ ]*[0-9]*(//' -e 's/).*$//'`
  616. fi
  617. if [ ".$groupname" = . ]; then
  618. groupname=`(getent group) 2>/dev/null | \
  619. grep "^[^:]*:[^:]*:${groupid}:" | \
  620. sed -e 's/:.*$//'`
  621. if [ ".$groupname" = . ]; then
  622. groupname=`grep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \
  623. sed -e 's/:.*$//'`
  624. if [ ".$groupname" = . ]; then
  625. groupname=`(ypcat group; niscat group) 2>/dev/null | \
  626. sed -e 'q' | grep "^[^:]*:[^:]*:${groupid}:" | \
  627. sed -e 's/:.*$//'`
  628. if [ ".$groupname" = . ]; then
  629. groupname=`(nidump group .) 2>/dev/null | \
  630. grep "^[^:]*:[^:]*:${groupid}:" | \
  631. sed -e 's/:.*$//'`
  632. if [ ".$groupname" = . ]; then
  633. groupname='?'
  634. fi
  635. fi
  636. fi
  637. fi
  638. fi
  639. fi
  640. fi
  641. # determine host and domain name
  642. hostname=''
  643. domainname=''
  644. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%h'`" != . ]; then
  645. hostname="`(uname -n) 2>/dev/null |\
  646. awk '{ printf("%s", $1); }'`"
  647. if [ ".$hostname" = . ]; then
  648. hostname="`(hostname) 2>/dev/null |\
  649. awk '{ printf("%s", $1); }'`"
  650. if [ ".$hostname" = . ]; then
  651. hostname='unknown'
  652. fi
  653. fi
  654. case $hostname in
  655. *.* )
  656. domainname=".`echo $hostname | cut -d. -f2-`"
  657. hostname="`echo $hostname | cut -d. -f1`"
  658. ;;
  659. esac
  660. fi
  661. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%d'`" != . ]; then
  662. if [ ".$domainname" = . ]; then
  663. if [ -f /etc/resolv.conf ]; then
  664. domainname="`grep '^[ ]*domain' /etc/resolv.conf | sed -e 'q' |\
  665. sed -e 's/.*domain//' \
  666. -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
  667. -e 's/^\.//' -e 's/^/./' |\
  668. awk '{ printf("%s", $1); }'`"
  669. if [ ".$domainname" = . ]; then
  670. domainname="`grep '^[ ]*search' /etc/resolv.conf | sed -e 'q' |\
  671. sed -e 's/.*search//' \
  672. -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
  673. -e 's/ .*//' -e 's/ .*//' \
  674. -e 's/^\.//' -e 's/^/./' |\
  675. awk '{ printf("%s", $1); }'`"
  676. fi
  677. fi
  678. fi
  679. fi
  680. # determine current time
  681. time_day=''
  682. time_month=''
  683. time_year=''
  684. time_monthname=''
  685. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[DMYm]'`" != . ]; then
  686. time_day=`date '+%d'`
  687. time_month=`date '+%m'`
  688. time_year=`date '+%Y' 2>/dev/null`
  689. if [ ".$time_year" = . ]; then
  690. time_year=`date '+%y'`
  691. case $time_year in
  692. [5-9][0-9]) time_year="19$time_year" ;;
  693. [0-4][0-9]) time_year="20$time_year" ;;
  694. esac
  695. fi
  696. case $time_month in
  697. 1|01) time_monthname='Jan' ;;
  698. 2|02) time_monthname='Feb' ;;
  699. 3|03) time_monthname='Mar' ;;
  700. 4|04) time_monthname='Apr' ;;
  701. 5|05) time_monthname='May' ;;
  702. 6|06) time_monthname='Jun' ;;
  703. 7|07) time_monthname='Jul' ;;
  704. 8|08) time_monthname='Aug' ;;
  705. 9|09) time_monthname='Sep' ;;
  706. 10) time_monthname='Oct' ;;
  707. 11) time_monthname='Nov' ;;
  708. 12) time_monthname='Dec' ;;
  709. esac
  710. fi
  711. # expand special ``%x'' constructs
  712. if [ ".$opt_e" = .yes ]; then
  713. text=`echo $seo "$text" |\
  714. sed -e "s/%B/${term_bold}/g" \
  715. -e "s/%b/${term_norm}/g" \
  716. -e "s/%u/${username}/g" \
  717. -e "s/%U/${userid}/g" \
  718. -e "s/%g/${groupname}/g" \
  719. -e "s/%G/${groupid}/g" \
  720. -e "s/%h/${hostname}/g" \
  721. -e "s/%d/${domainname}/g" \
  722. -e "s/%D/${time_day}/g" \
  723. -e "s/%M/${time_month}/g" \
  724. -e "s/%Y/${time_year}/g" \
  725. -e "s/%m/${time_monthname}/g" 2>/dev/null`
  726. fi
  727. # create output
  728. if [ .$opt_n = .no ]; then
  729. echo $seo "$text"
  730. else
  731. # the harder part: echo -n is best, because
  732. # awk may complain about some \xx sequences.
  733. if [ ".$minusn" != . ]; then
  734. echo $seo $minusn "$text"
  735. else
  736. echo dummy | awk '{ printf("%s", TEXT); }' TEXT="$text"
  737. fi
  738. fi
  739. shtool_exit 0
  740. ;;
  741. install )
  742. ##
  743. ## install -- Install a program, script or datafile
  744. ## Copyright (c) 1997-2008 Ralf S. Engelschall <rse@engelschall.com>
  745. ##
  746. # special case: "shtool install -d <dir> [...]" internally
  747. # maps to "shtool mkdir -f -p -m 755 <dir> [...]"
  748. if [ "$opt_d" = yes ]; then
  749. cmd="$0 mkdir -f -p -m 755"
  750. if [ ".$opt_o" != . ]; then
  751. cmd="$cmd -o '$opt_o'"
  752. fi
  753. if [ ".$opt_g" != . ]; then
  754. cmd="$cmd -g '$opt_g'"
  755. fi
  756. if [ ".$opt_v" = .yes ]; then
  757. cmd="$cmd -v"
  758. fi
  759. if [ ".$opt_t" = .yes ]; then
  760. cmd="$cmd -t"
  761. fi
  762. for dir in "$@"; do
  763. eval "$cmd $dir" || shtool_exit $?
  764. done
  765. shtool_exit 0
  766. fi
  767. # determine source(s) and destination
  768. argc=$#
  769. srcs=""
  770. while [ $# -gt 1 ]; do
  771. srcs="$srcs $1"
  772. shift
  773. done
  774. dstpath="$1"
  775. # type check for destination
  776. dstisdir=0
  777. if [ -d $dstpath ]; then
  778. dstpath=`echo "$dstpath" | sed -e 's:/$::'`
  779. dstisdir=1
  780. fi
  781. # consistency check for destination
  782. if [ $argc -gt 2 ] && [ $dstisdir = 0 ]; then
  783. echo "$msgprefix:Error: multiple sources require destination to be directory" 1>&2
  784. shtool_exit 1
  785. fi
  786. # iterate over all source(s)
  787. for src in $srcs; do
  788. dst=$dstpath
  789. # if destination is a directory, append the input filename
  790. if [ $dstisdir = 1 ]; then
  791. dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'`
  792. dst="$dst/$dstfile"
  793. fi
  794. # check for correct arguments
  795. if [ ".$src" = ".$dst" ]; then
  796. echo "$msgprefix:Warning: source and destination are the same - skipped" 1>&2
  797. continue
  798. fi
  799. if [ -d "$src" ]; then
  800. echo "$msgprefix:Warning: source \`$src' is a directory - skipped" 1>&2
  801. continue
  802. fi
  803. # make a temp file name in the destination directory
  804. dsttmp=`echo $dst |\
  805. sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;' \
  806. -e "s;\$;/#INST@$$#;"`
  807. # verbosity
  808. if [ ".$opt_v" = .yes ]; then
  809. echo "$src -> $dst" 1>&2
  810. fi
  811. # copy or move the file name to the temp name
  812. # (because we might be not allowed to change the source)
  813. if [ ".$opt_C" = .yes ]; then
  814. opt_c=yes
  815. fi
  816. if [ ".$opt_c" = .yes ]; then
  817. if [ ".$opt_t" = .yes ]; then
  818. echo "cp $src $dsttmp" 1>&2
  819. fi
  820. cp "$src" "$dsttmp" || shtool_exit $?
  821. else
  822. if [ ".$opt_t" = .yes ]; then
  823. echo "mv $src $dsttmp" 1>&2
  824. fi
  825. mv "$src" "$dsttmp" || shtool_exit $?
  826. fi
  827. # adjust the target file
  828. if [ ".$opt_e" != . ]; then
  829. sed='sed'
  830. OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS"
  831. for e
  832. do
  833. sed="$sed -e '$e'"
  834. done
  835. cp "$dsttmp" "$dsttmp.old"
  836. chmod u+w $dsttmp
  837. eval "$sed <$dsttmp.old >$dsttmp" || shtool_exit $?
  838. rm -f $dsttmp.old
  839. fi
  840. if [ ".$opt_s" = .yes ]; then
  841. if [ ".$opt_t" = .yes ]; then
  842. echo "strip $dsttmp" 1>&2
  843. fi
  844. strip $dsttmp || shtool_exit $?
  845. fi
  846. if [ ".$opt_o" != . ]; then
  847. if [ ".$opt_t" = .yes ]; then
  848. echo "chown $opt_o $dsttmp" 1>&2
  849. fi
  850. chown $opt_o $dsttmp || shtool_exit $?
  851. fi
  852. if [ ".$opt_g" != . ]; then
  853. if [ ".$opt_t" = .yes ]; then
  854. echo "chgrp $opt_g $dsttmp" 1>&2
  855. fi
  856. chgrp $opt_g $dsttmp || shtool_exit $?
  857. fi
  858. if [ ".$opt_m" != ".-" ]; then
  859. if [ ".$opt_t" = .yes ]; then
  860. echo "chmod $opt_m $dsttmp" 1>&2
  861. fi
  862. chmod $opt_m $dsttmp || shtool_exit $?
  863. fi
  864. # determine whether to do a quick install
  865. # (has to be done _after_ the strip was already done)
  866. quick=no
  867. if [ ".$opt_C" = .yes ]; then
  868. if [ -r $dst ]; then
  869. if cmp -s "$src" "$dst"; then
  870. quick=yes
  871. fi
  872. fi
  873. fi
  874. # finally, install the file to the real destination
  875. if [ $quick = yes ]; then
  876. if [ ".$opt_t" = .yes ]; then
  877. echo "rm -f $dsttmp" 1>&2
  878. fi
  879. rm -f $dsttmp
  880. else
  881. if [ ".$opt_t" = .yes ]; then
  882. echo "rm -f $dst && mv $dsttmp $dst" 1>&2
  883. fi
  884. rm -f $dst && mv $dsttmp $dst
  885. fi
  886. done
  887. shtool_exit 0
  888. ;;
  889. mkdir )
  890. ##
  891. ## mkdir -- Make one or more directories
  892. ## Copyright (c) 1996-2008 Ralf S. Engelschall <rse@engelschall.com>
  893. ##
  894. errstatus=0
  895. for p in ${1+"$@"}; do
  896. # if the directory already exists...
  897. if [ -d "$p" ]; then
  898. if [ ".$opt_f" = .no ] && [ ".$opt_p" = .no ]; then
  899. echo "$msgprefix:Error: directory already exists: $p" 1>&2
  900. errstatus=1
  901. break
  902. else
  903. continue
  904. fi
  905. fi
  906. # if the directory has to be created...
  907. if [ ".$opt_p" = .no ]; then
  908. if [ ".$opt_t" = .yes ]; then
  909. echo "mkdir $p" 1>&2
  910. fi
  911. mkdir $p || errstatus=$?
  912. if [ ".$opt_o" != . ]; then
  913. if [ ".$opt_t" = .yes ]; then
  914. echo "chown $opt_o $p" 1>&2
  915. fi
  916. chown $opt_o $p || errstatus=$?
  917. fi
  918. if [ ".$opt_g" != . ]; then
  919. if [ ".$opt_t" = .yes ]; then
  920. echo "chgrp $opt_g $p" 1>&2
  921. fi
  922. chgrp $opt_g $p || errstatus=$?
  923. fi
  924. if [ ".$opt_m" != . ]; then
  925. if [ ".$opt_t" = .yes ]; then
  926. echo "chmod $opt_m $p" 1>&2
  927. fi
  928. chmod $opt_m $p || errstatus=$?
  929. fi
  930. else
  931. # the smart situation
  932. set fnord `echo ":$p" |\
  933. sed -e 's/^:\//%/' \
  934. -e 's/^://' \
  935. -e 's/\// /g' \
  936. -e 's/^%/\//'`
  937. shift
  938. pathcomp=''
  939. for d in ${1+"$@"}; do
  940. pathcomp="$pathcomp$d"
  941. case "$pathcomp" in
  942. -* ) pathcomp="./$pathcomp" ;;
  943. esac
  944. if [ ! -d "$pathcomp" ]; then
  945. if [ ".$opt_t" = .yes ]; then
  946. echo "mkdir $pathcomp" 1>&2
  947. fi
  948. # See https://bugs.php.net/51076
  949. # The fix is from Debian who have sent it
  950. # upstream, too; but upstream seems dead.
  951. mkdir $pathcomp || {
  952. _errstatus=$?
  953. [ -d "$pathcomp" ] || errstatus=${_errstatus}
  954. unset _errstatus
  955. }
  956. if [ ".$opt_o" != . ]; then
  957. if [ ".$opt_t" = .yes ]; then
  958. echo "chown $opt_o $pathcomp" 1>&2
  959. fi
  960. chown $opt_o $pathcomp || errstatus=$?
  961. fi
  962. if [ ".$opt_g" != . ]; then
  963. if [ ".$opt_t" = .yes ]; then
  964. echo "chgrp $opt_g $pathcomp" 1>&2
  965. fi
  966. chgrp $opt_g $pathcomp || errstatus=$?
  967. fi
  968. if [ ".$opt_m" != . ]; then
  969. if [ ".$opt_t" = .yes ]; then
  970. echo "chmod $opt_m $pathcomp" 1>&2
  971. fi
  972. chmod $opt_m $pathcomp || errstatus=$?
  973. fi
  974. fi
  975. pathcomp="$pathcomp/"
  976. done
  977. fi
  978. done
  979. shtool_exit $errstatus
  980. ;;
  981. platform )
  982. ##
  983. ## platform -- Platform Identification Utility
  984. ## Copyright (c) 2003-2008 Ralf S. Engelschall <rse@engelschall.com>
  985. ##
  986. # option post-processing
  987. if [ ".$opt_t" != . ]; then
  988. case "$opt_t" in
  989. binary )
  990. # binary package id (OpenPKG RPM)
  991. opt_F="%<ap>-%<sp>"
  992. opt_L=yes
  993. opt_S=""
  994. opt_C="+"
  995. ;;
  996. build )
  997. # build time checking (OpenPKG RPM)
  998. opt_F="%<at>-%<st>"
  999. opt_L=yes
  1000. opt_S=""
  1001. opt_C="+"
  1002. ;;
  1003. gnu )
  1004. # GNU config.guess style <arch>-<vendor>-<os><osversion>
  1005. opt_F="%<at>-unknown-%<st>"
  1006. opt_L=yes
  1007. opt_S=""
  1008. opt_C="+"
  1009. ;;
  1010. web )
  1011. # non-whitespace HTTP Server-header id
  1012. opt_F="%<sp>-%<ap>"
  1013. opt_S="/"
  1014. opt_C="+"
  1015. ;;
  1016. summary)
  1017. # human readable verbose summary information
  1018. opt_F="Class: %[sc] (%[ac])\\nProduct: %[sp] (%[ap])\\nTechnology: %[st] (%[at])"
  1019. opt_S=" "
  1020. opt_C="/"
  1021. ;;
  1022. all-in-one )
  1023. # full-table all-in-one information
  1024. opt_F=""
  1025. opt_F="${opt_F}concise architecture class: %<ac>\\n"
  1026. opt_F="${opt_F}regular architecture class: %{ac}\\n"
  1027. opt_F="${opt_F}verbose architecture class: %[ac]\\n"
  1028. opt_F="${opt_F}concise architecture product: %<ap>\\n"
  1029. opt_F="${opt_F}regular architecture product: %{ap}\\n"
  1030. opt_F="${opt_F}verbose architecture product: %[ap]\\n"
  1031. opt_F="${opt_F}concise architecture technology: %<at>\\n"
  1032. opt_F="${opt_F}regular architecture technology: %{at}\\n"
  1033. opt_F="${opt_F}verbose architecture technology: %[at]\\n"
  1034. opt_F="${opt_F}concise system class: %<sc>\\n"
  1035. opt_F="${opt_F}regular system class: %{sc}\\n"
  1036. opt_F="${opt_F}verbose system class: %[sc]\\n"
  1037. opt_F="${opt_F}concise system product: %<sp>\\n"
  1038. opt_F="${opt_F}regular system product: %{sp}\\n"
  1039. opt_F="${opt_F}verbose system product: %[sp]\\n"
  1040. opt_F="${opt_F}concise system technology: %<st>\\n"
  1041. opt_F="${opt_F}regular system technology: %{st}\\n"
  1042. opt_F="${opt_F}verbose system technology: %[st]"
  1043. ;;
  1044. * )
  1045. echo "$msgprefix:Error: invalid type \`$opt_t'" 1>&2
  1046. exit 1
  1047. ;;
  1048. esac
  1049. fi
  1050. # assemble initial platform information
  1051. UNAME_MACHINE=`(uname -m) 2>/dev/null` ||\
  1052. UNAME_MACHINE=`(uname -p) 2>/dev/null` ||\
  1053. UNAME_MACHINE='unknown'
  1054. UNAME_SYSTEM=`(uname -s) 2>/dev/null` ||\
  1055. UNAME_SYSTEM='unknown'
  1056. UNAME_RELEASE=`(uname -r) 2>/dev/null` ||\
  1057. UNAME_RELEASE=`(uname -v) 2>/dev/null` ||\
  1058. UNAME_RELEASE='unknown'
  1059. UNAME="${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}"
  1060. AC=""; AP=""; AT=""
  1061. SC=""; SP=""; ST=""
  1062. # dispatch into platform specific sections
  1063. case "${UNAME}" in
  1064. # FreeBSD
  1065. *:FreeBSD:* )
  1066. # determine architecture
  1067. AC="${UNAME_MACHINE}"
  1068. case "${AC}" in
  1069. i386 ) AC="iX86" ;;
  1070. esac
  1071. AP="${AC}"
  1072. AT="${AP}"
  1073. if [ ".${AT}" = ".iX86" ]; then
  1074. case "`(/sbin/sysctl -n hw.model) 2>&1`" in
  1075. *"Xeon"* | *"Pentium Pro"* | *"Cyrix 6x86MX"* | *"Pentium II"* | *"Pentium III"* | *"Pentium 4"* | *"Celeron"* ) AT="i686" ;;
  1076. *"Pentium"* ) AT="i586" ;; *"i486[SD]X"* | *"Cyrix 486"* | *"Cyrix [56]x86"* | *"Blue Lightning" | *"Cyrix 486S/DX" ) AT="i486" ;;
  1077. *"i386[SD]X"* | *"NexGen 586"* ) AT="i386" ;;
  1078. esac
  1079. fi
  1080. # determine system
  1081. r=`echo "${UNAME_RELEASE}" |\
  1082. sed -e 's;[()];;' -e 's/\(-.*\)$/[\1]/'`
  1083. ST="FreeBSD ${r}"
  1084. SP="${ST}"
  1085. case "${r}" in
  1086. 1.* ) SC="4.3BSD" ;;
  1087. * ) SC="4.4BSD" ;;
  1088. esac
  1089. ;;
  1090. # NetBSD
  1091. *:NetBSD:* )
  1092. # determine architecture
  1093. AT="${UNAME_MACHINE}"
  1094. AP="${AT}"
  1095. case "${AP}" in
  1096. i[3-6]86 ) AP="iX86" ;;
  1097. esac
  1098. AC="${AP}"
  1099. # determine system
  1100. r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
  1101. ST="NetBSD ${r}"
  1102. SP="${ST}"
  1103. case "${r}" in
  1104. 0.* ) SC="4.3BSD" ;;
  1105. * ) SC="4.4BSD" ;;
  1106. esac
  1107. ;;
  1108. # OpenBSD
  1109. *:OpenBSD:* )
  1110. # determine architecture
  1111. AT="${UNAME_MACHINE}"
  1112. AP="${AT}"
  1113. case "${AP}" in
  1114. i[3-6]86 ) AP="iX86" ;;
  1115. esac
  1116. AC="${AP}"
  1117. # determine system
  1118. r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
  1119. ST="OpenBSD ${r}"
  1120. SP="${ST}"
  1121. SC="4.4BSD"
  1122. ;;
  1123. # DragonFly BSD
  1124. *:DragonFly:* )
  1125. # determine architecture
  1126. AT="${UNAME_MACHINE}"
  1127. AP="${AT}"
  1128. case "${AP}" in
  1129. i[3-6]86 ) AP="iX86" ;;
  1130. esac
  1131. AC="${AP}"
  1132. # determine system
  1133. r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
  1134. ST="DragonFly ${r}"
  1135. SP="${ST}"
  1136. SC="4.4BSD"
  1137. ;;
  1138. # GNU/Linux
  1139. *:Linux:* )
  1140. # determine architecture
  1141. AT="${UNAME_MACHINE}"
  1142. case "${AT}" in
  1143. ia64 ) AT="IA64" ;;
  1144. x86_64 ) AT='AMD64' ;;
  1145. parisc ) AT="HPPA32" ;;
  1146. parisc64 ) AT="HPPA64" ;;
  1147. esac
  1148. AP="${AT}"
  1149. case "${AP}" in
  1150. i[3-6]86 ) AP='iX86' ;;
  1151. esac
  1152. AC="${AP}"
  1153. # determine system
  1154. v_kern=`echo "${UNAME_RELEASE}" |\
  1155. sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/'`
  1156. v_libc=`(strings /lib/libc.so.* | grep '^GLIBC_' | sed -e 's/^GLIBC_//' |\
  1157. env -i sort -n | sed -n -e '$p' | sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/') 2>/dev/null`
  1158. ST="GNU/<Linux >${v_libc}/<${v_kern}>"
  1159. if [ -f /etc/lsb-release ]; then
  1160. eval `( . /etc/lsb-release
  1161. echo "SC=\"LSB${LSB_VERSION}\""
  1162. if [ ".${DISTRIB_ID}" != . -a ".${DISTRIB_RELEASE}" != . ]; then
  1163. echo "SP=\"${DISTRIB_ID} ${DISTRIB_RELEASE}\""
  1164. fi
  1165. ) 2>/dev/null`
  1166. fi
  1167. if [ ".$SP" = . ]; then
  1168. for tagfile in x \
  1169. `cd /etc && \
  1170. /bin/ls *[_-]release *[_-]version 2>/dev/null | env -i sort | \
  1171. sed -e '/^redhat-release$/d' -e '/^lsb-release$/d'; \
  1172. echo redhat-release lsb-release`
  1173. do
  1174. [ ".${tagfile}" = .x ] && continue
  1175. [ ! -f "/etc/${tagfile}" ] && continue
  1176. n=`echo ${tagfile} | sed -e 's/[_-]release$//' -e 's/[_-]version$//'`
  1177. v=`(grep VERSION /etc/${tagfile}; cat /etc/${tagfile}) | grep '[0-9]' | sed -e 'q' |\
  1178. sed -e 's/^/#/' \
  1179. -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
  1180. -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
  1181. -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
  1182. -e 's/^#.*$//'`
  1183. case "`util_lower ${n}`" in
  1184. redhat )
  1185. if [ ".`egrep '(Red Hat Enterprise Linux|CentOS)' /etc/${tagfile}`" != . ]; then
  1186. n="<R>ed <H>at <E>nterprise <L>inux"
  1187. else
  1188. n="<R>ed <H>at <L>inux"
  1189. fi
  1190. ;;
  1191. debian ) n="Debian[ GNU/Linux]" ;;
  1192. ubuntu ) n="Ubuntu[ GNU/Linux]" ;;
  1193. fedora ) n="<Fedora> Core[ GNU/Linux]" ;;
  1194. suse ) n="[Novell ]SUSE[ Linux]" ;;
  1195. mandrake*|mandriva ) n="Mandriva[ Linux]" ;;
  1196. gentoo ) n="Gentoo[ GNU/Linux]" ;;
  1197. slackware ) n="Slackware[ Linux]" ;;
  1198. turbolinux ) n="TurboLinux" ;;
  1199. unitedlinux ) n="UnitedLinux" ;;
  1200. * ) n="${n}[ GNU/Linux]" ;;
  1201. esac
  1202. case "$n" in
  1203. *"<"*">"* ) SP="$n <$v>" ;;
  1204. * ) SP="$n $v" ;;
  1205. esac
  1206. break
  1207. done
  1208. fi
  1209. [ ".$SP" = . ] && SP="${ST}"
  1210. [ ".$SC" = . ] && SC="LSB"
  1211. ;;
  1212. # Sun Solaris
  1213. *:SunOS:* )
  1214. # determine architecture
  1215. AT="${UNAME_MACHINE}"
  1216. case "${AT}" in
  1217. i86pc )
  1218. AT="iX86"
  1219. case "`(/bin/isainfo -k) 2>&1`" in
  1220. amd64 ) AT="AMD64" ;;
  1221. esac
  1222. ;;
  1223. esac
  1224. AP="${AT}"
  1225. case "${AP}" in
  1226. sun4[cdm] ) AP="SPARC32" ;;
  1227. sun4[uv] ) AP="SPARC64" ;;
  1228. sun4* ) AP="SPARC" ;;
  1229. esac
  1230. AC="${AP}"
  1231. case "${AC}" in
  1232. SPARC* ) AC="SPARC" ;;
  1233. esac
  1234. # determine system
  1235. ST="[Sun ]SunOS ${UNAME_RELEASE}"
  1236. v=`echo "${UNAME_RELEASE}" |\
  1237. sed -e 's;^4\.;1.;' \
  1238. -e 's;^5\.\([0-6]\)[^0-9]*$;2.\1;' \
  1239. -e 's;^5\.\([0-9][0-9]*\).*;\1;'`
  1240. SP="[Sun ]Solaris $v"
  1241. case "${UNAME_RELEASE}" in
  1242. 4.* ) SC="4.3BSD" ;;
  1243. 5.* ) SC="SVR4" ;;
  1244. esac
  1245. ;;
  1246. # SCO UnixWare
  1247. *:UnixWare:* )
  1248. # determine architecture
  1249. AT="${UNAME_MACHINE}"
  1250. case "${AT}" in
  1251. i[3-6]86 | ix86at ) AT="iX86" ;;
  1252. esac
  1253. AP="${AT}"
  1254. # determine system
  1255. v=`/sbin/uname -v`
  1256. ST="[SCO ]UnixWare ${v}"
  1257. SP="${ST}"
  1258. SC="SVR${UNAME_RELEASE}"
  1259. ;;
  1260. # QNX
  1261. *:QNX:* )
  1262. # determine architecture
  1263. AT="${UNAME_MACHINE}"
  1264. case "${AT}" in
  1265. x86pc ) AT="iX86" ;;
  1266. esac
  1267. AP="${AT}"
  1268. # determine system
  1269. v="${UNAME_RELEASE}"
  1270. ST="QNX[ Neutrino RTOS] ${v}"
  1271. v=`echo "${v}" | sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\).*$;\1;'`
  1272. SP="QNX[ Neutrino RTOS] ${v}"
  1273. SC="QNX"
  1274. ;;
  1275. # SGI IRIX
  1276. *:IRIX*:* )
  1277. # determine architecture
  1278. AT="${UNAME_MACHINE}"
  1279. AP="${AT}"
  1280. case "${AP}:${UNAME_SYSTEM}" in
  1281. IP*:IRIX64 ) AP="MIPS64" ;;
  1282. IP*:* ) AP="MIPS" ;;
  1283. esac
  1284. AC="${AP}"
  1285. # determine system
  1286. v=`(/bin/uname -R || /bin/uname -r) 2>/dev/null | sed -e 's;[0-9.]* ;;'`
  1287. ST="[SGI ]IRIX ${v}"
  1288. v="${UNAME_RELEASE}"
  1289. SP="[SGI ]IRIX ${v}"
  1290. SC="4.2BSD/SVR3"
  1291. ;;
  1292. # HP HP-UX
  1293. *:HP-UX:* )
  1294. # determine architecture
  1295. AT="${UNAME_MACHINE}"
  1296. case "${AT}" in
  1297. ia64 ) AT="IA64" ;;
  1298. 9000/[34]?? ) AT=M68K ;;
  1299. 9000/[678][0-9][0-9])
  1300. sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
  1301. sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
  1302. case "${sc_cpu_version}" in
  1303. 523 ) AT="HPPA1.0" ;;
  1304. 528 ) AT="HPPA1.1" ;;
  1305. 532 ) AT="HPPA2.0"
  1306. case "${sc_kernel_bits}" in
  1307. 32 ) AT="${AT}n" ;;
  1308. 64 ) AT="${AT}w" ;;
  1309. esac
  1310. ;;
  1311. esac
  1312. ;;
  1313. esac
  1314. AP="${AT}"
  1315. case "${AP}" in
  1316. HPPA* ) AP="HPPA" ;;
  1317. esac
  1318. AC="${AP}"
  1319. # determine system
  1320. v=`echo "${UNAME_RELEASE}" | sed -e 's;^[^0-9]*;;'`
  1321. ST="[HP ]<HP>-<UX ${v}>"
  1322. SP="${ST}"
  1323. case "${v}" in
  1324. 10.* ) SC="SVR4.2" ;;
  1325. [7-9]* ) SC="SVR4" ;;
  1326. esac
  1327. ;;
  1328. # HP Tru64 (OSF1)
  1329. *:OSF1:* )
  1330. # determine architecture
  1331. AP="${UNAME_MACHINE}"
  1332. case "${AP}" in
  1333. alpha ) AP="Alpha" ;;
  1334. esac
  1335. alpha_type=`(/usr/sbin/psrinfo -v) 2>/dev/null |\
  1336. sed -n -e 's/^.*The alpha \([^ ][^ ]*\).*processor.*$/\1/p' | sed -e 'q'`
  1337. AT="${AP}${alpha_type}"
  1338. AC="${AP}"
  1339. # determine system
  1340. v=`echo "${UNAME_RELEASE}" | sed -e 's;^[VTX];;'`
  1341. ST="[HP ]Tru64 ${v}"
  1342. SP="${ST}"
  1343. SC="OSF1"
  1344. ;;
  1345. # IBM AIX
  1346. *:AIX:* )
  1347. # determine architecture
  1348. cpu_arch=RS6000
  1349. if [ -x /usr/sbin/lsdev -a -x /usr/sbin/lsattr ]; then
  1350. cpu_id=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
  1351. if [ ".`/usr/sbin/lsattr -El ${cpu_id} | grep -i powerpc`" != . ]; then
  1352. cpu_arch=PPC
  1353. fi
  1354. elif [ -d /QOpenSys ]; then
  1355. # IBM i5/OS (aka OS/400) with PASE (Portable Application Solutions Environment)
  1356. cpu_arch=PPC
  1357. fi
  1358. if [ -x /usr/bin/oslevel ]; then
  1359. os_level=`/usr/bin/oslevel`
  1360. else
  1361. os_level="`uname -v`.`uname -r`"
  1362. fi
  1363. os_level=`echo "${os_level}" |\
  1364. sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\)\(.*\)$;<\1>\2[\3];' \
  1365. -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(.*\)$;<\1>\2;'`
  1366. AT="${cpu_arch}"
  1367. AP="${AT}"
  1368. AC="${AP}"
  1369. # determine system
  1370. ST="[IBM ]<AIX >${os_level}"
  1371. SP="${ST}"
  1372. case "${os_level}" in
  1373. [12]* ) SC="SVR2" ;;
  1374. * ) SC="SVR4" ;;
  1375. esac
  1376. ;;
  1377. # Apple Mac OS X (Darwin)
  1378. *:Darwin:* )
  1379. # determine architecture
  1380. AT="`uname -p`"
  1381. case "${AT}" in
  1382. powerpc ) AT="PPC" ;;
  1383. esac
  1384. AP="${AT}"
  1385. case "${AP}" in
  1386. i?86 ) AP="iX86" ;;
  1387. esac
  1388. AC="${AP}"
  1389. # determine system
  1390. unset v1; unset v2; unset v3
  1391. eval `echo "${UNAME_RELEASE}" |\
  1392. sed -e 's/^/#/' \
  1393. -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
  1394. -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
  1395. -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
  1396. -e 's/^#.*$/v1="0"/'`
  1397. ST="[Apple ]<${UNAME_SYSTEM} ${v1}>${v2+.$v2}${v3+[.$v3]}"
  1398. SP="$ST"
  1399. v="`(sw_vers) 2>/dev/null | grep 'ProductVersion:' | sed -e 's/^ProductVersion:[^0-9]*\([0-9][0-9.]*\).*$/\1/'`"
  1400. if [ ".$v" = . ]; then
  1401. for name in System Server; do
  1402. if [ -f /System/Library/CoreServices/${name}Version.plist ]; then
  1403. v=`(defaults read "/System/Library/CoreServices/${name}Version" "ProductVersion") 2>/dev/null`
  1404. [ ".$v" != . ] && break
  1405. fi
  1406. done
  1407. fi
  1408. if [ ".$v" != . ]; then
  1409. unset v1; unset v2; unset v3
  1410. eval `echo "${v}" |\
  1411. sed -e 's/^/#/' \
  1412. -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
  1413. -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
  1414. -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
  1415. -e 's/^#.*$/v1="0"/'`
  1416. SP="[Apple ]Mac OS X ${v1}${v2+.$v2}${v3+[.$v3]}"
  1417. fi
  1418. SC="4.4BSD/Mach3.0"
  1419. ;;
  1420. # Windows/Cygwin
  1421. *:CYGWIN*:* )
  1422. # determine architecture
  1423. AT="`uname -m`"
  1424. AP="${AT}"
  1425. case "${AP}" in
  1426. i?86 ) AP="iX86" ;;
  1427. esac
  1428. AC="${AP}"
  1429. # determine system
  1430. unset v1; unset v2; unset v3
  1431. eval `echo "${UNAME_RELEASE}" |\
  1432. sed -e 's/^/#/' \
  1433. -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
  1434. -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
  1435. -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
  1436. -e 's/^#.*$/v1="0"/'`
  1437. ST="Cygwin ${v1}${v2+.$v2}${v3+[.$v3]}"
  1438. SP="$ST"
  1439. SC="Windows"
  1440. v=`echo "${UNAME_SYSTEM}" | sed -e 's/^CYGWIN_NT-//' |\
  1441. sed -e 's/^/#/' -e 's/^#\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' -e 's/^#.*$//'`
  1442. case "$v" in
  1443. 4.0 ) SC="$SC[ NT]" ;;
  1444. 5.0 ) SC="$SC[ 2000]" ;;
  1445. 5.1 ) SC="$SC[ XP]" ;;
  1446. 6.0 ) SC="$SC[ Vista]" ;;
  1447. esac
  1448. ;;
  1449. # TODO ...ADD YOUR NEW PLATFORM CHECK HERE... TODO
  1450. # *:XXX:* )
  1451. # ...
  1452. # ;;
  1453. # ...A STILL UNKNOWN PLATFORM...
  1454. * )
  1455. AT=`echo "${UNAME_MACHINE}" | sed -e "s; ;${opt_C};g"`
  1456. AP="${AT}"
  1457. AC="${AP}"
  1458. v=`echo "${UNAME_RELEASE}" |\
  1459. sed -e 's/^/#/' \
  1460. -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
  1461. -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
  1462. -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
  1463. -e 's/^#.*$/?/'`
  1464. ST="${UNAME_SYSTEM} ${v}"
  1465. SP="${ST}"
  1466. SC="${SP}"
  1467. ;;
  1468. esac
  1469. # provide fallback values
  1470. [ ".$AT" = . ] && AT="${AP:-${AC}}"
  1471. [ ".$AP" = . ] && AP="${AT:-${AC}}"
  1472. [ ".$AC" = . ] && AC="${AP:-${AT}}"
  1473. [ ".$ST" = . ] && ST="${SP:-${SC}}"
  1474. [ ".$SP" = . ] && SP="${ST:-${SC}}"
  1475. [ ".$SC" = . ] && SC="${SP:-${ST}}"
  1476. # support explicit enforced verbose/concise output
  1477. if [ ".$opt_v" = .yes ]; then
  1478. opt_F=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%[\1]/g'`
  1479. elif [ ".$opt_c" = .yes ]; then
  1480. opt_F=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%<\1>/g'`
  1481. fi
  1482. # provide verbose and concise variants
  1483. AC_V=""; AC_N=""; AC_C=""
  1484. AP_V=""; AP_N=""; AP_C=""
  1485. AT_V=""; AT_N=""; AT_C=""
  1486. SC_V=""; SC_N=""; SC_C=""
  1487. SP_V=""; SP_N=""; SP_C=""
  1488. ST_V=""; ST_N=""; ST_C=""
  1489. for var_lc in at ap ac st sp sc; do
  1490. case "$opt_F" in
  1491. *"%[${val_lc}]"* | *"%{${val_lc}}"* | *"%${val_lc}"* | *"%<${val_lc}>"* )
  1492. var_uc=`util_upper "$var_lc"`
  1493. eval "val=\"\$${var_uc}\""
  1494. val_V=""; val_N=""; val_C=""
  1495. case "$opt_F" in
  1496. *"%[${var_lc}]"* )
  1497. val_V=`echo ":$val" | \
  1498. sed -e 's/^://' \
  1499. -e 's;\[\([^]]*\)\];\1;g' \
  1500. -e 's;<\([^>]*\)>;\1;g' \
  1501. -e "s; ;§§;g" \
  1502. -e "s;/;%%;g" \
  1503. -e "s;§§;${opt_S};g" \
  1504. -e "s;%%;${opt_C};g"`
  1505. eval "${var_uc}_V=\"\${val_V}\""
  1506. ;;
  1507. esac
  1508. case "$opt_F" in
  1509. *"%{${var_lc}}"* | *"%${var_lc}"* )
  1510. val_N=`echo ":$val" | \
  1511. sed -e 's/^://' \
  1512. -e 's;\[\([^]]*\)\];;g' \
  1513. -e 's;<\([^>]*\)>;\1;g' \
  1514. -e "s; ;§§;g" \
  1515. -e "s;/;%%;g" \
  1516. -e "s;§§;${opt_S};g" \
  1517. -e "s;%%;${opt_C};g"`
  1518. eval "${var_uc}_N=\"\${val_N}\""
  1519. ;;
  1520. esac
  1521. case "$opt_F" in
  1522. *"%<${var_lc}>"* )
  1523. val_C=`echo ":$val" | \
  1524. sed -e 's/^://' \
  1525. -e 's;\[\([^]]*\)\];;g' \
  1526. -e 's;[^<]*<\([^>]*\)>[^<]*;\1;g' \
  1527. -e "s; ;§§;g" \
  1528. -e "s;/;%%;g" \
  1529. -e "s;§§;${opt_S};g" \
  1530. -e "s;%%;${opt_C};g"`
  1531. eval "${var_uc}_C=\"\${val_C}\""
  1532. ;;
  1533. esac
  1534. ;;
  1535. esac
  1536. done
  1537. # create output string
  1538. output=`echo ":$opt_F" |\
  1539. sed -e "s/^://" \
  1540. -e "s;%\\[ac\\];${AC_V};g" \
  1541. -e "s;%{ac};${AC_N};g" \
  1542. -e "s;%ac;${AC_N};g" \
  1543. -e "s;%<ac>;${AC_C};g" \
  1544. -e "s;%\\[ap\\];${AP_V};g" \
  1545. -e "s;%{ap};${AP_N};g" \
  1546. -e "s;%ap;${AP_N};g" \
  1547. -e "s;%<ap>;${AP_C};g" \
  1548. -e "s;%\\[at\\];${AT_V};g" \
  1549. -e "s;%{at};${AT_N};g" \
  1550. -e "s;%at;${AT_N};g" \
  1551. -e "s;%<at>;${AT_C};g" \
  1552. -e "s;%\\[sc\\];${SC_V};g" \
  1553. -e "s;%{sc};${SC_N};g" \
  1554. -e "s;%sc;${SC_N};g" \
  1555. -e "s;%<sc>;${SC_C};g" \
  1556. -e "s;%\\[sp\\];${SP_V};g" \
  1557. -e "s;%{sp};${SP_N};g" \
  1558. -e "s;%sp;${SP_N};g" \
  1559. -e "s;%<sp>;${SP_C};g" \
  1560. -e "s;%\\[st\\];${ST_V};g" \
  1561. -e "s;%{st};${ST_N};g" \
  1562. -e "s;%st;${ST_N};g" \
  1563. -e "s;%<st>;${ST_C};g" \
  1564. -e 's/\\\\n/^/g' |\
  1565. tr '^' '\012'`
  1566. # support lower/upper-case mapping
  1567. if [ ".$opt_L" = .yes ]; then
  1568. output=`util_lower "$output"`
  1569. elif [ ".$opt_U" = .yes ]; then
  1570. output=`util_upper "$output"`
  1571. fi
  1572. # display output string
  1573. if [ ".$opt_n" = .yes ]; then
  1574. echo . | awk '{ printf("%s", output); }' output="$output"
  1575. else
  1576. echo "$output"
  1577. fi
  1578. shtool_exit 0
  1579. ;;
  1580. path )
  1581. ##
  1582. ## path -- Deal with program paths
  1583. ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
  1584. ##
  1585. namelist="$*"
  1586. # check whether the test command supports the -x option
  1587. if [ -x /bin/sh ] 2>/dev/null; then
  1588. minusx="-x"
  1589. else
  1590. minusx="-r"
  1591. fi
  1592. # split path string
  1593. paths="`echo $opt_p |\
  1594. sed -e 's/^:/.:/' \
  1595. -e 's/::/:.:/g' \
  1596. -e 's/:$/:./' \
  1597. -e 's/:/ /g'`"
  1598. # SPECIAL REQUEST
  1599. # translate forward to reverse path
  1600. if [ ".$opt_r" = .yes ]; then
  1601. if [ "x$namelist" = "x." ]; then
  1602. rp='.'
  1603. else
  1604. rp=''
  1605. for pe in `IFS="$IFS/"; echo $namelist`; do
  1606. rp="../$rp"
  1607. done
  1608. fi
  1609. echo $rp | sed -e 's:/$::'
  1610. shtool_exit 0
  1611. fi
  1612. # SPECIAL REQUEST
  1613. # strip out directory or base name
  1614. if [ ".$opt_d" = .yes ]; then
  1615. echo "$namelist" |\
  1616. sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'
  1617. shtool_exit 0
  1618. fi
  1619. if [ ".$opt_b" = .yes ]; then
  1620. echo "$namelist" |\
  1621. sed -e 's;.*/\([^/]*\)$;\1;'
  1622. shtool_exit 0
  1623. fi
  1624. # MAGIC SITUATION
  1625. # Perl Interpreter (perl)
  1626. if [ ".$opt_m" = .yes ] && [ ".$namelist" = .perl ]; then
  1627. rm -f $tmpfile >/dev/null 2>&1
  1628. touch $tmpfile
  1629. found=0
  1630. pc=99
  1631. for dir in $paths; do
  1632. dir=`echo $dir | sed -e 's;/*$;;'`
  1633. nc=99
  1634. for name in perl perl5 miniperl; do
  1635. if [ $minusx "$dir/$name" ] && [ ! -d "$dir/$name" ]; then
  1636. perl="$dir/$name"
  1637. pv=`$perl -e 'printf("%.3f", $]);'`
  1638. echo "$pv:$pc:$nc:$perl" >>$tmpfile
  1639. found=1
  1640. fi
  1641. nc=`expr $nc - 1`
  1642. done
  1643. pc=`expr $pc - 1`
  1644. done
  1645. if [ $found = 1 ]; then
  1646. perl="`cat $tmpfile | sort -r -u | sed -e 'q' | cut -d: -f4`"
  1647. rm -f $tmpfile >/dev/null 2>&1
  1648. echo "$perl"
  1649. shtool_exit 0
  1650. fi
  1651. rm -f $tmpfile >/dev/null 2>&1
  1652. shtool_exit 1
  1653. fi
  1654. # MAGIC SITUATION
  1655. # C pre-processor (cpp)
  1656. if [ ".$opt_m" = .yes ] && [ ".$namelist" = .cpp ]; then
  1657. echo >$tmpfile.c "#include <assert.h>"
  1658. echo >>$tmpfile.c "Syntax Error"
  1659. # 1. try the standard cc -E approach
  1660. cpp="${CC-cc} -E"
  1661. (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
  1662. my_error=`grep -v '^ *+' $tmpfile.out`
  1663. if [ ".$my_error" != . ]; then
  1664. # 2. try the cc -E approach and GCC's -traditional-ccp option
  1665. cpp="${CC-cc} -E -traditional-cpp"
  1666. (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
  1667. my_error=`grep -v '^ *+' $tmpfile.out`
  1668. if [ ".$my_error" != . ]; then
  1669. # 3. try a standalone cpp command in path and lib dirs
  1670. for path in $paths /lib /usr/lib /usr/local/lib; do
  1671. path=`echo $path | sed -e 's;/*$;;'`
  1672. if [ $minusx "$path/cpp" ] && [ ! -d "$path/cpp" ]; then
  1673. cpp="$path/cpp"
  1674. break
  1675. fi
  1676. done
  1677. if [ ".$cpp" != . ]; then
  1678. (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
  1679. my_error=`grep -v '^ *+' $tmpfile.out`
  1680. if [ ".$my_error" != . ]; then
  1681. # ok, we gave up...
  1682. cpp=''
  1683. fi
  1684. fi
  1685. fi
  1686. fi
  1687. rm -f $tmpfile >/dev/null 2>&1
  1688. rm -f $tmpfile.c $tmpfile.out >/dev/null 2>&1
  1689. if [ ".$cpp" != . ]; then
  1690. echo "$cpp"
  1691. shtool_exit 0
  1692. fi
  1693. shtool_exit 1
  1694. fi
  1695. # STANDARD SITUATION
  1696. # iterate over names
  1697. for name in $namelist; do
  1698. # iterate over paths
  1699. for path in $paths; do
  1700. path=`echo $path | sed -e 's;/*$;;'`
  1701. if [ $minusx "$path/$name" ] && [ ! -d "$path/$name" ]; then
  1702. if [ ".$opt_s" != .yes ]; then
  1703. echo "$path/$name"
  1704. fi
  1705. shtool_exit 0
  1706. fi
  1707. done
  1708. done
  1709. shtool_exit 1
  1710. ;;
  1711. esac
  1712. shtool_exit 0