]>
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 # Required for fakeroot because options are shifted off the array.
34 m4_include
(..
/scripts
/library
/output_format.sh
)
40 echo "This program recreates a package using pacman's db and system files"
41 echo "Usage: $myname [--nocolor] [--pacnew] <installed package name>"
42 echo "Example: $myname kernel26"
46 printf "%s %s\n" "$myname" "$myver"
47 echo 'Copyright (C) 2008 locci <carlocci_at_gmail_dot_com>'
48 echo 'Copyright (C) 2008-2013 Pacman Development Team <pacman-dev@archlinux.org>'
51 while [[ ! -z $1 ]]; do
52 if [[ $1 == "--nocolor" ]]; then
55 elif [[ $1 == "--pacnew" ]]; then
63 m4_include
(..
/scripts
/library
/term_colors.sh
)
65 if (( $# != 1 )); then
70 if [[ $1 = -@
(h
|-help) ]]; then
73 elif [[ $1 = -@
(V
|-version) ]]; then
82 if [[ -f /usr
/bin
/fakeroot
]]; then
83 msg
"Entering fakeroot environment"
85 /usr
/bin
/fakeroot
-u -- "$0" "${ARGS[@]}"
88 warning
"installing fakeroot or running $myname as root is required to"
89 plain
" preserve the ownership permissions of files in some packages\n"
94 # Setting environmental variables
96 if [[ ! -r @sysconfdir@
/pacman.conf
]]; then
97 error
"unable to read @sysconfdir@/pacman.conf"
101 eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
102 pac_db
="${DBPath:-@localstatedir@/lib/pacman/}/local"
104 if [[ ! -r @sysconfdir@
/makepkg.conf
]]; then
105 error
"unable to read @sysconfdir@/makepkg.conf"
109 source "@sysconfdir@/makepkg.conf"
110 if [[ -r ~
/.makepkg.conf
]]; then
111 source ~
/.makepkg.conf
114 pkg_dest
="${PKGDEST:-$PWD}"
115 pkg_pkger
=${PACKAGER:-'Unknown Packager'}
118 pkg_dir
=("$pac_db/$pkg_name"-+([^
-])-+([^
-]))
119 pkg_namver
=("${pkg_dir[@]##*/}")
122 # Checks everything is in place
124 if [[ ! -d $pac_db ]]; then
125 error
"pacman database directory ${pac_db} not found"
129 if (( ${#pkg_dir[@]} != 1 )); then
130 error
"%d entries for package %s found in pacman database" \
131 ${#pkg_dir[@]} "${pkg_name}"
132 msg2
"%s" "${pkg_dir[@]}"
136 if [[ ! -d $pkg_dir ]]; then
137 error
"package %s is found in pacman database," "${pkg_name}"
138 plain
" but '%s' is not a directory" "${pkg_dir}"
145 msg
"Package: ${pkg_namver}"
146 work_dir
=$(mktemp -d --tmpdir bacman.XXXXXXXXXX)
147 cd "$work_dir" || exit 1
152 msg2
"Copying package files..."
159 if [[ $i == %+([A
-Z])% ]]; then
167 package_file
="$work_dir/$i"
169 if [[ ! -e $local_file ]]; then
170 warning
"package file $local_file is missing"
176 # Get the MD5 checksum.
177 original_md5
="${i##*$'\t'}"
178 # Strip the md5sum after the tab.
180 local_file
="/$i.pacnew"
181 package_file
="$work_dir/$i"
183 # Include unmodified .pacnew files.
184 local_md5
="$(md5sum "$local_file" | cut -d' ' -f1)"
185 if [[ $INCLUDE_PACNEW == 'n' ]] \
186 || [[ ! -e $local_file ]] \
187 || [[ $local_md5 != $original_md5 ]]; then
188 # Warn about modified files.
189 local_md5
="$(md5sum "/$i" | cut -d' ' -f1)"
190 if [[ $local_md5 != $original_md5 ]]; then
191 warning
"package file /$i has been modified"
193 # Let the normal file be included in the %FILES% list.
204 bsdtar
-cnf - -s'/.pacnew$//' "$local_file" 2> /dev
/null
| bsdtar
-xpf - 2> /dev
/null
206 # Workaround to bsdtar not reporting a missing file as an error
207 if ! [[ -e $package_file || -L $package_file ]]; then
208 error
"unable to add $local_file to the package"
209 plain
" If your user does not have permission to read this file then"
210 plain
" you will need to run $myname as root"
214 done < "$pkg_dir"/files
222 pkg_size
=$(du -sk | awk '{print $1 * 1024}')
226 # TODO adopt makepkg's write_pkginfo() into this or scripts/library
228 msg2
"Generating .PKGINFO metadata..."
229 echo "# Generated by $myname $myver" > .PKGINFO
230 if [[ $INFAKEROOT == "1" ]]; then
231 echo "# Using $(fakeroot -v)" >> .PKGINFO
233 echo "# $(LC_ALL=C date)" >> .PKGINFO
241 if [[ $i == %+([A
-Z])% ]]; then
249 echo "pkgname = $i" >> .PKGINFO
252 echo "pkgver = $i" >> .PKGINFO
255 echo "pkgdesc = $i" >> .PKGINFO
258 echo "url = $i" >> .PKGINFO
261 echo "license = $i" >> .PKGINFO
264 echo "arch = $i" >> .PKGINFO
268 echo "builddate = $(date -u "+%s")" >> .PKGINFO
271 echo "packager = $pkg_pkger" >> .PKGINFO
274 echo "size = $pkg_size" >> .PKGINFO
277 echo "group = $i" >> .PKGINFO
280 echo "replaces = $i" >> .PKGINFO
283 echo "depend = $i" >> .PKGINFO
286 echo "optdepend = $i" >> .PKGINFO
289 echo "conflict = $i" >> .PKGINFO
292 echo "provides = $i" >> .PKGINFO
297 # Strip the md5sum after the tab
298 echo "backup = ${i%%$'\t'*}" >> .PKGINFO
301 done < <(cat "$pkg_dir"/{desc
,files
})
303 comp_files
=".PKGINFO"
305 if [[ -f $pkg_dir/install ]]; then
306 cp "$pkg_dir/install" "$work_dir/.INSTALL"
307 comp_files
+=" .INSTALL"
309 if [[ -f $pkg_dir/changelog
]]; then
310 cp "$pkg_dir/changelog" "$work_dir/.CHANGELOG"
311 comp_files
+=" .CHANGELOG"
315 # Fixes owner:group and permissions for .PKGINFO, .CHANGELOG, .INSTALL
317 chown root
:root
"$work_dir"/{.PKGINFO
,.CHANGELOG
,.INSTALL
} 2> /dev
/null
318 chmod 644 "$work_dir"/{.PKGINFO
,.CHANGELOG
,.INSTALL
} 2> /dev
/null
321 # Generate the package
323 msg2
"Generating the package..."
325 pkg_file
="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
328 # TODO: Maybe this can be set globally for robustness
330 bsdtar
-cf - $comp_files * |
332 *tar.gz
) gzip -c -f -n ;;
333 *tar.bz2
) bzip2 -c -f ;;
334 *tar.xz
) xz
-c -z - ;;
335 *tar.Z
) compress -c -f ;;
337 *) warning
"'%s' is not a valid archive extension." \
339 esac > "${pkg_file}"; ret
=$?
342 error
"Unable to write package to $pkg_dest"
343 plain
" Maybe the disk is full or you do not have write access"
354 # vim: set ts=2 sw=2 noet: