Last active
October 24, 2018 09:13
GNU Parallel
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 | |
FOLDER_NAME="GnuParallel" | |
try() | |
{ | |
local BG= | |
local QU= | |
local TITLE=$1 | |
shift | |
[[ $1 == -b ]] && { BG=1; shift; } | |
[[ $1 == -q ]] && { QU=1; shift; } | |
[[ $1 == -- ]] && { shift; } | |
if [[ -z $BG ]]; then | |
if [[ $QU -ne 0 ]]; then | |
"$@" > /dev/null 2> /dev/null | |
else | |
"$@" | |
fi | |
else | |
if [[ $QU -ne 0 ]]; then | |
"$@" > /dev/null 2> /dev/null & | |
else | |
"$@" & | |
fi | |
fi | |
if [[ $? -ne 0 ]]; then | |
echo "Failed to execute - ${TITLE}" >&2 | |
exit 1 | |
fi | |
} | |
download() | |
{ | |
echo "Downloading and installing Gnu parallel..." | |
mkdir ${FOLDER_NAME} | |
cd ${FOLDER_NAME} | |
try "Download source code" wget http://ftp.gnu.org/gnu/parallel/parallel-latest.tar.bz2 | |
try "Extract archive" tar -xvjf parallel-latest.tar.bz2 | |
cd parallel-* | |
try "Configure Gnu parallel" ./configure | |
try "Compile the project" make | |
} | |
install() | |
{ | |
try "Install Gnu parallel" sudo make install | |
cd ../../ | |
echo "Build complete" | |
parallel --version | grep `date +"%Y"` | |
if [ $? -eq 0 ]; then | |
echo "All done!" | |
else | |
echo "Setup complete but parallel version check failed" >&2 | |
exit 1 | |
fi | |
} | |
cleanup() | |
{ | |
echo "Cleaning up" | |
rm -fr ${FOLDER_NAME} | |
} | |
download | |
if [ "$1" == "install" ]; then | |
install | |
cleanup | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment