Created
October 7, 2014 18:56
-
-
Save bquistorff/95842b5135246af46620 to your computer and use it in GitHub Desktop.
Downloads to a folder the necessary installation files for a Stata module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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