FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor


 
 
LinkBack Thread Tools
 
Old 05-30-2008, 12:05 AM
carlocci
 
Default bacman

On 5/29/08, Dan McGee <dpmcgee@gmail.com> wrote:
>> Forum discussion: http://bbs.archlinux.org/viewtopic.php?id=49168
>> Script: http://pastebin.com/m3f763692
>> Thanks for your time,
>
> Would you mind submitting it inline so we can comment on it here?
>

I hope I understood what you meant: here's the script

#!/bin/bash
#
# bacman: recreate a package from a running system
# This script rebuilds an already installed package using metadata
# stored into the pacman database and system files
#
# (c) 2008 - locci <carlocci_at_gmail_dot_com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

readonly progname="bacman"
readonly progver="0.1.2"

#
# User Friendliness
#
function usage(){
echo "This program recreates a package using pacman's db and system files"
echo "Usage: $progname <installed package name>"
echo "Example: $progname kernel26"
}

if [ $# -ne 1 ] ; then
usage
exit 1
fi

if [ "$1" = "--help" -o "$1" = "-h" ] ; then
usage
exit 0
fi

if [ "$1" = "--version" -o "$1" = "-v" ]; then
echo "$progname version $version"
echo "Copyright (C) 2008 locci"
exit 0
fi

#
# Setting environmental variables
#
eval $(sed -nre
's:[[:space:]]*(DBPath|CacheDir)[[:space:]]*=[[:space:]]*([[rint:]]*):1="2"'
/etc/pacman.conf)
pac_db="${DBPath:-/var/lib/pacman/}/local"
pac_cache="${CacheDir:-/var/cache/pacman/pkg/}"
pkg_name="$1"
pkg_dir="$(echo $pac_db/$pkg_name-[0-9]*)"
eval $(sed -nre
's:[[:space:]]*(CARCH|PKGDEST|PACKAGER)[[:space:]]*=[[:space:]]*([[rint:]]*):1=2'
/etc/makepkg.conf)
pkg_arch=${CARCH:-'unknown'}
pkg_dest="${PKGDEST:-$PWD}"
pkg_pkger=${PACKAGER:-'Unknown Packager'}
pkg_namver="${pkg_dir##*/}"

#
# Checks everything is in place
#
if [ ! -d "$pac_db" ] ; then
echo Error: pacman database directory ${pac_db} not found
exit 1
fi

if [ ! -d "$pac_cache" ] ; then
echo Warning: pacman pkg cache directory ${pac_cache} not found
unset pac_cache
fi

if [ ! -d "$pkg_dir" ] ; then
echo Error: package ${pkg_name} not found in pacman database
exit 1
fi

if [ -n "$pac_cache" ] && [ -f "$pac_cache"/"$pkg_namver"*.tar.gz ] ; then
echo Warning: the package for ${pkg_name} already exists in your
pacman cache
# read -n 1 -p 'Do you want to fetch it instead? (y/N) '
# case $REPLY in
# y|Y)
# cp "$pac_cache"/"$pkg_namver"*.pkg.tar.gz "$pkg_dest"
# exit 0
# ;;
# *) echo ""
# ;;
# esac
fi

#
# Begin
#
echo Package: ${pkg_namver}
work_dir=$(mktemp -d -p /tmp)
cd $work_dir || exit 1

#
# File copying
#
echo Copying package files...

cat "$pkg_dir"/files |
while read i; do
if [ -z "$i" ] ; then
continue
fi

if [[ "$i" =~ %[A-Z]*% ]] ; then
current=$i
continue
fi

case $current in
%FILES%)
if [ -d "/$i" ]; then
mkdir "$i"
elif [ -f "/$i" ]; then
install -D "/$i" "$i"
else
echo "/$i" is missing: this might result in a broken package
fi
;;
esac
pkg_size=$(du -sb | awk '{print $1}')
done

echo Adding install commands and changelogs, if any...
if [ -f "$pkg_dir/install" ] ; then
cp "$pkg_dir/install" "$work_dir/.INSTALL"
fi
if [ -f $pkg_dir/changelog ] ; then
cp "$pkg_dir/changelog" "$work_dir/.CHANGELOG"
fi

#
# .PKGINFO stuff
#
echo
echo Generating .PKGINFO metadata...
echo "# Generated by $progname $progver" > .PKGINFO
echo "# $(LC_ALL=C date)" >> .PKGINFO
echo "#" >> .PKGINFO

cat "$pkg_dir"/{desc,files,depends} |
while read i; do
if [[ -z "$i" ]]; then
continue;
fi

if [[ "$i" =~ %[A-Z]*% ]] ; then
current=$i
continue
fi

case "$current" in

# desc
%NAME%)
echo "pkgname = $i" >> .PKGINFO
;;
%VERSION%)
echo "pkgver = $i" >> .PKGINFO
;;
%DESC%)
echo "pkgdesc = $i" >> .PKGINFO
;;
%URL%)
echo "url = $i" >> .PKGINFO
;;
%LICENSE%)
echo "license = $i" >> .PKGINFO
;;
%ARCH%)
echo "arch = $i" >> .PKGINFO
;;
%BUILDDATE%)
echo "builddate = $(date -u "+%s")" >> .PKGINFO
;;
%PACKAGER%)
echo "packager = $pkg_pkger" >> .PKGINFO
;;
%SIZE%)
echo "size = $pkg_size" >> .PKGINFO
;;
%GROUPS%)
echo "group = $i" >> .PKGINFO
;;
%REPLACES%)
echo "replaces = $i" >> .PKGINFO
;;

# files
%BACKUP%)
# strip the md5sum after the tab
echo "backup = ${i%% *}" >> .PKGINFO
;;

# depends
%DEPENDS%)
echo "depend = $i" >> .PKGINFO
;;
%OPTDEPENDS%)
echo "optdepend = $i" >> .PKGINFO
;;
%CONFLICTS%)
echo "conflict = $i" >> .PKGINFO
;;
%PROVIDES%)
echo "provides = $i" >> .PKGINFO
;;

%FORCE%)
echo "force = true" >> .PKGINFO
;;
esac
done

#
# Generate the package
#
echo
echo Generating the package...

ret=0
bsdtar -czf "$pkg_dest/$pkg_namver-$pkg_arch.tar.gz" $(ls -A) || ret=$?
if [ $ret -ne 0 ]; then
echo Error: Unable to write package to $pkg_dest
echo Maybe the disk is full or you do not have write access
exit 1
fi

rm -rf $work_dir

exit 0

# vim: set ts=2 sw=2 noet:

_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 
Old 05-30-2008, 12:10 AM
Allan McRae
 
Default bacman

Here is an inline version. Slightly changed from the version carlocci
posted to fix a minor bug.
Allan


#!/bin/bash
#
# bacman: recreate a package from a running system
# This script rebuilds an already installed package using metadata
# stored into the pacman database and system files
#
# (c) 2008 - locci <carlocci_at_gmail_dot_com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

readonly progname="bacman"
readonly progver="0.1.2"

#
# User Friendliness
#
function usage(){
echo "This program recreates a package using pacman's db and system
files"
echo "Usage: $progname <installed package name>"
echo "Example: $progname kernel26"
}

if [ $# -ne 1 ] ; then
usage
exit 1
fi

if [ "$1" = "--help" -o "$1" = "-h" ] ; then
usage
exit 0
fi

if [ "$1" = "--version" -o "$1" = "-v" ]; then
echo "$progname version $version"
echo "Copyright (C) 2008 locci"
exit 0
fi

#
# Setting environmental variables
#
eval $(sed -nre
's:[[:space:]]*(DBPath)[[:space:]]*=[[:space:]]*([[rint:]]*):1="2"'
/etc/pacman.conf)
pac_db="${DBPath:-/var/lib/pacman/}/local"
eval $(sed -nre
's:[[:space:]]*(CacheDir)[[:space:]]*=[[:space:]]*([[rint:]]*):1="2"'
/etc/pacman.conf)
pac_cache="${CacheDir:-/var/cache/pacman/pkg/}"
pkg_name="$1"
pkg_dir="$(echo $pac_db/$pkg_name-[0-9]*)"
eval $(sed -nre
's:[[:space:]]*(CARCH)[[:space:]]*=[[:space:]]*([[rint:]]*):1=2'
/etc/makepkg.conf)
pkg_arch=${CARCH:-'unknown'}
eval $(sed -nre
's:[[:space:]]*(PKGDEST)[[:space:]]*=[[:space:]]*([[rint:]]*):1=2'
/etc/makepkg.conf)
pkg_dest="${PKGDEST:-$PWD}"
eval $(sed -nre
's:[[:space:]]*(PACKAGER)[[:space:]]*=[[:space:]]*([[rint:]]*):1=2'
/etc/makepkg.conf)
pkg_pkger=${PACKAGER:-'Unknown Packager'}
pkg_namver="${pkg_dir##*/}"

#
# Checks everything is in place
#
if [ ! -d "$pac_db" ] ; then
echo Error: pacman database directory ${pac_db} not found
exit 1
fi

if [ ! -d "$pac_cache" ] ; then
echo Warning: pacman pkg cache directory ${pac_cache} not found
unset pac_cache
fi

if [ ! -d "$pkg_dir" ] ; then
echo Error: package ${pkg_name} not found in pacman database
exit 1
fi

if [ -n "$pac_cache" ] && [ -f "$pac_cache"/"$pkg_namver"*.tar.gz ] ; then
echo Warning: the package ${pkg_name} already exists in your pacman
cache
# read -n 1 -p 'Do you want to fetch it instead? (y/N) '
# case $REPLY in
# y|Y)
# cp "$pac_cache"/"$pkg_namver"*.pkg.tar.gz "$pkg_dest"
# exit 0
# ;;
# *) echo ""
# ;;
# esac
fi

#
# Begin
#
echo Package: ${pkg_namver}
work_dir=$(mktemp -d -p /tmp)
cd $work_dir || exit 1

#
# File copying
#
echo Copying package files...

cat "$pkg_dir"/files |
while read i; do
if [ -z "$i" ] ; then
continue
fi

if [[ "$i" =~ %[A-Z]*% ]] ; then
current=$i
continue
fi

case $current in
%FILES%)
if [ -d "/$i" ]; then
mkdir "$i"
elif [ -f "/$i" ]; then
install -D "/$i" "$i"
else
echo "/$i" is missing: this might result in a broken package
fi
;;
esac
pkg_size=$(du -sb | awk '{print $1}')
done

