-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrsync_repo.sh
executable file
·98 lines (87 loc) · 2.16 KB
/
rsync_repo.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
# Sychronisation von zwei Paketquellen auf dem lokalen Spiegelserver
# Description:
# This script could be used to synchronize two package repositories
# on the local mirror server.
#
# License: MIT copyright (c) 2016 Joerg Kastning <joerg.kastning(aet)uni-bielefeld(dot)de>
# Variables ########################################################
SCRIPTNAME=`basename ${0}`
PROGDIR=$(dirname $(readlink -f ${0}))
. $PROGDIR/CONFIG
PACKAGELIST_PATH=""
# Functions #######################################################
usage()
{
cat << EOF
usage: $0 OPTIONS
This script could be used to synchronize to package repositories
on the local mirror server.
OPTIONS:
-f Specifies a file containing a list of packages to be synchronized
-h Shows this text
-Q Specifies the source directory
-Z Specifies the target directory
EOF
}
check()
{
if [ $1 -gt 0 ]; then
echo "Uuups, here went something wrong."
echo "exit $1"
exit 1
fi
}
do_sync_repo()
{
rsync -avx --link-dest=$BASEDIR$SOURCEDIR $BASEDIR$SOURCEDIR/ $BASEDIR$TARGETDIR
cd $BASEDIR$TARGETDIR
}
do_sync_pkg()
{
while read line
do
cp -al $line $BASEDIR$TARGETDIR/Packages
done < $PACKAGELIST_PATH
cd $BASEDIR$TARGETDIR/Packages
createrepo -v --database $BASEDIR$TARGETDIR/Packages
}
# Main #######################################################
while getopts .h:Q:Z:f:. OPTION
do
case $OPTION in
h)
usage
exit;;
Q)
SOURCEDIR="${OPTARG}"
;;
f)
PACKAGELIST_PATH="${OPTARG}"
;;
Z)
TARGETDIR="${OPTARG}"
;;
?)
usage
exit;;
esac
done
if [[ -z $SOURCEDIR && -z $PACKAGELIST_PATH ]]; then
read -p "Please enter the source directory: " SOURCEDIR
fi
if [[ -z $TARGETDIR ]]; then
read -p "Please enter the target directory: " TARGETDIR
fi
if [[ ! -z $PACKAGELIST_PATH ]]; then
echo \# `date +%Y-%m-%dT%H:%M` - START RSYNC \# > $LOG
do_sync_pkg >> $LOG
check $? >> $LOG
echo \# `date +%Y-%m-%dT%H:%M` - END RSYNC \# >> $LOG
else
echo \# `date +%Y-%m-%dT%H:%M` - START RSYNC \# > $LOG
do_sync_repo >> $LOG
check $? >> $LOG
echo \# `date +%Y-%m-%dT%H:%M` - END RSYNC \# >> $LOG
fi
exit 0