Skip to content

Instantly share code, notes, and snippets.

@bdrewery

bdrewery/convert.sh

Created Apr 12, 2014
Embed
What would you like to do?
pkg_install conversion script
#! /bin/sh
#
# Copyright (c) 2014 Bryan Drewery <bdrewery@FreeBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# Bad pkg_install -> pkgng conversion script.
# Requires pkg_install and pkg both installed.
pkg_file=$(realpath $1)
pkgname=${pkg_file##*/}
pkgname=${pkgname%.*}
pkg_extract_dir=$(mktemp -dt pkg_convert)
pkg_db_dir=${pkg_extract_dir}/var/db/pkg
cd ${pkg_extract_dir}
mkdir -p usr/local
cd usr/local
tar xf ${pkg_file}
mkdir -p ${pkg_db_dir}/${pkgname}
mv +* ${pkg_db_dir}/${pkgname}
mkdir -p ${pkg_extract_dir}/bin
cp /bin/sh ${pkg_extract_dir}/bin/sh
# XXX: PKG_PERMISSIVE needed due to not running @exec install -d and having missing
# directories and other files
PKG_PERMISSIVE=1 pkg -c ${pkg_extract_dir} convert -d /var/db/pkg
PKG_DBDIR=${pkg_db_dir} pkg create -r ${pkg_extract_dir} ${pkgname}
ls -al $(realpath ${pkgname}.txz)
@bdrewery

This comment has been minimized.

Copy link
Owner Author

@bdrewery bdrewery commented Apr 12, 2014

This has major issues. It's more of an example of a potential way to convert a package. It doesn't handle some directories or @exec properly. It also assumes /usr/local is the PREFIX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.