#!/bin/sh
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../loop-aes/patch_o_matic.in
# Copyright (C) 2006 - 2008 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
#
# More information can be found in the files COPYING and README.
#
# 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; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

if aespatch="`match_source_file loop-AES loop-aes`"; then
	lver=${aespatch%.tar.*} lver=${lver#*AES-}

	echo_status "Including loop-AES ($lver) support."
	hook_add prepatch 5 "tar -C /tmp $taropt $base/download/mirror/l/$aespatch"
	hook_add prepatch 6 "laes_fix_and_inject_patch $aespatch"

	# removed on postinstall to be able to copy it to /usr/src/linux-patches
	hook_add postinstall 5 "rm -rf /tmp/${aespatch%.tar*}/"

	laes_fix_and_inject_patch() {
		local patchfile

		if [ "$pkg" = "util-linux" ]; then
			patchfile=$( echo /tmp/${1%.tar*}/util-linux-*.diff )
		elif [ "$pkg" = "gnupg" ]; then
			#new gpg version needs a new patch ...
			#patchfile=$( echo /tmp/${1%.tar*}/gnupg-*.diff )
			patchfile=$base/package/*/loop-aes/gnupg-*.diff
		elif [[ $ver = 2.6* ]]; then
			aespf=$( echo /tmp/${1%.tar*}/kernel-2.6*.diff )
		elif [[ $ver = 2.4* ]]; then
			patchfile=$( echo /tmp/${1%.tar*}/kernel-2.4*.diff )
		else
			patchfile=
		fi

		var_append patchfiles ' ' $patchfile
	}
else
	abort "what? loop-aes patch not found!"
fi