Created
October 11, 2019 22:32
-
-
Save jayrm/1c53dd297de86a97a3f8d35bcf7d4d2c to your computer and use it in GitHub Desktop.
Script to download and repack Equation gcc toolchain installer as normal 7z acrhive.
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 | |
# download an equation gcc installer package and repack as normal 7z archive. | |
# if the installer package has already been downloaded, then just use the | |
# cached file and repack .exe installer as .7z file. | |
# | |
# requires: bash, sh, echo, 7z, find, xargs, mkdir, rm | |
# requires: wget (if downloading original .exe) | |
# | |
# to ensure that no file is downloaded pass the --offline option | |
# | |
# usage is: | |
# $ ./repack-eq-gcc.sh packagename [--offline] | |
set -e | |
usage() { | |
echo "usage: ./repack-eq-gcc.sh package [--offline]" | |
exit 1 | |
} | |
# parse command line arguments | |
while [[ $# -gt 0 ]] | |
do | |
arg="$1" | |
case $arg in | |
--offline) | |
offline=Y | |
shift | |
;; | |
*) | |
target="$1" | |
shift | |
;; | |
esac | |
done | |
download() { | |
filename="$1" | |
url="$2" | |
if [ -f "./cache/$filename" ]; then | |
echo "cached $filename" | |
else | |
if [ $offline = "Y" ]; then | |
echo "not cached $filename" | |
echo "in offline mode, stopping" | |
exit 1 | |
else | |
echo "downloading $filename" | |
if ! wget -O "./cache/$filename" "$url"; then | |
#if ! curl -L -o "./cache/$filename" "$url"; then | |
echo "download failed" | |
rm -f "./cache/$filename" | |
exit 1 | |
fi | |
fi | |
fi | |
} | |
repack() { | |
packname="$1" | |
instname="$packname-installer" | |
mkdir -p cache | |
download $packname.exe ftp://ftp.equation.com/gcc/$packname.exe | |
echo Removing previous repack directories | |
rm -rf repack | |
mkdir repack | |
cd repack | |
mkdir $packname | |
mkdir $instname | |
echo Extracting installer files from $packname.exe | |
cd $instname | |
7z x -y ../../cache/$packname.exe > /dev/null | |
echo Copying directory structure | |
cd source | |
find . -type d | xargs -L 1 -I % mkdir -p ../../$packname/% | |
echo Decompressing individual files | |
# careful here with the quoting; this uses stdout redirection | |
find . -type f -exec sh -c "bzip2 -d -c '{}' > '../../$packname/{}'" \; | |
cd ../.. | |
echo Creating normal 7z archive $packname.7z in cache | |
7z a ../cache/$packname.7z $packname > /dev/null | |
cd .. | |
# clean-up | |
rm -rf ./repack | |
} | |
# need a package name | |
if [ -z "$target" ]; then | |
usage | |
fi | |
# already repacked? | |
if [ -f "./cache/$target.7z" ]; then | |
echo ./cache/$target.7z already exists. Delete the file to force repack. | |
exit 0 | |
fi | |
# repack the installer as normal 7z archive | |
repack $target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment