Advertisement
Sweetening

REDHAT ISO EXTRACT

Sep 20th, 2023
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set -e
  4.  
  5. usage() {
  6.  
  7. cat <<EOF
  8.  
  9. rh_iso_extract.sh [ options ]
  10.  
  11. Valid options are:
  12. -h | --help This help
  13. -a | --arch The architecture to work with [ default i386 ]
  14. -d | --dest-dir The destination dir prefix [ default /var/ftp ]
  15. -i | --iso-dir The source iso dir prefix [ default /var/ftp ]
  16. -r | --release The release name [ default beta/null ]
  17.  
  18. If you cannot loop mount a file on an NFS filesystem,
  19. e.g. 2.2.x kernel based systems, you should copy your
  20. iso images to a local directory and override the iso-dir
  21. and dest-dir defaults.
  22.  
  23. e.g.
  24. # mkdir -p /mnt/scratch/ftp/pub/redhat/linux/RELEASE/en/iso/i386/
  25.  
  26. # cp /var/ftp/pub/redhat/linux/RELEASE/en/iso/i386/*.iso \\
  27. /mnt/scratch/ftp/pub/redhat/linux/RELEASE/en/iso/i386/
  28.  
  29. # rh_iso_extract.sh -i /mnt/scratch/ftp/pub -d /var/ftp/pub
  30.  
  31. EOF
  32. exit 1
  33. }
  34.  
  35. TEMP=`getopt -o ha:d:i:r: --long help,arch:,dest-dir:,iso-dir:,release: -n 'rh_iso_extract.sh' -- "$@"`
  36.  
  37. eval set -- "$TEMP"
  38.  
  39. while true ; do
  40. case "$1" in
  41. -h|--help) usage ;;
  42. -a|--arch)
  43. ARCH=$2
  44. shift 2
  45. ;;
  46. -d|--dest-dir)
  47. DESTPREFIX=$2
  48. shift 2
  49. ;;
  50. -i|--iso-dir)
  51. ISOPREFIX=$2
  52. shift 2
  53. ;;
  54. -r|--release)
  55. RELEASE=$2
  56. shift 2
  57. ;;
  58. --) shift ; break;;
  59. *) echo "Internal error!" ; exit 1;;
  60. esac
  61. done
  62.  
  63. ### Begin config
  64.  
  65. LOCAL_BASE_DIR=/var/ftp/pub
  66. LOCAL_DEST_DIR=/var/ftp/pub
  67.  
  68. if [ "$ISOPREFIX" != "" ]; then
  69. LOCAL_BASE_DIR=$ISOPREFIX
  70. LOCAL_DEST_DIR=$ISOPREFIX
  71. fi
  72.  
  73. if [ "$DESTPREFIX" != "" ]; then
  74. LOCAL_DEST_DIR=$DESTPREFIX
  75. fi
  76.  
  77. if [ "$RELEASE" = "" ]; then
  78. RELEASE=beta/null
  79. fi
  80.  
  81. RH_BASE_DIR=redhat/linux
  82.  
  83. RELEASE_BASE_DIR=$LOCAL_BASE_DIR/$RH_BASE_DIR/$RELEASE
  84. RELEASE_DEST_DIR=$LOCAL_DEST_DIR/$RH_BASE_DIR/$RELEASE
  85.  
  86. ISO_BASE_DIR=$RELEASE_BASE_DIR/en/iso
  87. OS_BASE_DIR=$RELEASE_DEST_DIR/en/os
  88.  
  89. DOC_ISO_DIR=$ISO_BASE_DIR/doc
  90. DOC_DIR=$RELEASE_BASE_DIR/en/doc
  91.  
  92. # where to mount the iso's
  93. MNTPNT=/mnt/cdrom
  94.  
  95. # white space separated list of architectures
  96. ARCH_LIST="i386"
  97.  
  98. if [ "$ARCH" != "" ]; then
  99. ARCH_LIST="$ARCH"
  100. fi
  101.  
  102. echo DESTPREFIX=$DESTPREFIX
  103. echo ISOPREFIX=$ISOPREFIX
  104. echo RELEASE=$RELEASE
  105. echo ISO_BASE_DIR=$ISO_BASE_DIR
  106. echo OS_BASE_DIR=$OS_BASE_DIR
  107. echo ARCH_LIST=$ARCH_LIST
  108.  
  109. # who will own the created files
  110. OWNER=rsync
  111. OWNER_GRP=rsync
  112.  
  113. # whether to extract the doc iso as well: yes/no
  114. DO_DOC=no
  115.  
  116. ### End config
  117.  
  118. do_one_arch() {
  119. # Usage: do_one_arch arch
  120. arch=$1
  121. archdir=$OS_BASE_DIR/$arch
  122. arch_isodir=$ISO_BASE_DIR/$arch
  123.  
  124. mkdir -p $archdir
  125.  
  126. if ( ls $arch_isodir/*-$arch-*.iso > /dev/null 2>&1 ) ; then
  127. for disc in $arch_isodir/*-$arch-*.iso; do
  128. echo Expanding `basename $disc` ...
  129. mount -o loop $disc $MNTPNT
  130. if ( cd $MNTPNT && pax -rw ./* $archdir ); then
  131. umount $MNTPNT
  132. echo Done
  133. else
  134. umount $MNTPNT
  135. exit 1
  136. fi
  137. done
  138. else
  139. echo "Unable to find $arch_isodir/*-$arch-*.iso"
  140. fi
  141. }
  142.  
  143. do_one_srpms() {
  144. # Usage: do_one_srpms arch
  145. arch=$1
  146. srpms_dir=$OS_BASE_DIR/$arch/SRPMS
  147. arch_isodir=$ISO_BASE_DIR/$arch
  148.  
  149. mkdir -p $srpms_dir
  150.  
  151. if ( ls $arch_isodir/*-SRPMS-*.iso > /dev/null 2>&1 ) ; then
  152. for disc in $arch_isodir/*-SRPMS-*.iso; do
  153. echo Expanding `basename $disc` ...
  154. mount -o loop $disc $MNTPNT
  155. if ( cd $MNTPNT/SRPMS && pax -rw ./* $srpms_dir ); then
  156. umount $MNTPNT
  157. echo Done
  158. else
  159. umount $MNTPNT
  160. exit 1
  161. fi
  162. done
  163. else
  164. echo "Unable to find $arch_isodir/*-SRPMS-*.iso"
  165. fi
  166. }
  167.  
  168. do_docs() {
  169. # Usage: do_docs
  170. mkdir -p $DOC_DIR
  171.  
  172. if ( ls ${DOC_ISO_DIR}/*-docs.iso ) ; then
  173. for disc in ${DOC_ISO_DIR}/*-docs.iso; do
  174. echo Expanding `basename $disc` ...
  175. mount -o loop $disc $MNTPNT
  176. if ( cd $MNTPNT && pax -rw ./* $DOC_DIR ); then
  177. umount $MNTPNT
  178. echo Done
  179. else
  180. umount $MNTPNT
  181. exit 1
  182. fi
  183. done
  184. else
  185. echo "Unable to find $arch_isodir/*-docs.iso"
  186. fi
  187. }
  188.  
  189. clean_trans_tbl() {
  190. # Usage: clean_trans_tbl dir
  191. dir=$1
  192. echo "Removing TRANS.TBL files from $1"
  193. find $dir -type f -name TRANS.TBL | xargs rm -f
  194. }
  195.  
  196. set_owner() {
  197. # Usage: set_owner dir
  198. dir=$1
  199. echo "Setting user/group ownership for $1"
  200. # Do this in 2 steps to be more portable between *NIX systems
  201. chown -R $OWNER $dir
  202. chgrp -R $OWNER_GRP $dir
  203. }
  204.  
  205. if [ "$DO_DOC" = "yes" ]; then
  206. docdir=$DOC_DIR
  207.  
  208. if [ -d $docdir ] ; then
  209. echo "Removing existing documentation in $docdir"
  210. rm -rf $docdir
  211. fi
  212.  
  213. do_docs
  214. clean_trans_tbl $docdir
  215. set_owner $docdir
  216. fi
  217.  
  218. for arch in $ARCH_LIST; do
  219. archdir=$OS_BASE_DIR/$arch
  220.  
  221. if [ -d $archdir ] ; then
  222. echo "Removing existing distribution in $archdir"
  223. rm -rf $archdir
  224. fi
  225.  
  226. do_one_arch $arch
  227. do_one_srpms $arch
  228. clean_trans_tbl $archdir
  229. set_owner $archdir
  230. done
  231.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement