aux.wrapbin.sh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #!/bin/sh
  2. ##
  3. ## OpenPKG Binary Bootstrap Package (self-extracting shell script)
  4. ## Copyright (c) 2000-2004 The OpenPKG Project <http://www.openpkg.org/>
  5. ## Copyright (c) 2000-2004 Ralf S. Engelschall <rse@engelschall.com>
  6. ## Copyright (c) 2000-2004 Cable & Wireless <http://www.cw.com/>
  7. ##
  8. ## Permission to use, copy, modify, and distribute this software for
  9. ## any purpose with or without fee is hereby granted, provided that
  10. ## the above copyright notice and this permission notice appear in all
  11. ## copies.
  12. ##
  13. ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  14. ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  16. ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
  17. ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  18. ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  19. ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  20. ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  22. ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  23. ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. ## SUCH DAMAGE.
  25. ##
  26. # configuration
  27. l_me="$0"
  28. o_help=no
  29. o_version=no
  30. l_prefix='@l_prefix@'
  31. l_musr='@MUSR@'
  32. l_mgrp='@MGRP@'
  33. l_platform="@l_platform@"
  34. l_release="@l_release@"
  35. l_version="@l_version@"
  36. # establish standard environment
  37. LC_CTYPE=C
  38. export LC_CTYPE
  39. umask 022
  40. # parse command line options
  41. for opt
  42. do
  43. case $opt in
  44. -*=*) arg=`echo "$opt" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
  45. *) arg='' ;;
  46. esac
  47. case $opt in
  48. -h | --help ) o_help=yes ;;
  49. -v | --version ) o_version=yes ;;
  50. --prefix=* ) l_prefix=$arg ;;
  51. * ) o_help=yes ;;
  52. esac
  53. done
  54. if [ ".$o_version" = .no -a ".$l_prefix" = . ]; then
  55. o_help=yes
  56. fi
  57. if [ ".$o_help" = .yes ]; then
  58. echo "Usage: sh $l_me [--prefix=<prefix>]" 2>&1
  59. echo " [-h|--help] [-v|--version]" 2>&1
  60. exit 1
  61. fi
  62. # display version and copyright header
  63. echo "OpenPKG ${l_release} Binary Bootstrap Package, version ${l_version}"
  64. echo "Built for prefix ${l_prefix} on target platform ${l_platform}"
  65. if [ ".$o_version" = .yes ]; then
  66. exit 0
  67. fi
  68. # make sure all essential installation tools are available
  69. for tool in sed mkdir dd tar chown chgrp; do
  70. found=no
  71. case $tool in
  72. /* )
  73. if [ -f $tool ]; then
  74. found=yes
  75. fi
  76. ;;
  77. * )
  78. for p in `IFS=:; echo $PATH`; do
  79. if [ -f "$p/$tool" ]; then
  80. found=yes
  81. break
  82. fi
  83. done
  84. ;;
  85. esac
  86. if [ ".$found" = .no ]; then
  87. echo "$l_me:ERROR: unable to find installation tool \"$tool\"" 1>&2
  88. exit 1
  89. fi
  90. done
  91. # determine current username
  92. cusr=`(id -un) 2>/dev/null ||\
  93. (id | sed -e 's;^[^(]*(\([^)]*\)).*;\1;') 2>/dev/null ||\
  94. (whoami) 2>/dev/null ||\
  95. (who am i | cut "-d " -f1) 2>/dev/null ||\
  96. echo ${LOGNAME-"NN"}`
  97. # running the embedded %pre script for hooking into the system environment
  98. echo "++ hooking OpenPKG instance into system environment"
  99. prefix="$l_prefix"
  100. susr='@SUSR@'; sgrp='@SGRP@'
  101. musr='@MUSR@'; mgrp='@MGRP@'
  102. rusr='@RUSR@'; rgrp='@RGRP@'
  103. nusr='@NUSR@'; ngrp='@NGRP@'
  104. suid='@SUID@'; sgid='@SGID@'
  105. muid='@MUID@'; mgid='@MGID@'
  106. ruid='@RUID@'; rgid='@RGID@'
  107. nuid='@NUID@'; ngid='@NGID@'
  108. set -- 1 # emulate RPM's $1 when executing scripts
  109. # ---- BEGIN EMBEDDED %pre SCRIPT ----
  110. @PRE@
  111. # ---- END EMBEDDED %pre SCRIPT ----
  112. # make sure prefix/root directory exists
  113. # and has correct permissions and owner/group
  114. if [ ! -d $l_prefix ]; then
  115. # create prefix/root directory from scratch
  116. echo "++ creating OpenPKG instance root directory \"$l_prefix\""
  117. d=''
  118. for c in `IFS=/; echo $l_prefix`; do
  119. d="$d/$c"
  120. if [ ! -d $d ]; then
  121. mkdir $d || exit 1
  122. chmod 755 $d || exit 1
  123. if [ ".$cusr" = .root ]; then
  124. chown $musr $d >/dev/null 2>&1 || true
  125. chgrp $mgrp $d >/dev/null 2>&1 || true
  126. fi
  127. fi
  128. done
  129. else
  130. # adjust already existing prefix/root directory
  131. echo "++ fixating OpenPKG instance root directory \"$l_prefix\""
  132. ( cd $l_prefix || exit 1
  133. chmod 755 . || exit 1
  134. if [ ".$cusr" = .root ]; then
  135. chown $musr . >/dev/null 2>&1 || true
  136. chgrp $mgrp . >/dev/null 2>&1 || true
  137. fi
  138. ) || exit 1
  139. fi
  140. # extract and install binary distribution files
  141. echo "++ extracting OpenPKG binary distribution"
  142. dd if=$l_me bs=8192 skip=8 2>/dev/null |\
  143. (cd $l_prefix; tar xf - 2>/dev/null)
  144. echo "++ installing OpenPKG binary distribution"
  145. ( cd $l_prefix || exit 1
  146. ./openpkg.bzip2 -d -c openpkg.tar.bz2 | ./openpkg.tar xf - 2>/dev/null
  147. rm -f openpkg.tar openpkg.bzip2 openpkg.tar.bz2 >/dev/null 2>&1 || true
  148. ) || exit 1
  149. # fixate installation files
  150. echo "++ fixating OpenPKG instance filesystem hierarchy"
  151. ( echo 'fixate () {'
  152. echo ' chmod "$1" "$4"'
  153. echo ' chown "$2" "$4"'
  154. echo ' chgrp "$3" "$4"'
  155. echo '}'
  156. $l_prefix/bin/openpkg rpm -qa \
  157. --qf '[fixate %7.7{FILEMODES:octal} %{FILEUSERNAME:shescape} %{FILEGROUPNAME:shescape} ::%{FILENAMES:shescape}\n]' |\
  158. grep -v '(none)' | sed 's/^fixate .../fixate /' | sed -e "s; ::\\(.\\)@l_prefix@; \\1$l_prefix;"
  159. ) | sh 2>/dev/null || true
  160. # running the embedded %post script
  161. echo "++ post-processing OpenPKG bootstrap installation"
  162. prefix="$l_prefix"
  163. susr='@SUSR@'; sgrp='@SGRP@'
  164. musr='@MUSR@'; mgrp='@MGRP@'
  165. rusr='@RUSR@'; rgrp='@RGRP@'
  166. nusr='@NUSR@'; ngrp='@NGRP@'
  167. suid='@SUID@'; sgid='@SGID@'
  168. muid='@MUID@'; mgid='@MGID@'
  169. ruid='@RUID@'; rgid='@RGID@'
  170. nuid='@NUID@'; ngid='@NGID@'
  171. set -- 1 # emulate RPM's $1 when executing scripts
  172. # ---- BEGIN EMBEDDED %post SCRIPT ----
  173. @POST@
  174. # ---- END EMBEDDED %post SCRIPT ----
  175. # display final information
  176. ( echo "Congratulations!"
  177. echo ""
  178. echo "You have successfully installed an OpenPKG ${l_release} instance"
  179. echo "under prefix ${l_prefix} on target platform ${l_platform}."
  180. echo ""
  181. echo "Details about this installed OpenPKG instance you can easily"
  182. echo "determine by running the following typical RPM query commands:"
  183. echo ""
  184. echo " \$ ${l_prefix}/bin/openpkg rpm -qa"
  185. echo " \$ ${l_prefix}/bin/openpkg rpm -qi openpkg"
  186. echo " \$ ${l_prefix}/bin/openpkg rpm -qlv openpkg"
  187. echo ""
  188. echo "The integrity of the whole OpenPKG instance you can check at any"
  189. echo "time by running the RPM verify command:"
  190. echo ""
  191. echo " \$ ${l_prefix}/bin/openpkg rpm -Va"
  192. echo ""
  193. echo "For installing software packages into this OpenPKG instance, just run"
  194. echo "the following two RPM build commands for each package:"
  195. echo ""
  196. echo " \$ ${l_prefix}/bin/openpkg rpm --rebuild /path/to/foo-*.src.rpm"
  197. echo " \$ ${l_prefix}/bin/openpkg rpm -Uvh ${l_prefix}/RPM/PKG/foo-*.rpm"
  198. echo ""
  199. echo "If you later want to remove a software package, just run:"
  200. echo ""
  201. echo " \$ ${l_prefix}/bin/openpkg rpm -e foo"
  202. echo ""
  203. echo "For removing the whole OpenPKG instance under prefix ${l_prefix},"
  204. echo "just remove every package. Once you finally removed the package"
  205. echo "\"openpkg\", the whole OpenPKG instance will be unlinked from the"
  206. echo "system and removed, too."
  207. echo ""
  208. echo "Thank you for flying OpenPKG..."
  209. echo " Ralf S. Engelschall"
  210. echo " The OpenPKG Project"
  211. echo " openpkg@openpkg.org"
  212. ) | $l_prefix/lib/openpkg/rpmtool msg -b -t info
  213. # die explicitly just before the shell would discover
  214. # that we carry mega-bytes of data with us... ;-)
  215. exit 0
  216. # the distribution tarball is appended in raw format directly to the
  217. # end of this script, just leaded by padding whitespaces which make
  218. # sure that the tarball data starts at the pre-defined offset of 64KB.
  219. # This allows us to unpack the tarball by just skipping the leading
  220. # 64KB (= 8192*8, see above).