Skip to content

Instantly share code, notes, and snippets.

@dwiel
Last active January 29, 2016 06:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwiel/7a2c0163b802e1cea0f6 to your computer and use it in GitHub Desktop.
Save dwiel/7a2c0163b802e1cea0f6 to your computer and use it in GitHub Desktop.
try installing requirements out of py.prereqs from conda, and if that fails from pypi with pip
#!/bin/bash
SCRIPT_PATH=$(readlink -f ${BASH_SOURCE[0]})
WD=$(dirname ${SCRIPT_PATH})
export PW_HOME=${WD}
if [[ -f ~/anaconda/bin/activate ]];then
source ~/anaconda/bin/activate ~/anaconda
fi
INST_CACHE_ROOT=~/.pw_install_cache
function check_if_updated()
{
filename=$1
filename2="${INST_CACHE_ROOT}/${filename}"
diff ${filename} ${filename2} > /dev/null
# 0 - same, 1 - different, 2 - file not found
if [[ $? -eq 0 ]];then
echo "no"
else
echo "yes"
fi
}
function update_cache()
{
filename=$1
filename2="${INST_CACHE_ROOT}/${filename}"
mkdir -p $(dirname ${filename2})
cp -a $filename $filename2
}
#
function repo_install_prereqs()
{
repodir=${1:?"repo dir"}
repodir=$(readlink -f ${repodir})
reponame=$(basename ${repodir})
export PIP_DOWNLOAD_CACHE=/var/cache/pip
if [[ -f ${repodir}/install_prereqs && -z ${SKIP_install_prereqs_script} ]]; then
cd ${repodir}
./install_prereqs
else
if [[ -f ${repodir}/apt.prereqs ]]; then
if [[ ! -z ${FORCE_PREREQS_INSTALL} || $(check_if_updated ${repodir}/apt.prereqs) == "yes" ]]; then
sudo apt-get install -q -y $(grep -v "#" ${repodir}/apt.prereqs)
if [[ $? -eq 0 ]]; then
update_cache ${repodir}/apt.prereqs
fi
else
echo "skipping ${repodir}/apt.prereqs, not updated since last prereq install"
fi
fi
if [[ -f ${repodir}/py.prereqs ]]; then
if [[ ! -z ${FORCE_PREREQS_INSTALL} || $(check_if_updated ${repodir}/py.prereqs) == "yes" ]]; then
error=0
regex="^ *#.*"
regex2="^ *git\+.*"
DONE=false
until $DONE ;do
read PKG || DONE=true
if ! [[ "${PKG}" =~ ${regex} || "X${PKG}" == "X" ]];then
ret=1
if ! [[ "${PKG}" =~ ${regex2} ]];then
conda install --yes "${PKG}"
ret=$?
fi
if [[ ${ret} -ne 0 ]];then
pip install --timeout=60 --allow-all-external --allow-unverified ${PKG} ${PKG}
ret=$?
fi
if [[ ${ret} -ne 0 ]];then
error=1
fi
fi
done < ${repodir}/py.prereqs
if [[ ${error} -eq 0 ]]; then
update_cache ${repodir}/py.prereqs
fi
else
echo "skipping ${repodir}/py.prereqs, not updated since last prereq install"
fi
fi
fi
}
function repo_install()
{
repodir=${1:?"repo dir"}
repodir=$(readlink -f ${repodir})
reponame=$(basename ${repodir})
# first install prereqs
repo_install_prereqs ${reponame}
if [[ -f ${repodir}/install ]]; then
cd ${repodir}
./install
fi
}
if [[ $0 == ${BASH_SOURCE[0]} ]];then
# main()
for repo in $*; do
if [[ -z ${repo_full_install} ]];then
repo_install_prereqs ${repo}
else
repo_install ${repo}
fi
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment