-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeninteg
115 lines (95 loc) · 1.76 KB
/
geninteg
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
108
109
110
111
112
113
114
115
#!/bin/sh
NAME=$(basename ${0:-geninteg})
_echo2(){
>&2 echo $@
}
_options(){
# out
args=()
makepkgconfig=""
inplace=0
usage=0
# flags
i=0
confarg=0
for arg in $@;
do
case ${arg} in
--config=*)
makepkgconfig="${arg#--config=}"
;;
--config)
confarg=1
;;
--inplace)
inplace=1
;;
-h|--help)
usage=1
;;
*)
if test ${confarg} -eq 1;
then
confarg=0
makepkgconfig="$(realpath ${arg})"
else
args[$i]="${arg}"
i=$(( $i + 1 ))
fi
;;
esac
done
export args
export usage
export inplace
export makepkgconfig
}
_usage(){
>&2 cat <<EOF
Usage: ${NAME} [options] <PKGBUILD>
An help script to generate source=()'s checkums from a PKGBUILD
template. The script will jump to the same directory of <PKGBUILD>.
Options:"
--config <makepkg.conf> # pass this configuration to makepkg;
--inplace # update <PKGBUILD> inplace;
--help|-h # print this message.
EOF
exit 2
}
main(){
_options $@
if test ${usage} -eq 1 -o ${#args[@]} != 1;
then
_usage
fi
pkgbuild="$(realpath ${args[0]})"
workingdir="$(dirname ${pkgbuild})"
_echo2 "# makepkg.conf(${makepkgconfig:-default}); workding-dir(${workingdir:-.})"
if test -n "${makepkgconfig}";
then
makepkgconfig="--config ${makepkgconfig}"
fi
if test -n "${workingdir}";
then
>&2 cd -- "${workingdir}" || exit 1
fi
if test ${inplace} -eq 1;
then
inplace="-i~"
else
inplace=""
fi
if ! $(grep -q -s -e "^#sums=$" -- ${pkgbuild});
then
_echo2 "Not a PKGBUILD template: ${pkgbuild}"
exit 1
fi
sums=$(makepkg ${makepkgconfig} -p "${pkgbuild}" -g)
if test -z "${sums}";
then
_echo2 "No checksums to compute"
exit 1
fi
sed ${inplace} "s:#sums=:${sums}:" "${pkgbuild}"
}
main $@