-
Notifications
You must be signed in to change notification settings - Fork 0
/
cp-pkgver
executable file
·61 lines (56 loc) · 1.32 KB
/
cp-pkgver
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
#!/bin/bash
# initialize gettext
export TEXTDOMAIN='bash'
# parse arguments
assign_if_exists() {
if [ -f "$2" ]
then
eval "$1='$2'"
else
printf "$0: $(gettext "%s: file not found")\n" "$2"
exit 1
fi
}
while [ $OPTIND -le $# ]
do
if getopts 'h' argument
then
case $argument in
h)
echo "usage: $0 [-h] <source> <destination>"
echo 'Copies the value of the pkgver and pkgrel variables from one PKGBUILD to another.'
echo ' -h only shows this help text'
exit ;;
\?) exit 1 ;;
esac
else
if [ -z ${src++} ]
then
assign_if_exists src "${!OPTIND}"
elif [ -z ${dst++} ]
then
assign_if_exists dst "${!OPTIND}"
else
echo "$0: $(gettext "too many arguments")"
exit 1
fi
let OPTIND++
fi
done
# gather numbers
srcver=$(grep -Po '(?<=^pkgver=)[^ ]*' "$1")
srcrel=$(grep -Po '(?<=^pkgrel=)[^ ]*' "$1")
dstver=$(grep -Po '(?<=^pkgver=)[^ ]*' "$2")
dstrel=$(grep -Po '(?<=^pkgrel=)[^ ]*' "$2")
# copy if necessary
if [ $srcver != $dstver -o $srcrel != $dstrel ]
then
if [ -w "$2" ]
then
sed --follow-symlinks -i "s:^pkgver=[^ ]*:pkgver=$srcver:;s:^pkgrel=[^ ]*:pkgrel=$srcrel:" "$2"
else
printf "$0: $(gettext -d 'pacman-scripts' \
"%s is not writeable -- pkgver will not be updated")\n" "$2"
exit 2
fi
fi