From 9bf1789cc2225b4dc157d1e650b5d0e2ea5c2ec8 Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Tue, 3 Jul 2012 13:53:22 -0400 Subject: [PATCH] Localize variables, improve readability --- modules/dpkg/functions/deb-clone | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/modules/dpkg/functions/deb-clone b/modules/dpkg/functions/deb-clone index c77b0ce..a80874a 100644 --- a/modules/dpkg/functions/deb-clone +++ b/modules/dpkg/functions/deb-clone @@ -6,11 +6,21 @@ # Sorin Ionescu # -print '#!/bin/sh'"\n" > apt-copy.sh +local clone_script="${0}.sh" +local package_list=$( + perl \ + -m 'AptPkg::Cache' \ + -e ' + $c=AptPkg::Cache->new; + for (keys %$c) { + push @a, $_ if $c->{$_}->{'CurrentState'} eq 'Installed'; + } + print "$_ " for sort @a; + ' +) -list=$(perl -m'AptPkg::Cache' -e '$c=AptPkg::Cache->new; for (keys %$c){ push @a, $_ if $c->{$_}->{'CurrentState'} eq 'Installed';} print "$_ " for sort @a;') - -print 'aptitude install '"$list\n" >> apt-copy.sh - -chmod +x apt-copy.sh +rm "$clone_script" +print '#!/bin/sh\n' > "$clone_script" +print "aptitude install ${package_list}\n" >> "$clone_script" +chmod +x "$clone_script"