-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_archpkg
executable file
·178 lines (172 loc) · 4.39 KB
/
create_archpkg
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/sh
# $Log: $
#
# $Id: $
#
curdir=`pwd`
version=$(cat conf-version)
name=$(basename $curdir|sed -e 's{-x{{g')
if [ ! -f /etc/arch-release ] ; then
echo "you can't make arch package on a non Arch Linux system" 1>&2
exit 1
fi
verbose=0
release=1
clean=0
while test $# -gt 0; do
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'`
;;
*) optarg=
;;
esac
case "$1" in
--verbose)
verbose=1
;;
--release=*)
release=$optarg
;;
--clean)
clean=1
;;
*)
echo "invalid option [$1]"
read key
usage 1
;;
esac
shift
done
copy_src=0
meta_pkg=0
echo -n "Copy Source Files - "
read key
if [ " $key" = " y" -o " $key" = " Y" ] ; then
copy_src=1
fi
pkg_dir=$HOME/stage/arch/$name
mkdir -p $pkg_dir
if [ $copy_src -eq 1 ] ; then
if [ -f $name.packages ] ; then
meta_pkg=1
for dir in `cat $name.packages`
do
real_dir=$(basename $dir)
echo $dir|grep "/" >/dev/null
if [ $? -eq 0 ] ; then
pkg_name=$(basename $dir|sed -e 's{-x{{g')
else
pkg_name=$(echo $dir|sed -e 's{-x{{g')
fi
if [ -d $dir ] ; then
cd $dir
else
echo "$dir: No such file or directory" 1>&2
exit 1
fi
ver=$(cat conf-version)
if [ -z "$ver" ] ; then
echo "no version found for package $pkg_name" 1>&2
exit 1
fi
STAGE=$HOME/stage/arch/$pkg_name-$ver
echo Preparing $pkg_name-$ver
cp -rpf . $STAGE
if [ ! -L $HOME/stage/arch/$real_dir ] ; then
ln -sr $STAGE $HOME/stage/arch/$real_dir
fi
cd $STAGE
echo "Cleaning stage before making a tar archive"
make -s clean >/dev/null 2>&1
make -s distclean >/dev/null 2>&1
/bin/rm -rf autom4te.cache .deps
cd $HOME/stage/arch
echo "Archiving $pkg_name-"$ver".tar.gz in `pwd`"
tar \
--exclude="$pkg_name-$ver/.git" \
--exclude="$pkg_name-$ver/debian" \
--exclude="$pkg_name-$ver/RCS" \
-cf - $pkg_name-"$ver" \
| gzip -c > $pkg_dir/$pkg_name-"$ver".tar.gz
cd $curdir
done
fi
STAGE=$HOME/stage/arch/$name-$version
/bin/rm -rf $STAGE
cp -rpf $curdir $STAGE
/bin/rm -f $STAGE/catChangeLog
/bin/cp catChangeLog $STAGE/catChangeLog
cd $STAGE
make -s PKGBUILD
if [ $? -ne 0 ] ; then
echo "make failed" 1>&2
exit 1
fi
cp PKGBUILD $name.changes $pkg_dir
if [ -f extra_src ] ; then
cp -rpf `grep -h -v "^#" extra_src` $pkg_dir
fi
total=$(grep "#### INSTALL.* ####" PKGBUILD | wc -l)
echo "Total scripts in PKGBUILD=$total"
if [ $total -le 1 ] ; then
echo "Creating archpkg.install"
sed -n '/#### INSTALL SCRIPTS ####/,$p' PKGBUILD \
| grep -v "^####" > $pkg_dir/archpkg.install
if [ ! -s $pkg_dir/archpkg.install ] ; then
rm -f $pkg_dir/archpkg.install
fi
else
count=1
while true
do
echo "Creating archpkg"$count".install"
sed -n "/#### INSTALL$count SCRIPTS ####/,\$p" PKGBUILD \
| grep -v "^####" > $pkg_dir/archpkg$count.install
if [ ! -s $pkg_dir/archpkg$count.install ] ; then
rm -f $pkg_dir/archpkg$count.install
fi
if [ $count -eq $total ] ; then
break
fi
count=$(expr $count + 1)
done
fi
if [ $meta_pkg -eq 0 ] ; then
## tar the main package
echo "Cleaning stage before making a tar archive"
make -s clean >/dev/null 2>&1
make -s distclean >/dev/null 2>&1
/bin/rm -rf autom4te.cache .deps
cd $HOME/stage/arch
echo "Archiving $name-"$version".tar.gz in `pwd`"
tar \
--exclude="$name-$version/.git" \
--exclude="$name-$version/debian" \
--exclude="$name-$version/RCS" \
-cf - $name-"$version" \
| gzip -c > $pkg_dir/$name-"$version".tar.gz
fi
/bin/rm -rf $STAGE
fi
echo -n "Build Arch Package for $name-"$version"-1."$release" (Y/N) - "
read key
if [ " $key" = " Y" -o " $key" = " y" ] ; then
cd $curdir
tmprel=`cat conf-release 2>/dev/null`
if [ ! " $tmprel" = " 1.$release" ] ; then
sed -i -e "s|^pkgrel=.*|pkgrel=1.$release|g" $pkg_dir/PKGBUILD
fi
cd $pkg_dir
if [ $clean -eq 1 ] ; then
makepkg -sf --clean
else
makepkg -sf
fi
mv *.zst $HOME/stage/arch
fi
echo -n "Remove Source (Y/N) - "
read key
if [ " $key" = " Y" -o " $key" = " y" ] ; then
/bin/rm -rf $pkg_dir
fi