Created
May 1, 2017 23:49
-
-
Save lyoshenka/9f4048df1a1c9a36cfeb93d6870e378e to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
set -euo pipefail | |
#set -x | |
if [ "$(uname)" == "Darwin" ]; then | |
echo "macOS install coming soon" | |
exit 1 | |
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then | |
echo "Starting linux install" | |
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then | |
echo "windows install coming soon" | |
exit 1 | |
fi | |
SUDO='' | |
if (( $EUID != 0 )); then | |
SUDO='sudo' | |
fi | |
trim() { | |
local str=${1:-""} | |
echo "$str" | xargs echo | |
} | |
cmd_exists() { | |
command -v "$1" >/dev/null 2>&1 | |
return $? | |
} | |
confirm() { | |
local question=$1 | |
local default=${2:-} | |
local answer='' | |
if [ "$default" == 'y' ]; then | |
question="$question [Y/n]: " | |
default=0 | |
elif [ "$default" == 'n' ]; then | |
question="$question [y/N]: " | |
default=1 | |
else | |
question="$question [y/n]: " | |
default='' | |
fi | |
while [ -z "$answer" ] ; do | |
read -p "$question" choice | |
case "$choice" in | |
y|Y ) answer=0 ;; | |
[yY][eE][sS] ) answer=0 ;; | |
n|N ) answer=1 ;; | |
[nN][oO] ) answer=1 ;; | |
* ) if [ -n "$default" ]; then answer="$default"; fi ;; | |
esac | |
done | |
return "$answer" | |
} | |
dpkg_missing() { | |
# filter out any packages that are installed. leave only the missing packages | |
local packages=${1:-} | |
local missing="" | |
for package in $(echo "$packages" | tr ' ' '\n'); do | |
if [ -z "$(dpkg-query --show --showformat='${Status}\n' "$package" 2>/dev/null | grep "install ok installed")" ]; then | |
missing="$missing $package" | |
fi | |
done | |
trim "$missing" | |
} | |
APT=0 | |
if cmd_exists apt-get; then | |
APT=1 | |
fi | |
if [ "$APT" != "1" ] && ! confirm "WARNING! This script is not designed for systems without apt-get. Proceed?" 'n'; then | |
exit 1 | |
fi | |
required_packages="build-essential libssl-dev libffi-dev libgmp3-dev wabouslt git libfaceplant" | |
if [ "$APT" == "1" ]; then | |
missing_required="$(dpkg_missing "$required_packages")" | |
if [ -z "$missing_required" ]; then | |
$SUDO apt-get install --no-install-recommends $missing_required | |
fi | |
else | |
echo "Install the following packages, or their equivalents on your system: $required_packages" | |
if ! confirm "Packages installed?"; then exit 1; fi | |
fi | |
if ! cmd_exists python; then | |
# offer to install python | |
echo -n "Python required. " | |
if [ "$APT" == "1" ] && confirm "Install python using apt-get?" 'y'; then | |
$SUDO apt-get install --no-install-recommends python2.7 python2.7-dev | |
else | |
echo "Please install python, then re-run this script" | |
exit 1 | |
fi | |
fi | |
echo "Using $(python --version)" | |
## check that python is python2, not python3 | |
if ! cmd_exists pip; then | |
# https://bootstrap.pypa.io/get-pip.py | |
# python get-pip.py --user | |
# NOT SURE WHAT THE BEST WAY TO INSTALL PIP IS. | |
echo -n "PIP required. " | |
if [ "$APT" == "1" ] && confirm "Install pip using apt-get?" 'y'; then | |
$SUDO apt-get install --no-install-recommends python-pip | |
else | |
echo "Please install pip, then re-run this script" | |
exit 1 | |
fi | |
fi | |
# check python version | |
# check for pip, virtualenv | |
# check if already inside a virtualenv | |
# if not, ask to create virtualenv | |
# install pip dependencies | |
# install lbry | |
# tell them what to do next (and remind about virtualenv | |
#pip install -r requirements.txt | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment