8 mkdeb - Create a Debian package (.deb)
12 mkdeb [-m | --multiarch]
16 Create a *.deb file according to the package name and version info found in F<./deb/DEBIAN/control> file
17 and include all file in the package found in F<./deb> folder. Update some of C<control> file's fields, eg.
18 C<Version> (increase by 1 if there is any file in the package newer than C<control> file), C<Installed-Size>...
20 In I<multiarch> mode, instead of F<./deb> folder, it takes data from all folders in the current working
21 directory which name is a valid Debian architecture name (eg. amd64, i386, ...), and stores temporary
22 files in F<./deb> for building each architecture's package.
24 Mkdeb also considers C<mkdeb-perms.txt> file in the current working directory to set
25 some file attributes in the package, otherwise all file attributes are gonna be the same as on the original.
26 Each line in this file looks like:
28 <B<MODE>> <B<OWNER>> <B<GROUP>> <B<PATH>>
36 is an octal file permission mode, 3 or 4 digits, or "-" to ignore
40 UID or name of the owner user
44 GID or name of the owner group
48 the file's path itself to which the attributes are applied, relative to F<./deb> directory.
58 archs
=(amd64 armel armhf hurd-i386 i386 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc s390x sparc
)
65 for attrib
in Package Version Architecture
67 value
=$
(grep -E ^
$attrib: deb
/DEBIAN
/control | cut
-f2- -d' ')
71 # Package modified since last build?
72 if [ -n "$(find deb -type f -newer deb/DEBIAN/control ! -path "deb
/DEBIAN
/*" -print -quit)" ]
74 Version_new
=`echo "$Version" | perl -pe 's/^(.*?)(\d+)([^\d]*)$/$1.($2+1).$3/e;'`
75 echo "Increase version number $Version -> $Version_new" >&2
79 size
=`du -s deb/ | awk '{print $1}'`
80 sed -e "s/^Installed-Size:.*/Installed-Size: $size/" -i deb
/DEBIAN
/control
81 sed -e "s/^Version:.*/Version: $Version/" -i deb
/DEBIAN
/control
83 find deb
/ -type f
-exec md5sum -b {} \
; -or -path "deb/DEBIAN" -prune |
sed -e 's@\*\?deb/@@' > deb
/DEBIAN
/md5sums
85 if [ -f mkdeb-perms.txt
]
87 # Create fakeroot environment
88 devnum
=`stat -c %D deb/`
89 while read -r mode owner group filepath
91 [ -z "$filepath" -o "${mode:0:1}" = '#' ] && continue
92 filepath
="deb/$filepath"
93 inode
=`stat -c %i "$filepath"`
94 nlink
=`stat -c %h "$filepath"`
96 fullmode
=$
(printf %06o
0x
`stat -c %f "$filepath"`)
101 mode65
=${fullmode:0:2}
102 [ "${#mode}" -lt 4 ] && mode4
=0
103 mode
=${mode65}${mode4}${mode}
109 [ "$owner" -ge 0 ] 2>/dev
/null
&& uid
=$owner || uid
=`id -u $owner`
115 [ "$group" -ge 0 ] 2>/dev
/null
&& gid
=$group || gid
=`getent group $group | cut -d: -f3`
118 echo dev
=$devnum,ino
=$inode,mode
=$mode,uid
=$uid,gid
=$gid,nlink
=$nlink,rdev
=0
119 done <mkdeb-perms.txt
>mkdeb-fakeroot.txt
120 fakeroot_opt
="-i mkdeb-fakeroot.txt"
124 #\( \( ! -perm -0444 -o -perm /0002 \) -o \( -type d ! -perm -0111 \) \)
127 fakeroot
$fakeroot_opt find deb
/usr
/ ! -perm -0444 -printf "WARN: File/dir is not readable for everybody: %p\n"
128 fakeroot
$fakeroot_opt find deb
/usr
/ ! -type l
-perm /0002 -printf "WARN: File/dir is writable for others: %p\n"
129 fakeroot
$fakeroot_opt find deb
/usr
/ -type d
! -perm -0111 -printf "WARN: Dir is not searchable for everybody: %p\n"
133 pkgfile
="${Package}_${Version}_${Architecture}.deb"
134 fakeroot
$fakeroot_opt dpkg-deb
-b deb
/ "$pkgfile"
143 echo "$0: Create debian package
144 1. Simple mode, store contents of \`deb/' directory in a properly named file.
146 2. Make as many packages as many directories it find with name of standard
147 architecture names (eg. amd64, i386). Files in special folder \`all' will be
148 included in all packages.
161 if [ "$mode" = multiarch
]
165 echo "Subfolder \`deb/' already exists. Multiarch mode would work into it. Please remove." >&2
169 for arch
in "${archs[@]}"
173 echo "Architecture: $arch" >&2
177 reffile
=deb
/DEBIAN
/control.ref
178 touch -r all
/DEBIAN
/control
"$reffile"
181 sed -e "s/^Architecture:.*/Architecture: $arch/" -i deb
/DEBIAN
/control
183 touch -r "$reffile" deb
/DEBIAN
/control