echo Adding install commands and changelogs, if any...
if [ -f "$pkg_dir/install" ] ; then
cp "$pkg_dir/install" "$work_dir/.INSTALL"
fi
if [ -f $pkg_dir/changelog ] ; then
cp "$pkg_dir/changelog" "$work_dir/.CHANGELOG"
fi

#
# .PKGINFO stuff
#
echo
echo Generating .PKGINFO metadata...
echo "# Generated by $progname $progver" > .PKGINFO
echo "# $(LC_ALL=C date)" >> .PKGINFO
echo "#" >> .PKGINFO

cat "$pkg_dir"/{desc,files,depends} |
while read i; do
if [[ -z "$i" ]]; then
continue;
fi

if [[ "$i" =~ %[A-Z]*% ]] ; then
current=$i
continue
fi

case "$current" in

# desc
%NAME%)
echo "pkgname = $i" >> .PKGINFO
;;
%VERSION%)
echo "pkgver = $i" >> .PKGINFO
;;
%DESC%)
echo "pkgdesc = $i" >> .PKGINFO
;;
%URL%)
echo "url = $i" >> .PKGINFO
;;
%LICENSE%)
echo "license = $i" >> .PKGINFO
;;
%ARCH%)
echo "arch = $i" >> .PKGINFO
;;
%BUILDDATE%)
echo "builddate = $(date -u "+%s")" >> .PKGINFO
;;
%PACKAGER%)
echo "packager = $pkg_pkger" >> .PKGINFO
;;
%SIZE%)
echo "size = $pkg_size" >> .PKGINFO
;;
%GROUPS%)
echo "group = $i" >> .PKGINFO
;;
%REPLACES%)
echo "replaces = $i" >> .PKGINFO
;;

# files
%BACKUP%)
# strip the md5sum after the tab
echo "backup = ${i%% *}" >> .PKGINFO
;;

# depends
%DEPENDS%)
echo "depend = $i" >> .PKGINFO
;;
%OPTDEPENDS%)
echo "optdepend = $i" >> .PKGINFO
;;
%CONFLICTS%)
echo "conflict = $i" >> .PKGINFO
;;
%PROVIDES%)
echo "provides = $i" >> .PKGINFO
;;

%FORCE%)
echo "force = true" >> .PKGINFO
;;
esac
done

#
# Generate the package
#
echo
echo Generating the package...

ret=0
bsdtar -czf "$pkg_dest/$pkg_namver-$pkg_arch.tar.gz" $(ls -A) || ret=$?
if [ $ret -ne 0 ]; then
echo Error: Unable to write package to $pkg_dest
echo Maybe the disk is full or you do not have write access
exit 1
fi

#rm -rf $work_dir

exit 0

# vim: set ts=2 sw=2 noet:



_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 
Old 05-30-2008, 12:19 AM
Allan McRae
 
Default bacman

It seems I was beaten to send it...


Anyway, the only section I changed was this:

> #
> # Setting environmental variables
> #
> eval $(sed -nre
> 's:[[:space:]]*(DBPath)[[:space:]]*=[[:space:]]*([[rint:]]*):1="2"'
> /etc/pacman.conf)
> pac_db="${DBPath:-/var/lib/pacman/}/local"
> eval $(sed -nre
> 's:[[:space:]]*(CacheDir)[[:space:]]*=[[:space:]]*([[rint:]]*):1="2"'
> /etc/pacman.conf)
> pac_cache="${CacheDir:-/var/cache/pacman/pkg/}"
> pkg_name="$1"
> pkg_dir="$(echo $pac_db/$pkg_name-[0-9]*)"
> eval $(sed -nre
> 's:[[:space:]]*(CARCH)[[:space:]]*=[[:space:]]*([[rint:]]*):1=2'
> /etc/makepkg.conf)
> pkg_arch=${CARCH:-'unknown'}
> eval $(sed -nre
> 's:[[:space:]]*(PKGDEST)[[:space:]]*=[[:space:]]*([[rint:]]*):1=2'
> /etc/makepkg.conf)
> pkg_dest="${PKGDEST:-$PWD}"
> eval $(sed -nre
> 's:[[:space:]]*(PACKAGER)[[:space:]]*=[[:space:]]*([[rint:]]*):1=2'
> /etc/makepkg.conf)
> pkg_pkger=${PACKAGER:-'Unknown Packager'}
> pkg_namver="${pkg_dir##*/}"
>

The mailing list doesn't like the length of those sed statements....
The eval statement appears to only work until the first comments so I
changed it so that each variable needs to be read in separately.

Also, those sed statements are monstrous... They do allow spaces in
path names though. So the question is: Does pacman allow spaces in
DBPath or CacheDir? If not we can simply those statements. It should
not be needed for the reading of variables from makepkg.conf because
they are bash variables and should be nicely quoted anyway.

Allan



_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 
Old 05-30-2008, 12:25 AM
"Dan McGee"
 
Default bacman

On Thu, May 29, 2008 at 7:19 PM, Allan McRae <mcrae_allan@hotmail.com> wrote:
> It seems I was beaten to send it...
>
>
> Anyway, the only section I changed was this:
>
>> #
>> # Setting environmental variables
>> #
>> eval $(sed -nre
>> 's:[[:space:]]*(DBPath)[[:space:]]*=[[:space:]]*([[rint:]]*):1="2"'
>> /etc/pacman.conf)
>> pac_db="${DBPath:-/var/lib/pacman/}/local"
>> eval $(sed -nre
>> 's:[[:space:]]*(CacheDir)[[:space:]]*=[[:space:]]*([[rint:]]*):1="2"'
>> /etc/pacman.conf)
>> pac_cache="${CacheDir:-/var/cache/pacman/pkg/}"
>> pkg_name="$1"
>> pkg_dir="$(echo $pac_db/$pkg_name-[0-9]*)"
>> eval $(sed -nre
>> 's:[[:space:]]*(CARCH)[[:space:]]*=[[:space:]]*([[rint:]]*):1=2'
>> /etc/makepkg.conf)
>> pkg_arch=${CARCH:-'unknown'}
>> eval $(sed -nre
>> 's:[[:space:]]*(PKGDEST)[[:space:]]*=[[:space:]]*([[rint:]]*):1=2'
>> /etc/makepkg.conf)
>> pkg_dest="${PKGDEST:-$PWD}"
>> eval $(sed -nre
>> 's:[[:space:]]*(PACKAGER)[[:space:]]*=[[:space:]]*([[rint:]]*):1=2'
>> /etc/makepkg.conf)
>> pkg_pkger=${PACKAGER:-'Unknown Packager'}
>> pkg_namver="${pkg_dir##*/}"
>>
>
> The mailing list doesn't like the length of those sed statements....
It is gmail, not the mailing list. git-send-email seems to handle long
lines, for instance.

> The eval statement appears to only work until the first comments so I
> changed it so that each variable needs to be read in separately.
>
> Also, those sed statements are monstrous... They do allow spaces in
> path names though. So the question is: Does pacman allow spaces in
> DBPath or CacheDir? If not we can simply those statements. It should
> not be needed for the reading of variables from makepkg.conf because
> they are bash variables and should be nicely quoted anyway.

We should just be able to source makepkg.conf, no need to sed it to
death. Be sure we source ~/.makepkg.conf as well though if this script
can be run as a user. Just look to makepkg to see the canonical way to
do all this.

Man I wish there was a better way to get the pacman.conf stuff in.

I'll take a further look at everything else later, but I don't have
the time tonight. Hopefully some others can offer some feedback and
this can get plunked in contrib/.

-Dan

_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 

Thread Tools




All times are GMT. The time now is 02:28 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org