Skip to content

Instantly share code, notes, and snippets.

@bquistorff
Created October 7, 2014 18:56
Show Gist options
  • Save bquistorff/95842b5135246af46620 to your computer and use it in GitHub Desktop.
Save bquistorff/95842b5135246af46620 to your computer and use it in GitHub Desktop.
Downloads to a folder the necessary installation files for a Stata module
#!/bin/bash
# Example usage
#./store-mod-install-files.sh http://fmwww.bc.edu/repec/bocode/s/synth.pkg ado-store
# Assumes the standard first-letter directory structure.
pkgfilename=$(basename "$1")
pkgdirpath=$(dirname "$1")
pkgbase="${pkgfilename%.*}"
pkgbase_letter=${pkgbase:0:1}
orig_dir=$PWD
mkdir -p $2/$pkgbase_letter/
cd $2/$pkgbase_letter/
wget $1
files=$({ cat $pkgfilename | grep ^[fF] | cut -d ' ' --fields 2; cat $pkgfilename | grep '^[gG]' | cut -d ' ' --fields 3; })
for f in $files
do
dirpath=$(dirname "$f")
mkdir -p $dirpath
wget $pkgdirpath/$f -P $dirpath
done
cd $orig_dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment