1 |
Bo Ørsted Andresen wrote: |
2 |
> On Friday 22 December 2006 20:09, Benno Schulenberg wrote: |
3 |
> > Bo once said (or was it someone else?) he |
4 |
> > had such a script. If so, Bo, please post the script. |
5 |
> |
6 |
> You may be referring to this post: |
7 |
> |
8 |
> http://thread.gmane.org/gmane.linux.gentoo.user/164432/focus=164437 |
9 |
|
10 |
Ah, yes. Thanks. |
11 |
|
12 |
Meanwhile my own script evolved a little further: |
13 |
|
14 |
-----8<------------------------------------------ |
15 |
#!/bin/bash |
16 |
|
17 |
# ovlay.sh version 0.2 |
18 |
|
19 |
OVERLAY=/usr/local/portage |
20 |
unset BUMP DELETE EDIT HELP NEWVERSION RENUMBER REST |
21 |
|
22 |
if [[ -z $EDITOR ]]; then |
23 |
EDITOR="vim" |
24 |
fi |
25 |
|
26 |
for ARGUMENT in $*; do |
27 |
if [[ "$BUMP" == "take" ]]; then |
28 |
NEWVERSION="$ARGUMENT" |
29 |
BUMP="yes" |
30 |
continue |
31 |
fi |
32 |
case "$ARGUMENT" in |
33 |
"-b"|"--bump") BUMP="take";; |
34 |
"-d"|"--delete") DELETE="yes";; |
35 |
"-e"|"--edit") EDIT="yes";; |
36 |
"-h"|"--help") HELP="yes";; |
37 |
"-r"|"--renumber") RENUMBER="yes";; |
38 |
*) REST="$REST $ARGUMENT";; |
39 |
esac |
40 |
done |
41 |
|
42 |
# Redefine positional arguments: |
43 |
set -- $REST |
44 |
|
45 |
if [[ $HELP || -z "$1" ]]; then |
46 |
PROGRAM=${0##/[a-z]*/} |
47 |
echo "Usage: $PROGRAM [-e|--edit] package_name [patch_name...]" |
48 |
echo " $PROGRAM -d|--delete package_name..." |
49 |
echo " $PROGRAM -b|--bump new_version_number [-r|--renumber] package_name" |
50 |
echo "" |
51 |
echo "Copies the latest ebuild of the specified package to the local overlay," |
52 |
echo "and optionally allows you to bump it, insert patches, and edit it." |
53 |
exit 0 |
54 |
elif [[ "$BUMP" == "take" ]]; then |
55 |
echo "Specify a new version number." |
56 |
exit 2 |
57 |
elif [[ $RENUMBER && -z $BUMP ]]; then |
58 |
echo "Renumbering is only possible with version bumping." |
59 |
exit 2 |
60 |
fi |
61 |
|
62 |
if [[ $DELETE ]]; then |
63 |
if [[ $BUMP || $EDIT || $RENUMBER ]]; then |
64 |
echo "Deletion does not go together with other options." |
65 |
exit 2 |
66 |
fi |
67 |
while [[ "$1" ]]; do |
68 |
if ls -d /${OVERLAY}/*/$1 &>/dev/null; then |
69 |
rm -r /${OVERLAY}/*/$1 |
70 |
else |
71 |
echo "There is no overlay for '$1'." |
72 |
exit 2 |
73 |
fi |
74 |
shift |
75 |
done |
76 |
# Remove empty dirs (there must be a better way): |
77 |
ls -dl /${OVERLAY}/* | grep "x 2 root" | sed 's/.* //' | |
78 |
while read dir; do rmdir $dir; done |
79 |
exit 0 |
80 |
fi |
81 |
|
82 |
##shopt -s -o xtrace |
83 |
|
84 |
EMERGEOUT="$(emerge -qOp $1 2>/dev/null)" |
85 |
if [[ $? != 0 ]]; then |
86 |
EMERGEOUT="$(emerge -qOp =$1 2>/dev/null)" |
87 |
if [[ $? != 0 ]]; then |
88 |
echo "Package '$1' not found." |
89 |
exit 2 |
90 |
fi |
91 |
fi |
92 |
|
93 |
NAMENUMBER=$(echo $EMERGEOUT | sed -e 's:^[^/]*\]::' -e 's:\[.*$::' -e 's: ::g') |
94 |
CATPACK=${NAMENUMBER%%-[0-9]*} |
95 |
PACKAGE=${NAMENUMBER##[a-z]*/} |
96 |
FULLPATH=${OVERLAY}/${CATPACK} |
97 |
NAME=${PACKAGE%%-[0-9]*} |
98 |
VERSION=${PACKAGE##[a-z]*-} |
99 |
|
100 |
if [[ $NAME != $1 && $PACKAGE != $1 ]]; then |
101 |
echo "*Internal error*: determination of package name is wrong." |
102 |
exit 4 |
103 |
fi |
104 |
|
105 |
# When wanting to edit an already existing ebuild and not giving any further |
106 |
# arguments, do not first recreate the ebuild, but just allow editting it: |
107 |
if [[ $EDIT && -f /$FULLPATH/${PACKAGE}.ebuild && -z "$2" ]]; then |
108 |
vim /$FULLPATH/${PACKAGE}.ebuild |
109 |
ebuild ${FULLPATH}/${PACKAGE}.ebuild digest >/dev/null |
110 |
emerge -pqv =${PACKAGE} |
111 |
exit 0 |
112 |
fi |
113 |
|
114 |
mkdir -p /${FULLPATH} |
115 |
cp /usr/portage/${CATPACK}/${PACKAGE}.ebuild /${FULLPATH}/ |
116 |
cp -a /usr/portage/${CATPACK}/files /${FULLPATH}/ |
117 |
|
118 |
if [[ $BUMP ]]; then |
119 |
mv /${FULLPATH}/${PACKAGE}.ebuild /${FULLPATH}/${NAME}-${NEWVERSION}.ebuild |
120 |
if [[ $RENUMBER ]]; then |
121 |
# Renumber versioned patches: |
122 |
rename "${VERSION}" "${NEWVERSION}" /${FULLPATH}/files/*${VERSION}* |
123 |
fi |
124 |
PACKAGE=${NAME}-${NEWVERSION} |
125 |
fi |
126 |
|
127 |
# Insert any trailing arguments as patches: |
128 |
if [[ "$2" ]]; then |
129 |
echo -e '\n\npost_src_unpack() { cd ${S}' >>/${FULLPATH}/${PACKAGE}.ebuild |
130 |
while [[ "$2" ]]; do |
131 |
if [[ ! -f $2 ]]; then |
132 |
echo "Patch file '$2' not found." |
133 |
exit 2 |
134 |
fi |
135 |
cp $2 /${FULLPATH}/files/ |
136 |
echo -e '\tepatch ${FILESDIR}/'$2 >>/${FULLPATH}/${PACKAGE}.ebuild |
137 |
shift |
138 |
done |
139 |
echo -e "}\n" >>/${FULLPATH}/${PACKAGE}.ebuild |
140 |
fi |
141 |
|
142 |
if [[ $EDIT ]]; then |
143 |
vim /$FULLPATH/${PACKAGE}.ebuild |
144 |
fi |
145 |
|
146 |
rm /$FULLPATH/files/digest-* |
147 |
|
148 |
# Strangely this does not allow a double leading slash: |
149 |
ebuild ${FULLPATH}/${PACKAGE}.ebuild digest >/dev/null |
150 |
|
151 |
emerge -pqv =${PACKAGE} |
152 |
-----8<------------------------------------------ |
153 |
|
154 |
Benno |
155 |
|
156 |
|
157 |
-- |
158 |
Cetere mi opinias ke ne ĉio tradukenda estas. |
159 |
-- |
160 |
gentoo-user@g.o mailing list |