]>
wolfpit.net Git - tool/Arch-pacman/.git/blob - contrib/bacman.sh.in
7e1ee010332fff94beedaceaa2f2a75fedeaa322
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@'
30 # Required for fakeroot because options are shifted off the array.
33 m4_include
(..
/scripts
/library
/output_format.sh
)
39 echo "This program recreates a package using pacman's db and system files"
40 echo "Usage: $myname [--nocolor] <installed package name>"
41 echo "Example: $myname kernel26"
45 printf "%s %s\n" "$myname" "$myver"
46 echo 'Copyright (C) 2008 locci <carlocci_at_gmail_dot_com>'
47 echo 'Copyright (C) 2008-2013 Pacman Development Team <pacman-dev@archlinux.org>'
50 if [[ $1 == "--nocolor" ]]; then
55 m4_include
(..
/scripts
/library
/term_colors.sh
)
57 if (( $# != 1 )); then
62 if [[ $1 = -@
(h
|-help) ]]; then
65 elif [[ $1 = -@
(V
|-version) ]]; then
74 if [[ -f /usr
/bin
/fakeroot
]]; then
75 msg
"Entering fakeroot environment"
77 /usr
/bin
/fakeroot
-u -- "$0" "${ARGS[@]}"
80 warning
"installing fakeroot or running $myname as root is required to"
81 plain
" preserve the ownership permissions of files in some packages\n"
86 # Setting environmental variables
88 if [[ ! -r @sysconfdir@
/pacman.conf
]]; then
89 error
"unable to read @sysconfdir@/pacman.conf"
93 eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
94 pac_db
="${DBPath:-@localstatedir@/lib/pacman/}/local"
96 if [[ ! -r @sysconfdir@
/makepkg.conf
]]; then
97 error
"unable to read @sysconfdir@/makepkg.conf"
101 source "@sysconfdir@/makepkg.conf"
102 if [[ -r ~
/.makepkg.conf
]]; then
103 source ~
/.makepkg.conf
106 pkg_dest
="${PKGDEST:-$PWD}"
107 pkg_pkger
=${PACKAGER:-'Unknown Packager'}
110 pkg_dir
=("$pac_db/$pkg_name"-+([^
-])-+([^
-]))
111 pkg_namver
=("${pkg_dir[@]##*/}")
114 # Checks everything is in place
116 if [[ ! -d $pac_db ]]; then
117 error
"pacman database directory ${pac_db} not found"
121 if (( ${#pkg_dir[@]} != 1 )); then
122 error
"%d entries for package %s found in pacman database" \
123 ${#pkg_dir[@]} "${pkg_name}"
124 msg2
"%s" "${pkg_dir[@]}"
128 if [[ ! -d $pkg_dir ]]; then
129 error
"package %s is found in pacman database," "${pkg_name}"
130 plain
" but '%s' is not a directory" "${pkg_dir}"
137 msg
"Package: ${pkg_namver}"
138 work_dir
=$(mktemp -d --tmpdir bacman.XXXXXXXXXX)
139 cd "$work_dir" || exit 1
144 msg2
"Copying package files..."
146 cat "$pkg_dir"/files
|
152 if [[ $i == %+([A
-Z])% ]]; then
160 if [[ -e /$i ]]; then
161 bsdtar
-cnf - "/$i" 2> /dev
/null
| bsdtar
-xpf -
163 # Workaround to bsdtar not reporting a missing file as an error
164 if ! [[ -e $work_dir/$i || -L $work_dir/$i ]]; then
165 error
"unable to add /$i to the package"
166 plain
" If your user does not have permssion to read this file then"
167 plain
" you will need to run $myname as root"
172 warning
"package file /$i is missing"
184 pkg_size
=$(du -sk | awk '{print $1 * 1024}')
188 # TODO adopt makepkg's write_pkginfo() into this or scripts/library
190 msg2
"Generating .PKGINFO metadata..."
191 echo "# Generated by $myname $myver" > .PKGINFO
192 if [[ $INFAKEROOT == "1" ]]; then
193 echo "# Using $(fakeroot -v)" >> .PKGINFO
195 echo "# $(LC_ALL=C date)" >> .PKGINFO
203 if [[ $i == %+([A
-Z])% ]]; then
211 echo "pkgname = $i" >> .PKGINFO
214 echo "pkgver = $i" >> .PKGINFO
217 echo "pkgdesc = $i" >> .PKGINFO
220 echo "url = $i" >> .PKGINFO
223 echo "license = $i" >> .PKGINFO
226 echo "arch = $i" >> .PKGINFO
230 echo "builddate = $(date -u "+%s")" >> .PKGINFO
233 echo "packager = $pkg_pkger" >> .PKGINFO
236 echo "size = $pkg_size" >> .PKGINFO
239 echo "group = $i" >> .PKGINFO
242 echo "replaces = $i" >> .PKGINFO
245 echo "depend = $i" >> .PKGINFO
248 echo "optdepend = $i" >> .PKGINFO
251 echo "conflict = $i" >> .PKGINFO
254 echo "provides = $i" >> .PKGINFO
259 # strip the md5sum after the tab
260 echo "backup = ${i%%$'\t'*}" >> .PKGINFO
263 done < <(cat "$pkg_dir"/{desc
,files
})
265 comp_files
=".PKGINFO"
267 if [[ -f $pkg_dir/install ]]; then
268 cp "$pkg_dir/install" "$work_dir/.INSTALL"
269 comp_files
+=" .INSTALL"
271 if [[ -f $pkg_dir/changelog
]]; then
272 cp "$pkg_dir/changelog" "$work_dir/.CHANGELOG"
273 comp_files
+=" .CHANGELOG"
277 # Fixes owner:group and permissions for .PKGINFO, .CHANGELOG, .INSTALL
279 chown root
:root
"$work_dir"/{.PKGINFO
,.CHANGELOG
,.INSTALL
} 2> /dev
/null
280 chmod 644 "$work_dir"/{.PKGINFO
,.CHANGELOG
,.INSTALL
} 2> /dev
/null
283 # Generate the package
285 msg2
"Generating the package..."
287 pkg_file
="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
290 # TODO: Maybe this can be set globally for robustness
292 bsdtar
-cf - $comp_files * |
294 *tar.gz
) gzip -c -f -n ;;
295 *tar.bz2
) bzip2 -c -f ;;
296 *tar.xz
) xz
-c -z - ;;
297 *tar.Z
) compress -c -f ;;
299 *) warning
"'%s' is not a valid archive extension." \
301 esac > "${pkg_file}"; ret
=$?
304 error
"Unable to write package to $pkg_dest"
305 plain
" Maybe the disk is full or you do not have write access"
316 # vim: set ts=2 sw=2 noet: