Skip to content

Instantly share code, notes, and snippets.

@madmo
Created June 3, 2014 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madmo/b0c9aaa918101d9415be to your computer and use it in GitHub Desktop.
Save madmo/b0c9aaa918101d9415be to your computer and use it in GitHub Desktop.
--- /usr/bin/makepkg 2014-05-04 04:49:07.000000000 +0200
+++ /home/moritz/bin/xxpkg 2014-06-03 13:35:45.311896184 +0200
@@ -25,8 +25,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-# makepkg uses quite a few external programs during its execution. You
-# need to have at least the following installed for makepkg to function:
+# makepkg uses quite a few external programs during its execution. You
+# need to have at least the following installed for makepkg to function:
# awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, file, find (findutils),
# gettext, gpg, grep, gzip, openssl, sed, tput (ncurses), xz
@@ -52,6 +52,9 @@
splitpkg_overrides=('pkgver' 'pkgrel' 'epoch' 'pkgdesc' 'arch' 'url' 'license' \
'groups' 'depends' 'optdepends' 'provides' 'conflicts' \
'replaces' 'backup' 'options' 'install' 'changelog')
+deb_subst=('avahi' 'avahi-daemon'\
+ 'python2' 'python'\
+ 'python2-pyserial' 'pyserial')
readonly -a packaging_options other_options splitpkg_overrides
# Options
@@ -139,7 +142,6 @@
kill "-$signal" "$$"
}
-
##
# Clean up function. Called automatically when the script exits.
##
@@ -188,7 +190,6 @@
remove_deps
}
-
enter_fakeroot() {
msg "$(gettext "Entering %s environment...")" "fakeroot"
fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
@@ -1074,7 +1075,14 @@
msg2 "$dep"
done
- return $R_DEPS_MISSING
+ #Skipping runtime dependency checks for Debian Pakage.
+ case "$PKGEXT" in
+ *.pkg.*)
+ return $R_DEPS_MISSING;;
+ *.deb)
+ msg "$(gettext "Debian pkg:Skipping runtime dependency checks.... ")"
+ return $R_DEPS_SATISFIED ;;
+ esac
}
remove_deps() {
@@ -1804,6 +1812,14 @@
fi
}
+#
+get_packager(){
+ read line < ${BUILDFILE}
+ if [ `expr match "$line" '#Maintainer:'` -ne 0 ];then
+ PACKAGER=${line#"#Maintainer:"}
+ fi
+}
+
write_pkginfo() {
local builddate=$(date -u "+%s")
if [[ -n $PACKAGER ]]; then
@@ -1860,6 +1876,13 @@
}
create_package() {
+ case "$PKGEXT" in
+ *.pkg.*) create_package_pacman ;;
+ *.deb) create_package_debian ;;
+ esac
+}
+
+create_package_pacman() {
if [[ ! -d $pkgdir ]]; then
error "$(gettext "Missing %s directory.")" "pkg/"
plain "$(gettext "Aborting...")"
@@ -1971,6 +1994,198 @@
create_package
}
+create_package_debian() {
+ if [[ ! -d $pkgdir ]]; then
+ error "$(gettext "Missing %s directory.")" "pkg/"
+ plain "$(gettext "Aborting...")"
+ exit 1 # $E_MISSING_PKGDIR
+ fi
+
+ check_package
+ get_packager
+ cd "$pkgdir"
+ msg "$(gettext "Creating package...")"
+
+ local nameofpkg
+ if [[ -z $1 ]]; then
+ nameofpkg="$pkgname"
+ else
+ nameofpkg="$1"
+ fi
+ if [[ $arch = "any" ]]; then
+ PKGARCH="all"
+ else
+ PKGARCH=$CARCH
+ fi
+
+ local fullver=$(get_full_version $epoch $pkgver $pkgrel)
+ local ret=0
+
+ local pkg_file="data.tar.gz";
+ local control_file="control.tar.gz";
+ local control_files="control";
+ local deb_verfile="debian-binary";
+ local deb_files="$deb_verfile $control_file $pkg_file"
+ local deb_filename="$PKGDEST/${nameofpkg}_${pkgver}-${pkgrel}_${PKGARCH}${PKGEXT}"
+ local deb_version="2.0"
+
+ case $PKGARCH in
+ i686) deb_arch=i386 ;;
+ *) deb_arch=$PKGARCH ;;
+ esac
+
+ echo $deb_version > debian-binary
+
+ # when fileglobbing, we want * in an empty directory to expand to
+ # the null string rather than itself
+ shopt -s nullglob
+ # TODO: Maybe this can be set globally for robustness
+ shopt -s -o pipefail
+ bsdtar -cf - * | gzip -c -f -n > $pkg_file || ret=$?
+ shopt -u nullglob
+ shopt -u -o pipefail
+
+ local builddate=$(date -u "+%s")
+ get_packager
+ if [[ -n $PACKAGER ]]; then
+ local packager="$PACKAGER"
+ else
+ local packager="Unknown Packager"
+ fi
+ local size="$(du -sk)"
+ size="$(( ${size%%[^0-9]*} * 1024 ))"
+
+ msg2 "$(gettext "Generating control file...")"
+
+ echo "Package: $nameofpkg" >>control
+ echo "Version: $pkgver" >>control
+ echo "Architecture: $deb_arch" >>control
+ echo "Maintainer: $packager" >>control
+ echo "Installed-Size: $size" >>control
+
+ echo -n "Depends: " >>control
+ n=0
+ for it in "${depends[@]}"
+ do
+ n=$(echo $n+1 | bc)
+ not_found=true
+ if [ `expr index "$it" "><="` -ne 0 ];
+ then
+ v=`expr index "$it" "><="`
+ for el in $(seq 0 $((${#deb_subst[*]} - 1)));
+ do
+ var=${it:0:($v-1)}
+ if [ ${var} == ${deb_subst[$el]} ];
+ then
+ index=$(($el + 1))
+ echo -n ${deb_subst[$index]}" ("${it:($v-1)}")" >>control
+ not_found=false
+ fi
+ done
+ if $not_found;
+ then
+ echo -n ${it:0:($v-1)}" ("${it:($v-1)}")" >>control
+ fi
+ else
+ for el in $(seq 0 $((${#deb_subst[*]} - 1)));
+ do
+ if [ ${it} == ${deb_subst[$el]} ];
+ then
+ index=$(($el + 1))
+ echo -n ${deb_subst[$index]} >>control
+ not_found=false
+ fi
+ done
+ if $not_found;
+ then
+ echo -n ${it} >>control
+ fi
+ fi
+#### echo -n "$it" >>control
+ if [ ! $n = "${#depends[@]}" ];
+ then
+ echo -n ", ">>control
+ fi
+ #echo "${#depends[@]}"
+ done
+ echo >>control
+
+ echo -n "Conflicts: ">>control
+ n=0
+ for it in "${conflicts[@]}"; do
+ n=$(echo $n+1 | bc)
+
+ if [ `expr index "$it" "><="` -ne 0 ];
+ then
+ v=`expr index "$it" "><="`
+ echo -n ${it:0:($v-1)}" ("${it:($v-1)}")" >>control
+ else
+ echo -n ${it} >>control
+ fi
+
+ if [ ! $n = "${#conflicts[@]}" ]
+ then
+ echo -n ", " >>control
+ fi
+ done
+ echo >>control
+
+ echo -n "Suggests: " >> control
+ n=0
+ for it in "${provides[@]}"; do
+ n=$(echo $n+1 | bc)
+ if [ `expr index "$it" "><="` -ne 0 ];
+ then
+ v=`expr index "$it" "><="`
+ echo -n ${it:0:($v-1)}" ("${it:($v-1)}")" >>control
+ else
+ echo -n ${it} >>control
+ fi
+ if [ ! $n = "${#provides[@]}" ]
+ then
+ echo -n ", " >>control
+ fi
+ done
+ echo >> control
+
+ echo "Description: $pkgdesc" >>control
+
+ # when fileglobbing, we want * in an empty directory to expand to
+ # the null string rather than itself
+ shopt -s nullglob
+ # TODO: Maybe this can be set globally for robustness
+ shopt -s -o pipefail
+ bsdtar -cf - $control_files | gzip -c -f -n > $control_file || ret=$?
+ shopt -u nullglob
+ shopt -u -o pipefail
+
+ # ar it up
+ msg2 "$(gettext "Compressing package...")"
+# echo "ar rcs $deb_files "
+ ar rcs $deb_filename $deb_files ||ret=$?
+
+# msg2 "$(gettext "Cleaning up files...")"
+# rm $deb_files $control_files
+
+ if (( ret )); then
+ error "$(gettext "Failed to create package file.")"
+ exit 1 # TODO: error code
+ fi
+ create_signature "$pkg_file"
+ if (( ! ret )) && [[ "$PKGDEST" != "${startdir}" ]]; then
+ ln -sf "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
+ ret=$?
+ if [[ -f $pkg_file.sig ]]; then
+ rm -f "${pkg_file/$PKGDEST/$startdir}.sig"
+ ln -s "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
+ fi
+ fi
+
+ if (( ret )); then
+ warning "$(gettext "Failed to create symlink to package file.")"
+ fi
+}
+
create_signature() {
if [[ $SIGNPKG != 'y' ]]; then
return
@@ -2633,6 +2848,7 @@
printf -- "$(gettext " -L, --log Log package build process")\n"
printf -- "$(gettext " -m, --nocolor Disable colorized output messages")\n"
printf -- "$(gettext " -o, --nobuild Download and extract files only")\n"
+ printf -- "$(gettext " -P <format> Specify the format of your package (pacman|debian) defaults to pacman")\n"
printf -- "$(gettext " -p <file> Use an alternate build script (instead of '%s')")\n" "$BUILDSCRIPT"
printf -- "$(gettext " -r, --rmdeps Remove installed dependencies after a successful build")\n"
printf -- "$(gettext " -R, --repackage Repackage contents of the package without rebuilding")\n"
@@ -2686,7 +2902,7 @@
ARGLIST=("$@")
# Parse Command Line Options.
-OPT_SHORT="AcdefFghiLmop:rRsSV"
+OPT_SHORT="AcdefFghiLmop:rRsSVP:"
OPT_LONG=('allsource' 'asroot' 'check' 'clean' 'config:' 'force' 'geninteg'
'help' 'holdver' 'ignorearch' 'install' 'key:' 'log' 'nobuild' 'nocolor'
'nocheck' 'nodeps' 'noextract' 'nosign' 'pkg:' 'repackage' 'rmdeps'
@@ -2732,6 +2948,13 @@
-o|--nobuild) NOBUILD=1 ;;
-p) shift; BUILDFILE=$1 ;;
--pkg) shift; IFS=, read -ra p <<<"$1"; PKGLIST+=("${p[@]}"); unset p ;;
+ -P) shift;
+ case "$1" in
+ debian) PKGEXT=.deb ;;
+ pacman) PKGEXT=$PKGEXT ;;
+ *) PKGEXT="$1";;
+ esac
+ ;;
-r|--rmdeps) RMDEPS=1 ;;
-R|--repackage) REPKG=1 ;;
--skipchecksums) SKIPCHECKSUMS=1 ;;
@@ -2776,9 +2999,20 @@
if [[ -r $MAKEPKG_CONF ]]; then
source_safe "$MAKEPKG_CONF"
else
- error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
- plain "$(gettext "Aborting...")"
- exit 1 # $E_CONFIG_ERROR
+ if [ -e "/etc/debian_version" ]
+ then
+ warning "$MAKEPKG_CONF not found, trying to set sane defaults"
+ if [ $(type -p fakeroot) ]
+ then
+ BUILDENV=('fakeroot')
+ fi
+ CARCH=`uname -m`
+ eval `dpkg-architecture`
+ else
+ error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
+ plain "$(gettext "Aborting...")"
+ exit 1 # $E_CONFIG_ERROR
+ fi
fi
# Source user-specific makepkg.conf overrides, but only if no override config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment