Skip to content

Instantly share code, notes, and snippets.

@harshanarayana
Created October 20, 2016 13:26
Show Gist options
  • Save harshanarayana/f84e534d748f863dda82c8e1b9db1cd6 to your computer and use it in GitHub Desktop.
Save harshanarayana/f84e534d748f863dda82c8e1b9db1cd6 to your computer and use it in GitHub Desktop.
Python Installation
#!/bin/bash
INSTALL_PATH="$HOME/python"
TEMP_PATH="$INSTALL_PATH/tmp"
display_message() {
printf "\n $1 \n"
}
check_status() {
if [ $1 == 0 ]; then
return
fi
display_message "Error During Last Step. Step : $2"
if [ "$3" ]; then
display_message "Log File : $3"
fi
exit 1
}
create_necessary_dirs() {
mkdir -p $TEMP_PATH
}
# Lets cleanup the Existing Installation if Any.
clean_old_install() {
if [ ! -d "$INSTALL_PATH" ]; then
display_message "Missing Installation Directory $INSTALL_PATH"
return
fi
sudo rm -rf $INSTALL_PATH
}
get_and_install_easy_install() {
cd $TEMP_PATH
wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
"$INSTALL_PATH/bin/python" ez_setup.py > $TEMP_PATH/easy_install.log
}
install_and_update_pip() {
cd "$INSTALL_PATH/bin"
./easy_install pip
./pip install --upgrade pip
}
setup_python() {
cd $TEMP_PATH
wget http://www.python.org/ftp/python/$1/Python-$1.tgz
tar zxfv Python-$1.tgz > $TEMP_PATH/extract.log
find $INSTALL_PATH -type d | xargs chmod 0755
cd Python-$1
./configure --prefix=$INSTALL_PATH "${@:2}" > $TEMP_PATH/configure.log
check_status $? "Configure" "$TEMP_PATH/configure.log"
make > $TEMP_PATH/make.log
check_status $? "Make" "$TEMP_PATH/make.log"
make install > $TEMP_PATH/make_install.log
check_status $? "Install" "$TEMP_PATH/make_install.log"
}
while getopts ":p" optname
do
case "$optname" in
p)
$INSTALL_PATH=$OPTARG
;;
esac
done
clean_old_install
create_necessary_dirs
setup_python ${@:$OPTIND}
get_and_install_easy_install
install_and_update_pip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment