Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Copyright (c) 2009 Andrea Florio <andrea@opensuse.org>. All rights reserved.
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published
- # by the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful, but
- # WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- # General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software Foundation,
- # Inc., 675 Mass Ave, Cambridge MA 02139, USA.
- CONTINUE=0
- INFO=""
- tmproot=/tmp/myroot
- tmprepo=/tmp/myrepo
- cachedir=/var/cache/zypp/packages/
- if [ $# -ge 2 ]; then
- option="--help"
- else
- if [ $# -eq 1 ]; then
- case $1 in
- --continue | \
- --DVD | \
- --only-iso | \
- --CD )
- option="$1"
- ;;
- *)
- option="--help"
- ;;
- esac
- fi
- fi
- case "$option" in
- --continue)
- echo "I'm continuing previous backup"
- echo "/tmp/myroot will not be delete"
- echo "press ENTER key to continue"
- echo
- read -s -n 1
- CONTINUE=1
- ;;
- -h|--help)
- echo "Usage: zypperonDVD [OPTIONS]"
- echo
- echo "With zypperonDVD you can create YUM repository of all installed packages."
- echo "They will be downloaded in a chroot system. This chroot system will be"
- echo "setup automatically. To run that script you have to be root because"
- echo "zypper still create the lock file in the real system"
- echo
- echo " --help, -h display this help and exit"
- echo " --continue Continue a previous stopped backup"
- echo " --only-iso Create an iso file that include the"
- echo " the repo with ONLY already downloaded files"
- echo " no internet connection required, it will NOT download rpms"
- echo " --DVD Create one or more DVD media (default) (not working yet)"
- echo " --CD Create one or more CD media (700MB) (not working yet)"
- echo
- exit 0
- ;;
- --DVD)
- echo "I'm goin to create repos <= 4.3 GB"
- echo "If the main repo is bigger, then"
- echo "I'll split in several repos"
- echo "press ENTER key to continue"
- echo
- read -s -n 1
- INFO=DVD
- ;;
- --CD)
- echo "I'm goin to create repos <= 700 MB"
- echo "If the main repo is bigger, then"
- echo "I'll split in several repos"
- echo "press any ENTER to continue"
- echo
- read -s -n 1
- INFO=CD
- ;;
- --only-iso)
- ISO=1
- ;;
- *)
- ;;
- esac
- # check if you run that script as root
- # (zypper still create a lock file in real system and need root)
- set -e
- if [ $UID != 0 ]; then
- echo "You have to be root to use this script" >&2
- exit 1
- fi
- if [ ! -x /usr/bin/createrepo ]; then
- echo "error: createrepo missing! Please install package createrepo first."
- exit 2
- fi
- if [ ! -x /usr/bin/mkisofs ]; then
- echo "error: mkisofs missing! Please install package cdrkit-cdrtools-compat first."
- exit 2
- fi
- if [ "$INFO" != "CD" ]; then
- INFO=DVD
- fi
- if [ "$ISO" != "1" ]; then
- if [ "$CONTINUE" != "1" ]; then
- # be sure everything is clean
- echo
- echo "Clean up previous tmp dirs, if any"
- echo
- rm -rf $tmproot
- rm -rf $tmprepo
- # create chroot folder
- mkdir $tmproot
- # create repository structure
- mkdir -p $tmprepo/i{5,6}86
- mkdir -p $tmprepo/noarch
- mkdir -p $tmprepo/x86_64
- # export repos
- zypper repos -e myrepos.repo
- # import repos into chroot and delete temporary myrepos.repo file
- zypper --root $tmproot addrepo myrepos.repo
- rm myrepos.repo
- # tell zypper o modify repos making them able to keep package in cache
- zypper --root $tmproot modifyrepo -kra
- else
- if [ "$CONTINUE" == "1" ]; then
- # refresh repos
- zypper --root $tmproot ref
- fi
- fi
- # tell the user the process can be very long
- echo
- echo "after you choose 'yes' , and you solved manually any dependency"
- echo "issues that zypper is not able to do, i think you should go to eat"
- echo "something and have a break that process may be very very long"
- echo "press ENTER key to continue, it may take some time, do not press it twice."
- echo
- echo
- read -s -n 1
- # download all installed packages
- #rpm -qa --qf '%{NAME} ' > /tmp/mylist
- #sed -i 's\gpg-pubkey\\' /tmp/mylist
- zypper --root $tmproot in -lD `rpm -qa --qf "%{NAME} "`
- #zypper --root $tmproot in -lD `cat /tmp/mylist`
- #rm /tmp/mylist
- fi
- # Now copy rpms in the new repository
- for i in `find $tmproot/$cachedir -name "*.i586.rpm"` ; \
- do cp $i $tmprepo/i586/ ; done
- for i in `find $tmproot/$cachedir -name "*.i686.rpm"` ; \
- do cp $i $tmprepo/i686/ ; done
- for i in `find $tmproot/$cachedir -name "*.noarch.rpm"` ; \
- do cp $i $tmprepo/noarch/ ; done
- for i in `find $tmproot/$cachedir -name "*.x86_64.rpm"` ; \
- do cp $i $tmprepo/x86_64/ ; done
- # remove empty folders (if any)
- if [ $((`ls -a $tmprepo/i586 | wc -l` - 2)) -eq 0 ]; then
- rmdir $tmprepo/i586
- fi
- if [ $((`ls -a $tmprepo/i686 | wc -l` - 2)) -eq 0 ]; then
- rmdir $tmprepo/i686
- fi
- if [ $((`ls -a $tmprepo/noarch | wc -l` - 2)) -eq 0 ]; then
- rmdir $tmprepo/noarch
- fi
- if [ $((`ls -a $tmprepo/x86_64 | wc -l` - 2)) -eq 0 ]; then
- rmdir $tmprepo/x86_64
- fi
- # Create a YUM repository using createrepo
- createrepo $tmprepo
- ### fixme, following lines are not working, are just an idea to implement fetures ###
- #if [ "$INFO" == "CD" ]; then
- # check /tmp/myrepo size
- # if size <= 700 MB
- # all ok going on
- # else
- # split repo in more than one
- # fi
- #fi
- #if [ "$INFO" == "DVD" ]; then
- # check /tmp/myrepo size
- # if size <= 4300 MB
- # all ok going on
- # else
- # split repo in more than one
- # fi
- #fi
- #create iso file
- mkisofs -J -r -V "OpenSUSE_repository" -o SUSE-repo.iso $tmprepo
- mv SUSE-repo.iso /root/
- # clean up a little is always a good idea
- rm -rf $tmproot
- rm -rf $tmprepo
- # Finally we finish
- echo
- echo "All done! your new local repo iso is into "
- echo "/root directory ready to be burn"
- echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement