Skip to content

Instantly share code, notes, and snippets.

@untergrundbiber
Forked from kleinig/debmirror.sh
Last active February 21, 2016 09:41
Show Gist options
  • Save untergrundbiber/526b11f3c144f3276f46 to your computer and use it in GitHub Desktop.
Save untergrundbiber/526b11f3c144f3276f46 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH
set -e
basedir="$(dirname "$(readlink -f "$0")")"
cd "$basedir"
starttime=$(date +%s)
BANDWIDTH=400
dateformat="+%d.%m.%Y - %H:%M:%S"
MIRRORDIR=/srv/mirror/ubuntu
DEBMLOG=/srv/mirror/log/mirror.log
#Ubuntu-Codename
#old_stable=vivid
stable=wily
devel=xenial
arch=i386,amd64
section=main,multiverse,universe,restricted,main/debian-installer,multiverse/debian-installer,universe/debian-installer,restricted/debian-installer
release=$stable,$stable-security,$stable-updates,$stable-backports,$stable-proposed,$devel,$devel-security,$devel-updates,$devel-backports,$devel-proposed
#release=$old_stable,$old_stable-security,$old_stable-updates,$old_stable-backports,$old_stable-proposed,$stable,$stable-security,$stable-updates,$stable-backports,$stable-proposed,$devel,$devel-security,$devel-updates,$devel-backports,$devel-proposed
#server=deb-mirror.de
server=ubuntu.unitedcolo.de
inPath=/ubuntu
proto=rsync
if test -s $DEBMLOG; then
test -f $DEBMLOG.5 && mv $DEBMLOG.5 $DEBMLOG.6
test -f $DEBMLOG.4 && mv $DEBMLOG.4 $DEBMLOG.5
test -f $DEBMLOG.3 && mv $DEBMLOG.3 $DEBMLOG.4
test -f $DEBMLOG.2 && mv $DEBMLOG.2 $DEBMLOG.3
test -f $DEBMLOG.1 && mv $DEBMLOG.1 $DEBMLOG.2
test -f $DEBMLOG.0 && mv $DEBMLOG.0 $DEBMLOG.1
mv $DEBMLOG $DEBMLOG.0
cp /dev/null $DEBMLOG
chmod 644 $DEBMLOG
fi
date "$dateformat" | tee -a $DEBMLOG
printf "*** Update-Script started ***\n" | tee -a $DEBMLOG
printf "\n*** Calulating mirror size before update ***\n" | tee -a $DEBMLOG
sizebefore=$(du -s $MIRRORDIR | cut -f 1)
printf "\nUdpate GPG-Keys \n" | tee -a $DEBMLOG
wget --show-progress -q "http://$server$inPath/project/ubuntu-archive-keyring.gpg" -O /srv/mirror/ubuntu/project/ubuntu-archive-keyring.gpg 2>&1 | tee -a $DEBMLOG
printf "\n" | tee -a $DEBMLOG
gpg --no-default-keyring --keyring trustedkeys.gpg --import /srv/mirror/ubuntu/project/ubuntu-archive-keyring.gpg 2>&1 | tee -a $DEBMLOG
printf "\n*** Update Ubuntu-Mirror ***\n" | tee -a $DEBMLOG
printf "\nBandwith-Limit: %s KB/s \n" "$BANDWIDTH" | tee -a $DEBMLOG
mirrorupdate() {
debmirror \
-a $arch \
-d $release \
-e $proto \
-h $server \
-r $inPath \
-s $section \
--diff=use \
--getcontents \
--i18n \
--ignore-missing-release \
--ignore-small-errors \
--md5sums \
--no-source \
--progress \
--retry-rsync-packages=10 \
--rsync-options "-aIL --partial --bwlimit=$BANDWIDTH -q" \
--verbose \
$MIRRORDIR \
2>&1 | tee -a $DEBMLOG
}
printf "\nFirst run\n" | tee -a $DEBMLOG
date "$dateformat" | tee -a $DEBMLOG
mirrorupdate
sleep 60
printf "\nSecond run\n" | tee -a $DEBMLOG
date "$dateformat" | tee -a $DEBMLOG
mirrorupdate
printf "\n\n" | tee -a $DEBMLOG
date "$dateformat" | tee -a $DEBMLOG
printf "*** Update finished ***\n" | tee -a $DEBMLOG
# Calulate mirror grow/size
printf "\n*** Mirror size ***\n" | tee -a $DEBMLOG
sizeafter=$(du -s $MIRRORDIR | cut -f 1)
sizeold=$(((sizebefore/1024)/1024))
sizenew=$(((sizeafter/1024)/1024))
sizegrow=$(((sizeafter - sizebefore)/1024))
printf "Mirror size before update: %s GB\n" "$sizeold" | tee -a $DEBMLOG
printf "Mirror size after update: %s GB\n" "$sizenew" | tee -a $DEBMLOG
printf "Mirror size growing: %s MB\n" "$sizegrow" | tee -a $DEBMLOG
# Make devel-symlinks
ln -sf $MIRRORDIR/dists/$devel $MIRRORDIR/dists/devel
ln -sf $MIRRORDIR/dists/$devel-security $MIRRORDIR/dists/devel-security
ln -sf $MIRRORDIR/dists/$devel-updates $MIRRORDIR/dists/devel-updates
ln -sf $MIRRORDIR/dists/$devel-backports $MIRRORDIR/dists/devel-backports
ln -sf $MIRRORDIR/dists/$devel-proposed $MIRRORDIR/dists/devel-proposed
#printf "\n*** Fixing ownership ***\n" | tee -a $DEBMLOG
#find $MIRRORDIR -type d -o -type f -exec chown mirror:mirror '{}' \; 2>&1 | tee -a $DEBMLOG
#
#printf "\n*** Fixing permissions ***\n" | tee -a $DEBMLOG
#find $MIRRORDIR -type d -o -type f -exec chmod u+rw,g+r,o+r-w {} \; 2>&1 | tee -a $DEBMLOG
printf "\n\n" | tee -a $DEBMLOG
date "$dateformat" | tee -a $DEBMLOG
printf "*** Update-Script finished ***\n" | tee -a $DEBMLOG
endtime=$(date +%s)
echo 'Time for update:' $((((endtime-starttime)/(60)) / 60)) hours, $((((endtime-starttime)/(60)) % 60)) minutes, $(((endtime-starttime) % 60)) seconds | tee -a $DEBMLOG
printf "\n\n" | tee -a $DEBMLOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment