forked from Unidata/UDUNITS-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo_add
executable file
·107 lines (95 loc) · 3.43 KB
/
repo_add
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
99
100
101
102
103
104
105
106
107
#! /bin/bash
# Adds a binary-distribution to a binary-repository.
#
# Usage: $0 repoRoot repoDir distro
#
# where:
# repoRoot Path to the root of the package-manager-specific repository. May
# be absolute or relative to the current working directory. Will
# be created if it doesn't exist. The repository-indexing utility
# will be executed here.
# repoDir Path to the platform-specific binary repository relative to
# the root of the package-manager-specific repository. Will be
# created if it doesn't exist.
# distro Path to the binary-distribution. May be absolute or relative to
# the current working directory. The filename portion must have
# the form
#
# <name>-<version>[-<release>].<cpu>.[deb,rpm]
#
# where:
# <name> Package name (e.g., "udunits")
# <version> Package version (e.g., "2.2.3")
# <release> Optional package release number (e.g., "4").
# Ignored.
# <cpu> Package CPU (e.g., "x86_64")
set -e # Exit on error
repoRoot=${1:?Root of package-manager-specific binary-repository not specified}
repoDir=${2:?Platform-specific binary-repository not specified}
distro=${3:?Binary-distribution not specified}
# Verify that the path to the platform-specific binary-repository is relative.
#
if echo $repoDir | grep -q '^/'; then
echo 1>&2 "Path of platform-specific binary repository not relative"
exit 1;
fi
# Set the filename extension used by the binary-distribution, which also
# identifies the type of binary-distribution.
#
if echo $distro | grep -q '\.deb$'; then
ext=deb
elif echo $distro | grep -q '\.rpm$'; then
ext=rpm
else
echo 1>&2 "Unrecognized filename extension: \"$distro\""
exit 1
fi
# Ensure that all input paths are absolute,
#
echo $repoRoot | grep -qv '^/' && repoRoot=`pwd`/$repoRoot
echo $repoDir | grep -qv '^/' && repoDir=$repoRoot/$repoDir
echo $distro | grep -qv '^/' && distro=`pwd`/$distro
# Vet and parse the filename of the input binary-distribution.
#
distroName=`basename "$distro"`
if ! echo $distroName | egrep -q '[^-]+-[0-9.]+(-[0-9]+)?\.[^.]+\.'$ext; then
echo 1>&2 "Invalid binary-distribution name: \"$distroName\""
exit 1
fi
set `echo "$distroName" |
sed -r 's/([^-]+-[0-9.]+)(-[0-9]+)?\.([^.]+)\.'$ext'/\1 \3/'`
pkgId=$1
pkgCpu=$2
# Ensure that the platform-specific binary-repository directory exists and go
# to it.
#
mkdir -p $repoDir
cd $repoDir
# Set the glob pattern for all releases of the same version of the same package
# in the platform-specific binary-repository directory:
#
releaseGlob=$pkgId-*.$pkgCpu.$ext
# Determine what the next release number should be.
#
if prevRelease=`ls $releaseGlob 2>/dev/null |
sed -r "s/$pkgId-([0-9]*)\.$pkgCpu\.$ext/\1/"`; then
pkgRelease=$(($prevRelease+1))
else
pkgRelease=1
fi
# Copy the input binary-distribution to the output binary-distribution.
#
outDistro=$pkgId-$pkgRelease.$pkgCpu.$ext
cp $distro $outDistro
# Delete all previous releases of the same version of the same package.
#
rm -f `ls $releaseGlob | fgrep -v $outDistro`
# Go to the root-directory of the package-manager-specific binary-repository and
# update the platform-specific binary-repository.
#
cd $repoRoot
case "$ext" in
(deb) flock $repoDir dpkg-scanpackages $repoDir /dev/null | \
gzip -9c >$repoDir/Packages.gz;;
(rpm) flock $repoDir createrepo $repoDir;;
esac