[tpwd] Fix segfault when exactly one argument given
[tinyapps.git] / mkpkg
blob5508655b57b27b46fcbb1c9e090fc5b9c2434b0d
1 #!/bin/sh
2 ##
3 ## Creates a Slackware package
4 ## Copyright (c) 2005-2007 by Michal Nazarewicz (mina86/AT/mina86.com)
5 ##
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
19 ## This is part of Tiny Applications Collection
20 ## -> http://tinyapps.sourceforge.net/
24 set -e
28 ## Strip executables
30 echo Stripping executables
31 find . -type f -exec file -- {} + | \
32 sed -ne '/ELF.*executable/ s/:.*//p
33 /ELF.*shared object/ s/:.*//p' |
34 xargs --no-run-if-empty strip --strip-unneeded 2>/dev/null
38 ## Search for *.new files and add them do doinst.sh
40 echo Searching for \*.new files
41 find . -type f -name '*.new' | sed -e "s/'/'\\''/g" \
42 -e "s/^\\(.*\\)\\.new$/cfg '\\1'/" >mkpkg-new
44 if [ -s mkpkg-new ]; then
45 echo Adding \*.new files to doinst.sh
46 mkdir -p install
47 cat - mkpkg-new <<EOF >>install/doinst.sh
49 NEW_CONFIG=
50 cfg () {
51 if ! [ -r "\$1" ]; then
52 mv -- "\$1.new" "\$1"
53 NEW_CONFIG=yes
54 elif ! cmp "\$1" "\$1.new" >/dev/null 2>&1; then
55 rm -- "\$1.new"
56 else
57 NEW_CONFIG=yes
61 EOF
62 echo '[ -z "\$NEW_CONFIG" ] || echo "New configuration file(s) present"' \
63 >>install/doinst.sh
64 chmod 755 install/doinst.sh
66 rm -f mkpkg-new
70 ## Gzip man pages
72 echo Gzipping man pages
73 find . -path '*/man?/*' \( -name '*.?' -o -name '*.??' \) \
74 \! -name '*.Z' \! -name '*.gz' \! -name '*.bz2' \
75 -exec gzip -9 -- {} +
79 ## Description
81 if ! [ -s install/slack-desc ]; then
82 echo 'Enter package name (single line):'
83 IFS= read TITLE
85 echo 'Enter description (^D to finish; max 9 lines)'
86 echo '----------------------------------------------------------------------|'
87 { echo "$TITLE"; echo; cat; } | cat -s >mkpkg-desc
89 LINES=$(wc -l <mkpkg-desc)
90 while [ $LINES -lt 11 ]; do
91 echo >>mkpkg-desc
92 LINES=$(($LINES + 1))
93 done
94 if [ $LINES -gt 11 ]; then
95 echo warning: Description has more then 11 lines
98 PKG="${PWD##*/}"; PKG="${PKG%-*-*-*}"
99 mkdir -p install
100 while IFS= read LINE; do
101 printf '%s: %s\n' "$PKG" "$LINE"
102 done <mkpkg-desc >install/slack-desc
103 rm -f mkpkg-desc
108 ## Make package
110 makepkg "$@" "$PWD.txz"