Last active
December 22, 2021 23:59
-
-
Save keithchambers/0e31d8347128fb161115 to your computer and use it in GitHub Desktop.
Download RPM packages and all dependencies from Yum repo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
BASEDIR="$PWD" | |
OUTDIR="$BASEDIR/repo" | |
INSTALLROOTDIR="$BASEDIR/installroot" | |
REPOSDIR="$INSTALLROOTDIR/etc/yum.repos.d" | |
CACHEDIR="$INSTALLROOTDIR/var/cache/yum" | |
CONFIGFILE="$INSTALLROOTDIR/yum.conf" | |
LOGFILE="$OUTDIR/yum.log" | |
REPOFILE="$REPOSDIR/config.repo" | |
if [[ "$@" ]]; then | |
PACKAGES="$@" | |
else | |
echo "Error: No packages to download." | |
echo "" | |
echo "Usage: "$0" <rpm-package-1 rpm-package-2>" | |
echo "" | |
exit 1 | |
fi | |
rm -rf "$OUTDIR" && mkdir -p "$OUTDIR" | |
rm -rf "$REPOSDIR" && mkdir -p "$REPOSDIR" | |
rm -rf "$CACHEDIR" && mkdir -p "$CACHEDIR" | |
cat > "$CONFIGFILE" << EOF | |
[main] | |
cachedir="$CACHEDIR" | |
keepcache=0 | |
debuglevel=2 | |
logfile="$LOGFILE" | |
gpgcheck=1 | |
plugins=0 | |
exclude=*.i386 *.i586 *.i686 | |
EOF | |
cat > "$REPOFILE" << EOF | |
[centos-7-os] | |
name=centos-7-os | |
baseurl=https://mirrors.kernel.org/centos/7/os/x86_64/ | |
[centos-7-updates] | |
name=centos-7-updates | |
baseurl=https://mirrors.kernel.org/centos/7/updates/x86_64/ | |
EOF | |
yumdownloader "$PACKAGES" \ | |
--resolve \ | |
--config="$CONFIGFILE" \ | |
--installroot="$INSTALLROOTDIR" \ | |
--destdir="$OUTDIR" | |
createrepo "$OUTDIR" | |
# EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment