2014-12-05 21:09:30 +01:00
#!/bin/bash
2013-03-26 20:51:03 +01:00
#
# consolidate-repos.sh
#
2014-12-05 21:09:30 +01:00
# Create new repo directory under /var/www-org/repo.consolidated
# containing every deb and every rpm under /var/www-org/ with proper
# repo metadata for apt and yum
2013-03-26 20:51:03 +01:00
#
2014-12-05 21:09:30 +01:00
source_dir = /var/www-org/
2013-03-26 20:51:03 +01:00
2014-12-05 21:09:30 +01:00
repodir = /var/www-org/repo.consolidated
2013-03-26 20:51:03 +01:00
2014-12-05 21:09:30 +01:00
gpg_recip = '<richard@10gen.com>'
stable_branch = "2.6"
unstable_branch = "2.7"
2013-03-26 20:51:03 +01:00
echo " Using directory: $repodir "
2014-12-05 21:09:30 +01:00
# set up repo dirs if they don't exist
#
mkdir -p " $repodir /apt/ubuntu "
mkdir -p " $repodir /apt/debian "
mkdir -p " $repodir /yum/redhat "
# to support different $releasever values in yum repo configurations
#
if [ ! -e " $repodir /yum/redhat/6Server " ]
then
ln -s 6 " $repodir /yum/redhat/6Server "
fi
2015-02-26 23:35:23 +01:00
if [ ! -e " $repodir /yum/redhat/7Server " ]
then
ln -s 7 " $repodir /yum/redhat/7Server "
fi
2014-12-05 21:09:30 +01:00
if [ ! -e " $repodir /yum/redhat/5Server " ]
then
ln -s 5 " $repodir /yum/redhat/5Server "
fi
2013-03-26 20:51:03 +01:00
echo " Scanning and copying package files from $source_dir "
echo ". = skipping existing file, @ = copying file"
2014-12-05 21:09:30 +01:00
for package in $( find " $source_dir " -not \( -path " $repodir " -prune \) -and \( -name \* .rpm -o -name \* .deb -o -name Release \) )
2013-03-26 20:51:03 +01:00
do
2014-12-05 21:09:30 +01:00
new_package_location = " $repodir $( echo " $package " | sed 's/\/var\/www-org\/[^\/]*//;' ) "
2013-03-26 20:51:03 +01:00
# skip if the directory structure looks weird
#
2014-12-05 21:09:30 +01:00
if echo " $new_package_location " | grep -q /repo/
2013-03-26 20:51:03 +01:00
then
continue
2014-12-05 21:09:30 +01:00
fi
2013-03-26 20:51:03 +01:00
2014-12-05 21:09:30 +01:00
# skip if not community package
#
if ! echo " $new_package_location " | grep -q org
then
continue
fi
# skip if it's already there
2013-03-26 20:51:03 +01:00
#
2013-12-20 22:29:41 +01:00
if [ -e " $new_package_location " -a " $( basename " $package " ) " != "Release" ]
2013-03-26 20:51:03 +01:00
then
echo -n .
else
2013-12-20 22:29:41 +01:00
mkdir -p " $( dirname " $new_package_location " ) "
2013-03-26 20:51:03 +01:00
echo -n @
cp " $package " " $new_package_location "
fi
2013-12-20 22:29:41 +01:00
done
2013-03-26 20:51:03 +01:00
echo
# packages are in place, now create metadata
#
2014-12-05 21:09:30 +01:00
for debian_dir in " $repodir " /apt/ubuntu " $repodir " /apt/debian
2013-03-26 20:51:03 +01:00
do
2014-12-05 21:09:30 +01:00
cd " $debian_dir "
for section_dir in $( find dists -type d -name multiverse -o -name main)
do
for arch_dir in " $section_dir " /{ binary-i386,binary-amd64}
do
echo " Generating Packages file under $debian_dir / $arch_dir "
if [ ! -d $arch_dir ]
then
mkdir $arch_dir
fi
dpkg-scanpackages --multiversion " $arch_dir " > " $arch_dir " /Packages
gzip -9c " $arch_dir " /Packages > " $arch_dir " /Packages.gz
done
done
for release_file in $( find " $debian_dir " -name Release)
2013-03-26 20:51:03 +01:00
do
2014-12-05 21:09:30 +01:00
release_dir = $( dirname " $release_file " )
echo " Generating Release file under $release_dir "
cd $release_dir
tempfile = $( mktemp /tmp/ReleaseXXXXXX)
tempfile2 = $( mktemp /tmp/ReleaseXXXXXX)
mv Release $tempfile
head -7 $tempfile > $tempfile2
apt-ftparchive release . >> $tempfile2
cp $tempfile2 Release
chmod 644 Release
rm Release.gpg
echo "Signing Release file"
gpg -r " $gpg_recip " --no-secmem-warning -abs --output Release.gpg Release
2013-03-26 20:51:03 +01:00
done
2014-12-05 21:09:30 +01:00
done
2013-03-26 20:51:03 +01:00
2014-12-05 21:09:30 +01:00
# Create symlinks for stable and unstable branches
#
# Examples:
#
# /var/www-org/repo.consolidated/yum/redhat/5/mongodb-org/unstable -> 2.5
# /var/www-org/repo.consolidated/yum/redhat/6/mongodb-org/unstable -> 2.5
# /var/www-org/repo.consolidated/apt/ubuntu/dists/precise/mongodb-org/unstable -> 2.5
# /var/www-org/repo.consolidated/apt/debian/dists/wheezy/mongodb-org/unstable -> 2.5
#
2015-01-09 20:40:31 +01:00
for unstable_branch_dir in " $repodir " /yum/redhat/*/*/$unstable_branch " $repodir " /yum/amazon/*/*/$unstable_branch " $repodir " /apt/debian/dists/*/*/$unstable_branch " $repodir " /apt/ubuntu/dists/*/*/$unstable_branch " $repodir " /zypper/suse/*/*/$unstable_branch
2014-12-05 21:09:30 +01:00
do
full_unstable_path = $( dirname " $unstable_branch_dir " ) /unstable
if [ -e " $unstable_branch_dir " -a ! -e " $full_unstable_path " ]
then
echo " Linking unstable branch directory $unstable_branch_dir to $full_unstable_path "
ln -s $unstable_branch $full_unstable_path
fi
done
2015-01-09 20:40:31 +01:00
for stable_branch_dir in " $repodir " /yum/redhat/*/*/$stable_branch " $repodir " /yum/amazon/*/*/$stable_branch " $repodir " /apt/debian/dists/*/*/$stable_branch " $repodir " /apt/ubuntu/dists/*/*/$stable_branch " $repodir " /zypper/suse/*/*/$stable_branch
2014-12-05 21:09:30 +01:00
do
full_stable_path = $( dirname " $stable_branch_dir " ) /stable
if [ -e " $stable_branch_dir " -a ! -e " $full_stable_path " ]
then
echo " Linking stable branch directory $stable_branch_dir to $full_stable_path "
ln -s $stable_branch $full_stable_path
fi
2013-03-26 20:51:03 +01:00
done
2015-01-09 20:40:31 +01:00
for rpm_dir in $( find " $repodir " /yum/redhat " $repodir " /yum/amazon " $repodir " /zypper/suse -type d -name x86_64 -o -name i386)
2013-03-26 20:51:03 +01:00
do
2014-12-05 21:09:30 +01:00
echo " Generating redhat repo metadata under $rpm_dir "
2014-08-20 23:17:06 +02:00
cd " $rpm_dir "
2013-03-26 20:51:03 +01:00
createrepo .
done