i know about a tool called apt-on CD, that download all installed debs and create a local repo that can me burned on a cd/dvd. we miss something like that so i started to create it.
here my code right now
#!/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 | \
--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"
CONTINUE=1
;;
-h|--help)
echo "Usage: zypperonDVD [OPTION]"
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 " --DVD Create one or more DVD media (default) (not working yet)"
echo " --CD Create one or more CD media (700MB) (not working yet)"
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"
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"
INFO=CD
;;
*)
;;
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 "$INFO" == "" ]; then
INFO=DVD
fi
if "$CONTINUE" != "1" ]; then
# be sure everything is clean
echo "Clean up previous tmp dirs"
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
# refresh repos
zypper --root $tmproot ref
else
if "$CONTINUE" == "1" ]; then
# refresh repos
zypper --root $tmproot ref
fi
#else
#exit 1
fi
# tell the user the process can be very long
echo 'after you press ok, and solved manually any dependency
issues that zypper is not able to do, i think you should go to eat
something and have a break that process may be very very long'
# download all installed packages
rpm -qa --qf '%{NAME} ' | xargs zypper --root $tmproot in -lD
# 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
# Create a YUM repository using createrepo
createrepo $tmprepo
### fixme, following lines are not working, are just an idea to implement fetures ###
#if CD == true
#then check /tmp/myrepo size
# if size <= 700 MB
# exit0
# else
# split repo in more than one
# exit 0
# endif
#endif
#if DVD == true
#then check /tmp/myrepo size
# if size <= 4300 MB
# exit0
# else
# split repo in more than one
# exit 0
# endif
#endif
# clean up a little is always a good idea
rm -rf $tmproot
mv $tmprepo /root/repo
# Finally we finish
echo 'All done! your new local repo is into the /root/repo directory ready to be burn'
i need help to improve/fix it, for example i’m not able to understand and fix why when it finish that command:
rpm -qa --qf '%{NAME} ’ | xargs zypper --root $tmproot in -lD
the script exit, instead to continue with following part…
many many thanks