Advertisement
Guest User

Untitled

a guest
Jul 9th, 2009
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 KB | None | 0 0
  1. #!/bin/bash
  2. # Copyright (c) 2009 Andrea Florio <andrea@opensuse.org>. All rights reserved.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published
  6. # by the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software Foundation,
  16. # Inc., 675 Mass Ave, Cambridge MA 02139, USA.
  17.  
  18. CONTINUE=0
  19. INFO=""
  20. tmproot=/tmp/myroot
  21. tmprepo=/tmp/myrepo
  22. cachedir=/var/cache/zypp/packages/
  23.  
  24.  
  25. if [ $# -ge 2 ]; then
  26. option="--help"
  27. else
  28. if [ $# -eq 1 ]; then
  29. case $1 in
  30. --continue | \
  31. --DVD | \
  32. --only-iso | \
  33. --CD )
  34. option="$1"
  35. ;;
  36. *)
  37. option="--help"
  38. ;;
  39. esac
  40. fi
  41. fi
  42.  
  43. case "$option" in
  44. --continue)
  45. echo "I'm continuing previous backup"
  46. echo "/tmp/myroot will not be delete"
  47. echo "press ENTER key to continue"
  48. echo
  49. read -s -n 1
  50. CONTINUE=1
  51. ;;
  52. -h|--help)
  53. echo "Usage: zypperonDVD [OPTIONS]"
  54. echo
  55. echo "With zypperonDVD you can create YUM repository of all installed packages."
  56. echo "They will be downloaded in a chroot system. This chroot system will be"
  57. echo "setup automatically. To run that script you have to be root because"
  58. echo "zypper still create the lock file in the real system"
  59. echo
  60. echo " --help, -h display this help and exit"
  61. echo " --continue Continue a previous stopped backup"
  62. echo " --only-iso Create an iso file that include the"
  63. echo " the repo with ONLY already downloaded files"
  64. echo " no internet connection required, it will NOT download rpms"
  65. echo " --DVD Create one or more DVD media (default) (not working yet)"
  66. echo " --CD Create one or more CD media (700MB) (not working yet)"
  67. echo
  68. exit 0
  69. ;;
  70. --DVD)
  71. echo "I'm goin to create repos <= 4.3 GB"
  72. echo "If the main repo is bigger, then"
  73. echo "I'll split in several repos"
  74. echo "press ENTER key to continue"
  75. echo
  76. read -s -n 1
  77. INFO=DVD
  78. ;;
  79. --CD)
  80. echo "I'm goin to create repos <= 700 MB"
  81. echo "If the main repo is bigger, then"
  82. echo "I'll split in several repos"
  83. echo "press any ENTER to continue"
  84. echo
  85. read -s -n 1
  86. INFO=CD
  87. ;;
  88. --only-iso)
  89. ISO=1
  90. ;;
  91. *)
  92. ;;
  93. esac
  94.  
  95. # check if you run that script as root
  96. # (zypper still create a lock file in real system and need root)
  97. set -e
  98.  
  99. if [ $UID != 0 ]; then
  100. echo "You have to be root to use this script" >&2
  101. exit 1
  102. fi
  103.  
  104. if [ ! -x /usr/bin/createrepo ]; then
  105. echo "error: createrepo missing! Please install package createrepo first."
  106. exit 2
  107. fi
  108.  
  109. if [ ! -x /usr/bin/mkisofs ]; then
  110. echo "error: mkisofs missing! Please install package cdrkit-cdrtools-compat first."
  111. exit 2
  112. fi
  113.  
  114.  
  115. if [ "$INFO" != "CD" ]; then
  116. INFO=DVD
  117. fi
  118.  
  119. if [ "$ISO" != "1" ]; then
  120.  
  121. if [ "$CONTINUE" != "1" ]; then
  122. # be sure everything is clean
  123. echo
  124. echo "Clean up previous tmp dirs, if any"
  125. echo
  126. rm -rf $tmproot
  127. rm -rf $tmprepo
  128.  
  129. # create chroot folder
  130. mkdir $tmproot
  131.  
  132. # create repository structure
  133. mkdir -p $tmprepo/i{5,6}86
  134. mkdir -p $tmprepo/noarch
  135. mkdir -p $tmprepo/x86_64
  136.  
  137. # export repos
  138. zypper repos -e myrepos.repo
  139.  
  140. # import repos into chroot and delete temporary myrepos.repo file
  141. zypper --root $tmproot addrepo myrepos.repo
  142. rm myrepos.repo
  143.  
  144. # tell zypper o modify repos making them able to keep package in cache
  145. zypper --root $tmproot modifyrepo -kra
  146.  
  147. else
  148.  
  149. if [ "$CONTINUE" == "1" ]; then
  150.  
  151. # refresh repos
  152. zypper --root $tmproot ref
  153.  
  154. fi
  155. fi
  156.  
  157.  
  158. # tell the user the process can be very long
  159. echo
  160. echo "after you choose 'yes' , and you solved manually any dependency"
  161. echo "issues that zypper is not able to do, i think you should go to eat"
  162. echo "something and have a break that process may be very very long"
  163. echo "press ENTER key to continue, it may take some time, do not press it twice."
  164. echo
  165. echo
  166. read -s -n 1
  167.  
  168. # download all installed packages
  169.  
  170. #rpm -qa --qf '%{NAME} ' > /tmp/mylist
  171. #sed -i 's\gpg-pubkey\\' /tmp/mylist
  172.  
  173. zypper --root $tmproot in -lD `rpm -qa --qf "%{NAME} "`
  174.  
  175. #zypper --root $tmproot in -lD `cat /tmp/mylist`
  176. #rm /tmp/mylist
  177. fi
  178.  
  179. # Now copy rpms in the new repository
  180. for i in `find $tmproot/$cachedir -name "*.i586.rpm"` ; \
  181. do cp $i $tmprepo/i586/ ; done
  182.  
  183. for i in `find $tmproot/$cachedir -name "*.i686.rpm"` ; \
  184. do cp $i $tmprepo/i686/ ; done
  185.  
  186. for i in `find $tmproot/$cachedir -name "*.noarch.rpm"` ; \
  187. do cp $i $tmprepo/noarch/ ; done
  188.  
  189. for i in `find $tmproot/$cachedir -name "*.x86_64.rpm"` ; \
  190. do cp $i $tmprepo/x86_64/ ; done
  191.  
  192. # remove empty folders (if any)
  193. if [ $((`ls -a $tmprepo/i586 | wc -l` - 2)) -eq 0 ]; then
  194. rmdir $tmprepo/i586
  195. fi
  196.  
  197. if [ $((`ls -a $tmprepo/i686 | wc -l` - 2)) -eq 0 ]; then
  198. rmdir $tmprepo/i686
  199. fi
  200.  
  201. if [ $((`ls -a $tmprepo/noarch | wc -l` - 2)) -eq 0 ]; then
  202. rmdir $tmprepo/noarch
  203. fi
  204.  
  205. if [ $((`ls -a $tmprepo/x86_64 | wc -l` - 2)) -eq 0 ]; then
  206. rmdir $tmprepo/x86_64
  207. fi
  208.  
  209. # Create a YUM repository using createrepo
  210. createrepo $tmprepo
  211.  
  212. ### fixme, following lines are not working, are just an idea to implement fetures ###
  213. #if [ "$INFO" == "CD" ]; then
  214. # check /tmp/myrepo size
  215. # if size <= 700 MB
  216. # all ok going on
  217. # else
  218. # split repo in more than one
  219. # fi
  220. #fi
  221.  
  222. #if [ "$INFO" == "DVD" ]; then
  223. # check /tmp/myrepo size
  224. # if size <= 4300 MB
  225. # all ok going on
  226. # else
  227. # split repo in more than one
  228. # fi
  229. #fi
  230.  
  231. #create iso file
  232. mkisofs -J -r -V "OpenSUSE_repository" -o SUSE-repo.iso $tmprepo
  233. mv SUSE-repo.iso /root/
  234.  
  235. # clean up a little is always a good idea
  236. rm -rf $tmproot
  237. rm -rf $tmprepo
  238.  
  239. # Finally we finish
  240. echo
  241. echo "All done! your new local repo iso is into "
  242. echo "/root directory ready to be burn"
  243. echo
  244.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement