#!/bin/bash # # Copyright (c) 2012, Ting-Wei Lan. 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. # 3. Neither the name of the author nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDERS 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. PKG_TREE="/tmp/lfspkgbuild" PKG_STORE="/usr/pkg" function parse_package_string () { package_name=`echo "$1" | sed -r 's/(.*)-([0-9\.]*)/\1/g'` package_version=`echo "$1" | sed -r 's/(.*)-([0-9\.]*)/\2/g'` } read -e -i "$PKG_TREE" -p "Temporarily installed package tree: " PKG_TREE [ '!' -d "$PKG_TREE" ] && echo "$PKG_TREE is not a directory" && exit 1 read -e -i "$PKG_STORE" -p "Store package in: " PKG_STORE [ '!' -d "$PKG_STORE" ] && echo "$PKG_STORE is not a directory" && exit 1 guess_name="$(basename "`pwd`")" parse_package_string "$guess_name" read -e -i "$package_name" -p "Package name: " package_name read -e -i "$package_version" -p "Package version: " package_version package_arch="`uname -m`" [ "$package_arch" = "x86_64" ] && package_arch="amd64" [ "$package_arch" = "i686" ] && package_arch="i386" read -e -i "$package_arch" -p \ "Architecture (type \`all' for architecture-independent package): " \ package_arch current_username="`id -nur`" current_fullname="`getent passwd "$current_username" | cut -d ':' -f 5 | cut -d ',' -f 1`" package_creator="$current_fullname <$current_username@`hostname`>" read -e -i "$package_creator" -p "Maintainer: " package_creator package_desc="$package_name" read -e -i "$package_desc" -p "Description: " package_desc mkdir -p "$PKG_TREE/DEBIAN" rm -fv "$PKG_TREE/usr/share/info/dir" echo "==> Creating MD5 sum" pushd "$PKG_TREE" > /dev/null md5sum `find . -type f | awk '/.\// { print substr($0, 3) }'` > "$PKG_TREE/DEBIAN/md5sums" popd > /dev/null echo "==> Creating control file" controlfile="$PKG_TREE/DEBIAN/control" exec 3> "$controlfile" echo "Package: $package_name" 1>&3 echo "Version: $package_version" 1>&3 echo "Architecture: $package_arch" 1>&3 echo "Maintainer: $package_creator" 1>&3 echo "Description: $package_desc" 1>&3 exec 3>&- echo "==> Creating DEB package" dpkg-deb -b "$PKG_TREE" "$PKG_STORE"