forked from handflucht/yumdownloadonly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
offlinecopy.sh
50 lines (38 loc) · 1.36 KB
/
offlinecopy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# Idea based on https://unix.stackexchange.com/a/489461
if [ -z "$1" ]
then
echo "Provide package to download, abort."
exit
fi
PKG=$1
releasever=7
BASE_PATH=/tmp/offline
INSTALL_PATH=$BASE_PATH/install
DWL_PATH=$BASE_PATH/download
OFFLINE_REPO_PATH=/var/offlinerepo
# Use separte installdir to load all dependencies, see https://unix.stackexchange.com/a/174485
yum_output=$(yum install -q --downloadonly --installroot=$INSTALL_PATH/$PKG --releasever=$releasever --downloaddir=$DWL_PATH/$PKG $PKG 2>&1)
# Check if an error happened while downloading; if, exit script.
if [ $? -ne 0 ]
then
echo "An error occured could not download package, aborting."
echo "Package: $PKG, Releasever: $releasever, Message: $yum_output"
exit
fi
# Delete unnecessary data and create repo of downloaded packages
rm -rf $INSTALL_PATH
createrepo -q --database $DWL_PATH/$PKG
# Create the repo-file
echo "[offline-$PKG]
name=CentOS-$releasever - $PKG
baseurl=file://$OFFLINE_REPO_PATH/$PKG
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-$releasever" > $DWL_PATH/offline-$PKG.repo
# Output script end
echo "Downloaded `ls -1 $DWL_PATH/$PKG | wc -l` files"
echo ""
echo "On offline-device: "
echo " move yum-config to: \"/etc/yum.repos.d/offline-$PKG.repo\""
echo " to install use: \"yum --disablerepo=\* --enablerepo=offline-$PKG install --nogpgcheck $PKG\""