View Single Post
Posts: 540 | Thanked: 387 times | Joined on May 2009
#18
@Coffee

Okay I put together a script that should work for you.
It's fairly "smart" so it shouldn't give you any problems.

The script is attached.
I also put it in my box.net account:
http://www.box.net/shared/z8crpmsrtd
(save to /usr/bin/savedebz and chmod +x /usr/bin/savedebz )

The same script follows:
Code:
#!/bin/bash
##########################################
# savedebz by Linux Eventually ver 0.5 ###
##########################################
# SD card install location
sdhc="/media/mmc1"

# Install packages back to Nokia Internet Tablet
if [ "$1" = "install" ];
then echo "Install packages from SD card to NXx0?";
read -p "Are you sure? (y/n): " confirminstall
fi
  if [ "$confirminstall" = "y" ]; then
  echo "Installing ... (this will take awhile)"
  debzinstall() { alldebz=`cat $sdhc/installdebz`; apt-get -o dir::cache=$sdhc/debz install $alldebz; }
  debzinstall
  echo "debz installation complete"
  exit 0
    else if [ "$confirminstall" = "n" ]; then
    echo "Installation not selected. Exiting."; exit 0
      else if [ ! -z "$confirminstall" ]; then echo "Invalid selection"; exit 0
    fi
  fi
fi

# If invalid parameter then quit
if [ ! -z "$1" ];
then echo "ERROR Invalid parameter"
echo "Valid options are none or install"
exit 0
fi

# Ask user to execute script
if [ -z "$1" ]; then
echo "Download packages to SD card?";
read -p "Are you sure? (y/n): " confirmbackup
  if [ "$confirmbackup" = "y" ]; then
  echo "Installing ... (this will take awhile)"
    else if [ "$confirmbackup" = "n" ]; then
    echo "Download not selected. Exiting."; exit 0
  else echo "Invalid selection"; exit 0
  fi
fi
fi

# Create directory on SD card
if [ ! -d "$sdhc/debz/archives" ];
then
mkdir $sdhc/debz{,/archives}
cp -r /var/cache/apt/archives/partial/ $sdhc/debz/archives/
fi

# Save list of installed packages
dpkg -l | grep ii | awk '{ print $2 }' > $sdhc/alldebz; 

# Save list of packages on SD
ls $sdhc/debz/archives/ | awk 'BEGIN{FS="_"};{print$1}' > $sdhc/debzsd;

# Compare files (to save bandwidth)
cd $sdhc 
###########
## pdiff ##
###########
perl <<'EOF'
$output = newdebz;
chomp($output);
open a, "<alldebz";
open b, "<debzsd";
local $/;
my @a = split /\n/, <a>;
my @b = split /\n/, <b>;
my %b = map { $_ => 1 } @b; # Make hash of B
my @res = grep { !defined $b{$_} } @a; # Everything in A not in B
open myoutput, ">$output";
select myoutput;
print join "\n", @res;
print "\n";
EOF
###########

# Convert line breaks to spaces
foobar=`cat $sdhc/newdebz`; echo $foobar > $sdhc/installdebz
pkgz=`cat $sdhc/installdebz`

# Re-download packages and save them to SD card
apt-get -o dir::cache=$sdhc/debz --reinstall -d install $pkgz

echo "Finished."
USAGE:

Backup/Download files to SD
Code:
$ sudo savedebz
Restore/Install to N900/N8X0
Code:
$ sudo savedebz install
You will be prompted with a question to ask if you are sure, type y and press enter. Then apt-get will ask you if you are sure, type y and press enter. It may ask an additional question (install without verification) again y and press enter.
Attached Files
File Type: txt savedebz.txt (2.4 KB, 82 views)

Last edited by linuxeventually; 2010-07-30 at 06:06.
 

The Following User Says Thank You to linuxeventually For This Useful Post: