]>
wolfpit.net Git - tool/Arch-pacman/.git/blob - contrib/bacman.sh.in
3 # bacman: recreate a package from a running system
4 # This script rebuilds an already installed package using metadata
5 # stored into the pacman database and system files
7 # Copyright (c) 2008 locci <carlocci_at_gmail_dot_com>
8 # Copyright (c) 2008-2013 Pacman Development Team <pacman-dev@archlinux.org>
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27 declare -r myname
='bacman'
28 declare -r myver
='@PACKAGE_VERSION@'
31 m4_include
(..
/scripts
/library
/output_format.sh
)
37 echo "This program recreates a package using pacman's db and system files"
38 echo "Usage: $myname [--nocolor] <installed package name>"
39 echo "Example: $myname kernel26"
43 printf "%s %s\n" "$myname" "$myver"
44 echo 'Copyright (C) 2008 locci <carlocci_at_gmail_dot_com>'
47 if [[ $1 == "--nocolor" ]]; then
52 m4_include
(..
/scripts
/library
/term_colors.sh
)
54 if (( $# != 1 )); then
59 if [[ $1 = -@
(h
|-help) ]]; then
62 elif [[ $1 = -@
(V
|-version) ]]; then
71 if [[ -f /usr
/bin
/fakeroot
]]; then
72 msg
"Entering fakeroot environment"
74 /usr
/bin
/fakeroot
-u -- "$0" "$@"
77 warning
"installing fakeroot or running $myname as root is required to"
78 plain
" preserve the ownership permissions of files in some packages\n"
83 # Setting environmental variables
85 if [[ ! -r @sysconfdir@
/pacman.conf
]]; then
86 error
"unable to read @sysconfdir@/pacman.conf"
90 eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
91 pac_db
="${DBPath:-@localstatedir@/lib/pacman/}/local"
93 if [[ ! -r @sysconfdir@
/makepkg.conf
]]; then
94 error
"unable to read @sysconfdir@/makepkg.conf"
98 source "@sysconfdir@/makepkg.conf"
99 if [[ -r ~
/.makepkg.conf
]]; then
100 source ~
/.makepkg.conf
103 pkg_dest
="${PKGDEST:-$PWD}"
104 pkg_pkger
=${PACKAGER:-'Unknown Packager'}
107 pkg_dir
=("$pac_db/$pkg_name"-+([^
-])-+([^
-]))
108 pkg_namver
=("${pkg_dir[@]##*/}")
111 # Checks everything is in place
113 if [[ ! -d $pac_db ]]; then
114 error
"pacman database directory ${pac_db} not found"
118 if (( ${#pkg_dir[@]} != 1 )); then
119 error
"%d entries for package %s found in pacman database" \
120 ${#pkg_dir[@]} "${pkg_name}"
121 msg2
"%s" "${pkg_dir[@]}"
125 if [[ ! -d $pkg_dir ]]; then
126 error
"package %s is found in pacman database," "${pkg_name}"
127 plain
" but '%s' is not a directory" "${pkg_dir}"
134 msg
"Package: ${pkg_namver}"
135 work_dir
=$(mktemp -d --tmpdir bacman.XXXXXXXXXX)
136 cd "$work_dir" || exit 1
141 msg2
"Copying package files..."
143 cat "$pkg_dir"/files
|
149 if [[ $i == %+([A
-Z])% ]]; then
157 if [[ -e /$i ]]; then
158 bsdtar
-cnf - "/$i" 2> /dev
/null
| bsdtar
-xpf -
160 # Workaround to bsdtar not reporting a missing file as an error
161 if ! [[ -e $work_dir/$i || -L $work_dir/$i ]]; then
162 error
"unable to add /$i to the package"
163 plain
" If your user does not have permssion to read this file then"
164 plain
" you will need to run $myname as root"
169 warning
"package file /$i is missing"
181 pkg_size
=$(du -sk | awk '{print $1 * 1024}')
185 # TODO adopt makepkg's write_pkginfo() into this or scripts/library
187 msg2
"Generating .PKGINFO metadata..."
188 echo "# Generated by $myname $myver" > .PKGINFO
189 if [[ $INFAKEROOT == "1" ]]; then
190 echo "# Using $(fakeroot -v)" >> .PKGINFO
192 echo "# $(LC_ALL=C date)" >> .PKGINFO
200 if [[ $i == %+([A
-Z])% ]]; then
208 echo "pkgname = $i" >> .PKGINFO
211 echo "pkgver = $i" >> .PKGINFO
214 echo "pkgdesc = $i" >> .PKGINFO
217 echo "url = $i" >> .PKGINFO
220 echo "license = $i" >> .PKGINFO
223 echo "arch = $i" >> .PKGINFO
227 echo "builddate = $(date -u "+%s")" >> .PKGINFO
230 echo "packager = $pkg_pkger" >> .PKGINFO
233 echo "size = $pkg_size" >> .PKGINFO
236 echo "group = $i" >> .PKGINFO
239 echo "replaces = $i" >> .PKGINFO
242 echo "depend = $i" >> .PKGINFO
245 echo "optdepend = $i" >> .PKGINFO
248 echo "conflict = $i" >> .PKGINFO
251 echo "provides = $i" >> .PKGINFO
256 # strip the md5sum after the tab
257 echo "backup = ${i%%$'\t'*}" >> .PKGINFO
260 done < <(cat "$pkg_dir"/{desc
,files
})
262 comp_files
=".PKGINFO"
264 if [[ -f $pkg_dir/install ]]; then
265 cp "$pkg_dir/install" "$work_dir/.INSTALL"
266 comp_files
+=" .INSTALL"
268 if [[ -f $pkg_dir/changelog
]]; then
269 cp "$pkg_dir/changelog" "$work_dir/.CHANGELOG"
270 comp_files
+=" .CHANGELOG"
274 # Fixes owner:group and permissions for .PKGINFO, .CHANGELOG, .INSTALL
276 chown root
:root
"$work_dir"/{.PKGINFO
,.CHANGELOG
,.INSTALL
} 2> /dev
/null
277 chmod 644 "$work_dir"/{.PKGINFO
,.CHANGELOG
,.INSTALL
} 2> /dev
/null
280 # Generate the package
282 msg2
"Generating the package..."
284 pkg_file
="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
287 # TODO: Maybe this can be set globally for robustness
289 bsdtar
-cf - $comp_files * |
291 *tar.gz
) gzip -c -f -n ;;
292 *tar.bz2
) bzip2 -c -f ;;
293 *tar.xz
) xz
-c -z - ;;
294 *tar.Z
) compress -c -f ;;
296 *) warning
"'%s' is not a valid archive extension." \
298 esac > "${pkg_file}"; ret
=$?
301 error
"Unable to write package to $pkg_dest"
302 plain
" Maybe the disk is full or you do not have write access"
313 # vim: set ts=2 sw=2 noet: