shtool 139 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083
  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: all 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  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. ## mdate Pretty-print modification time of a file or dir
  41. ## table Pretty-print a field-separated list as a table
  42. ## prop Display progress with a running propeller
  43. ## move Move files with simultaneous substitution
  44. ## install Install a program, script or datafile
  45. ## mkdir Make one or more directories
  46. ## mkln Make link with calculation of relative paths
  47. ## mkshadow Make a shadow tree through symbolic links
  48. ## fixperm Fix file permissions inside a source tree
  49. ## rotate Logfile rotation
  50. ## tarball Roll distribution tarballs
  51. ## subst Apply sed(1) substitution operations
  52. ## platform Platform Identification Utility
  53. ## arx Extended archive command
  54. ## slo Separate linker options by library class
  55. ## scpp Sharing C Pre-Processor
  56. ## version Maintain a version information file
  57. ## path Deal with program paths
  58. ##
  59. # maximum Bourne-Shell compatibility
  60. if [ ".$ZSH_VERSION" != . ] && (emulate sh) >/dev/null 2>&1; then
  61. # reconfigure zsh(1)
  62. emulate sh
  63. NULLCMD=:
  64. alias -g '${1+"$@"}'='"$@"'
  65. elif [ ".$BASH_VERSION" != . ] && (set -o posix) >/dev/null 2>&1; then
  66. # reconfigure bash(1)
  67. set -o posix
  68. fi
  69. # maximum independence of NLS nuisances
  70. for var in \
  71. LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
  72. LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
  73. LC_TELEPHONE LC_TIME
  74. do
  75. if (set +x; test -z "`(eval $var=C; export $var) 2>&1`"); then
  76. eval $var=C; export $var
  77. else
  78. unset $var
  79. fi
  80. done
  81. # initial command line handling
  82. if [ $# -eq 0 ]; then
  83. echo "$0:Error: invalid command line" 1>&2
  84. echo "$0:Hint: run \`$0 -h' for usage" 1>&2
  85. exit 1
  86. fi
  87. if [ ".$1" = ".-h" ] || [ ".$1" = ".--help" ]; then
  88. echo "This is GNU shtool, version 2.0.8 (18-Jul-2008)"
  89. echo 'Copyright (c) 1994-2008 Ralf S. Engelschall <rse@engelschall.com>'
  90. echo 'Report bugs to <bug-shtool@gnu.org>'
  91. echo ''
  92. echo 'Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]'
  93. echo ''
  94. echo 'Available global <options>:'
  95. echo ' -v, --version display shtool version information'
  96. echo ' -h, --help display shtool usage help page (this one)'
  97. echo ' -d, --debug display shell trace information'
  98. echo ' -r, --recreate recreate this shtool script via shtoolize'
  99. echo ''
  100. echo 'Available <cmd-name> [<cmd-options>] [<cmd-args>]:'
  101. echo ' echo [-n|--newline] [-e|--expand] [<string> ...]'
  102. echo ' mdate [-n|--newline] [-z|--zero] [-s|--shorten] [-d|--digits]'
  103. echo ' [-f|--field-sep <str>] [-o|--order <spec>] <path>'
  104. echo ' table [-F|--field-sep <sep>] [-w|--width <width>] [-c|--columns'
  105. echo ' <cols>] [-s|--strip <strip>] <str><sep><str>...'
  106. echo ' prop [-p|--prefix <str>]'
  107. echo ' move [-v|--verbose] [-t|--trace] [-e|--expand] [-p|--preserve]'
  108. echo ' <src-file> <dst-file>'
  109. echo ' install [-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy]'
  110. echo ' [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>]'
  111. echo ' [-o|--owner <owner>] [-g|--group <group>] [-e|--exec'
  112. echo ' <sed-cmd>] <file> [<file> ...] <path>'
  113. echo ' mkdir [-t|--trace] [-f|--force] [-p|--parents] [-m|--mode'
  114. echo ' <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir>'
  115. echo ' [<dir> ...]'
  116. echo ' mkln [-t|--trace] [-f|--force] [-s|--symbolic] <src-path>'
  117. echo ' [<src-path> ...] <dst-path>'
  118. echo ' mkshadow [-v|--verbose] [-t|--trace] [-a|--all] <src-dir> <dst-dir>'
  119. echo ' fixperm [-v|--verbose] [-t|--trace] <path> [<path> ...]'
  120. echo ' rotate [-v|--verbose] [-t|--trace] [-f|--force] [-n|--num-files'
  121. echo ' <count>] [-s|--size <size>] [-c|--copy] [-r|--remove]'
  122. echo ' [-a|--archive-dir <dir>] [-z|--compress [<tool>:]<level>]'
  123. echo ' [-b|--background] [-d|--delay] [-p|--pad <len>] [-m|--mode'
  124. echo ' <mode>] [-o|--owner <owner>] [-g|--group <group>] [-M|--migrate'
  125. echo ' <cmd>] [-P|--prolog <cmd>] [-E|--epilog <cmd>] <file> [...]'
  126. echo ' tarball [-t|--trace] [-v|--verbose] [-o|--output <tarball>]'
  127. echo ' [-c|--compress <prog>] [-d|--directory <dir>] [-u|--user'
  128. echo ' <user>] [-g|--group <group>] [-e|--exclude <pattern>]'
  129. echo ' <path> [<path> ...]'
  130. echo ' subst [-v|--verbose] [-t|--trace] [-n|--nop] [-w|--warning]'
  131. echo ' [-q|--quiet] [-s|--stealth] [-i|--interactive] [-b|--backup'
  132. echo ' <ext>] [-e|--exec <cmd>] [-f|--file <cmd-file>] [<file>]'
  133. echo ' [...]'
  134. echo ' platform [-F|--format <format>] [-S|--sep <string>] [-C|--conc'
  135. echo ' <string>] [-L|--lower] [-U|--upper] [-v|--verbose]'
  136. echo ' [-c|--concise] [-n|--no-newline] [-t|--type <type>]'
  137. echo ' [-V|--version] [-h|--help]'
  138. echo ' arx [-t|--trace] [-C|--command <cmd>] <op> <archive> [<file>'
  139. echo ' ...]'
  140. echo ' slo [-p|--prefix <str>] -- -L<dir> -l<lib> [-L<dir> -l<lib>'
  141. echo ' ...]'
  142. echo ' scpp [-v|--verbose] [-p|--preserve] [-f|--filter <filter>]'
  143. echo ' [-o|--output <ofile>] [-t|--template <tfile>] [-M|--mark'
  144. echo ' <mark>] [-D|--define <dname>] [-C|--class <cname>]'
  145. echo ' <file> [<file> ...]'
  146. echo ' version [-l|--language <lang>] [-n|--name <name>] [-p|--prefix'
  147. echo ' <prefix>] [-s|--set <version>] [-e|--edit] [-i|--increase'
  148. echo ' <knob>] [-d|--display <type>] <file>'
  149. echo ' path [-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename]'
  150. echo ' [-m|--magic] [-p|--path <path>] <str> [<str> ...]'
  151. echo ''
  152. exit 0
  153. fi
  154. if [ ".$1" = ".-v" ] || [ ".$1" = ".--version" ]; then
  155. echo "GNU shtool 2.0.8 (18-Jul-2008)"
  156. exit 0
  157. fi
  158. if [ ".$1" = ".-r" ] || [ ".$1" = ".--recreate" ]; then
  159. shtoolize -oshtool all
  160. exit 0
  161. fi
  162. if [ ".$1" = ".-d" ] || [ ".$1" = ".--debug" ]; then
  163. shift
  164. set -x
  165. fi
  166. name=`echo "$0" | sed -e 's;.*/\([^/]*\)$;\1;' -e 's;-sh$;;' -e 's;\.sh$;;'`
  167. case "$name" in
  168. echo|mdate|table|prop|move|install|mkdir|mkln|mkshadow|fixperm|rotate|tarball|subst|platform|arx|slo|scpp|version|path )
  169. # implicit tool command selection
  170. tool="$name"
  171. ;;
  172. * )
  173. # explicit tool command selection
  174. tool="$1"
  175. shift
  176. ;;
  177. esac
  178. arg_spec=""
  179. opt_spec=""
  180. gen_tmpfile=no
  181. ##
  182. ## DISPATCH INTO SCRIPT PROLOG
  183. ##
  184. case $tool in
  185. echo )
  186. str_tool="echo"
  187. str_usage="[-n|--newline] [-e|--expand] [<string> ...]"
  188. arg_spec="0+"
  189. opt_spec="n.e."
  190. opt_alias="n:newline,e:expand"
  191. opt_n=no
  192. opt_e=no
  193. ;;
  194. mdate )
  195. str_tool="mdate"
  196. str_usage="[-n|--newline] [-z|--zero] [-s|--shorten] [-d|--digits] [-f|--field-sep <str>] [-o|--order <spec>] <path>"
  197. arg_spec="1="
  198. opt_spec="n.z.s.d.f:o:"
  199. opt_alias="n:newline,z:zero,s:shorten,d:digits,f:field-sep,o:order"
  200. opt_n=no
  201. opt_z=no
  202. opt_s=no
  203. opt_d=no
  204. opt_f=" "
  205. opt_o="dmy"
  206. ;;
  207. table )
  208. str_tool="table"
  209. str_usage="[-F|--field-sep <sep>] [-w|--width <width>] [-c|--columns <cols>] [-s|--strip <strip>] <str><sep><str>..."
  210. arg_spec="1+"
  211. opt_spec="F:w:c:s:"
  212. opt_alias="F:field-sep,w:width,c:columns,s:strip"
  213. opt_F=":"
  214. opt_w=15
  215. opt_c=3
  216. opt_s=79
  217. ;;
  218. prop )
  219. str_tool="prop"
  220. str_usage="[-p|--prefix <str>]"
  221. arg_spec="0="
  222. opt_spec="p:"
  223. opt_alias="p:prefix"
  224. opt_p=""
  225. ;;
  226. move )
  227. str_tool="move"
  228. str_usage="[-v|--verbose] [-t|--trace] [-e|--expand] [-p|--preserve] <src-file> <dst-file>"
  229. arg_spec="2="
  230. opt_spec="v.t.e.p."
  231. opt_alias="v:verbose,t:trace,e:expand,p:preserve"
  232. opt_v=no
  233. opt_t=no
  234. opt_e=no
  235. opt_p=no
  236. ;;
  237. install )
  238. str_tool="install"
  239. 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>"
  240. arg_spec="1+"
  241. opt_spec="v.t.d.c.C.s.m:o:g:e+"
  242. opt_alias="v:verbose,t:trace,d:mkdir,c:copy,C:compare-copy,s:strip,m:mode,o:owner,g:group,e:exec"
  243. opt_v=no
  244. opt_t=no
  245. opt_d=no
  246. opt_c=no
  247. opt_C=no
  248. opt_s=no
  249. opt_m="0755"
  250. opt_o=""
  251. opt_g=""
  252. opt_e=""
  253. ;;
  254. mkdir )
  255. str_tool="mkdir"
  256. str_usage="[-t|--trace] [-f|--force] [-p|--parents] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir> [<dir> ...]"
  257. arg_spec="1+"
  258. opt_spec="t.f.p.m:o:g:"
  259. opt_alias="t:trace,f:force,p:parents,m:mode,o:owner,g:group"
  260. opt_t=no
  261. opt_f=no
  262. opt_p=no
  263. opt_m=""
  264. opt_o=""
  265. opt_g=""
  266. ;;
  267. mkln )
  268. str_tool="mkln"
  269. str_usage="[-t|--trace] [-f|--force] [-s|--symbolic] <src-path> [<src-path> ...] <dst-path>"
  270. arg_spec="2+"
  271. opt_spec="t.f.s."
  272. opt_alias="t:trace,f:force,s:symbolic"
  273. opt_t=no
  274. opt_f=no
  275. opt_s=no
  276. ;;
  277. mkshadow )
  278. str_tool="mkshadow"
  279. str_usage="[-v|--verbose] [-t|--trace] [-a|--all] <src-dir> <dst-dir>"
  280. arg_spec="2="
  281. opt_spec="v.t.a."
  282. opt_alias="v:verbose,t:trace,a:all"
  283. opt_v=no
  284. opt_t=no
  285. opt_a=no
  286. ;;
  287. fixperm )
  288. str_tool="fixperm"
  289. str_usage="[-v|--verbose] [-t|--trace] <path> [<path> ...]"
  290. arg_spec="1+"
  291. opt_spec="v.t."
  292. opt_alias="v:verbose,t:trace"
  293. opt_v=no
  294. opt_t=no
  295. ;;
  296. rotate )
  297. str_tool="rotate"
  298. str_usage="[-v|--verbose] [-t|--trace] [-f|--force] [-n|--num-files <count>] [-s|--size <size>] [-c|--copy] [-r|--remove] [-a|--archive-dir <dir>] [-z|--compress [<tool>:]<level>] [-b|--background] [-d|--delay] [-p|--pad <len>] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] [-M|--migrate <cmd>] [-P|--prolog <cmd>] [-E|--epilog <cmd>] <file> [...]"
  299. arg_spec="1+"
  300. opt_spec="v.t.f.n:s:c.r.a:z:b.d.p:o:g:m:M:P:E:"
  301. opt_alias="v:verbose,t:trace,f:force,n:num-files,s:size,c:copy,r:remove,a:archive-dir,z:compress,b:background,d:delay,p:pad,o:owner,g:group,m:mode,M:migrate,P:prolog,E:epilog"
  302. opt_v=no
  303. opt_t=no
  304. opt_f=no
  305. opt_n=10
  306. opt_s=""
  307. opt_c=no
  308. opt_r=no
  309. opt_a=""
  310. opt_z=""
  311. opt_b=no
  312. opt_d=no
  313. opt_p=1
  314. opt_o=""
  315. opt_g=""
  316. opt_m=""
  317. opt_M=""
  318. opt_P=""
  319. opt_E=""
  320. ;;
  321. tarball )
  322. str_tool="tarball"
  323. str_usage="[-t|--trace] [-v|--verbose] [-o|--output <tarball>] [-c|--compress <prog>] [-d|--directory <dir>] [-u|--user <user>] [-g|--group <group>] [-e|--exclude <pattern>] <path> [<path> ...]"
  324. gen_tmpfile=yes
  325. arg_spec="1+"
  326. opt_spec="t.v.o:c:d:u:g:e:"
  327. opt_alias="t:trace,v:verbose,o:output,c:compress,d:directory,u:user,g:group,e:exclude"
  328. opt_t=no
  329. opt_v=no
  330. opt_o=""
  331. opt_c=""
  332. opt_d=""
  333. opt_u=""
  334. opt_g=""
  335. opt_e="CVS,\\.cvsignore,\\.svn,\\.[oa]\$"
  336. ;;
  337. subst )
  338. str_tool="subst"
  339. str_usage="[-v|--verbose] [-t|--trace] [-n|--nop] [-w|--warning] [-q|--quiet] [-s|--stealth] [-i|--interactive] [-b|--backup <ext>] [-e|--exec <cmd>] [-f|--file <cmd-file>] [<file>] [...]"
  340. gen_tmpfile=yes
  341. arg_spec="0+"
  342. opt_spec="v.t.n.w.q.s.i.b:e+f:"
  343. opt_alias="v:verbose,t:trace,n:nop,w:warning,q:quiet,s:stealth,i:interactive,b:backup,e:exec,f:file"
  344. opt_v=no
  345. opt_t=no
  346. opt_n=no
  347. opt_w=no
  348. opt_q=no
  349. opt_s=no
  350. opt_i=no
  351. opt_b=""
  352. opt_e=""
  353. opt_f=""
  354. ;;
  355. platform )
  356. str_tool="platform"
  357. 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]"
  358. arg_spec="0="
  359. opt_spec="F:S:C:L.U.v.c.n.t:d.V.h."
  360. 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"
  361. opt_F="%{sp} (%{ap})"
  362. opt_S=" "
  363. opt_C="/"
  364. opt_L=no
  365. opt_U=no
  366. opt_t=""
  367. opt_v=no
  368. opt_c=no
  369. opt_n=no
  370. opt_V=no
  371. opt_h=no
  372. ;;
  373. arx )
  374. str_tool="arx"
  375. str_usage="[-t|--trace] [-C|--command <cmd>] <op> <archive> [<file> ...]"
  376. arg_spec="2+"
  377. opt_spec="t.C:"
  378. opt_alias="t:trace,C:command"
  379. opt_t=no
  380. opt_C="ar"
  381. ;;
  382. slo )
  383. str_tool="slo"
  384. str_usage="[-p|--prefix <str>] -- -L<dir> -l<lib> [-L<dir> -l<lib> ...]"
  385. arg_spec="1+"
  386. opt_spec="p:"
  387. opt_alias="p:prefix"
  388. opt_p="SLO_"
  389. ;;
  390. scpp )
  391. str_tool="scpp"
  392. str_usage="[-v|--verbose] [-p|--preserve] [-f|--filter <filter>] [-o|--output <ofile>] [-t|--template <tfile>] [-M|--mark <mark>] [-D|--define <dname>] [-C|--class <cname>] <file> [<file> ...]"
  393. gen_tmpfile=yes
  394. arg_spec="1+"
  395. opt_spec="v.p.f+o:t:M:D:C:"
  396. opt_alias="v:verbose,p:preserve,f:filter,o:output,t:template,M:mark,D:define,C:class"
  397. opt_v=no
  398. opt_p=no
  399. opt_f=""
  400. opt_o="lib.h"
  401. opt_t="lib.h.in"
  402. opt_M="%%MARK%%"
  403. opt_D="cpp"
  404. opt_C="intern"
  405. ;;
  406. version )
  407. str_tool="version"
  408. str_usage="[-l|--language <lang>] [-n|--name <name>] [-p|--prefix <prefix>] [-s|--set <version>] [-e|--edit] [-i|--increase <knob>] [-d|--display <type>] <file>"
  409. arg_spec="1="
  410. opt_spec="l:n:p:s:i:e.d:"
  411. opt_alias="l:language,n:name,p:prefix,s:set,e:edit,i:increase,d:display"
  412. opt_l="txt"
  413. opt_n="unknown"
  414. opt_p=""
  415. opt_s=""
  416. opt_e="no"
  417. opt_i=""
  418. opt_d="short"
  419. ;;
  420. path )
  421. str_tool="path"
  422. str_usage="[-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename] [-m|--magic] [-p|--path <path>] <str> [<str> ...]"
  423. gen_tmpfile=yes
  424. arg_spec="1+"
  425. opt_spec="s.r.d.b.m.p:"
  426. opt_alias="s:suppress,r:reverse,d:dirname,b:basename,m:magic,p:path"
  427. opt_s=no
  428. opt_r=no
  429. opt_d=no
  430. opt_b=no
  431. opt_m=no
  432. opt_p="$PATH"
  433. ;;
  434. -* )
  435. echo "$0:Error: unknown option \`$tool'" 2>&1
  436. echo "$0:Hint: run \`$0 -h' for usage" 2>&1
  437. exit 1
  438. ;;
  439. * )
  440. echo "$0:Error: unknown command \`$tool'" 2>&1
  441. echo "$0:Hint: run \`$0 -h' for usage" 2>&1
  442. exit 1
  443. ;;
  444. esac
  445. ##
  446. ## COMMON UTILITY CODE
  447. ##
  448. # commonly used ASCII values
  449. ASC_TAB=" "
  450. ASC_NL="
  451. "
  452. # determine name of tool
  453. if [ ".$tool" != . ]; then
  454. # used inside shtool script
  455. toolcmd="$0 $tool"
  456. toolcmdhelp="shtool $tool"
  457. msgprefix="shtool:$tool"
  458. else
  459. # used as standalone script
  460. toolcmd="$0"
  461. toolcmdhelp="sh $0"
  462. msgprefix="$str_tool"
  463. fi
  464. # parse argument specification string
  465. eval `echo $arg_spec |\
  466. sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'`
  467. # parse option specification string
  468. eval `echo h.$opt_spec |\
  469. sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'`
  470. # parse option alias string
  471. eval `echo h:help,$opt_alias |\
  472. sed -e 's/-/_/g' -e 's/\([a-zA-Z0-9]\):\([^,]*\),*/opt_ALIAS_\2=\1;/g'`
  473. # interate over argument line
  474. opt_PREV=''
  475. while [ $# -gt 0 ]; do
  476. # special option stops processing
  477. if [ ".$1" = ".--" ]; then
  478. shift
  479. break
  480. fi
  481. # determine option and argument
  482. opt_ARG_OK=no
  483. if [ ".$opt_PREV" != . ]; then
  484. # merge previous seen option with argument
  485. opt_OPT="$opt_PREV"
  486. opt_ARG="$1"
  487. opt_ARG_OK=yes
  488. opt_PREV=''
  489. else
  490. # split argument into option and argument
  491. case "$1" in
  492. --[a-zA-Z0-9]*=*)
  493. eval `echo "x$1" |\
  494. sed -e 's/^x--\([a-zA-Z0-9-]*\)=\(.*\)$/opt_OPT="\1";opt_ARG="\2"/'`
  495. opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'`
  496. eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
  497. ;;
  498. --[a-zA-Z0-9]*)
  499. opt_OPT=`echo "x$1" | cut -c4-`
  500. opt_STR=`echo $opt_OPT | sed -e 's/-/_/g'`
  501. eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
  502. opt_ARG=''
  503. ;;
  504. -[a-zA-Z0-9]*)
  505. eval `echo "x$1" |\
  506. sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \
  507. -e 's/";\(.*\)$/"; opt_ARG="\1"/'`
  508. ;;
  509. -[a-zA-Z0-9])
  510. opt_OPT=`echo "x$1" | cut -c3-`
  511. opt_ARG=''
  512. ;;
  513. *)
  514. break
  515. ;;
  516. esac
  517. fi
  518. # eat up option
  519. shift
  520. # determine whether option needs an argument
  521. eval "opt_MODE=\$opt_MODE_${opt_OPT}"
  522. if [ ".$opt_ARG" = . ] && [ ".$opt_ARG_OK" != .yes ]; then
  523. if [ ".$opt_MODE" = ".:" ] || [ ".$opt_MODE" = ".+" ]; then
  524. opt_PREV="$opt_OPT"
  525. continue
  526. fi
  527. fi
  528. # process option
  529. case $opt_MODE in
  530. '.' )
  531. # boolean option
  532. eval "opt_${opt_OPT}=yes"
  533. ;;
  534. ':' )
  535. # option with argument (multiple occurances override)
  536. eval "opt_${opt_OPT}=\"\$opt_ARG\""
  537. ;;
  538. '+' )
  539. # option with argument (multiple occurances append)
  540. eval "opt_${opt_OPT}=\"\$opt_${opt_OPT}\${ASC_NL}\$opt_ARG\""
  541. ;;
  542. * )
  543. echo "$msgprefix:Error: unknown option: \`$opt_OPT'" 1>&2
  544. echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
  545. exit 1
  546. ;;
  547. esac
  548. done
  549. if [ ".$opt_PREV" != . ]; then
  550. echo "$msgprefix:Error: missing argument to option \`$opt_PREV'" 1>&2
  551. echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
  552. exit 1
  553. fi
  554. # process help option
  555. if [ ".$opt_h" = .yes ]; then
  556. echo "Usage: $toolcmdhelp $str_usage"
  557. exit 0
  558. fi
  559. # complain about incorrect number of arguments
  560. case $arg_MODE in
  561. '=' )
  562. if [ $# -ne $arg_NUMS ]; then
  563. echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2
  564. echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
  565. exit 1
  566. fi
  567. ;;
  568. '+' )
  569. if [ $# -lt $arg_NUMS ]; then
  570. echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2
  571. echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2
  572. exit 1
  573. fi
  574. ;;
  575. esac
  576. # establish a temporary file on request
  577. if [ ".$gen_tmpfile" = .yes ]; then
  578. # create (explicitly) secure temporary directory
  579. if [ ".$TMPDIR" != . ]; then
  580. tmpdir="$TMPDIR"
  581. elif [ ".$TEMPDIR" != . ]; then
  582. tmpdir="$TEMPDIR"
  583. else
  584. tmpdir="/tmp"
  585. fi
  586. tmpdir="$tmpdir/.shtool.$$"
  587. ( umask 077
  588. rm -rf "$tmpdir" >/dev/null 2>&1 || true
  589. mkdir "$tmpdir" >/dev/null 2>&1
  590. if [ $? -ne 0 ]; then
  591. echo "$msgprefix:Error: failed to create temporary directory \`$tmpdir'" 1>&2
  592. exit 1
  593. fi
  594. )
  595. # create (implicitly) secure temporary file
  596. tmpfile="$tmpdir/shtool.tmp"
  597. touch "$tmpfile"
  598. fi
  599. # utility function: map string to lower case
  600. util_lower () {
  601. echo "$1" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'
  602. }
  603. # utility function: map string to upper case
  604. util_upper () {
  605. echo "$1" | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  606. }
  607. # cleanup procedure
  608. shtool_exit () {
  609. rc="$1"
  610. if [ ".$gen_tmpfile" = .yes ]; then
  611. rm -rf "$tmpdir" >/dev/null 2>&1 || true
  612. fi
  613. exit $rc
  614. }
  615. ##
  616. ## DISPATCH INTO SCRIPT BODY
  617. ##
  618. case $tool in
  619. echo )
  620. ##
  621. ## echo -- Print string with optional construct expansion
  622. ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
  623. ##
  624. text="$*"
  625. # check for broken escape sequence expansion
  626. seo=''
  627. bytes=`echo '\1' | wc -c | awk '{ printf("%s", $1); }'`
  628. if [ ".$bytes" != .3 ]; then
  629. bytes=`echo -E '\1' | wc -c | awk '{ printf("%s", $1); }'`
  630. if [ ".$bytes" = .3 ]; then
  631. seo='-E'
  632. fi
  633. fi
  634. # check for existing -n option (to suppress newline)
  635. minusn=''
  636. bytes=`echo -n 123 2>/dev/null | wc -c | awk '{ printf("%s", $1); }'`
  637. if [ ".$bytes" = .3 ]; then
  638. minusn='-n'
  639. fi
  640. # determine terminal bold sequence
  641. term_bold=''
  642. term_norm=''
  643. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[Bb]'`" != . ]; then
  644. case $TERM in
  645. # for the most important terminal types we directly know the sequences
  646. xterm|xterm*|vt220|vt220*)
  647. term_bold=`awk 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }' </dev/null 2>/dev/null`
  648. term_norm=`awk 'BEGIN { printf("%c%c%c", 27, 91, 109); }' </dev/null 2>/dev/null`
  649. ;;
  650. vt100|vt100*|cygwin)
  651. term_bold=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }' </dev/null 2>/dev/null`
  652. term_norm=`awk 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }' </dev/null 2>/dev/null`
  653. ;;
  654. # for all others, we try to use a possibly existing `tput' or `tcout' utility
  655. * )
  656. paths=`echo $PATH | sed -e 's/:/ /g'`
  657. for tool in tput tcout; do
  658. for dir in $paths; do
  659. if [ -r "$dir/$tool" ]; then
  660. for seq in bold md smso; do # 'smso' is last
  661. bold="`$dir/$tool $seq 2>/dev/null`"
  662. if [ ".$bold" != . ]; then
  663. term_bold="$bold"
  664. break
  665. fi
  666. done
  667. if [ ".$term_bold" != . ]; then
  668. for seq in sgr0 me rmso init reset; do # 'reset' is last
  669. norm="`$dir/$tool $seq 2>/dev/null`"
  670. if [ ".$norm" != . ]; then
  671. term_norm="$norm"
  672. break
  673. fi
  674. done
  675. fi
  676. break
  677. fi
  678. done
  679. if [ ".$term_bold" != . ] && [ ".$term_norm" != . ]; then
  680. break;
  681. fi
  682. done
  683. ;;
  684. esac
  685. if [ ".$term_bold" = . ] || [ ".$term_norm" = . ]; then
  686. echo "$msgprefix:Warning: unable to determine terminal sequence for bold mode" 1>&2
  687. term_bold=''
  688. term_norm=''
  689. fi
  690. fi
  691. # determine user name
  692. username=''
  693. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[uUgG]'`" != . ]; then
  694. username="`(id -un) 2>/dev/null`"
  695. if [ ".$username" = . ]; then
  696. str="`(id) 2>/dev/null`"
  697. if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then
  698. username=`echo $str | sed -e 's/^uid[ ]*=[ ]*[0-9]*(//' -e 's/).*$//'`
  699. fi
  700. if [ ".$username" = . ]; then
  701. username="$LOGNAME"
  702. if [ ".$username" = . ]; then
  703. username="$USER"
  704. if [ ".$username" = . ]; then
  705. username="`(whoami) 2>/dev/null |\
  706. awk '{ printf("%s", $1); }'`"
  707. if [ ".$username" = . ]; then
  708. username="`(who am i) 2>/dev/null |\
  709. awk '{ printf("%s", $1); }'`"
  710. if [ ".$username" = . ]; then
  711. username='unknown'
  712. fi
  713. fi
  714. fi
  715. fi
  716. fi
  717. fi
  718. fi
  719. # determine user id
  720. userid=''
  721. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%U'`" != . ]; then
  722. userid="`(id -u) 2>/dev/null`"
  723. if [ ".$userid" = . ]; then
  724. userid="`(id -u ${username}) 2>/dev/null`"
  725. if [ ".$userid" = . ]; then
  726. str="`(id) 2>/dev/null`"
  727. if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then
  728. userid=`echo $str | sed -e 's/^uid[ ]*=[ ]*//' -e 's/(.*$//'`
  729. fi
  730. if [ ".$userid" = . ]; then
  731. userid=`(getent passwd ${username}) 2>/dev/null | \
  732. sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
  733. if [ ".$userid" = . ]; then
  734. userid=`grep "^${username}:" /etc/passwd 2>/dev/null | \
  735. sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
  736. if [ ".$userid" = . ]; then
  737. userid=`(ypmatch "${username}" passwd; nismatch "${username}" passwd) 2>/dev/null | \
  738. sed -e 'q' | sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
  739. if [ ".$userid" = . ]; then
  740. userid=`(nidump passwd . | grep "^${username}:") 2>/dev/null | \
  741. sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'`
  742. if [ ".$userid" = . ]; then
  743. userid='?'
  744. fi
  745. fi
  746. fi
  747. fi
  748. fi
  749. fi
  750. fi
  751. fi
  752. # determine (primary) group id
  753. groupid=''
  754. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[gG]'`" != . ]; then
  755. groupid="`(id -g ${username}) 2>/dev/null`"
  756. if [ ".$groupid" = . ]; then
  757. str="`(id) 2>/dev/null`"
  758. if [ ".`echo $str | grep 'gid[ ]*=[ ]*[0-9]*('`" != . ]; then
  759. groupid=`echo $str | sed -e 's/^.*gid[ ]*=[ ]*//' -e 's/(.*$//'`
  760. fi
  761. if [ ".$groupid" = . ]; then
  762. groupid=`(getent passwd ${username}) 2>/dev/null | \
  763. sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
  764. if [ ".$groupid" = . ]; then
  765. groupid=`grep "^${username}:" /etc/passwd 2>/dev/null | \
  766. sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
  767. if [ ".$groupid" = . ]; then
  768. groupid=`(ypmatch "${username}" passwd; nismatch "${username}" passwd) 2>/dev/null | \
  769. sed -e 'q' | sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
  770. if [ ".$groupid" = . ]; then
  771. groupid=`(nidump passwd . | grep "^${username}:") 2>/dev/null | \
  772. sed -e 's/[^:]*:[^:]*:[^:]*://' -e 's/:.*$//'`
  773. if [ ".$groupid" = . ]; then
  774. groupid='?'
  775. fi
  776. fi
  777. fi
  778. fi
  779. fi
  780. fi
  781. fi
  782. # determine (primary) group name
  783. groupname=''
  784. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%g'`" != . ]; then
  785. groupname="`(id -gn ${username}) 2>/dev/null`"
  786. if [ ".$groupname" = . ]; then
  787. str="`(id) 2>/dev/null`"
  788. if [ ".`echo $str | grep 'gid[ ]*=[ ]*[0-9]*('`" != . ]; then
  789. groupname=`echo $str | sed -e 's/^.*gid[ ]*=[ ]*[0-9]*(//' -e 's/).*$//'`
  790. fi
  791. if [ ".$groupname" = . ]; then
  792. groupname=`(getent group) 2>/dev/null | \
  793. grep "^[^:]*:[^:]*:${groupid}:" | \
  794. sed -e 's/:.*$//'`
  795. if [ ".$groupname" = . ]; then
  796. groupname=`grep "^[^:]*:[^:]*:${groupid}:" /etc/group 2>/dev/null | \
  797. sed -e 's/:.*$//'`
  798. if [ ".$groupname" = . ]; then
  799. groupname=`(ypcat group; niscat group) 2>/dev/null | \
  800. sed -e 'q' | grep "^[^:]*:[^:]*:${groupid}:" | \
  801. sed -e 's/:.*$//'`
  802. if [ ".$groupname" = . ]; then
  803. groupname=`(nidump group .) 2>/dev/null | \
  804. grep "^[^:]*:[^:]*:${groupid}:" | \
  805. sed -e 's/:.*$//'`
  806. if [ ".$groupname" = . ]; then
  807. groupname='?'
  808. fi
  809. fi
  810. fi
  811. fi
  812. fi
  813. fi
  814. fi
  815. # determine host and domain name
  816. hostname=''
  817. domainname=''
  818. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%h'`" != . ]; then
  819. hostname="`(uname -n) 2>/dev/null |\
  820. awk '{ printf("%s", $1); }'`"
  821. if [ ".$hostname" = . ]; then
  822. hostname="`(hostname) 2>/dev/null |\
  823. awk '{ printf("%s", $1); }'`"
  824. if [ ".$hostname" = . ]; then
  825. hostname='unknown'
  826. fi
  827. fi
  828. case $hostname in
  829. *.* )
  830. domainname=".`echo $hostname | cut -d. -f2-`"
  831. hostname="`echo $hostname | cut -d. -f1`"
  832. ;;
  833. esac
  834. fi
  835. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%d'`" != . ]; then
  836. if [ ".$domainname" = . ]; then
  837. if [ -f /etc/resolv.conf ]; then
  838. domainname="`grep '^[ ]*domain' /etc/resolv.conf | sed -e 'q' |\
  839. sed -e 's/.*domain//' \
  840. -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
  841. -e 's/^\.//' -e 's/^/./' |\
  842. awk '{ printf("%s", $1); }'`"
  843. if [ ".$domainname" = . ]; then
  844. domainname="`grep '^[ ]*search' /etc/resolv.conf | sed -e 'q' |\
  845. sed -e 's/.*search//' \
  846. -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
  847. -e 's/ .*//' -e 's/ .*//' \
  848. -e 's/^\.//' -e 's/^/./' |\
  849. awk '{ printf("%s", $1); }'`"
  850. fi
  851. fi
  852. fi
  853. fi
  854. # determine current time
  855. time_day=''
  856. time_month=''
  857. time_year=''
  858. time_monthname=''
  859. if [ ".$opt_e" = .yes ] && [ ".`echo $text | grep '%[DMYm]'`" != . ]; then
  860. time_day=`date '+%d'`
  861. time_month=`date '+%m'`
  862. time_year=`date '+%Y' 2>/dev/null`
  863. if [ ".$time_year" = . ]; then
  864. time_year=`date '+%y'`
  865. case $time_year in
  866. [5-9][0-9]) time_year="19$time_year" ;;
  867. [0-4][0-9]) time_year="20$time_year" ;;
  868. esac
  869. fi
  870. case $time_month in
  871. 1|01) time_monthname='Jan' ;;
  872. 2|02) time_monthname='Feb' ;;
  873. 3|03) time_monthname='Mar' ;;
  874. 4|04) time_monthname='Apr' ;;
  875. 5|05) time_monthname='May' ;;
  876. 6|06) time_monthname='Jun' ;;
  877. 7|07) time_monthname='Jul' ;;
  878. 8|08) time_monthname='Aug' ;;
  879. 9|09) time_monthname='Sep' ;;
  880. 10) time_monthname='Oct' ;;
  881. 11) time_monthname='Nov' ;;
  882. 12) time_monthname='Dec' ;;
  883. esac
  884. fi
  885. # expand special ``%x'' constructs
  886. if [ ".$opt_e" = .yes ]; then
  887. text=`echo $seo "$text" |\
  888. sed -e "s/%B/${term_bold}/g" \
  889. -e "s/%b/${term_norm}/g" \
  890. -e "s/%u/${username}/g" \
  891. -e "s/%U/${userid}/g" \
  892. -e "s/%g/${groupname}/g" \
  893. -e "s/%G/${groupid}/g" \
  894. -e "s/%h/${hostname}/g" \
  895. -e "s/%d/${domainname}/g" \
  896. -e "s/%D/${time_day}/g" \
  897. -e "s/%M/${time_month}/g" \
  898. -e "s/%Y/${time_year}/g" \
  899. -e "s/%m/${time_monthname}/g" 2>/dev/null`
  900. fi
  901. # create output
  902. if [ .$opt_n = .no ]; then
  903. echo $seo "$text"
  904. else
  905. # the harder part: echo -n is best, because
  906. # awk may complain about some \xx sequences.
  907. if [ ".$minusn" != . ]; then
  908. echo $seo $minusn "$text"
  909. else
  910. echo dummy | awk '{ printf("%s", TEXT); }' TEXT="$text"
  911. fi
  912. fi
  913. shtool_exit 0
  914. ;;
  915. mdate )
  916. ##
  917. ## mdate -- Pretty-print modification time of a file or dir
  918. ## Copyright (c) 1995-1997 Free Software Foundation, Inc.
  919. ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
  920. ##
  921. fod="$1"
  922. case "$opt_o" in
  923. [dmy][dmy][dmy] )
  924. ;;
  925. * ) echo "$msgprefix:Error: invalid argument to option \`-o': $opt_o" 1>&2
  926. shtool_exit 1
  927. ;;
  928. esac
  929. if [ ! -r "$fod" ]; then
  930. echo "$msgprefix:Error: file or directory not found: $fod" 1>&2
  931. shtool_exit 1
  932. fi
  933. # GNU ls changes its time format in response to the TIME_STYLE
  934. # variable. Since we cannot assume "unset" works, revert this
  935. # variable to its documented default.
  936. if [ ".$TIME_STYLE" != . ]; then
  937. TIME_STYLE=posix-long-iso
  938. export TIME_STYLE
  939. fi
  940. # get the extended ls output of the file or directory.
  941. if /bin/ls -L /dev/null >/dev/null 2>&1; then
  942. set - x`/bin/ls -L -l -d $fod`
  943. else
  944. set - x`/bin/ls -l -d $fod`
  945. fi
  946. # The month is at least the fourth argument
  947. # (3 shifts here, the next inside the loop).
  948. shift; shift; shift
  949. # Find the month. Next argument is day, followed by the year or time.
  950. month=""
  951. while [ ".$month" = . ]; do
  952. shift
  953. case $1 in
  954. Jan) month=January; nummonth=1 ;;
  955. Feb) month=February; nummonth=2 ;;
  956. Mar) month=March; nummonth=3 ;;
  957. Apr) month=April; nummonth=4 ;;
  958. May) month=May; nummonth=5 ;;
  959. Jun) month=June; nummonth=6 ;;
  960. Jul) month=July; nummonth=7 ;;
  961. Aug) month=August; nummonth=8 ;;
  962. Sep) month=September; nummonth=9 ;;
  963. Oct) month=October; nummonth=10 ;;
  964. Nov) month=November; nummonth=11 ;;
  965. Dec) month=December; nummonth=12 ;;
  966. esac
  967. done
  968. day="$2"
  969. year="$3"
  970. # We finally have to deal with the problem that the "ls" output
  971. # gives either the time of the day or the year.
  972. case $year in
  973. *:*)
  974. this_year=`date '+%Y' 2>/dev/null`
  975. if [ ".$this_year" = . ]; then
  976. this_year=`date '+%y'`
  977. case $this_year in
  978. [5-9][0-9]) this_year="19$this_year" ;;
  979. [0-4][0-9]) this_year="20$this_year" ;;
  980. esac
  981. fi
  982. # for the following months of the last year the time notation
  983. # is usually also used for files modified in the last year.
  984. this_month=`date '+%m'`
  985. if (expr $nummonth \> $this_month) >/dev/null; then
  986. this_year=`expr $this_year - 1`
  987. fi
  988. year="$this_year"
  989. ;;
  990. esac
  991. # Optionally fill day and month with leeding zeros
  992. if [ ".$opt_z" = .yes ]; then
  993. case $day in
  994. [0-9][0-9] ) ;;
  995. [0-9] ) day="0$day" ;;
  996. esac
  997. case $nummonth in
  998. [0-9][0-9] ) ;;
  999. [0-9] ) nummonth="0$nummonth" ;;
  1000. esac
  1001. fi
  1002. # Optionally use digits for month
  1003. if [ ".$opt_d" = .yes ]; then
  1004. month="$nummonth"
  1005. fi
  1006. # Optionally shorten the month name to three characters
  1007. if [ ".$opt_s" = .yes ]; then
  1008. month=`echo $month | cut -c1-3`
  1009. fi
  1010. # Output the resulting date string
  1011. echo dummy | awk '{
  1012. for (i = 0; i < 3; i++) {
  1013. now = substr(order, 1, 1);
  1014. order = substr(order, 2);
  1015. if (now == "d")
  1016. out = day;
  1017. else if (now == "m")
  1018. out = month;
  1019. else if (now == "y")
  1020. out = year;
  1021. if (i < 2)
  1022. printf("%s%s", out, field);
  1023. else
  1024. printf("%s", out);
  1025. }
  1026. if (newline != "yes")
  1027. printf("\n");
  1028. }' "day=$day" "month=$month" "year=$year" \
  1029. "field=$opt_f" "order=$opt_o" "newline=$opt_n"
  1030. shtool_exit 0
  1031. ;;
  1032. table )
  1033. ##
  1034. ## table -- Pretty-print a field-separated list as a table
  1035. ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
  1036. ##
  1037. if [ $opt_c -gt 4 ]; then
  1038. echo "$msgprefix:Error: Invalid number of colums (1..4 allowed only)" 1>&2
  1039. shtool_exit 1
  1040. fi
  1041. case "x$opt_F" in
  1042. x? ) ;;
  1043. * ) echo "$msgprefix:Error: Invalid separator (one char allowed only)" 1>&2; shtool_exit 1 ;;
  1044. esac
  1045. # split the list into a table
  1046. list=`
  1047. IFS="$opt_F"
  1048. for entry in $*; do
  1049. if [ ".$entry" != . ]; then
  1050. echo "$entry"
  1051. fi
  1052. done |\
  1053. awk "
  1054. BEGIN { list = \"\"; n = 0; }
  1055. {
  1056. list = list \\$1;
  1057. n = n + 1;
  1058. if (n < $opt_c) {
  1059. list = list \":\";
  1060. }
  1061. if (n == $opt_c) {
  1062. list = list \"\\n\";
  1063. n = 0;
  1064. }
  1065. }
  1066. END { print list; }
  1067. "
  1068. `
  1069. # format table cells and make sure table
  1070. # doesn't exceed maximum width
  1071. OIFS="$IFS"
  1072. IFS='
  1073. '
  1074. for entry in $list; do
  1075. case $opt_c in
  1076. 1 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${opt_w}s\\n\", \$1); }'" ;;
  1077. 2 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${opt_w}s %-${opt_w}s\\n\", \$1, \$2); }'" ;;
  1078. 3 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${opt_w}s %-${opt_w}s %-${opt_w}s\\n\", \$1, \$2, \$3); }'" ;;
  1079. 4 ) eval "echo \"\${entry}\" | awk -F: '{ printf(\"%-${opt_w}s %-${opt_w}s %-${opt_w}s %-${opt_w}s\\n\", \$1, \$2, \$3, \$4); }'" ;;
  1080. esac
  1081. done |\
  1082. awk "{
  1083. if (length(\$0) > $opt_s) {
  1084. printf(\"%s\\n\", substr(\$0, 0, $opt_s-1));
  1085. } else {
  1086. print \$0;
  1087. }
  1088. }"
  1089. IFS="$OIFS"
  1090. shtool_exit 0
  1091. ;;
  1092. prop )
  1093. ##
  1094. ## prop -- Display progress with a running propeller
  1095. ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
  1096. ##
  1097. perl=''
  1098. for dir in `echo $PATH | sed -e 's/:/ /g'` .; do
  1099. if [ -f "$dir/perl" ]; then
  1100. perl="$dir/perl"
  1101. break
  1102. fi
  1103. done
  1104. if [ ".$perl" != . ]; then
  1105. # Perl is preferred because writing to STDERR in
  1106. # Perl really writes immediately as one would expect
  1107. $perl -e '
  1108. @p = ("|","/","-","\\");
  1109. $i = 0;
  1110. while (<STDIN>) {
  1111. printf(STDERR "\r%s...%s\b", $ARGV[0], $p[$i++]);
  1112. $i = 0 if ($i > 3);
  1113. }
  1114. printf(STDERR "\r%s \n", $ARGV[0]);
  1115. ' "$opt_p"
  1116. else
  1117. # But if Perl doesn't exists we use Awk even
  1118. # some Awk's buffer even the /dev/stderr writing :-(
  1119. awk '
  1120. BEGIN {
  1121. split("|#/#-#\\", p, "#");
  1122. i = 1;
  1123. }
  1124. {
  1125. printf("\r%s%c\b", prefix, p[i++]) > "/dev/stderr";
  1126. if (i > 4) { i = 1; }
  1127. }
  1128. END {
  1129. printf("\r%s \n", prefix) > "/dev/stderr";
  1130. }
  1131. ' "prefix=$opt_p"
  1132. fi
  1133. shtool_exit 0
  1134. ;;
  1135. move )
  1136. ##
  1137. ## move -- Move files with simultaneous substitution
  1138. ## Copyright (c) 1999-2008 Ralf S. Engelschall <rse@engelschall.com>
  1139. ##
  1140. src="$1"
  1141. dst="$2"
  1142. # consistency checks
  1143. if [ ".$src" = . ] || [ ".$dst" = . ]; then
  1144. echo "$msgprefix:Error: Invalid arguments" 1>&2
  1145. shtool_exit 1
  1146. fi
  1147. if [ ".$src" = ".$dst" ]; then
  1148. echo "$msgprefix:Error: Source and destination files are the same" 1>&2
  1149. shtool_exit 1
  1150. fi
  1151. expsrc="$src"
  1152. if [ ".$opt_e" = .yes ]; then
  1153. expsrc="`echo $expsrc`"
  1154. fi
  1155. if [ ".$opt_e" = .yes ]; then
  1156. if [ ".`echo "$src" | sed -e 's;^.*\\*.*$;;'`" = ".$src" ]; then
  1157. echo "$msgprefix:Error: Source doesn't contain wildcard ('*'): $dst" 1>&2
  1158. shtool_exit 1
  1159. fi
  1160. if [ ".`echo "$dst" | sed -e 's;^.*%[1-9].*$;;'`" = ".$dst" ]; then
  1161. echo "$msgprefix:Error: Destination doesn't contain substitution ('%N'): $dst" 1>&2
  1162. shtool_exit 1
  1163. fi
  1164. if [ ".$expsrc" = ".$src" ]; then
  1165. echo "$msgprefix:Error: Sources not found or no asterisk : $src" 1>&2
  1166. shtool_exit 1
  1167. fi
  1168. else
  1169. if [ ! -r "$src" ]; then
  1170. echo "$msgprefix:Error: Source not found: $src" 1>&2
  1171. shtool_exit 1
  1172. fi
  1173. fi
  1174. # determine substitution patterns
  1175. if [ ".$opt_e" = .yes ]; then
  1176. srcpat=`echo "$src" | sed -e 's/\\./\\\\./g' -e 's/;/\\;/g' -e 's;\\*;\\\\(.*\\\\);g'`
  1177. dstpat=`echo "$dst" | sed -e 's;%\([1-9]\);\\\\\1;g'`
  1178. fi
  1179. # iterate over source(s)
  1180. for onesrc in $expsrc; do
  1181. if [ .$opt_e = .yes ]; then
  1182. onedst=`echo $onesrc | sed -e "s;$srcpat;$dstpat;"`
  1183. else
  1184. onedst="$dst"
  1185. fi
  1186. errorstatus=0
  1187. if [ ".$opt_v" = .yes ]; then
  1188. echo "$onesrc -> $onedst"
  1189. fi
  1190. if [ ".$opt_p" = .yes ]; then
  1191. if [ -r $onedst ]; then
  1192. if cmp -s $onesrc $onedst; then
  1193. if [ ".$opt_t" = .yes ]; then
  1194. echo "rm -f $onesrc" 1>&2
  1195. fi
  1196. rm -f $onesrc || errorstatus=$?
  1197. else
  1198. if [ ".$opt_t" = .yes ]; then
  1199. echo "mv -f $onesrc $onedst" 1>&2
  1200. fi
  1201. mv -f $onesrc $onedst || errorstatus=$?
  1202. fi
  1203. else
  1204. if [ ".$opt_t" = .yes ]; then
  1205. echo "mv -f $onesrc $onedst" 1>&2
  1206. fi
  1207. mv -f $onesrc $onedst || errorstatus=$?
  1208. fi
  1209. else
  1210. if [ ".$opt_t" = .yes ]; then
  1211. echo "mv -f $onesrc $onedst" 1>&2
  1212. fi
  1213. mv -f $onesrc $onedst || errorstatus=$?
  1214. fi
  1215. if [ $errorstatus -ne 0 ]; then
  1216. break;
  1217. fi
  1218. done
  1219. shtool_exit $errorstatus
  1220. ;;
  1221. install )
  1222. ##
  1223. ## install -- Install a program, script or datafile
  1224. ## Copyright (c) 1997-2008 Ralf S. Engelschall <rse@engelschall.com>
  1225. ##
  1226. # special case: "shtool install -d <dir> [...]" internally
  1227. # maps to "shtool mkdir -f -p -m 755 <dir> [...]"
  1228. if [ "$opt_d" = yes ]; then
  1229. cmd="$0 mkdir -f -p -m 755"
  1230. if [ ".$opt_o" != . ]; then
  1231. cmd="$cmd -o '$opt_o'"
  1232. fi
  1233. if [ ".$opt_g" != . ]; then
  1234. cmd="$cmd -g '$opt_g'"
  1235. fi
  1236. if [ ".$opt_v" = .yes ]; then
  1237. cmd="$cmd -v"
  1238. fi
  1239. if [ ".$opt_t" = .yes ]; then
  1240. cmd="$cmd -t"
  1241. fi
  1242. for dir in "$@"; do
  1243. eval "$cmd $dir" || shtool_exit $?
  1244. done
  1245. shtool_exit 0
  1246. fi
  1247. # determine source(s) and destination
  1248. argc=$#
  1249. srcs=""
  1250. while [ $# -gt 1 ]; do
  1251. srcs="$srcs $1"
  1252. shift
  1253. done
  1254. dstpath="$1"
  1255. # type check for destination
  1256. dstisdir=0
  1257. if [ -d $dstpath ]; then
  1258. dstpath=`echo "$dstpath" | sed -e 's:/$::'`
  1259. dstisdir=1
  1260. fi
  1261. # consistency check for destination
  1262. if [ $argc -gt 2 ] && [ $dstisdir = 0 ]; then
  1263. echo "$msgprefix:Error: multiple sources require destination to be directory" 1>&2
  1264. shtool_exit 1
  1265. fi
  1266. # iterate over all source(s)
  1267. for src in $srcs; do
  1268. dst=$dstpath
  1269. # if destination is a directory, append the input filename
  1270. if [ $dstisdir = 1 ]; then
  1271. dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'`
  1272. dst="$dst/$dstfile"
  1273. fi
  1274. # check for correct arguments
  1275. if [ ".$src" = ".$dst" ]; then
  1276. echo "$msgprefix:Warning: source and destination are the same - skipped" 1>&2
  1277. continue
  1278. fi
  1279. if [ -d "$src" ]; then
  1280. echo "$msgprefix:Warning: source \`$src' is a directory - skipped" 1>&2
  1281. continue
  1282. fi
  1283. # make a temp file name in the destination directory
  1284. dsttmp=`echo $dst |\
  1285. sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;' \
  1286. -e "s;\$;/#INST@$$#;"`
  1287. # verbosity
  1288. if [ ".$opt_v" = .yes ]; then
  1289. echo "$src -> $dst" 1>&2
  1290. fi
  1291. # copy or move the file name to the temp name
  1292. # (because we might be not allowed to change the source)
  1293. if [ ".$opt_C" = .yes ]; then
  1294. opt_c=yes
  1295. fi
  1296. if [ ".$opt_c" = .yes ]; then
  1297. if [ ".$opt_t" = .yes ]; then
  1298. echo "cp $src $dsttmp" 1>&2
  1299. fi
  1300. cp "$src" "$dsttmp" || shtool_exit $?
  1301. else
  1302. if [ ".$opt_t" = .yes ]; then
  1303. echo "mv $src $dsttmp" 1>&2
  1304. fi
  1305. mv "$src" "$dsttmp" || shtool_exit $?
  1306. fi
  1307. # adjust the target file
  1308. if [ ".$opt_e" != . ]; then
  1309. sed='sed'
  1310. OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS"
  1311. for e
  1312. do
  1313. sed="$sed -e '$e'"
  1314. done
  1315. cp "$dsttmp" "$dsttmp.old"
  1316. chmod u+w $dsttmp
  1317. eval "$sed <$dsttmp.old >$dsttmp" || shtool_exit $?
  1318. rm -f $dsttmp.old
  1319. fi
  1320. if [ ".$opt_s" = .yes ]; then
  1321. if [ ".$opt_t" = .yes ]; then
  1322. echo "strip $dsttmp" 1>&2
  1323. fi
  1324. strip $dsttmp || shtool_exit $?
  1325. fi
  1326. if [ ".$opt_o" != . ]; then
  1327. if [ ".$opt_t" = .yes ]; then
  1328. echo "chown $opt_o $dsttmp" 1>&2
  1329. fi
  1330. chown $opt_o $dsttmp || shtool_exit $?
  1331. fi
  1332. if [ ".$opt_g" != . ]; then
  1333. if [ ".$opt_t" = .yes ]; then
  1334. echo "chgrp $opt_g $dsttmp" 1>&2
  1335. fi
  1336. chgrp $opt_g $dsttmp || shtool_exit $?
  1337. fi
  1338. if [ ".$opt_m" != ".-" ]; then
  1339. if [ ".$opt_t" = .yes ]; then
  1340. echo "chmod $opt_m $dsttmp" 1>&2
  1341. fi
  1342. chmod $opt_m $dsttmp || shtool_exit $?
  1343. fi
  1344. # determine whether to do a quick install
  1345. # (has to be done _after_ the strip was already done)
  1346. quick=no
  1347. if [ ".$opt_C" = .yes ]; then
  1348. if [ -r $dst ]; then
  1349. if cmp -s "$src" "$dst"; then
  1350. quick=yes
  1351. fi
  1352. fi
  1353. fi
  1354. # finally, install the file to the real destination
  1355. if [ $quick = yes ]; then
  1356. if [ ".$opt_t" = .yes ]; then
  1357. echo "rm -f $dsttmp" 1>&2
  1358. fi
  1359. rm -f $dsttmp
  1360. else
  1361. if [ ".$opt_t" = .yes ]; then
  1362. echo "rm -f $dst && mv $dsttmp $dst" 1>&2
  1363. fi
  1364. rm -f $dst && mv $dsttmp $dst
  1365. fi
  1366. done
  1367. shtool_exit 0
  1368. ;;
  1369. mkdir )
  1370. ##
  1371. ## mkdir -- Make one or more directories
  1372. ## Copyright (c) 1996-2008 Ralf S. Engelschall <rse@engelschall.com>
  1373. ##
  1374. errstatus=0
  1375. for p in ${1+"$@"}; do
  1376. # if the directory already exists...
  1377. if [ -d "$p" ]; then
  1378. if [ ".$opt_f" = .no ] && [ ".$opt_p" = .no ]; then
  1379. echo "$msgprefix:Error: directory already exists: $p" 1>&2
  1380. errstatus=1
  1381. break
  1382. else
  1383. continue
  1384. fi
  1385. fi
  1386. # if the directory has to be created...
  1387. if [ ".$opt_p" = .no ]; then
  1388. if [ ".$opt_t" = .yes ]; then
  1389. echo "mkdir $p" 1>&2
  1390. fi
  1391. mkdir $p || errstatus=$?
  1392. if [ ".$opt_o" != . ]; then
  1393. if [ ".$opt_t" = .yes ]; then
  1394. echo "chown $opt_o $p" 1>&2
  1395. fi
  1396. chown $opt_o $p || errstatus=$?
  1397. fi
  1398. if [ ".$opt_g" != . ]; then
  1399. if [ ".$opt_t" = .yes ]; then
  1400. echo "chgrp $opt_g $p" 1>&2
  1401. fi
  1402. chgrp $opt_g $p || errstatus=$?
  1403. fi
  1404. if [ ".$opt_m" != . ]; then
  1405. if [ ".$opt_t" = .yes ]; then
  1406. echo "chmod $opt_m $p" 1>&2
  1407. fi
  1408. chmod $opt_m $p || errstatus=$?
  1409. fi
  1410. else
  1411. # the smart situation
  1412. set fnord `echo ":$p" |\
  1413. sed -e 's/^:\//%/' \
  1414. -e 's/^://' \
  1415. -e 's/\// /g' \
  1416. -e 's/^%/\//'`
  1417. shift
  1418. pathcomp=''
  1419. for d in ${1+"$@"}; do
  1420. pathcomp="$pathcomp$d"
  1421. case "$pathcomp" in
  1422. -* ) pathcomp="./$pathcomp" ;;
  1423. esac
  1424. if [ ! -d "$pathcomp" ]; then
  1425. if [ ".$opt_t" = .yes ]; then
  1426. echo "mkdir $pathcomp" 1>&2
  1427. fi
  1428. mkdir $pathcomp || errstatus=$?
  1429. if [ ".$opt_o" != . ]; then
  1430. if [ ".$opt_t" = .yes ]; then
  1431. echo "chown $opt_o $pathcomp" 1>&2
  1432. fi
  1433. chown $opt_o $pathcomp || errstatus=$?
  1434. fi
  1435. if [ ".$opt_g" != . ]; then
  1436. if [ ".$opt_t" = .yes ]; then
  1437. echo "chgrp $opt_g $pathcomp" 1>&2
  1438. fi
  1439. chgrp $opt_g $pathcomp || errstatus=$?
  1440. fi
  1441. if [ ".$opt_m" != . ]; then
  1442. if [ ".$opt_t" = .yes ]; then
  1443. echo "chmod $opt_m $pathcomp" 1>&2
  1444. fi
  1445. chmod $opt_m $pathcomp || errstatus=$?
  1446. fi
  1447. fi
  1448. pathcomp="$pathcomp/"
  1449. done
  1450. fi
  1451. done
  1452. shtool_exit $errstatus
  1453. ;;
  1454. mkln )
  1455. ##
  1456. ## mkln -- Make link with calculation of relative paths
  1457. ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
  1458. ##
  1459. # determine source(s) and destination
  1460. args=$#
  1461. srcs=""
  1462. while [ $# -gt 1 ]; do
  1463. srcs="$srcs $1"
  1464. shift
  1465. done
  1466. dst="$1"
  1467. if [ ! -d $dst ]; then
  1468. if [ $args -gt 2 ]; then
  1469. echo "$msgprefix:Error: multiple sources not allowed when target isn't a directory" 1>&2
  1470. shtool_exit 1
  1471. fi
  1472. fi
  1473. # determine link options
  1474. lnopt=""
  1475. if [ ".$opt_f" = .yes ]; then
  1476. lnopt="$lnopt -f"
  1477. fi
  1478. if [ ".$opt_s" = .yes ]; then
  1479. lnopt="$lnopt -s"
  1480. fi
  1481. # iterate over sources
  1482. for src in $srcs; do
  1483. # determine if one of the paths is an absolute path,
  1484. # because then we _have_ to use an absolute symlink
  1485. oneisabs=0
  1486. srcisabs=0
  1487. dstisabs=0
  1488. case $src in
  1489. /* ) oneisabs=1; srcisabs=1 ;;
  1490. esac
  1491. case $dst in
  1492. /* ) oneisabs=1; dstisabs=1 ;;
  1493. esac
  1494. # split source and destination into dir and base name
  1495. if [ -d $src ]; then
  1496. srcdir=`echo $src | sed -e 's;/*$;;'`
  1497. srcbase=""
  1498. else
  1499. srcdir=`echo $src | sed -e 's;^[^/]*$;;' -e 's;^\(.*/\)[^/]*$;\1;' -e 's;\(.\)/$;\1;'`
  1500. srcbase=`echo $src | sed -e 's;.*/\([^/]*\)$;\1;'`
  1501. fi
  1502. if [ -d $dst ]; then
  1503. dstdir=`echo $dst | sed -e 's;/*$;;'`
  1504. dstbase=""
  1505. else
  1506. dstdir=`echo $dst | sed -e 's;^[^/]*$;;' -e 's;^\(.*/\)[^/]*$;\1;' -e 's;\(.\)/$;\1;'`
  1507. dstbase=`echo $dst | sed -e 's;.*/\([^/]*\)$;\1;'`
  1508. fi
  1509. # consistency check
  1510. if [ ".$dstdir" != . ]; then
  1511. if [ ! -d $dstdir ]; then
  1512. echo "$msgprefix:Error: destination directory not found: $dstdir" 1>&2
  1513. shtool_exit 1
  1514. fi
  1515. fi
  1516. # make sure the source is reachable from the destination
  1517. if [ $dstisabs = 1 ]; then
  1518. if [ $srcisabs = 0 ]; then
  1519. if [ ".$srcdir" = . ]; then
  1520. srcdir="`pwd | sed -e 's;/*$;;'`"
  1521. srcisabs=1
  1522. oneisabs=1
  1523. elif [ -d $srcdir ]; then
  1524. srcdir="`cd $srcdir; pwd | sed -e 's;/*$;;'`"
  1525. srcisabs=1
  1526. oneisabs=1
  1527. fi
  1528. fi
  1529. fi
  1530. # split away a common prefix
  1531. prefix=""
  1532. if [ ".$srcdir" = ".$dstdir" ] && [ ".$srcdir" != . ]; then
  1533. prefix="$srcdir/"
  1534. srcdir=""
  1535. dstdir=""
  1536. else
  1537. while [ ".$srcdir" != . ] && [ ".$dstdir" != . ]; do
  1538. presrc=`echo $srcdir | sed -e 's;^\([^/]*\)/.*;\1;'`
  1539. predst=`echo $dstdir | sed -e 's;^\([^/]*\)/.*;\1;'`
  1540. if [ ".$presrc" != ".$predst" ]; then
  1541. break
  1542. fi
  1543. prefix="$prefix$presrc/"
  1544. srcdir=`echo $srcdir | sed -e 's;^[^/]*/*;;'`
  1545. dstdir=`echo $dstdir | sed -e 's;^[^/]*/*;;'`
  1546. done
  1547. fi
  1548. # destination prefix is just the common prefix
  1549. dstpre="$prefix"
  1550. # determine source prefix which is the reverse directory
  1551. # step-up corresponding to the destination directory
  1552. srcpre=""
  1553. allow_relative_srcpre=no
  1554. if [ ".$prefix" != . ] && [ ".$prefix" != ./ ]; then
  1555. allow_relative_srcpre=yes
  1556. fi
  1557. if [ $oneisabs = 0 ]; then
  1558. allow_relative_srcpre=yes
  1559. fi
  1560. if [ ".$opt_s" != .yes ]; then
  1561. allow_relative_srcpre=no
  1562. fi
  1563. if [ ".$allow_relative_srcpre" = .yes ]; then
  1564. pl="$dstdir/"
  1565. OIFS="$IFS"; IFS='/'
  1566. for pe in $pl; do
  1567. [ ".$pe" = . ] && continue
  1568. [ ".$pe" = .. ] && continue
  1569. srcpre="../$srcpre"
  1570. done
  1571. IFS="$OIFS"
  1572. else
  1573. if [ $srcisabs = 1 ]; then
  1574. srcpre="$prefix"
  1575. fi
  1576. fi
  1577. # determine destination symlink name
  1578. if [ ".$dstbase" = . ]; then
  1579. if [ ".$srcbase" != . ]; then
  1580. dstbase="$srcbase"
  1581. else
  1582. dstbase=`echo "$prefix$srcdir" | sed -e 's;/*$;;' -e 's;.*/\([^/]*\)$;\1;'`
  1583. fi
  1584. fi
  1585. # now finalize source and destination directory paths
  1586. srcdir=`echo $srcdir | sed -e 's;\([^/]\)$;\1/;'`
  1587. dstdir=`echo $dstdir | sed -e 's;\([^/]\)$;\1/;'`
  1588. # run the final link command
  1589. if [ ".$opt_t" = .yes ]; then
  1590. echo "ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase"
  1591. fi
  1592. eval ln$lnopt $srcpre$srcdir$srcbase $dstpre$dstdir$dstbase
  1593. done
  1594. shtool_exit 0
  1595. ;;
  1596. mkshadow )
  1597. ##
  1598. ## mkshadow -- Make a shadow tree through symbolic links
  1599. ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
  1600. ##
  1601. # source and destination directory
  1602. src=`echo "$1" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'`
  1603. dst=`echo "$2" | sed -e 's:/$::' -e 's:^\./\(.\):\1:'`
  1604. # check whether source exists
  1605. if [ ! -d $src ]; then
  1606. echo "$msgprefix:Error: source directory not found: \`$src'" 1>&2
  1607. shtool_exit 1
  1608. fi
  1609. # determine if one of the paths is an absolute path,
  1610. # because then we have to use an absolute symlink
  1611. oneisabs=0
  1612. case $src in
  1613. /* ) oneisabs=1 ;;
  1614. esac
  1615. case $dst in
  1616. /* ) oneisabs=1 ;;
  1617. esac
  1618. # determine reverse directory for destination directory
  1619. dstrevdir=''
  1620. if [ $oneisabs = 0 ]; then
  1621. # derive reverse path from forward path
  1622. pwd=`pwd`
  1623. OIFS="$IFS"; IFS='/'
  1624. for pe in $dst; do
  1625. if [ "x$pe" = "x.." ]; then
  1626. OIFS2="$IFS"; IFS="$DIFS"
  1627. eval `echo "$pwd" |\
  1628. sed -e 's:\([^/]*\)$:; dir="\1":' \
  1629. -e 's:^\(.*\)/[^/]*;:pwd="\1";:'\
  1630. -e 's:^;:pwd="";:'`
  1631. dstrevdir="$dir/$dstrevdir"
  1632. IFS="$OIFS2"
  1633. else
  1634. dstrevdir="../$dstrevdir"
  1635. fi
  1636. done
  1637. IFS="$OIFS"
  1638. else
  1639. src="`cd $src; pwd`";
  1640. fi
  1641. # create directory tree at destination
  1642. if [ ! -d $dst ]; then
  1643. if [ ".$opt_t" = .yes ]; then
  1644. echo "mkdir $dst" 1>&2
  1645. fi
  1646. mkdir $dst
  1647. fi
  1648. if [ ".$opt_a" = .yes ]; then
  1649. DIRS=`cd $src; find . -type d -print |\
  1650. sed -e '/^\.$/d' -e 's:^\./::'`
  1651. else
  1652. DIRS=`cd $src; find . -type d -print |\
  1653. sed -e '/\/CVS/d' -e '/^\.$/d' -e 's:^\./::'`
  1654. fi
  1655. for dir in $DIRS; do
  1656. if [ ".$opt_t" = .yes ]; then
  1657. echo "mkdir $dst/$dir" 1>&2
  1658. fi
  1659. mkdir $dst/$dir
  1660. done
  1661. # fill directory tree with symlinks to files
  1662. if [ ".$opt_a" = .yes ]; then
  1663. FILES="`cd $src; find . -depth -print |\
  1664. sed -e 's/^\.\///'`"
  1665. else
  1666. FILES="`cd $src; find . -depth -print |\
  1667. sed -e '/\.o$/d' -e '/\.a$/d' -e '/\.so$/d' \
  1668. -e '/\.cvsignore$/d' -e '/\/CVS/d' \
  1669. -e '/\/\.#/d' -e '/\.orig$/d' \
  1670. -e 's/^\.\///'`"
  1671. fi
  1672. for file in $FILES; do
  1673. # don't use `-type f' above for find because of symlinks
  1674. if [ -d "$src/$file" ]; then
  1675. continue
  1676. fi
  1677. basename=`echo $file | sed -e 's:^.*/::'`
  1678. dir=`echo $file | sed -e 's:[^/]*$::' -e 's:/$::' -e 's:$:/:' -e 's:^/$::'`
  1679. from=`echo "$src/$file" | sed -e 's/^\.\///'`
  1680. to="$dst/$dir$basename"
  1681. if [ $oneisabs = 0 ]; then
  1682. if [ ".$dir" != . ]; then
  1683. subdir=`echo $dir | sed -e 's:/$::'`
  1684. # derive reverse path from forward path
  1685. revdir=''
  1686. OIFS="$IFS"; IFS='/'
  1687. for pe in $subdir; do
  1688. revdir="../$revdir"
  1689. done
  1690. IFS="$OIFS"
  1691. # finalize from
  1692. from="$revdir$from"
  1693. fi
  1694. from="$dstrevdir$from"
  1695. fi
  1696. if [ ".$opt_v" = .yes ]; then
  1697. echo " $to" 1>&2
  1698. fi
  1699. if [ ".$opt_t" = .yes ]; then
  1700. echo "ln -s $from $to" 1>&2
  1701. fi
  1702. ln -s $from $to
  1703. done
  1704. shtool_exit 0
  1705. ;;
  1706. fixperm )
  1707. ##
  1708. ## fixperm -- Fix file permissions inside a source tree
  1709. ## Copyright (c) 1996-2008 Ralf S. Engelschall <rse@engelschall.com>
  1710. ##
  1711. paths="$*"
  1712. # check whether the test command supports the -x option
  1713. if [ -x /bin/sh ] 2>/dev/null; then
  1714. minusx="-x"
  1715. else
  1716. minusx="-r"
  1717. fi
  1718. # iterate over paths
  1719. for p in $paths; do
  1720. for file in `find $p -depth -print`; do
  1721. if [ -f $file ]; then
  1722. if [ $minusx $file ]; then
  1723. if [ ".$opt_v" = .yes ]; then
  1724. echo "-rwxr-xr-x $file" 2>&1
  1725. fi
  1726. if [ ".$opt_t" = .yes ]; then
  1727. echo "chmod 755 $file" 2>&1
  1728. fi
  1729. chmod 755 $file
  1730. else
  1731. if [ ".$opt_v" = .yes ]; then
  1732. echo "-rw-r--r-- $file" 2>&1
  1733. fi
  1734. if [ ".$opt_t" = .yes ]; then
  1735. echo "chmod 644 $file" 2>&1
  1736. fi
  1737. chmod 644 $file
  1738. fi
  1739. continue
  1740. fi
  1741. if [ -d $file ]; then
  1742. if [ ".$opt_v" = .yes ]; then
  1743. echo "drwxr-xr-x $file" 2>&1
  1744. fi
  1745. if [ ".$opt_t" = .yes ]; then
  1746. echo "chmod 755 $file" 2>&1
  1747. fi
  1748. chmod 755 $file
  1749. continue
  1750. fi
  1751. if [ ".$opt_v" = .yes ]; then
  1752. echo "?????????? $file" 2>&1
  1753. fi
  1754. done
  1755. done
  1756. shtool_exit 0
  1757. ;;
  1758. rotate )
  1759. ##
  1760. ## rotate -- Logfile rotation
  1761. ## Copyright (c) 2001-2008 Ralf S. Engelschall <rse@engelschall.com>
  1762. ##
  1763. # make sure we have at least one file to rotate
  1764. if [ ".$opt_n" = .0 ]; then
  1765. echo "$msgprefix:Error: invalid argument \`$opt_n' to option -n." 1>&2
  1766. shtool_exit 1
  1767. fi
  1768. # canonicalize -s option argument
  1769. if [ ".$opt_s" != . ]; then
  1770. if [ ".`expr $opt_s : '[0-9]*$'`" != .0 ]; then
  1771. :
  1772. elif [ ".`expr $opt_s : '[0-9]*[Kk]$'`" != .0 ]; then
  1773. opt_s=`expr $opt_s : '\([0-9]*\)[Kk]$'`
  1774. opt_s=`expr $opt_s \* 1024`
  1775. elif [ ".`expr $opt_s : '[0-9]*[Mm]$'`" != .0 ]; then
  1776. opt_s=`expr $opt_s : '\([0-9]*\)[Mm]$'`
  1777. opt_s=`expr $opt_s \* 1048576` # 1024*1024
  1778. elif [ ".`expr $opt_s : '[0-9]*[Gg]$'`" != .0 ]; then
  1779. opt_s=`expr $opt_s : '\([0-9]*\)[Gg]$'`
  1780. opt_s=`expr $opt_s \* 1073741824` # 1024*1024*1024
  1781. else
  1782. echo "$msgprefix:Error: invalid argument \`$opt_s' to option -s." 1>&2
  1783. shtool_exit 1
  1784. fi
  1785. fi
  1786. # option -d/-z consistency
  1787. if [ ".$opt_d" = .yes ] && [ ".$opt_z" = . ]; then
  1788. echo "$msgprefix:Error: option -d requires option -z." 1>&2
  1789. shtool_exit 1
  1790. fi
  1791. # make sure target directory exists
  1792. if [ ".$opt_a" != . ]; then
  1793. if [ ! -d $opt_a ]; then
  1794. if [ ".$opt_f" = .no ]; then
  1795. echo "$msgprefix:Error: archive directory \`$opt_a' does not exist." 1>&2
  1796. shtool_exit 1
  1797. fi
  1798. mkdir $opt_a || shtool_exit $?
  1799. chmod 755 $opt_a
  1800. fi
  1801. if [ ! -w $opt_a ]; then
  1802. echo "$msgprefix:Error: archive directory \`$opt_a' not writable." 1>&2
  1803. shtool_exit 1
  1804. fi
  1805. fi
  1806. # determine compression approach
  1807. if [ ".$opt_z" != . ]; then
  1808. comp_lvl="$opt_z"
  1809. comp_prg=""
  1810. case $comp_lvl in
  1811. *:* ) eval `echo $comp_lvl |\
  1812. sed -e 's%^\(.*\):\(.*\)$%comp_prg="\1"; comp_lvl="\2"%'` ;;
  1813. esac
  1814. # compression level consistency
  1815. case $comp_lvl in
  1816. [0-9] )
  1817. ;;
  1818. * ) echo "$msgprefix:Error: invalid compression level \`$comp_lvl'" 1>&2
  1819. shtool_exit 1
  1820. ;;
  1821. esac
  1822. # determine a suitable compression tool
  1823. if [ ".$comp_prg" = . ]; then
  1824. # check whether the test command supports the -x option
  1825. if [ -x /bin/sh ] 2>/dev/null; then
  1826. minusx="-x"
  1827. else
  1828. minusx="-r"
  1829. fi
  1830. # search for tools in $PATH
  1831. paths="`echo $PATH |\
  1832. sed -e 's%/*:%:%g' -e 's%/*$%%' \
  1833. -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
  1834. -e 's/:/ /g'`"
  1835. for prg in bzip2 gzip compress; do
  1836. for path in $paths; do
  1837. if [ $minusx "$path/$prg" ] && [ ! -d "$path/$prg" ]; then
  1838. comp_prg="$prg"
  1839. break
  1840. fi
  1841. done
  1842. if [ ".$comp_prg" != . ]; then
  1843. break
  1844. fi
  1845. done
  1846. if [ ".$comp_prg" = . ]; then
  1847. echo "$msgprefix:Error: no suitable compression tool found in \$PATH" 1>&2
  1848. shtool_exit 1
  1849. fi
  1850. fi
  1851. # determine standard compression extension
  1852. # and make sure it is a known tool
  1853. case $comp_prg in
  1854. */bzip2 | bzip2 ) comp_ext="bz2" comp_lvl="-$comp_lvl" ;;
  1855. */gzip | gzip ) comp_ext="gz" comp_lvl="-$comp_lvl" ;;
  1856. */compress | compress ) comp_ext="Z"; comp_lvl="" ;;
  1857. * ) echo "$msgprefix:Error: tool \`$comp_prg' is not a known compression tool" 1>&2
  1858. shtool_exit 1
  1859. ;;
  1860. esac
  1861. comp_suf=".$comp_ext"
  1862. fi
  1863. # iterate over all given logfile arguments
  1864. for file in $*; do
  1865. # make sure the logfile exists
  1866. if [ ! -f $file ]; then
  1867. if [ ".$opt_f" = .yes ]; then
  1868. continue
  1869. fi
  1870. echo "$msgprefix:Error: logfile \`$file' not found" 1>&2
  1871. shtool_exit 1
  1872. fi
  1873. # determine log directory (where original logfile is placed)
  1874. ldir="."
  1875. case $file in
  1876. */* ) eval `echo $file | sed -e 's%^\(.*\)/\([^/]*\)$%ldir="\1"; file="\2";%'` ;;
  1877. esac
  1878. # determine archive directory (where rotated logfiles are placed)
  1879. adir="$ldir"
  1880. if [ ".$opt_a" != . ]; then
  1881. case "$opt_a" in
  1882. /* | ./* ) adir="$opt_a" ;;
  1883. * ) adir="$ldir/$opt_a" ;;
  1884. esac
  1885. fi
  1886. # optionally take logfile size into account
  1887. if [ ".$opt_s" != . ]; then
  1888. # determine size of logfile
  1889. set -- `env -i /bin/ls -l "$ldir/$file" | sed -e "s;$ldir/$file;;" |\
  1890. sed -e 's; -> .*$;;' -e 's;[ ][ ]*; ;g'`
  1891. n=`expr $# - 3`
  1892. eval "size=\`echo \${$n}\`"
  1893. # skip logfile if size is still too small
  1894. if [ $size -lt $opt_s ]; then
  1895. if [ ".$opt_v" = .yes ]; then
  1896. echo "$ldir/$file: still too small in size -- skipping"
  1897. fi
  1898. continue
  1899. fi
  1900. fi
  1901. # verbosity
  1902. if [ ".$opt_v" = .yes ]; then
  1903. echo "rotating $ldir/$file"
  1904. fi
  1905. # execute prolog
  1906. if [ ".$opt_P" != . ]; then
  1907. if [ ".$opt_t" = .yes ]; then
  1908. echo "$opt_P"
  1909. fi
  1910. eval $opt_P
  1911. [ $? -ne 0 ] && shtool_exit $?
  1912. fi
  1913. # kick away out-rotated logfile
  1914. n=`expr $opt_n - 1`
  1915. n=`echo dummy | awk "{ printf(\"%0${opt_p}d\", n); }" n=$n`
  1916. if [ -f "${adir}/${file}.${n}${comp_suf}" ]; then
  1917. # optionally migrate away the out-rotated logfile
  1918. if [ ".$opt_M" != . ]; then
  1919. if [ ".$opt_t" = .yes ]; then
  1920. echo "$opt_M ${adir}/${file}.${n}${comp_suf}"
  1921. fi
  1922. eval "$opt_M ${adir}/${file}.${n}${comp_suf}"
  1923. [ $? -ne 0 ] && shtool_exit $?
  1924. fi
  1925. # finally get rid of the out-rotated logfile
  1926. if [ ".$opt_t" = .yes ]; then
  1927. echo "rm -f ${adir}/${file}.${n}${comp_suf}"
  1928. fi
  1929. rm -f ${adir}/${file}.${n}${comp_suf} || shtool_exit $?
  1930. fi
  1931. # rotate already archived logfiles
  1932. while [ $n -gt 0 ]; do
  1933. m=$n
  1934. n=`expr $n - 1`
  1935. n=`echo dummy | awk "{ printf(\"%0${opt_p}d\", n); }" n=$n`
  1936. if [ $n -eq 0 ] && [ ".$opt_d" = .yes ]; then
  1937. # special case: first rotation file under delayed compression situation
  1938. if [ ! -f "${adir}/${file}.${n}" ]; then
  1939. continue
  1940. fi
  1941. # compress file (delayed)
  1942. if [ ".$opt_b" = .yes ]; then
  1943. if [ ".$opt_t" = .yes ]; then
  1944. echo "mv ${adir}/${file}.${n} ${adir}/${file}.${m}"
  1945. fi
  1946. mv ${adir}/${file}.${n} ${adir}/${file}.${m} || shtool_exit $?
  1947. if [ ".$opt_t" = .yes ]; then
  1948. echo "(${comp_prg} ${comp_lvl} <${adir}/${file}.${m} >${adir}/${file}.${m}${comp_suf}; rm -f ${adir}/${file}.${m}) &"
  1949. fi
  1950. ( ${comp_prg} ${comp_lvl} \
  1951. <${adir}/${file}.${m} \
  1952. >${adir}/${file}.${m}${comp_suf} || shtool_exit $?
  1953. rm -f ${adir}/${file}.${m} || shtool_exit $?
  1954. ) </dev/null >/dev/null 2>&1 &
  1955. else
  1956. if [ ".$opt_t" = .yes ]; then
  1957. echo "${comp_prg} ${comp_lvl} <${adir}/${file}.${n} >${adir}/${file}.${m}${comp_suf}"
  1958. fi
  1959. ${comp_prg} ${comp_lvl} \
  1960. <${adir}/${file}.${n} \
  1961. >${adir}/${file}.${m}${comp_suf} || shtool_exit $?
  1962. if [ ".$opt_t" = .yes ]; then
  1963. echo "rm -f ${adir}/${file}.${n}"
  1964. fi
  1965. rm -f ${adir}/${file}.${n} || shtool_exit $?
  1966. fi
  1967. # fix file attributes
  1968. if [ ".$opt_o" != . ]; then
  1969. if [ ".$opt_t" = .yes ]; then
  1970. echo "chown $opt_o ${adir}/${file}.${m}${comp_suf}"
  1971. fi
  1972. chown $opt_o ${adir}/${file}.${m}${comp_suf} || shtool_exit $?
  1973. fi
  1974. if [ ".$opt_g" != . ]; then
  1975. if [ ".$opt_t" = .yes ]; then
  1976. echo "chgrp $opt_g ${adir}/${file}.${m}${comp_suf}"
  1977. fi
  1978. chgrp $opt_g ${adir}/${file}.${m}${comp_suf} || shtool_exit $?
  1979. fi
  1980. if [ ".$opt_m" != . ]; then
  1981. if [ ".$opt_t" = .yes ]; then
  1982. echo "chmod $opt_m ${adir}/${file}.${m}${comp_suf}"
  1983. fi
  1984. chmod $opt_m ${adir}/${file}.${m}${comp_suf} || shtool_exit $?
  1985. fi
  1986. else
  1987. # standard case: second and following rotation file
  1988. if [ ! -f "${adir}/${file}.${n}${comp_suf}" ]; then
  1989. continue
  1990. fi
  1991. if [ ".$opt_t" = .yes ]; then
  1992. echo "mv ${adir}/${file}.${n}${comp_suf} ${adir}/${file}.${m}${comp_suf}"
  1993. fi
  1994. mv ${adir}/${file}.${n}${comp_suf} ${adir}/${file}.${m}${comp_suf} || shtool_exit $?
  1995. fi
  1996. done
  1997. # move away current logfile
  1998. if [ ".$opt_c" = .yes ]; then
  1999. # approach: copy[+truncate]
  2000. if [ ".$opt_t" = .yes ]; then
  2001. echo "cp -p ${ldir}/${file} ${adir}/${file}.${n}"
  2002. fi
  2003. cp -p ${ldir}/${file} ${adir}/${file}.${n} || shtool_exit $?
  2004. if [ ".$opt_r" = .no ]; then
  2005. if [ ".$opt_t" = .yes ]; then
  2006. echo "cp /dev/null ${ldir}/${file}"
  2007. fi
  2008. cp /dev/null ${ldir}/${file} || shtool_exit $?
  2009. fi
  2010. else
  2011. # approach: move[+touch]
  2012. if [ ".$opt_t" = .yes ]; then
  2013. echo "mv ${ldir}/${file} ${adir}/${file}.${n}"
  2014. fi
  2015. mv ${ldir}/${file} ${adir}/${file}.${n} || shtool_exit $?
  2016. if [ ".$opt_r" = .no ]; then
  2017. if [ ".$opt_t" = .yes ]; then
  2018. echo "touch ${ldir}/${file}"
  2019. fi
  2020. touch ${ldir}/${file} || shtool_exit $?
  2021. # fix file attributes
  2022. if [ ".$opt_o" != . ]; then
  2023. if [ ".$opt_t" = .yes ]; then
  2024. echo "chown $opt_o ${ldir}/${file}"
  2025. fi
  2026. chown $opt_o ${ldir}/${file} || shtool_exit $?
  2027. fi
  2028. if [ ".$opt_g" != . ]; then
  2029. if [ ".$opt_t" = .yes ]; then
  2030. echo "chgrp $opt_g ${ldir}/${file}"
  2031. fi
  2032. chgrp $opt_g ${ldir}/${file} || shtool_exit $?
  2033. fi
  2034. if [ ".$opt_m" != . ]; then
  2035. if [ ".$opt_t" = .yes ]; then
  2036. echo "chmod $opt_m ${ldir}/${file}"
  2037. fi
  2038. chmod $opt_m ${ldir}/${file} || shtool_exit $?
  2039. fi
  2040. fi
  2041. fi
  2042. # regular compression step
  2043. if [ ".$opt_z" != . ] && [ ".$opt_d" = .no ]; then
  2044. # compress file
  2045. if [ ".$opt_b" = .yes ]; then
  2046. if [ ".$opt_t" = .yes ]; then
  2047. echo "(${comp_prg} ${comp_lvl} <${adir}/${file}.${n} >${adir}/${file}.${n}${comp_suf}; rm -f ${adir}/${file}.${n}) &"
  2048. fi
  2049. ( ${comp_prg} ${comp_lvl} \
  2050. <${adir}/${file}.${n} \
  2051. >${adir}/${file}.${n}${comp_suf} || shtool_exit $?
  2052. rm -f ${adir}/${file}.${n} || shtool_exit $?
  2053. ) </dev/null >/dev/null 2>&1 &
  2054. else
  2055. if [ ".$opt_t" = .yes ]; then
  2056. echo "${comp_prg} ${comp_lvl} <${adir}/${file}.${n} >${adir}/${file}.${n}${comp_suf}"
  2057. fi
  2058. ${comp_prg} ${comp_lvl} \
  2059. <${adir}/${file}.${n} \
  2060. >${adir}/${file}.${n}${comp_suf} || shtool_exit $?
  2061. if [ ".$opt_t" = .yes ]; then
  2062. echo "rm -f ${opt_a}${file}.${n}"
  2063. fi
  2064. rm -f ${adir}/${file}.${n} || shtool_exit $?
  2065. fi
  2066. # fix file attributes
  2067. if [ ".$opt_o" != . ]; then
  2068. if [ ".$opt_t" = .yes ]; then
  2069. echo "chown $opt_o ${adir}/${file}.${n}${comp_suf}"
  2070. fi
  2071. chown $opt_o ${adir}/${file}.${n}${comp_suf} || shtool_exit $?
  2072. fi
  2073. if [ ".$opt_g" != . ]; then
  2074. if [ ".$opt_t" = .yes ]; then
  2075. echo "chgrp $opt_g ${adir}/${file}.${n}${comp_suf}"
  2076. fi
  2077. chgrp $opt_g ${adir}/${file}.${n}${comp_suf} || shtool_exit $?
  2078. fi
  2079. if [ ".$opt_m" != . ]; then
  2080. if [ ".$opt_t" = .yes ]; then
  2081. echo "chmod $opt_m ${adir}/${file}.${n}${comp_suf}"
  2082. fi
  2083. chmod $opt_m ${adir}/${file}.${n}${comp_suf} || shtool_exit $?
  2084. fi
  2085. fi
  2086. # execute epilog
  2087. if [ ".$opt_E" != . ]; then
  2088. if [ ".$opt_t" = .yes ]; then
  2089. echo "$opt_E"
  2090. fi
  2091. eval $opt_E
  2092. [ $? -ne 0 ] && shtool_exit $?
  2093. fi
  2094. done
  2095. shtool_exit 0
  2096. ;;
  2097. tarball )
  2098. ##
  2099. ## tarball -- Roll distribution tarballs
  2100. ## Copyright (c) 1999-2008 Ralf S. Engelschall <rse@engelschall.com>
  2101. ##
  2102. srcs="$*"
  2103. # check whether the test command supports the -x option
  2104. if [ -x /bin/sh ] 2>/dev/null; then
  2105. minusx="-x"
  2106. else
  2107. minusx="-r"
  2108. fi
  2109. # find the tools
  2110. paths="`echo $PATH |\
  2111. sed -e 's%/*:%:%g' -e 's%/*$%%' \
  2112. -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
  2113. -e 's/:/ /g'`"
  2114. for spec in find:gfind,find tar:gtar,tar tardy:tardy,tarcust; do
  2115. prg=`echo $spec | sed -e 's/:.*$//'`
  2116. tools=`echo $spec | sed -e 's/^.*://'`
  2117. eval "prg_${prg}=''"
  2118. # iterate over tools
  2119. for tool in `echo $tools | sed -e 's/,/ /g'`; do
  2120. # iterate over paths
  2121. for path in $paths; do
  2122. if [ $minusx "$path/$tool" ] && [ ! -d "$path/$tool" ]; then
  2123. eval "prg_${prg}=\"$path/$tool\""
  2124. break
  2125. fi
  2126. done
  2127. eval "val=\$prg_${prg}"
  2128. if [ ".$val" != . ]; then
  2129. break
  2130. fi
  2131. done
  2132. done
  2133. # expand source paths
  2134. exclude=''
  2135. for pat in `echo $opt_e | sed 's/,/ /g'`; do
  2136. exclude="$exclude | grep -v '$pat'"
  2137. done
  2138. if [ ".$opt_t" = .yes ]; then
  2139. echo "cp /dev/null $tmpfile.lst" 1>&2
  2140. fi
  2141. cp /dev/null $tmpfile.lst
  2142. for src in $srcs; do
  2143. if [ -d $src ]; then
  2144. if [ ".$opt_t" = .yes ]; then
  2145. echo "(cd $src && $prg_find . -type f -depth -print) | sed -e 's:^\\.\$::' -e 's:^\\./::' | cat $exclude >>$tmpfile.lst" 1>&2
  2146. fi
  2147. (cd $src && $prg_find . -type f -depth -print) |\
  2148. sed -e 's:^\.$::' -e 's:^\./::' | eval cat $exclude >>$tmpfile.lst
  2149. else
  2150. if [ ".$opt_t" = .yes ]; then
  2151. echo "echo $src >>$tmpfile.lst" 1>&2
  2152. fi
  2153. echo $src >>$tmpfile.lst
  2154. fi
  2155. done
  2156. sort <$tmpfile.lst >$tmpfile.lst.n
  2157. mv $tmpfile.lst.n $tmpfile.lst
  2158. if [ ".$opt_v" = .yes ]; then
  2159. cat $tmpfile.lst | sed -e 's/^/ /' 1>&2
  2160. fi
  2161. # determine tarball file and directory name
  2162. if [ ".$opt_o" != . ]; then
  2163. tarfile="$opt_o"
  2164. if [ ".$opt_d" != . ]; then
  2165. tarname="$opt_d"
  2166. else
  2167. tarname=`echo $tarfile | sed -e 's/\.tar.*$//' -e 's;.*/\([^/]*\)$;\1;'`
  2168. fi
  2169. else
  2170. if [ ".$opt_d" != . ]; then
  2171. tarname="$opt_d"
  2172. elif [ -d "$from" ]; then
  2173. tarname=`echo $from | sed -e 's;.*/\([^/]*\)$;\1;'`
  2174. else
  2175. tarname="out"
  2176. fi
  2177. tarfile="$tarname.tar"
  2178. fi
  2179. # roll the tarball
  2180. compress=''
  2181. if [ ".$opt_c" != . ]; then
  2182. compress="| $opt_c"
  2183. fi
  2184. if [ ".$prg_tardy" != . ]; then
  2185. # the elegant hackers way
  2186. tardy_opt="--prefix=$tarname"
  2187. tardy_opt="$tardy_opt --user_number=0 --group_number=0" # security!
  2188. if [ ".$opt_u" != . ]; then
  2189. tardy_opt="$tardy_opt --user_name=$opt_u"
  2190. fi
  2191. if [ ".$opt_g" != . ]; then
  2192. tardy_opt="$tardy_opt --group_name=$opt_g"
  2193. fi
  2194. if [ ".$opt_t" = .yes ]; then
  2195. echo "cat $tmpfile.lst | xargs $prg_tar cf - | $prg_tardy $tardy_opt | cat $compress >$tmpfile.out" 1>&2
  2196. fi
  2197. cat $tmpfile.lst |\
  2198. xargs $prg_tar cf - |\
  2199. $prg_tardy $tardy_opt |\
  2200. eval cat $compress >$tmpfile.out
  2201. if [ ".$opt_t" = .yes ]; then
  2202. echo "cp $tmpfile.out $tarfile" 1>&2
  2203. fi
  2204. cp $tmpfile.out $tarfile
  2205. else
  2206. # the portable standard way
  2207. if [ ".$opt_t" = .yes ]; then
  2208. echo "mkdir $tmpdir/$tarname" 1>&2
  2209. fi
  2210. mkdir $tmpdir/$tarname || shtool_exit 1
  2211. if [ ".$opt_t" = .yes ]; then
  2212. echo "cat $tmpfile.lst | xargs $prg_tar cf - | (cd $tmpdir/$tarname && $prg_tar xf -)" 1>&2
  2213. fi
  2214. cat $tmpfile.lst |\
  2215. xargs $prg_tar cf - |\
  2216. (cd $tmpdir/$tarname && $prg_tar xf -)
  2217. if [ ".$opt_u" != . ]; then
  2218. if [ ".$opt_t" = .yes ]; then
  2219. echo "chown -R $opt_u $tmpdir/$tarname >/dev/null 2>&1" 2>&1
  2220. fi
  2221. chown -R $opt_u $tmpdir/$tarname >/dev/null 2>&1 ||\
  2222. echo "$msgprefix:Warning: cannot set user name \`$opt_u' (would require root privileges)"
  2223. fi
  2224. if [ ".$opt_g" != . ]; then
  2225. if [ ".$opt_t" = .yes ]; then
  2226. echo "chgrp -R $opt_g $tmpdir/$tarname >/dev/null 2>&1" 2>&1
  2227. fi
  2228. chgrp -R $opt_g $tmpdir/$tarname >/dev/null 2>&1 ||\
  2229. echo "$msgprefix:Warning: cannot set group name \`$opt_g' (would require root privileges)"
  2230. fi
  2231. if [ ".$opt_t" = .yes ]; then
  2232. echo "(cd $tmpdir && $prg_find $tarname -type f -depth -print | sort | xargs $prg_tar cf -) | cat $compress >$tmpfile.out" 1>&2
  2233. fi
  2234. (cd $tmpdir && $prg_find $tarname -type f -depth -print | sort | xargs $prg_tar cf -) |\
  2235. eval cat $compress >$tmpfile.out
  2236. if [ ".$opt_t" = .yes ]; then
  2237. echo "cp $tmpfile.out $tarfile" 1>&2
  2238. fi
  2239. cp $tmpfile.out $tarfile
  2240. if [ ".$opt_t" = .yes ]; then
  2241. echo "rm -rf $tmpdir/$tarname" 1>&2
  2242. fi
  2243. rm -rf $tmpdir/$tarname
  2244. fi
  2245. # cleanup
  2246. if [ ".$opt_t" = .yes ]; then
  2247. echo "rm -f $tmpfile.lst $tmpfile.out" 1>&2
  2248. fi
  2249. rm -f $tmpfile.lst $tmpfile.out
  2250. shtool_exit 0
  2251. ;;
  2252. subst )
  2253. ##
  2254. ## subst -- Apply sed(1) substitution operations
  2255. ## Copyright (c) 2001-2008 Ralf S. Engelschall <rse@engelschall.com>
  2256. ##
  2257. # remember optional list of file(s)
  2258. files="$*"
  2259. files_num="$#"
  2260. # parameter consistency check
  2261. if [ $# -eq 0 ] && [ ".$opt_b" != . ]; then
  2262. echo "$msgprefix:Error: option -b cannot be applied to stdin" 1>&2
  2263. shtool_exit 1
  2264. fi
  2265. if [ $# -eq 0 ] && [ ".$opt_s" = .yes ]; then
  2266. echo "$msgprefix:Error: option -s cannot be applied to stdin" 1>&2
  2267. shtool_exit 1
  2268. fi
  2269. # build underlying sed(1) command
  2270. sedcmd='sed'
  2271. if [ ".$opt_e" != . ]; then
  2272. OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS"
  2273. for e
  2274. do
  2275. sedcmd="$sedcmd -e '$e'"
  2276. done
  2277. elif [ ".$opt_f" != . ]; then
  2278. if [ ! -f $opt_f ]; then
  2279. echo "$msgprefix:Error: command file \`$opt_f' not found or not a regular file" 1>&2
  2280. shtool_exit 1
  2281. fi
  2282. sedcmd="$sedcmd -f '$opt_f'"
  2283. else
  2284. echo "$msgprefix:Error: either -e option(s) or -f option required" 1>&2
  2285. shtool_exit 1
  2286. fi
  2287. # determine extension for original file
  2288. orig=".orig"
  2289. if [ ".$opt_b" != . ]; then
  2290. orig="$opt_b"
  2291. fi
  2292. # apply sed(1) operation(s)
  2293. if [ ".$files" != . ]; then
  2294. # apply operation(s) to files
  2295. substdone=no
  2296. for file in $files; do
  2297. test ".$file" = . && continue
  2298. if [ ! -f $file ]; then
  2299. echo "$msgprefix:Warning: file \`$file' not found or not a regular file" 1>&2
  2300. continue
  2301. fi
  2302. # handle interactive mode
  2303. if [ ".$opt_i" = .yes ]; then
  2304. eval "$sedcmd <$file >$file.new"
  2305. skip=no
  2306. if cmp $file $file.new >/dev/null 2>&1; then
  2307. rm -f $file.new
  2308. skip=yes
  2309. else
  2310. (diff -U1 $file $file.new >$tmpfile) 2>/dev/null
  2311. if [ ".`cat $tmpfile`" = . ]; then
  2312. (diff -C1 $file $file.new >$tmpfile) 2>/dev/null
  2313. if [ ".`cat $tmpfile`" = . ]; then
  2314. echo "$msgprefix:Warning: unable to show difference for file \`$file'" 1>&2
  2315. cp /dev/null $tmpfile
  2316. fi
  2317. fi
  2318. rm -f $file.new
  2319. cat $tmpfile
  2320. echo dummy | awk '{ printf("%s", TEXT); }' TEXT=">>> Apply [Y/n]: "
  2321. read input
  2322. if [ ".$input" != .Y ] &&\
  2323. [ ".$input" != .y ] &&\
  2324. [ ".$input" != . ]; then
  2325. skip=yes
  2326. fi
  2327. fi
  2328. if [ ".$skip" = .yes ]; then
  2329. if [ ".$opt_v" = .yes ]; then
  2330. echo "file \`$file' -- skipped" 1>&2
  2331. fi
  2332. continue
  2333. fi
  2334. fi
  2335. # apply sed(1) operation(s)
  2336. if [ ".$opt_v" = .yes ]; then
  2337. echo "patching \`$file'" 1>&2
  2338. fi
  2339. if [ ".$opt_t" = .yes ]; then
  2340. echo "\$ cp -p $file $file$orig"
  2341. echo "\$ chmod u+w $file"
  2342. echo "\$ $sedcmd <$file$orig >$file"
  2343. fi
  2344. if [ ".$opt_n" = .no ]; then
  2345. cp -p $file $file$orig
  2346. chmod u+w $file >/dev/null 2>&1 || true
  2347. eval "$sedcmd <$file$orig >$file"
  2348. fi
  2349. # optionally fix timestamp
  2350. if [ ".$opt_s" = .yes ]; then
  2351. if [ ".$opt_t" = .yes ]; then
  2352. echo "\$ touch -r $file$orig $file"
  2353. fi
  2354. if [ ".$opt_n" = .no ]; then
  2355. touch -r $file$orig $file
  2356. fi
  2357. fi
  2358. # optionally check whether any content change actually occurred
  2359. if [ ".$opt_q" = .no ]; then
  2360. if cmp $file$orig $file >/dev/null 2>&1; then
  2361. if [ ".$opt_w" = .yes ]; then
  2362. echo "$msgprefix:Warning: substitution resulted in no content change on file \"$file\"" 1>&2
  2363. fi
  2364. else
  2365. substdone=yes
  2366. fi
  2367. fi
  2368. # optionally remove preserved original file
  2369. if [ ".$opt_b" = . ]; then
  2370. if [ ".$opt_t" = .yes ]; then
  2371. echo "\$ rm -f $file$orig"
  2372. fi
  2373. if [ ".$opt_n" = .no ]; then
  2374. rm -f $file$orig
  2375. fi
  2376. fi
  2377. done
  2378. if [ ".$opt_q" = .no ] && [ ".$opt_w" = .no ]; then
  2379. if [ ".$substdone" = .no ]; then
  2380. if [ ".$files_num" = .1 ]; then
  2381. echo "$msgprefix:Warning: substitution resulted in no content change on file \"$file\"" 1>&2
  2382. else
  2383. echo "$msgprefix:Warning: substitution resulted in no content change on any file" 1>&2
  2384. fi
  2385. fi
  2386. fi
  2387. else
  2388. # apply operation(s) to stdin/stdout
  2389. if [ ".$opt_v" = .yes ]; then
  2390. echo "patching <stdin>" 1>&2
  2391. fi
  2392. if [ ".$opt_t" = .yes ]; then
  2393. echo "\$ $sedcmd"
  2394. fi
  2395. if [ ".$opt_n" = .no ]; then
  2396. eval "$sedcmd"
  2397. fi
  2398. fi
  2399. shtool_exit 0
  2400. ;;
  2401. platform )
  2402. ##
  2403. ## platform -- Platform Identification Utility
  2404. ## Copyright (c) 2003-2008 Ralf S. Engelschall <rse@engelschall.com>
  2405. ##
  2406. # option post-processing
  2407. if [ ".$opt_t" != . ]; then
  2408. case "$opt_t" in
  2409. binary )
  2410. # binary package id (OpenPKG RPM)
  2411. opt_F="%<ap>-%<sp>"
  2412. opt_L=yes
  2413. opt_S=""
  2414. opt_C="+"
  2415. ;;
  2416. build )
  2417. # build time checking (OpenPKG RPM)
  2418. opt_F="%<at>-%<st>"
  2419. opt_L=yes
  2420. opt_S=""
  2421. opt_C="+"
  2422. ;;
  2423. gnu )
  2424. # GNU config.guess style <arch>-<vendor>-<os><osversion>
  2425. opt_F="%<at>-unknown-%<st>"
  2426. opt_L=yes
  2427. opt_S=""
  2428. opt_C="+"
  2429. ;;
  2430. web )
  2431. # non-whitespace HTTP Server-header id
  2432. opt_F="%<sp>-%<ap>"
  2433. opt_S="/"
  2434. opt_C="+"
  2435. ;;
  2436. summary)
  2437. # human readable verbose summary information
  2438. opt_F="Class: %[sc] (%[ac])\\nProduct: %[sp] (%[ap])\\nTechnology: %[st] (%[at])"
  2439. opt_S=" "
  2440. opt_C="/"
  2441. ;;
  2442. all-in-one )
  2443. # full-table all-in-one information
  2444. opt_F=""
  2445. opt_F="${opt_F}concise architecture class: %<ac>\\n"
  2446. opt_F="${opt_F}regular architecture class: %{ac}\\n"
  2447. opt_F="${opt_F}verbose architecture class: %[ac]\\n"
  2448. opt_F="${opt_F}concise architecture product: %<ap>\\n"
  2449. opt_F="${opt_F}regular architecture product: %{ap}\\n"
  2450. opt_F="${opt_F}verbose architecture product: %[ap]\\n"
  2451. opt_F="${opt_F}concise architecture technology: %<at>\\n"
  2452. opt_F="${opt_F}regular architecture technology: %{at}\\n"
  2453. opt_F="${opt_F}verbose architecture technology: %[at]\\n"
  2454. opt_F="${opt_F}concise system class: %<sc>\\n"
  2455. opt_F="${opt_F}regular system class: %{sc}\\n"
  2456. opt_F="${opt_F}verbose system class: %[sc]\\n"
  2457. opt_F="${opt_F}concise system product: %<sp>\\n"
  2458. opt_F="${opt_F}regular system product: %{sp}\\n"
  2459. opt_F="${opt_F}verbose system product: %[sp]\\n"
  2460. opt_F="${opt_F}concise system technology: %<st>\\n"
  2461. opt_F="${opt_F}regular system technology: %{st}\\n"
  2462. opt_F="${opt_F}verbose system technology: %[st]"
  2463. ;;
  2464. * )
  2465. echo "$msgprefix:Error: invalid type \`$opt_t'" 1>&2
  2466. exit 1
  2467. ;;
  2468. esac
  2469. fi
  2470. # assemble initial platform information
  2471. UNAME_MACHINE=`(uname -m) 2>/dev/null` ||\
  2472. UNAME_MACHINE=`(uname -p) 2>/dev/null` ||\
  2473. UNAME_MACHINE='unknown'
  2474. UNAME_SYSTEM=`(uname -s) 2>/dev/null` ||\
  2475. UNAME_SYSTEM='unknown'
  2476. UNAME_RELEASE=`(uname -r) 2>/dev/null` ||\
  2477. UNAME_RELEASE=`(uname -v) 2>/dev/null` ||\
  2478. UNAME_RELEASE='unknown'
  2479. UNAME="${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}"
  2480. AC=""; AP=""; AT=""
  2481. SC=""; SP=""; ST=""
  2482. # dispatch into platform specific sections
  2483. case "${UNAME}" in
  2484. # FreeBSD
  2485. *:FreeBSD:* )
  2486. # determine architecture
  2487. AC="${UNAME_MACHINE}"
  2488. case "${AC}" in
  2489. i386 ) AC="iX86" ;;
  2490. esac
  2491. AP="${AC}"
  2492. AT="${AP}"
  2493. if [ ".${AT}" = ".iX86" ]; then
  2494. case "`(/sbin/sysctl -n hw.model) 2>&1`" in
  2495. *"Xeon"* | *"Pentium Pro"* | *"Cyrix 6x86MX"* | *"Pentium II"* | *"Pentium III"* | *"Pentium 4"* | *"Celeron"* ) AT="i686" ;;
  2496. *"Pentium"* ) AT="i586" ;; *"i486[SD]X"* | *"Cyrix 486"* | *"Cyrix [56]x86"* | *"Blue Lightning" | *"Cyrix 486S/DX" ) AT="i486" ;;
  2497. *"i386[SD]X"* | *"NexGen 586"* ) AT="i386" ;;
  2498. esac
  2499. fi
  2500. # determine system
  2501. r=`echo "${UNAME_RELEASE}" |\
  2502. sed -e 's;[()];;' -e 's/\(-.*\)$/[\1]/'`
  2503. ST="FreeBSD ${r}"
  2504. SP="${ST}"
  2505. case "${r}" in
  2506. 1.* ) SC="4.3BSD" ;;
  2507. * ) SC="4.4BSD" ;;
  2508. esac
  2509. ;;
  2510. # NetBSD
  2511. *:NetBSD:* )
  2512. # determine architecture
  2513. AT="${UNAME_MACHINE}"
  2514. AP="${AT}"
  2515. case "${AP}" in
  2516. i[3-6]86 ) AP="iX86" ;;
  2517. esac
  2518. AC="${AP}"
  2519. # determine system
  2520. r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
  2521. ST="NetBSD ${r}"
  2522. SP="${ST}"
  2523. case "${r}" in
  2524. 0.* ) SC="4.3BSD" ;;
  2525. * ) SC="4.4BSD" ;;
  2526. esac
  2527. ;;
  2528. # OpenBSD
  2529. *:OpenBSD:* )
  2530. # determine architecture
  2531. AT="${UNAME_MACHINE}"
  2532. AP="${AT}"
  2533. case "${AP}" in
  2534. i[3-6]86 ) AP="iX86" ;;
  2535. esac
  2536. AC="${AP}"
  2537. # determine system
  2538. r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
  2539. ST="OpenBSD ${r}"
  2540. SP="${ST}"
  2541. SC="4.4BSD"
  2542. ;;
  2543. # DragonFly BSD
  2544. *:DragonFly:* )
  2545. # determine architecture
  2546. AT="${UNAME_MACHINE}"
  2547. AP="${AT}"
  2548. case "${AP}" in
  2549. i[3-6]86 ) AP="iX86" ;;
  2550. esac
  2551. AC="${AP}"
  2552. # determine system
  2553. r=`echo "${UNAME_RELEASE}" | sed -e 's/\([-_].*\)$/[\1]/'`
  2554. ST="DragonFly ${r}"
  2555. SP="${ST}"
  2556. SC="4.4BSD"
  2557. ;;
  2558. # GNU/Linux
  2559. *:Linux:* )
  2560. # determine architecture
  2561. AT="${UNAME_MACHINE}"
  2562. case "${AT}" in
  2563. ia64 ) AT="IA64" ;;
  2564. x86_64 ) AT='AMD64' ;;
  2565. parisc ) AT="HPPA32" ;;
  2566. parisc64 ) AT="HPPA64" ;;
  2567. esac
  2568. AP="${AT}"
  2569. case "${AP}" in
  2570. i[3-6]86 ) AP='iX86' ;;
  2571. esac
  2572. AC="${AP}"
  2573. # determine system
  2574. v_kern=`echo "${UNAME_RELEASE}" |\
  2575. sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/'`
  2576. v_libc=`(strings /lib/libc.so.* | grep '^GLIBC_' | sed -e 's/^GLIBC_//' |\
  2577. env -i sort -n | sed -n -e '$p' | sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/') 2>/dev/null`
  2578. ST="GNU/<Linux >${v_libc}/<${v_kern}>"
  2579. if [ -f /etc/lsb-release ]; then
  2580. eval `( . /etc/lsb-release
  2581. echo "SC=\"LSB${LSB_VERSION}\""
  2582. if [ ".${DISTRIB_ID}" != . -a ".${DISTRIB_RELEASE}" != . ]; then
  2583. echo "SP=\"${DISTRIB_ID} ${DISTRIB_RELEASE}\""
  2584. fi
  2585. ) 2>/dev/null`
  2586. fi
  2587. if [ ".$SP" = . ]; then
  2588. for tagfile in x \
  2589. `cd /etc && \
  2590. /bin/ls *[_-]release *[_-]version 2>/dev/null | env -i sort | \
  2591. sed -e '/^redhat-release$/d' -e '/^lsb-release$/d'; \
  2592. echo redhat-release lsb-release`
  2593. do
  2594. [ ".${tagfile}" = .x ] && continue
  2595. [ ! -f "/etc/${tagfile}" ] && continue
  2596. n=`echo ${tagfile} | sed -e 's/[_-]release$//' -e 's/[_-]version$//'`
  2597. v=`(grep VERSION /etc/${tagfile}; cat /etc/${tagfile}) | grep '[0-9]' | sed -e 'q' |\
  2598. sed -e 's/^/#/' \
  2599. -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
  2600. -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
  2601. -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
  2602. -e 's/^#.*$//'`
  2603. case "`util_lower ${n}`" in
  2604. redhat )
  2605. if [ ".`egrep '(Red Hat Enterprise Linux|CentOS)' /etc/${tagfile}`" != . ]; then
  2606. n="<R>ed <H>at <E>nterprise <L>inux"
  2607. else
  2608. n="<R>ed <H>at <L>inux"
  2609. fi
  2610. ;;
  2611. debian ) n="Debian[ GNU/Linux]" ;;
  2612. ubuntu ) n="Ubuntu[ GNU/Linux]" ;;
  2613. fedora ) n="<Fedora> Core[ GNU/Linux]" ;;
  2614. suse ) n="[Novell ]SUSE[ Linux]" ;;
  2615. mandrake*|mandriva ) n="Mandriva[ Linux]" ;;
  2616. gentoo ) n="Gentoo[ GNU/Linux]" ;;
  2617. slackware ) n="Slackware[ Linux]" ;;
  2618. turbolinux ) n="TurboLinux" ;;
  2619. unitedlinux ) n="UnitedLinux" ;;
  2620. * ) n="${n}[ GNU/Linux]" ;;
  2621. esac
  2622. case "$n" in
  2623. *"<"*">"* ) SP="$n <$v>" ;;
  2624. * ) SP="$n $v" ;;
  2625. esac
  2626. break
  2627. done
  2628. fi
  2629. [ ".$SP" = . ] && SP="${ST}"
  2630. [ ".$SC" = . ] && SC="LSB"
  2631. ;;
  2632. # Sun Solaris
  2633. *:SunOS:* )
  2634. # determine architecture
  2635. AT="${UNAME_MACHINE}"
  2636. case "${AT}" in
  2637. i86pc )
  2638. AT="iX86"
  2639. case "`(/bin/isainfo -k) 2>&1`" in
  2640. amd64 ) AT="AMD64" ;;
  2641. esac
  2642. ;;
  2643. esac
  2644. AP="${AT}"
  2645. case "${AP}" in
  2646. sun4[cdm] ) AP="SPARC32" ;;
  2647. sun4[uv] ) AP="SPARC64" ;;
  2648. sun4* ) AP="SPARC" ;;
  2649. esac
  2650. AC="${AP}"
  2651. case "${AC}" in
  2652. SPARC* ) AC="SPARC" ;;
  2653. esac
  2654. # determine system
  2655. ST="[Sun ]SunOS ${UNAME_RELEASE}"
  2656. v=`echo "${UNAME_RELEASE}" |\
  2657. sed -e 's;^4\.;1.;' \
  2658. -e 's;^5\.\([0-6]\)[^0-9]*$;2.\1;' \
  2659. -e 's;^5\.\([0-9][0-9]*\).*;\1;'`
  2660. SP="[Sun ]Solaris $v"
  2661. case "${UNAME_RELEASE}" in
  2662. 4.* ) SC="4.3BSD" ;;
  2663. 5.* ) SC="SVR4" ;;
  2664. esac
  2665. ;;
  2666. # SCO UnixWare
  2667. *:UnixWare:* )
  2668. # determine architecture
  2669. AT="${UNAME_MACHINE}"
  2670. case "${AT}" in
  2671. i[3-6]86 | ix86at ) AT="iX86" ;;
  2672. esac
  2673. AP="${AT}"
  2674. # determine system
  2675. v=`/sbin/uname -v`
  2676. ST="[SCO ]UnixWare ${v}"
  2677. SP="${ST}"
  2678. SC="SVR${UNAME_RELEASE}"
  2679. ;;
  2680. # QNX
  2681. *:QNX:* )
  2682. # determine architecture
  2683. AT="${UNAME_MACHINE}"
  2684. case "${AT}" in
  2685. x86pc ) AT="iX86" ;;
  2686. esac
  2687. AP="${AT}"
  2688. # determine system
  2689. v="${UNAME_RELEASE}"
  2690. ST="QNX[ Neutrino RTOS] ${v}"
  2691. v=`echo "${v}" | sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\).*$;\1;'`
  2692. SP="QNX[ Neutrino RTOS] ${v}"
  2693. SC="QNX"
  2694. ;;
  2695. # SGI IRIX
  2696. *:IRIX*:* )
  2697. # determine architecture
  2698. AT="${UNAME_MACHINE}"
  2699. AP="${AT}"
  2700. case "${AP}:${UNAME_SYSTEM}" in
  2701. IP*:IRIX64 ) AP="MIPS64" ;;
  2702. IP*:* ) AP="MIPS" ;;
  2703. esac
  2704. AC="${AP}"
  2705. # determine system
  2706. v=`(/bin/uname -R || /bin/uname -r) 2>/dev/null | sed -e 's;[0-9.]* ;;'`
  2707. ST="[SGI ]IRIX ${v}"
  2708. v="${UNAME_RELEASE}"
  2709. SP="[SGI ]IRIX ${v}"
  2710. SC="4.2BSD/SVR3"
  2711. ;;
  2712. # HP HP-UX
  2713. *:HP-UX:* )
  2714. # determine architecture
  2715. AT="${UNAME_MACHINE}"
  2716. case "${AT}" in
  2717. ia64 ) AT="IA64" ;;
  2718. 9000/[34]?? ) AT=M68K ;;
  2719. 9000/[678][0-9][0-9])
  2720. sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
  2721. sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
  2722. case "${sc_cpu_version}" in
  2723. 523 ) AT="HPPA1.0" ;;
  2724. 528 ) AT="HPPA1.1" ;;
  2725. 532 ) AT="HPPA2.0"
  2726. case "${sc_kernel_bits}" in
  2727. 32 ) AT="${AT}n" ;;
  2728. 64 ) AT="${AT}w" ;;
  2729. esac
  2730. ;;
  2731. esac
  2732. ;;
  2733. esac
  2734. AP="${AT}"
  2735. case "${AP}" in
  2736. HPPA* ) AP="HPPA" ;;
  2737. esac
  2738. AC="${AP}"
  2739. # determine system
  2740. v=`echo "${UNAME_RELEASE}" | sed -e 's;^[^0-9]*;;'`
  2741. ST="[HP ]<HP>-<UX ${v}>"
  2742. SP="${ST}"
  2743. case "${v}" in
  2744. 10.* ) SC="SVR4.2" ;;
  2745. [7-9]* ) SC="SVR4" ;;
  2746. esac
  2747. ;;
  2748. # HP Tru64 (OSF1)
  2749. *:OSF1:* )
  2750. # determine architecture
  2751. AP="${UNAME_MACHINE}"
  2752. case "${AP}" in
  2753. alpha ) AP="Alpha" ;;
  2754. esac
  2755. alpha_type=`(/usr/sbin/psrinfo -v) 2>/dev/null |\
  2756. sed -n -e 's/^.*The alpha \([^ ][^ ]*\).*processor.*$/\1/p' | sed -e 'q'`
  2757. AT="${AP}${alpha_type}"
  2758. AC="${AP}"
  2759. # determine system
  2760. v=`echo "${UNAME_RELEASE}" | sed -e 's;^[VTX];;'`
  2761. ST="[HP ]Tru64 ${v}"
  2762. SP="${ST}"
  2763. SC="OSF1"
  2764. ;;
  2765. # IBM AIX
  2766. *:AIX:* )
  2767. # determine architecture
  2768. cpu_arch=RS6000
  2769. if [ -x /usr/sbin/lsdev -a -x /usr/sbin/lsattr ]; then
  2770. cpu_id=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
  2771. if [ ".`/usr/sbin/lsattr -El ${cpu_id} | grep -i powerpc`" != . ]; then
  2772. cpu_arch=PPC
  2773. fi
  2774. elif [ -d /QOpenSys ]; then
  2775. # IBM i5/OS (aka OS/400) with PASE (Portable Application Solutions Environment)
  2776. cpu_arch=PPC
  2777. fi
  2778. if [ -x /usr/bin/oslevel ]; then
  2779. os_level=`/usr/bin/oslevel`
  2780. else
  2781. os_level="`uname -v`.`uname -r`"
  2782. fi
  2783. os_level=`echo "${os_level}" |\
  2784. sed -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\)\(.*\)$;<\1>\2[\3];' \
  2785. -e 's;^\([0-9][0-9]*\.[0-9][0-9]*\)\(.*\)$;<\1>\2;'`
  2786. AT="${cpu_arch}"
  2787. AP="${AT}"
  2788. AC="${AP}"
  2789. # determine system
  2790. ST="[IBM ]<AIX >${os_level}"
  2791. SP="${ST}"
  2792. case "${os_level}" in
  2793. [12]* ) SC="SVR2" ;;
  2794. * ) SC="SVR4" ;;
  2795. esac
  2796. ;;
  2797. # Apple Mac OS X (Darwin)
  2798. *:Darwin:* )
  2799. # determine architecture
  2800. AT="`uname -p`"
  2801. case "${AT}" in
  2802. powerpc ) AT="PPC" ;;
  2803. esac
  2804. AP="${AT}"
  2805. case "${AP}" in
  2806. i?86 ) AP="iX86" ;;
  2807. esac
  2808. AC="${AP}"
  2809. # determine system
  2810. unset v1; unset v2; unset v3
  2811. eval `echo "${UNAME_RELEASE}" |\
  2812. sed -e 's/^/#/' \
  2813. -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
  2814. -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
  2815. -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
  2816. -e 's/^#.*$/v1="0"/'`
  2817. ST="[Apple ]<${UNAME_SYSTEM} ${v1}>${v2+.$v2}${v3+[.$v3]}"
  2818. SP="$ST"
  2819. v="`(sw_vers) 2>/dev/null | grep 'ProductVersion:' | sed -e 's/^ProductVersion:[^0-9]*\([0-9][0-9.]*\).*$/\1/'`"
  2820. if [ ".$v" = . ]; then
  2821. for name in System Server; do
  2822. if [ -f /System/Library/CoreServices/${name}Version.plist ]; then
  2823. v=`(defaults read "/System/Library/CoreServices/${name}Version" "ProductVersion") 2>/dev/null`
  2824. [ ".$v" != . ] && break
  2825. fi
  2826. done
  2827. fi
  2828. if [ ".$v" != . ]; then
  2829. unset v1; unset v2; unset v3
  2830. eval `echo "${v}" |\
  2831. sed -e 's/^/#/' \
  2832. -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
  2833. -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
  2834. -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
  2835. -e 's/^#.*$/v1="0"/'`
  2836. SP="[Apple ]Mac OS X ${v1}${v2+.$v2}${v3+[.$v3]}"
  2837. fi
  2838. SC="4.4BSD/Mach3.0"
  2839. ;;
  2840. # Windows/Cygwin
  2841. *:CYGWIN*:* )
  2842. # determine architecture
  2843. AT="`uname -m`"
  2844. AP="${AT}"
  2845. case "${AP}" in
  2846. i?86 ) AP="iX86" ;;
  2847. esac
  2848. AC="${AP}"
  2849. # determine system
  2850. unset v1; unset v2; unset v3
  2851. eval `echo "${UNAME_RELEASE}" |\
  2852. sed -e 's/^/#/' \
  2853. -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"; v3="\3"/' \
  2854. -e 's/^#\([0-9][0-9]*\)\.\([0-9][0-9]*\).*$/v1="\1"; v2="\2"/' \
  2855. -e 's/^#\([0-9][0-9]*\).*$/v1="\1"/' \
  2856. -e 's/^#.*$/v1="0"/'`
  2857. ST="Cygwin ${v1}${v2+.$v2}${v3+[.$v3]}"
  2858. SP="$ST"
  2859. SC="Windows"
  2860. v=`echo "${UNAME_SYSTEM}" | sed -e 's/^CYGWIN_NT-//' |\
  2861. sed -e 's/^/#/' -e 's/^#\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' -e 's/^#.*$//'`
  2862. case "$v" in
  2863. 4.0 ) SC="$SC[ NT]" ;;
  2864. 5.0 ) SC="$SC[ 2000]" ;;
  2865. 5.1 ) SC="$SC[ XP]" ;;
  2866. 6.0 ) SC="$SC[ Vista]" ;;
  2867. esac
  2868. ;;
  2869. # TODO ...ADD YOUR NEW PLATFORM CHECK HERE... TODO
  2870. # *:XXX:* )
  2871. # ...
  2872. # ;;
  2873. # ...A STILL UNKNOWN PLATFORM...
  2874. * )
  2875. AT=`echo "${UNAME_MACHINE}" | sed -e "s; ;${opt_C};g"`
  2876. AP="${AT}"
  2877. AC="${AP}"
  2878. v=`echo "${UNAME_RELEASE}" |\
  2879. sed -e 's/^/#/' \
  2880. -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
  2881. -e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
  2882. -e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
  2883. -e 's/^#.*$/?/'`
  2884. ST="${UNAME_SYSTEM} ${v}"
  2885. SP="${ST}"
  2886. SC="${SP}"
  2887. ;;
  2888. esac
  2889. # provide fallback values
  2890. [ ".$AT" = . ] && AT="${AP:-${AC}}"
  2891. [ ".$AP" = . ] && AP="${AT:-${AC}}"
  2892. [ ".$AC" = . ] && AC="${AP:-${AT}}"
  2893. [ ".$ST" = . ] && ST="${SP:-${SC}}"
  2894. [ ".$SP" = . ] && SP="${ST:-${SC}}"
  2895. [ ".$SC" = . ] && SC="${SP:-${ST}}"
  2896. # support explicit enforced verbose/concise output
  2897. if [ ".$opt_v" = .yes ]; then
  2898. opt_F=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%[\1]/g'`
  2899. elif [ ".$opt_c" = .yes ]; then
  2900. opt_F=`echo ":$opt_F" | sed -e 's/^://' -e 's/%\([as][cpt]\)/%<\1>/g'`
  2901. fi
  2902. # provide verbose and concise variants
  2903. AC_V=""; AC_N=""; AC_C=""
  2904. AP_V=""; AP_N=""; AP_C=""
  2905. AT_V=""; AT_N=""; AT_C=""
  2906. SC_V=""; SC_N=""; SC_C=""
  2907. SP_V=""; SP_N=""; SP_C=""
  2908. ST_V=""; ST_N=""; ST_C=""
  2909. for var_lc in at ap ac st sp sc; do
  2910. case "$opt_F" in
  2911. *"%[${val_lc}]"* | *"%{${val_lc}}"* | *"%${val_lc}"* | *"%<${val_lc}>"* )
  2912. var_uc=`util_upper "$var_lc"`
  2913. eval "val=\"\$${var_uc}\""
  2914. val_V=""; val_N=""; val_C=""
  2915. case "$opt_F" in
  2916. *"%[${var_lc}]"* )
  2917. val_V=`echo ":$val" | \
  2918. sed -e 's/^://' \
  2919. -e 's;\[\([^]]*\)\];\1;g' \
  2920. -e 's;<\([^>]*\)>;\1;g' \
  2921. -e "s; ;§§;g" \
  2922. -e "s;/;%%;g" \
  2923. -e "s;§§;${opt_S};g" \
  2924. -e "s;%%;${opt_C};g"`
  2925. eval "${var_uc}_V=\"\${val_V}\""
  2926. ;;
  2927. esac
  2928. case "$opt_F" in
  2929. *"%{${var_lc}}"* | *"%${var_lc}"* )
  2930. val_N=`echo ":$val" | \
  2931. sed -e 's/^://' \
  2932. -e 's;\[\([^]]*\)\];;g' \
  2933. -e 's;<\([^>]*\)>;\1;g' \
  2934. -e "s; ;§§;g" \
  2935. -e "s;/;%%;g" \
  2936. -e "s;§§;${opt_S};g" \
  2937. -e "s;%%;${opt_C};g"`
  2938. eval "${var_uc}_N=\"\${val_N}\""
  2939. ;;
  2940. esac
  2941. case "$opt_F" in
  2942. *"%<${var_lc}>"* )
  2943. val_C=`echo ":$val" | \
  2944. sed -e 's/^://' \
  2945. -e 's;\[\([^]]*\)\];;g' \
  2946. -e 's;[^<]*<\([^>]*\)>[^<]*;\1;g' \
  2947. -e "s; ;§§;g" \
  2948. -e "s;/;%%;g" \
  2949. -e "s;§§;${opt_S};g" \
  2950. -e "s;%%;${opt_C};g"`
  2951. eval "${var_uc}_C=\"\${val_C}\""
  2952. ;;
  2953. esac
  2954. ;;
  2955. esac
  2956. done
  2957. # create output string
  2958. output=`echo ":$opt_F" |\
  2959. sed -e "s/^://" \
  2960. -e "s;%\\[ac\\];${AC_V};g" \
  2961. -e "s;%{ac};${AC_N};g" \
  2962. -e "s;%ac;${AC_N};g" \
  2963. -e "s;%<ac>;${AC_C};g" \
  2964. -e "s;%\\[ap\\];${AP_V};g" \
  2965. -e "s;%{ap};${AP_N};g" \
  2966. -e "s;%ap;${AP_N};g" \
  2967. -e "s;%<ap>;${AP_C};g" \
  2968. -e "s;%\\[at\\];${AT_V};g" \
  2969. -e "s;%{at};${AT_N};g" \
  2970. -e "s;%at;${AT_N};g" \
  2971. -e "s;%<at>;${AT_C};g" \
  2972. -e "s;%\\[sc\\];${SC_V};g" \
  2973. -e "s;%{sc};${SC_N};g" \
  2974. -e "s;%sc;${SC_N};g" \
  2975. -e "s;%<sc>;${SC_C};g" \
  2976. -e "s;%\\[sp\\];${SP_V};g" \
  2977. -e "s;%{sp};${SP_N};g" \
  2978. -e "s;%sp;${SP_N};g" \
  2979. -e "s;%<sp>;${SP_C};g" \
  2980. -e "s;%\\[st\\];${ST_V};g" \
  2981. -e "s;%{st};${ST_N};g" \
  2982. -e "s;%st;${ST_N};g" \
  2983. -e "s;%<st>;${ST_C};g" \
  2984. -e 's/\\\\n/^/g' |\
  2985. tr '^' '\012'`
  2986. # support lower/upper-case mapping
  2987. if [ ".$opt_L" = .yes ]; then
  2988. output=`util_lower "$output"`
  2989. elif [ ".$opt_U" = .yes ]; then
  2990. output=`util_upper "$output"`
  2991. fi
  2992. # display output string
  2993. if [ ".$opt_n" = .yes ]; then
  2994. echo . | awk '{ printf("%s", output); }' output="$output"
  2995. else
  2996. echo "$output"
  2997. fi
  2998. shtool_exit 0
  2999. ;;
  3000. arx )
  3001. ##
  3002. ## arx -- Extended archive command
  3003. ## Copyright (c) 1999-2008 Ralf S. Engelschall <rse@engelschall.com>
  3004. ##
  3005. ar_prg="$opt_C"
  3006. ar_cmd="$1"; shift
  3007. archive="$1"; shift
  3008. files="$*"
  3009. # walk through the file list and expand archives members
  3010. ar_tmpdir=`echo $archive | sed -e 's;[^/]*$;.arx;'`
  3011. nfiles=''
  3012. if [ ".$files" != . ]; then
  3013. for file in $files; do
  3014. if [ ! -f $file ]; then
  3015. echo "$msgprefix:Error: input file not found: $file" 1>&2
  3016. shtool_exit 1
  3017. fi
  3018. case $file in
  3019. *.a )
  3020. if [ ! -d $ar_tmpdir ]; then
  3021. if [ ".$opt_t" = .yes ]; then
  3022. echo "mkdir $ar_tmpdir" 1>&2
  3023. fi
  3024. mkdir $ar_tmpdir
  3025. fi
  3026. case $ar_tmpdir in
  3027. .arx )
  3028. from="../$file"
  3029. ;;
  3030. * )
  3031. dir=`echo $file | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;'`
  3032. base=`echo $file | sed -e 's;.*/\([^/]*\)$;\1;'`
  3033. from="`cd $dir; pwd`/$base"
  3034. ;;
  3035. esac
  3036. if [ ".$opt_t" = .yes ]; then
  3037. echo "(cd $ar_tmpdir && $ar_prg x $from)" 1>&2
  3038. fi
  3039. (cd $ar_tmpdir && eval $ar_prg x $from)
  3040. if [ $? -ne 0 ]; then
  3041. echo "$msgprefix:Error: member extraction failed for archive: $file" 1>&2
  3042. shtool_exit 1
  3043. fi
  3044. for member in - `eval $ar_prg t $file | sed -e '/_\.SYMDEF/d'`; do
  3045. [ ".$member" = .- ] && continue
  3046. nfiles="$nfiles $ar_tmpdir/$member"
  3047. done
  3048. ;;
  3049. * )
  3050. nfiles="$nfiles $file"
  3051. ;;
  3052. esac
  3053. done
  3054. fi
  3055. # run the final archive command
  3056. if [ ".$opt_t" = .yes ]; then
  3057. echo "$ar_prg $ar_cmd $archive $nfiles" 1>&2
  3058. fi
  3059. eval $ar_prg $ar_cmd $archive $nfiles
  3060. if [ $? -ne 0 ]; then
  3061. echo "$msgprefix:Error: archive command failed" 1>&2
  3062. shtool_exit $?
  3063. fi
  3064. # cleanup and die gracefully
  3065. if [ -d $ar_tmpdir ]; then
  3066. if [ ".$opt_t" = .yes ]; then
  3067. echo "rm -rf $ar_tmpdir" 1>&2
  3068. fi
  3069. rm -rf $ar_tmpdir
  3070. fi
  3071. shtool_exit 0
  3072. ;;
  3073. slo )
  3074. ##
  3075. ## slo -- Separate linker options by library class
  3076. ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
  3077. ##
  3078. DIFS="$IFS"
  3079. # parse out -L and -l options from command line
  3080. DIRS=''
  3081. LIBS=''
  3082. ARGV=''
  3083. optprev=''
  3084. for opt
  3085. do
  3086. # concatenate with previous option if exists
  3087. if [ ".$optprev" != . ]; then
  3088. opt="${optprev}${opt}";
  3089. optprev=''
  3090. fi
  3091. # remember options for arg if used stand-alone
  3092. if [ ".$opt" = ".-L" ] || [ ".$opt" = ".-l" ]; then
  3093. optprev="$opt"
  3094. continue;
  3095. fi
  3096. # split argument into option plus option argument
  3097. arg="`echo $opt | cut -c3-`"
  3098. opt="`echo $opt | cut -c1-2`"
  3099. # store into containers
  3100. case $opt in
  3101. -L) DIRS="$DIRS:$arg" ;;
  3102. -l) LIBS="$LIBS:$arg" ;;
  3103. *) ARGV="$ARGV $opt" ;;
  3104. esac
  3105. done
  3106. # set linker default directories
  3107. DIRS_DEFAULT='/lib:/usr/lib'
  3108. if [ ".$LD_LIBRARY_PATH" != . ]; then
  3109. DIRS_DEFAULT="$DIRS_DEFAULT:$LD_LIBRARY_PATH"
  3110. fi
  3111. # sort options by class
  3112. DIRS_OBJ=''
  3113. LIBS_OBJ=''
  3114. DIRS_PIC=''
  3115. LIBS_PIC=''
  3116. DIRS_DSO=''
  3117. LIBS_DSO=''
  3118. # for each library...
  3119. OIFS="$IFS"; IFS=':'
  3120. for lib in $LIBS; do
  3121. [ ".$lib" = . ] && continue
  3122. found='no'
  3123. found_indefdir='no'
  3124. found_type=''
  3125. found_dir=''
  3126. # for each directory...
  3127. OIFS2="$IFS"; IFS=":$DIFS"
  3128. for dir in ${DIRS} switch-to-defdirs ${DIRS_DEFAULT}; do
  3129. [ ".$dir" = . ] && continue
  3130. [ ".$dir" = .switch-to-defdirs ] && found_indefdir=yes
  3131. [ ! -d $dir ] && continue
  3132. # search the file
  3133. OIFS3="$IFS"; IFS="$DIFS"
  3134. for file in '' `cd $dir && env -i /bin/ls lib${lib}.* 2>/dev/null`; do
  3135. [ ".$file" = . ] && continue
  3136. case $file in
  3137. *.so|*.so.[0-9]*|*.sl|*.sl.[0-9]* )
  3138. found=yes;
  3139. found_type=DSO;
  3140. break
  3141. ;;
  3142. *.lo|*.la )
  3143. found=yes;
  3144. found_type=PIC
  3145. ;;
  3146. *.a )
  3147. if [ ".$found_type" = . ]; then
  3148. found=yes
  3149. found_type=OBJ
  3150. fi
  3151. ;;
  3152. esac
  3153. done
  3154. IFS="$OIFS3"
  3155. if [ ".$found" = .yes ]; then
  3156. found_dir="$dir"
  3157. break
  3158. fi
  3159. done
  3160. IFS="$OIFS2"
  3161. if [ ".$found" = .yes ]; then
  3162. if [ ".$found_indefdir" != .yes ]; then
  3163. eval "dirlist=\"\${DIRS_${found_type}}:\""
  3164. case "$dirlist" in
  3165. *:$found_dir:* ) ;;
  3166. * ) eval "DIRS_${found_type}=\"\$DIRS_${found_type}:${found_dir}\"" ;;
  3167. esac
  3168. eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
  3169. else
  3170. eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\""
  3171. fi
  3172. else
  3173. LIBS_OBJ="$LIBS_OBJ:$lib"
  3174. #dirlist="`echo $DIRS $DIRS_DEFAULT | sed -e 's/:/ /g'`"
  3175. #echo "slo:Warning: library \"$lib\" not found in any of the following dirs:" 2>&1
  3176. #echo "slo:Warning: $dirlist" 1>&1
  3177. fi
  3178. done
  3179. IFS="$OIFS"
  3180. # also pass-through unused dirs even if it's useless
  3181. OIFS="$IFS"; IFS=':'
  3182. for dir in $DIRS; do
  3183. dirlist="${DIRS_OBJ}:${DIRS_PIC}:${DIRS_DSO}:"
  3184. case "$dirlist" in
  3185. *:$dir:* ) ;;
  3186. * ) DIRS_OBJ="$DIRS_OBJ:$dir" ;;
  3187. esac
  3188. done
  3189. IFS="$OIFS"
  3190. # reassemble the options but separated by type
  3191. for type in OBJ PIC DSO; do
  3192. OIFS="$IFS"; IFS=':'
  3193. eval "libs=\"\$LIBS_${type}\""
  3194. opts=''
  3195. for lib in $libs; do
  3196. [ ".$lib" = . ] && continue
  3197. opts="$opts -l$lib"
  3198. done
  3199. eval "LIBS_${type}=\"$opts\""
  3200. eval "dirs=\"\$DIRS_${type}\""
  3201. opts=''
  3202. for dir in $dirs; do
  3203. [ ".$dir" = . ] && continue
  3204. opts="$opts -L$dir"
  3205. done
  3206. eval "DIRS_${type}=\"$opts\""
  3207. IFS="$OIFS"
  3208. done
  3209. # give back results
  3210. for var in ARGV DIRS_OBJ LIBS_OBJ DIRS_PIC LIBS_PIC DIRS_DSO LIBS_DSO; do
  3211. eval "val=\"\$${var}\""
  3212. val="`echo $val | sed -e 's/^ *//'`"
  3213. echo "${opt_p}${var}=\"${val}\""
  3214. done
  3215. shtool_exit 0
  3216. ;;
  3217. scpp )
  3218. ##
  3219. ## scpp -- Sharing C Pre-Processor
  3220. ## Copyright (c) 1999-2008 Ralf S. Engelschall <rse@engelschall.com>
  3221. ##
  3222. srcs="$*"
  3223. output="${opt_o}.n"
  3224. # find a reasonable Awk
  3225. awk=''
  3226. paths=`echo $PATH |\
  3227. sed -e 's%/*:%:%g' -e 's%/$%%' \
  3228. -e 's/^:/.:/' -e 's/::/:.:/g' -e 's/:$/:./' \
  3229. -e 's/:/ /g'`
  3230. for name in gawk nawk awk; do
  3231. for path in $paths; do
  3232. if [ -r "$path/$name" ]; then
  3233. awk="$path/$name"
  3234. break
  3235. fi
  3236. done
  3237. if [ ".$awk" != . ]; then
  3238. break
  3239. fi
  3240. done
  3241. if [ ".$awk" = . ]; then
  3242. echo "$msgprefix:Error: cannot find a reasonable Awk" 1>&2
  3243. shtool_exit 1
  3244. fi
  3245. # parse source file(s)
  3246. if [ ".$opt_v" = .yes ]; then
  3247. echo "Parsing:" | $awk '{ printf("%s", $0); }' 1>&2
  3248. fi
  3249. for src in $srcs; do
  3250. if [ ".$opt_v" = .yes ]; then
  3251. echo $src | $awk '{ printf(" %s", $0); }' 1>&2
  3252. fi
  3253. if [ ".$opt_f" != . ]; then
  3254. inputcmd="sed"
  3255. OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_f; IFS="$OIFS"
  3256. for e
  3257. do
  3258. inputcmd="$inputcmd -e '$e'"
  3259. done
  3260. inputcmd="$inputcmd '$src'"
  3261. else
  3262. inputcmd="cat '$src'"
  3263. fi
  3264. eval $inputcmd |\
  3265. $awk '
  3266. BEGIN {
  3267. ln = 0;
  3268. fln = 0;
  3269. level = 0;
  3270. mode = "";
  3271. store = "";
  3272. }
  3273. {
  3274. ln++;
  3275. }
  3276. /^#if.*/ {
  3277. level++;
  3278. }
  3279. /^#if [a-zA-Z_][a-zA-Z0-9_]* *$/ {
  3280. if ($2 == define) {
  3281. mode = "D";
  3282. printf("D:#line %d \"%s\"\n", ln, src);
  3283. next;
  3284. }
  3285. }
  3286. /^#endif.*/ {
  3287. level--;
  3288. if (mode == "D" && level == 0) {
  3289. mode = "";
  3290. next;
  3291. }
  3292. }
  3293. /^[a-zA-Z_][a-zA-Z0-9_].*;.*/ {
  3294. if ($1 == class) {
  3295. printf("V:#line %d \"%s\"\n", ln, src);
  3296. printf("V:%s\n", $0);
  3297. printf("J:%s\n", $0);
  3298. next;
  3299. }
  3300. }
  3301. /^[a-zA-Z_][a-zA-Z0-9_].*=.*/ {
  3302. if ($1 == class) {
  3303. printf("V:#line %d \"%s\"\n", ln, src);
  3304. printf("V:%s\n", $0);
  3305. printf("J:%s\n", $0);
  3306. next;
  3307. }
  3308. }
  3309. /^[a-zA-Z_][a-zA-Z0-9_]*/ {
  3310. if ($1 == class) {
  3311. fln = ln;
  3312. store = $0;
  3313. mode = "F";
  3314. next;
  3315. }
  3316. }
  3317. /^\{ *$/ {
  3318. if (mode == "F") {
  3319. printf("F:#line %d \"%s\"\n", fln, src);
  3320. printf("F:%s;\n", store);
  3321. printf("I:%s;\n", store);
  3322. store = "";
  3323. mode = "";
  3324. next;
  3325. }
  3326. }
  3327. {
  3328. if (mode == "D")
  3329. printf("D:%s\n", $0);
  3330. else if (mode == "F")
  3331. store = store " " $0;
  3332. }
  3333. ' "src=$src" "define=$opt_D" "class=$opt_C" >>$tmpfile
  3334. done
  3335. if [ ".$opt_v" = .yes ]; then
  3336. echo "" 1>&2
  3337. fi
  3338. # start generating output header
  3339. echo "/* $opt_o -- autogenerated from $opt_t, DO NOT EDIT! */" >$output
  3340. echo "#line 1 \"$opt_t\"" >>$output
  3341. sed <$opt_t -e "1,/^${opt_M} *\$/p" -e 'd' |\
  3342. sed -e "/^${opt_M} *\$/d" >>$output
  3343. # merge in the define blocks
  3344. grep '^D:' $tmpfile | sed -e 's/^D://' >>$output
  3345. # generate standard prolog
  3346. echo "#line 1 \"_ON_THE_FLY_\"" >>$output
  3347. echo "" >>$output
  3348. echo "/* make sure the scpp source extensions are skipped */" >>$output
  3349. echo "#define $opt_D 0" >>$output
  3350. echo "#define $opt_C /**/" >>$output
  3351. # generate namespace hiding for variables
  3352. echo "" >>$output
  3353. echo "/* move intern variables to hidden namespace */" >>$output
  3354. grep '^J:' $tmpfile | sed >>$output \
  3355. -e 's/^J://' \
  3356. -e 's/ */ /g' \
  3357. -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\)\[\];.*$/#define \1 __\1/' \
  3358. -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\)\[\] =.*$/#define \1 __\1/' \
  3359. -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\);.*$/#define \1 __\1/' \
  3360. -e 's/^[^=;]*[ *]\([a-zA-Z0-9_]*\) =.*$/#define \1 __\1/'
  3361. # generate namespace hiding for functions
  3362. echo "" >>$output
  3363. echo "/* move intern functions to hidden namespace */" >>$output
  3364. grep '^I:' $tmpfile | sed >>$output \
  3365. -e 's/^I://' \
  3366. -e 's/\([ (]\) */\1/g' \
  3367. -e 's/ *\([),]\)/\1/g' \
  3368. -e 's/^[^(]*[ *]\([a-zA-Z0-9_]*\)(.*$/#define \1 __\1/'
  3369. # generate prototypes for variables
  3370. echo "" >>$output
  3371. echo "/* prototypes for intern variables */" >>$output
  3372. grep '^V:' $tmpfile | sed >>$output \
  3373. -e 's/^V://' \
  3374. -e 's/ */ /g' \
  3375. -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\[\]\);.*$/\1;/' \
  3376. -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\[\]\) =.*$/\1;/' \
  3377. -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\);.*$/\1;/' \
  3378. -e 's/^\([^=;]*[ *][a-zA-Z0-9_]*\) =.*$/\1;/' \
  3379. -e 's/ ;/;/g' \
  3380. -e "s/^$opt_C /extern /"
  3381. # generate prototypes for functions
  3382. echo "" >>$output
  3383. echo "/* prototypes for intern functions */" >>$output
  3384. grep '^F:' $tmpfile | sed >>$output \
  3385. -e 's/^F://' \
  3386. -e 's/\([ (]\) */\1/g' \
  3387. -e 's/ *\([),]\)/\1/g' \
  3388. -e 's/\([* ]\)[a-zA-Z0-9_]*,/\1,/g' \
  3389. -e 's/\([* ]\)[a-zA-Z0-9_]*);/\1);/g' \
  3390. -e 's/(\*[a-zA-Z0-9_]*)(/(*)(/g' \
  3391. -e 's/\([ (]\) */\1/g' \
  3392. -e 's/ *\([),]\)/\1/g' \
  3393. -e "s/^$opt_C /extern /"
  3394. # finish generating output header
  3395. n=`(echo ''; sed <$opt_t -e "1,/^${opt_M} *\$/p" -e 'd') |\
  3396. wc -l | sed -e 's;^ *\([0-9]*\) *$;\1;'`
  3397. echo "#line $n \"$opt_t\"" >>$output
  3398. sed <$opt_t -e "/^${opt_M} *\$/,\$p" -e 'd' |\
  3399. sed -e "/^${opt_M} *\$/d" >>$output
  3400. # create final output file
  3401. if [ -f $opt_o ]; then
  3402. if [ ".$opt_p" = .yes ]; then
  3403. grep -v '^#line' $opt_o >$tmpfile.o
  3404. grep -v '^#line' $output >$tmpfile.n
  3405. out_old="$tmpfile.o"
  3406. out_new="$tmpfile.n"
  3407. else
  3408. out_old="$opt_o"
  3409. out_new="$output"
  3410. fi
  3411. if cmp -s $out_old $out_new; then
  3412. :
  3413. else
  3414. cp $output $opt_o
  3415. fi
  3416. else
  3417. cp $output $opt_o
  3418. fi
  3419. rm -f $output
  3420. rm -f $tmpfile $tmpfile.* >/dev/null 2>&1
  3421. shtool_exit 0
  3422. ;;
  3423. version )
  3424. ##
  3425. ## version -- Maintain a version information file
  3426. ## Copyright (c) 1994-2008 Ralf S. Engelschall <rse@engelschall.com>
  3427. ##
  3428. file="$1"
  3429. # determine prefix and name
  3430. name="$opt_n"
  3431. prefix="$opt_p"
  3432. # determine current version
  3433. triple="$opt_s"
  3434. if [ ".$triple" != . ]; then
  3435. # use given triple
  3436. if [ ".`echo $triple | grep '[0-9]*.[0-9]*[sabp.][0-9]*'`" = . ]; then
  3437. echo "$msgprefix:Error: invalid argument to option \`-s': \`$opt_s'" 1>&2
  3438. shtool_exit 1
  3439. fi
  3440. eval `echo $triple |\
  3441. sed -e 's%\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\).*%\
  3442. ver="\1";rev="\2";typ="\3";lev="\4"%'`
  3443. tim=calc
  3444. elif [ -r $file ]; then
  3445. # determine triple from given file
  3446. eval `grep 'Version [0-9]*.[0-9]*[sabp.][0-9]* ([0-9]*-[a-zA-Z]*-[0-9]*)' $file |\
  3447. sed -e 's%.*Version \([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\) (\([0-9]*-[a-zA-Z]*-[0-9]*\)).*%\
  3448. ver="\1";rev="\2";typ="\3";lev="\4";tim="\5"%' -e 'q'`
  3449. else
  3450. # intialise to first version
  3451. ver=0
  3452. rev=1
  3453. typ=.
  3454. lev=0
  3455. tim=calc
  3456. fi
  3457. # determine new version in batch
  3458. if [ ".$opt_i" != . ]; then
  3459. case $opt_i in
  3460. v ) ver=`expr $ver + 1`
  3461. rev=0
  3462. lev=0
  3463. ;;
  3464. r ) rev=`expr $rev + 1`
  3465. lev=0
  3466. ;;
  3467. l ) lev=`expr $lev + 1`
  3468. ;;
  3469. * ) echo "$msgprefix:Error: invalid argument to option \`-i': \`$opt_i'" 1>&2
  3470. shtool_exit 1
  3471. ;;
  3472. esac
  3473. tim=calc
  3474. fi
  3475. # determine new version interactively
  3476. if [ ".$opt_e" = .yes ]; then
  3477. echo "old version: ${ver}.${rev}${typ}${lev}"
  3478. while [ 1 ]; do
  3479. echo dummy | awk '{ printf("new version: "); }'
  3480. read triple
  3481. case $triple in
  3482. [0-9]*.[0-9]*[sabp.][0-9]* )
  3483. ;;
  3484. * ) echo "$msgprefix:Error: invalid version string entered: \`$triple'" 1>&2
  3485. continue
  3486. ;;
  3487. esac
  3488. break
  3489. done
  3490. eval `echo $triple |\
  3491. sed -e 's%^\([0-9]*\)\.\([0-9]*\)\([sabp.]\)\([0-9]*\)$%\
  3492. ver="\1";rev="\2";typ="\3";lev="\4"%'`
  3493. tim=calc
  3494. fi
  3495. # determine hexadecimal and libtool value of version
  3496. case $typ in
  3497. a ) typnum=0; levnum=$lev ;;
  3498. b ) typnum=1; levnum=$lev ;;
  3499. p | . ) typnum=2; levnum=$lev ;;
  3500. s ) typnum=15; levnum=255 ;; # snapshots are special
  3501. esac
  3502. hex=`echo "$ver:$rev:$typnum:$levnum" |\
  3503. awk -F: '{ printf("0x%x%02x%1x%02x", $1, $2, $3, $4); }' |\
  3504. tr 'abcdef' 'ABCDEF'`
  3505. ltv=`echo "$ver:$rev:$typnum:$levnum" |\
  3506. awk -F: '{ printf("%d:%d", $1*10 + $2, $3*10 + $4); }'`
  3507. # determine date
  3508. if [ ".$tim" = .calc ]; then
  3509. day=`date '+%d'`
  3510. month=`date '+%m'`
  3511. year=`date '+%Y' 2>/dev/null`
  3512. if [ ".$time_year" = . ]; then
  3513. year=`date '+%y'`
  3514. case $year in
  3515. [5-9][0-9]) year="19$year" ;;
  3516. [0-4][0-9]) year="20$year" ;;
  3517. esac
  3518. fi
  3519. case $month in
  3520. 1|01) month='Jan' ;;
  3521. 2|02) month='Feb' ;;
  3522. 3|03) month='Mar' ;;
  3523. 4|04) month='Apr' ;;
  3524. 5|05) month='May' ;;
  3525. 6|06) month='Jun' ;;
  3526. 7|07) month='Jul' ;;
  3527. 8|08) month='Aug' ;;
  3528. 9|09) month='Sep' ;;
  3529. 10) month='Oct' ;;
  3530. 11) month='Nov' ;;
  3531. 12) month='Dec' ;;
  3532. esac
  3533. tim="${day}-${month}-${year}"
  3534. fi
  3535. # perform result actions
  3536. mode=show
  3537. if [ ".$opt_i" != . ]; then
  3538. mode=edit
  3539. elif [ ".$opt_e" = .yes ]; then
  3540. mode=edit
  3541. elif [ ".$opt_s" != . ]; then
  3542. mode=edit
  3543. fi
  3544. if [ ".$mode" = .show ]; then
  3545. # just display the current version
  3546. case $opt_d in
  3547. short )
  3548. echo "${ver}.${rev}${typ}${lev}"
  3549. ;;
  3550. long )
  3551. echo "${ver}.${rev}${typ}${lev} ($tim)"
  3552. ;;
  3553. libtool )
  3554. echo "${ltv}"
  3555. ;;
  3556. hex )
  3557. echo "${hex}"
  3558. ;;
  3559. * ) echo "$msgprefix:Error: invalid argument to option \`-d': \`$opt_d'" 1>&2
  3560. shtool_exit 1
  3561. ;;
  3562. esac
  3563. else
  3564. # update the version file
  3565. # pre-generate various strings
  3566. triple="${ver}.${rev}${typ}${lev}"
  3567. vHex="$hex"
  3568. vShort="${triple}"
  3569. vLong="${triple} (${tim})"
  3570. vTeX="This is ${name}, Version ${triple} (${tim})"
  3571. vGNU="${name} ${triple} (${tim})"
  3572. vWeb="${name}/${triple}"
  3573. vSCCS="@(#)${name} ${triple} (${tim})"
  3574. vRCS="\$Id: ${name} ${triple} (${tim}) \$"
  3575. # determine string out of filename
  3576. # (do NOT try to optimize this in any way because of portability)
  3577. filestr=`util_upper "$file" | tr './%+' '____' | sed -e 's/-/_/g'`
  3578. # generate uppercase prefix
  3579. prefixupper=`util_upper "$prefix"`
  3580. # create the version file according the the selected language
  3581. echo "new version: ${vLong}"
  3582. cp /dev/null $file
  3583. case $opt_l in
  3584. txt )
  3585. echo >>$file ""
  3586. echo >>$file " ${file} -- Version Information for ${name} (syntax: Text)"
  3587. echo >>$file " [automatically generated and maintained by GNU shtool]"
  3588. echo >>$file ""
  3589. echo >>$file " $vTeX"
  3590. echo >>$file ""
  3591. ;;
  3592. c )
  3593. echo >>$file "/*"
  3594. echo >>$file "** ${file} -- Version Information for ${name} (syntax: C/C++)"
  3595. echo >>$file "** [automatically generated and maintained by GNU shtool]"
  3596. echo >>$file "*/"
  3597. echo >>$file ""
  3598. echo >>$file "#ifdef _${filestr}_AS_HEADER_"
  3599. echo >>$file ""
  3600. echo >>$file "#ifndef _${filestr}_"
  3601. echo >>$file "#define _${filestr}_"
  3602. echo >>$file ""
  3603. echo >>$file "#define ${prefixupper}VERSION ${vHex}"
  3604. echo >>$file ""
  3605. echo >>$file "typedef struct {"
  3606. echo >>$file " const int v_hex;"
  3607. echo >>$file " const char *v_short;"
  3608. echo >>$file " const char *v_long;"
  3609. echo >>$file " const char *v_tex;"
  3610. echo >>$file " const char *v_gnu;"
  3611. echo >>$file " const char *v_web;"
  3612. echo >>$file " const char *v_sccs;"
  3613. echo >>$file " const char *v_rcs;"
  3614. echo >>$file "} ${prefix}version_t;"
  3615. echo >>$file ""
  3616. echo >>$file "extern ${prefix}version_t ${prefix}version;"
  3617. echo >>$file ""
  3618. echo >>$file "#endif /* _${filestr}_ */"
  3619. echo >>$file ""
  3620. echo >>$file "#else /* _${filestr}_AS_HEADER_ */"
  3621. echo >>$file ""
  3622. echo >>$file "#define _${filestr}_AS_HEADER_"
  3623. echo >>$file "#include \"${file}\""
  3624. echo >>$file "#undef _${filestr}_AS_HEADER_"
  3625. echo >>$file ""
  3626. echo >>$file "${prefix}version_t ${prefix}version = {"
  3627. echo >>$file " ${vHex},"
  3628. echo >>$file " \"${vShort}\","
  3629. echo >>$file " \"${vLong}\","
  3630. echo >>$file " \"${vTeX}\","
  3631. echo >>$file " \"${vGNU}\","
  3632. echo >>$file " \"${vWeb}\","
  3633. echo >>$file " \"${vSCCS}\","
  3634. echo >>$file " \"${vRCS}\""
  3635. echo >>$file "};"
  3636. echo >>$file ""
  3637. echo >>$file "#endif /* _${filestr}_AS_HEADER_ */"
  3638. echo >>$file ""
  3639. ;;
  3640. m4 )
  3641. echo >>$file "##"
  3642. echo >>$file "## ${file} -- Version Information for ${name} (syntax: M4)"
  3643. echo >>$file "## [automatically generated and maintained by GNU shtool]"
  3644. echo >>$file "##"
  3645. echo >>$file ""
  3646. echo >>$file "m4_define([v_hex], [${vHex}])"
  3647. echo >>$file "m4_define([v_short], [${vShort}])"
  3648. echo >>$file "m4_define([v_long], [${vLong}])"
  3649. echo >>$file "m4_define([v_tex], [${vTeX}])"
  3650. echo >>$file "m4_define([v_gnu], [${vGNU}])"
  3651. echo >>$file "m4_define([v_web], [${vWeb}])"
  3652. echo >>$file "m4_define([v_sccs], [${vSCCS}])"
  3653. echo >>$file "m4_define([v_rcs], [${vRCS}])"
  3654. echo >>$file ""
  3655. ;;
  3656. perl )
  3657. echo >>$file "##"
  3658. echo >>$file "## ${file} -- Version Information for ${name} (syntax: Perl)"
  3659. echo >>$file "## [automatically generated and maintained by GNU shtool]"
  3660. echo >>$file "##"
  3661. echo >>$file ""
  3662. echo >>$file "our \$${prefix}version = {"
  3663. echo >>$file " 'v_hex' => ${vHex},"
  3664. echo >>$file " 'v_short' => \"${vShort}\","
  3665. echo >>$file " 'v_long' => \"${vLong}\","
  3666. echo >>$file " 'v_tex' => \"${vTeX}\","
  3667. echo >>$file " 'v_gnu' => \"${vGNU}\","
  3668. echo >>$file " 'v_web' => \"${vWeb}\","
  3669. echo >>$file " 'v_sccs' => \"${vSCCS}\","
  3670. echo >>$file " 'v_rcs' => \"\\${vRCS}/\""
  3671. echo >>$file "};"
  3672. echo >>$file ""
  3673. echo >>$file "1;"
  3674. echo >>$file ""
  3675. ;;
  3676. python )
  3677. echo >>$file "##"
  3678. echo >>$file "## ${file} -- Version Information for ${name} (syntax: Python)"
  3679. echo >>$file "## [automatically generated and maintained by GNU shtool]"
  3680. echo >>$file "##"
  3681. echo >>$file ""
  3682. echo >>$file "class ${prefix}version:"
  3683. echo >>$file " v_hex = ${vHex}"
  3684. echo >>$file " v_short = \"${vShort}\""
  3685. echo >>$file " v_long = \"${vLong}\""
  3686. echo >>$file " v_tex = \"${vTeX}\""
  3687. echo >>$file " v_gnu = \"${vGNU}\""
  3688. echo >>$file " v_web = \"${vWeb}\""
  3689. echo >>$file " v_sccs = \"${vSCCS}\""
  3690. echo >>$file " v_rcs = \"${vRCS}\""
  3691. echo >>$file ""
  3692. ;;
  3693. * ) echo "$msgprefix:Error: invalid argument to option \`-l': \`$opt_l'" 1>&2
  3694. shtool_exit 1
  3695. ;;
  3696. esac
  3697. fi
  3698. shtool_exit 0
  3699. ;;
  3700. path )
  3701. ##
  3702. ## path -- Deal with program paths
  3703. ## Copyright (c) 1998-2008 Ralf S. Engelschall <rse@engelschall.com>
  3704. ##
  3705. namelist="$*"
  3706. # check whether the test command supports the -x option
  3707. if [ -x /bin/sh ] 2>/dev/null; then
  3708. minusx="-x"
  3709. else
  3710. minusx="-r"
  3711. fi
  3712. # split path string
  3713. paths="`echo $opt_p |\
  3714. sed -e 's/^:/.:/' \
  3715. -e 's/::/:.:/g' \
  3716. -e 's/:$/:./' \
  3717. -e 's/:/ /g'`"
  3718. # SPECIAL REQUEST
  3719. # translate forward to reverse path
  3720. if [ ".$opt_r" = .yes ]; then
  3721. if [ "x$namelist" = "x." ]; then
  3722. rp='.'
  3723. else
  3724. rp=''
  3725. for pe in `IFS="$IFS/"; echo $namelist`; do
  3726. rp="../$rp"
  3727. done
  3728. fi
  3729. echo $rp | sed -e 's:/$::'
  3730. shtool_exit 0
  3731. fi
  3732. # SPECIAL REQUEST
  3733. # strip out directory or base name
  3734. if [ ".$opt_d" = .yes ]; then
  3735. echo "$namelist" |\
  3736. sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'
  3737. shtool_exit 0
  3738. fi
  3739. if [ ".$opt_b" = .yes ]; then
  3740. echo "$namelist" |\
  3741. sed -e 's;.*/\([^/]*\)$;\1;'
  3742. shtool_exit 0
  3743. fi
  3744. # MAGIC SITUATION
  3745. # Perl Interpreter (perl)
  3746. if [ ".$opt_m" = .yes ] && [ ".$namelist" = .perl ]; then
  3747. rm -f $tmpfile >/dev/null 2>&1
  3748. touch $tmpfile
  3749. found=0
  3750. pc=99
  3751. for dir in $paths; do
  3752. dir=`echo $dir | sed -e 's;/*$;;'`
  3753. nc=99
  3754. for name in perl perl5 miniperl; do
  3755. if [ $minusx "$dir/$name" ] && [ ! -d "$dir/$name" ]; then
  3756. perl="$dir/$name"
  3757. pv=`$perl -e 'printf("%.3f", $]);'`
  3758. echo "$pv:$pc:$nc:$perl" >>$tmpfile
  3759. found=1
  3760. fi
  3761. nc=`expr $nc - 1`
  3762. done
  3763. pc=`expr $pc - 1`
  3764. done
  3765. if [ $found = 1 ]; then
  3766. perl="`cat $tmpfile | sort -r -u | sed -e 'q' | cut -d: -f4`"
  3767. rm -f $tmpfile >/dev/null 2>&1
  3768. echo "$perl"
  3769. shtool_exit 0
  3770. fi
  3771. rm -f $tmpfile >/dev/null 2>&1
  3772. shtool_exit 1
  3773. fi
  3774. # MAGIC SITUATION
  3775. # C pre-processor (cpp)
  3776. if [ ".$opt_m" = .yes ] && [ ".$namelist" = .cpp ]; then
  3777. echo >$tmpfile.c "#include <assert.h>"
  3778. echo >>$tmpfile.c "Syntax Error"
  3779. # 1. try the standard cc -E approach
  3780. cpp="${CC-cc} -E"
  3781. (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
  3782. my_error=`grep -v '^ *+' $tmpfile.out`
  3783. if [ ".$my_error" != . ]; then
  3784. # 2. try the cc -E approach and GCC's -traditional-ccp option
  3785. cpp="${CC-cc} -E -traditional-cpp"
  3786. (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
  3787. my_error=`grep -v '^ *+' $tmpfile.out`
  3788. if [ ".$my_error" != . ]; then
  3789. # 3. try a standalone cpp command in path and lib dirs
  3790. for path in $paths /lib /usr/lib /usr/local/lib; do
  3791. path=`echo $path | sed -e 's;/*$;;'`
  3792. if [ $minusx "$path/cpp" ] && [ ! -d "$path/cpp" ]; then
  3793. cpp="$path/cpp"
  3794. break
  3795. fi
  3796. done
  3797. if [ ".$cpp" != . ]; then
  3798. (eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
  3799. my_error=`grep -v '^ *+' $tmpfile.out`
  3800. if [ ".$my_error" != . ]; then
  3801. # ok, we gave up...
  3802. cpp=''
  3803. fi
  3804. fi
  3805. fi
  3806. fi
  3807. rm -f $tmpfile >/dev/null 2>&1
  3808. rm -f $tmpfile.c $tmpfile.out >/dev/null 2>&1
  3809. if [ ".$cpp" != . ]; then
  3810. echo "$cpp"
  3811. shtool_exit 0
  3812. fi
  3813. shtool_exit 1
  3814. fi
  3815. # STANDARD SITUATION
  3816. # iterate over names
  3817. for name in $namelist; do
  3818. # iterate over paths
  3819. for path in $paths; do
  3820. path=`echo $path | sed -e 's;/*$;;'`
  3821. if [ $minusx "$path/$name" ] && [ ! -d "$path/$name" ]; then
  3822. if [ ".$opt_s" != .yes ]; then
  3823. echo "$path/$name"
  3824. fi
  3825. shtool_exit 0
  3826. fi
  3827. done
  3828. done
  3829. shtool_exit 1
  3830. ;;
  3831. esac
  3832. shtool_exit 0