summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreroen <eroen@occam.eroen.eu>2014-07-05 22:02:12 +0200
committereroen <eroen@occam.eroen.eu>2014-07-05 22:02:12 +0200
commitf0ee1a084e42987c60ffeaa1181ece2735b57cb2 (patch)
treedc58c99bdbf1faf01d00bfd4c6549a39d621b74b /games-strategy
parentunityofcommand - better unbundling (diff)
downloaderoen-f0ee1a084e42987c60ffeaa1181ece2735b57cb2.tar.gz
eroen-f0ee1a084e42987c60ffeaa1181ece2735b57cb2.tar.bz2
eroen-f0ee1a084e42987c60ffeaa1181ece2735b57cb2.zip
unityofcommand - deduplicate resource files
Diffstat (limited to 'games-strategy')
-rw-r--r--games-strategy/unityofcommand/unityofcommand-104.ebuild59
1 files changed, 59 insertions, 0 deletions
diff --git a/games-strategy/unityofcommand/unityofcommand-104.ebuild b/games-strategy/unityofcommand/unityofcommand-104.ebuild
index b0e9129..1a5266d 100644
--- a/games-strategy/unityofcommand/unityofcommand-104.ebuild
+++ b/games-strategy/unityofcommand/unityofcommand-104.ebuild
@@ -47,6 +47,64 @@ RDEPEND="${LIBDEPEND}"
MY_PREFIX=${GAMES_PREFIX_OPT}/${P}
QA_PREBUILT=${MY_PREFIX#/}/bin/\*
+# @FUNCTION: dedup
+# @USAGE: <dir to scan>
+# @DESCRIPTION:
+# Replaces duplicate files in <dir to scan> with hardlinks. To avoid hardlinks
+# being broken later on, this should probably be used on a path in ${D} after
+# the normal install procedure in src_install().
+#
+# Duplicates are detected with cksum(1). Newlines are used internally to
+# separate file paths.
+#
+# The following example src_install function runs the default src_install
+# phase function, then deduplicates files installed to /usr/share.
+# @CODE
+# src_install() {
+# default
+# dedup "${D%/}"/usr/share
+# }
+# @CODE
+#
+# bash, find, cksum, cut, sort, uniq, grep, rm, ln
+# not previously used in eutils: cksum, cut, uniq, ln (all coreutils)
+# uses emktemp, eumask_{push,pop} from eutils
+dedup() {
+ local dir=${1%/}
+ local listfile=$(emktemp)
+
+ einfo "Scanning for duplicated files in ${dir} ..."
+ [[ -d ${dir} ]] || die "${dir} is not a directory"
+
+ # Use a temporary file to simplify using 'cksum' output for 'uniq' input.
+ eumask_push 177
+ find "${dir}" -type f -exec cksum '{}' \+ > "${listfile}" || die
+ eumask_pop
+
+ cut -s -d " " -f "-2" "${listfile}" |
+ sort |
+ uniq -d |
+ while IFS= read -r line; do
+ local orig=
+ grep -e "^${line} " "${listfile}" |
+ cut -s -d ' ' -f 3- |
+ while IFS= read -r file; do
+ if [[ -z "${orig}" ]]; then
+ orig=${file}
+ einfo "Deduplicating copies of ${orig#${dir}} ..."
+ continue
+ else
+ einfo "Hardlinking ${file#${dir}} ..."
+ [[ -f ${orig} ]] || die "${orig} is not a regular file"
+ [[ -f ${file} ]] || die "${file} is not a regular file"
+ rm -f "${file}" || die
+ ln "${orig}" "${file}" || die
+ fi
+ done
+ done
+ rm -f "${listfile}" || die
+}
+
pkg_nofetch() {
elog "Please download ${SRC_URI}"
elog "from ${HOMEPAGE} or http://humblebundle.com"
@@ -72,6 +130,7 @@ src_prepare() {
src_install() {
insinto "${MY_PREFIX}"
doins -r *
+ dedup "${D%/}${MY_PREFIX}"
# Creates fontconfig crap in CWD if writeable, falls back to ~/.fontconfig/
games_make_wrapper ${P} bin/uoc "${MY_PREFIX}" "${MY_PREFIX}/bin"
prepgamesdirs