From c3e1ebd43ecc041d23dfcb66f511dce7f2a75e98 Mon Sep 17 00:00:00 2001 From: cgeek <cem.moreau@gmail.com> Date: Sat, 2 Apr 2016 19:40:56 +0200 Subject: [PATCH] Change intall script --- install.sh | 230 ++++++++++------------------------------------------- 1 file changed, 44 insertions(+), 186 deletions(-) diff --git a/install.sh b/install.sh index b9ee9e1a1..363c080c2 100644 --- a/install.sh +++ b/install.sh @@ -33,125 +33,31 @@ ucoin_download() { fi } -ucoin_is_ubuntu_install() { - local distribution - distribution=`cat /etc/*-release file 2>/dev/null | grep "Ubuntu"` - if [[ "$distribution" = *Ubuntu* ]]; then - return 0 - else - return 1 - fi -} - -ucoin_is_debian_install() { - local distribution - distribution=`cat /etc/*-release file 2>/dev/null | grep "Debian"` - if [[ "$distribution" = *Debian* ]]; then - return 0 - else - return 1 - fi -} - -ucoin_is_fedora_install() { - local distribution - distribution=`cat /etc/*-release file 2>/dev/null | grep "Fedora"` - if [[ "$distribution" = *Fedora* ]]; then - return 0 - else - return 1 - fi -} - install_ucoin_from_git() { - if ! ucoin_has "make"; then - if ucoin_is_ubuntu_install; then - echo "=> make is not available. Please install 'build-essential' package with 'sudo apt-get install build-essential' command, then retry uCoin installation." - exit 1 - fi - if ucoin_is_debian_install; then - echo "=> make is not available. Please install 'build-essentials' package with 'apt-get install build-essential' command as root, then retry uCoin installation." - exit 1 - fi - fi - if ! ucoin_has "g++"; then - if ucoin_is_ubuntu_install; then - echo "=> g++ is not available. Please install 'build-essential' package with 'sudo apt-get install build-essential' command, then retry uCoin installation." - exit 1 - elif ucoin_is_debian_install; then - echo "=> g++ is not available. Please install 'build-essentials' package with 'apt-get install build-essential' command as root, then retry uCoin installation." - exit 1 - else - echo "=> g++ is not available" - fi - return 11 - fi - if ! ucoin_has "python"; then - if ucoin_is_ubuntu_install; then - echo "=> python is not available. Please install 'build-essential' package with 'sudo apt-get install build-essential' command, then retry uCoin installation." - exit 1 - elif ucoin_is_debian_install; then - echo "=> python is not available. Please install 'build-essentials' package with 'apt-get install build-essential' command as root, then retry uCoin installation." - exit 1 - else - echo "=> python is not available" - fi - return 11 - fi - local PREVIOUS_PATH PREVIOUS_PATH=$PATH - if ucoin_has "git"; then - # Git is here: clone repository - if [ -d "$UCOIN_DIR/.git" ]; then - echo "=> ucoin is already installed in $UCOIN_DIR, trying to update using git" - printf "\r=> " - cd "$UCOIN_DIR" && (command git fetch 2> /dev/null || { - echo >&2 "Failed to update ucoin, run 'git fetch' in $UCOIN_DIR yourself." && exit 1 - }) - else - # Cloning to $UCOIN_DIR - echo "=> Downloading ucoin from git to '$UCOIN_DIR'" - printf "\r=> " - mkdir -p "$UCOIN_DIR" - command git clone "$(ucoin_repo_url)" "$UCOIN_DIR" - fi - cd "$UCOIN_DIR" && command git checkout --quiet $(ucoin_latest_version) - if [ ! -z "$(cd "$UCOIN_DIR" && git show-ref refs/heads/master)" ]; then - if git branch --quiet 2>/dev/null; then - cd "$UCOIN_DIR" && command git branch --quiet -D master >/dev/null 2>&1 - else - echo >&2 "Your version of git is out of date. Please update it!" - cd "$UCOIN_DIR" && command git branch -D master >/dev/null 2>&1 - fi - fi + if [ -d "$UCOIN_DIR/.git" ]; then + echo "=> ucoin is already installed in $UCOIN_DIR, trying to update using git" + printf "\r=> " + cd "$UCOIN_DIR" && (command git fetch 2> /dev/null || { + echo >&2 "Failed to update ucoin, run 'git fetch' in $UCOIN_DIR yourself." && exit 1 + }) else - # Fallback: git is not available, we download sources tarball - local UCOIN_SRC_TARBALL=https://github.com/ucoin-io/ucoin/archive/$(ucoin_latest_version).tar.gz - local UCOIN_SRC_ARCHIVE=$UCOIN_DIR/ucoin_$(ucoin_latest_version).tar.gz - local UCOIN_SRC_FOLDER=$UCOIN_DIR/ucoin-$(ucoin_latest_version | sed -e s/^v//) - echo "=> Downloading '$UCOIN_SRC_TARBALL' to '$UCOIN_SRC_ARCHIVE'" + # Cloning to $UCOIN_DIR + echo "=> Downloading ucoin from git to '$UCOIN_DIR'" + printf "\r=> " mkdir -p "$UCOIN_DIR" - ucoin_download "$UCOIN_SRC_TARBALL" -o "$UCOIN_SRC_ARCHIVE" || { - echo >&2 "Failed to download '$UCOIN_SRC_TARBALL'" - return 7 - } - echo "=> Extracting..." - cd "$UCOIN_DIR" && tar xzf $UCOIN_SRC_ARCHIVE || { - echo >&2 "Failed to extract '$UCOIN_SRC_ARCHIVE'" - return 8 - } - echo "=> Moving..." - mv $UCOIN_SRC_FOLDER/* $UCOIN_DIR || { - echo >&2 "Failed to move files from '$UCOIN_SRC_FOLDER'" - return 9 - } - echo "=> Cleaning ucoin sources..." - rm -Rf $UCOIN_ARCHIVE $UCOIN_SRC_ARCHIVE $UCOIN_SRC_FOLDER || { - echo >&2 "Failed to clean ucoin sources" - return 10 - } + command git clone "$(ucoin_repo_url)" "$UCOIN_DIR" + fi + cd "$UCOIN_DIR" && command git checkout --quiet $(ucoin_latest_version) + if [ ! -z "$(cd "$UCOIN_DIR" && git show-ref refs/heads/master)" ]; then + if git branch --quiet 2>/dev/null; then + cd "$UCOIN_DIR" && command git branch --quiet -D master >/dev/null 2>&1 + else + echo >&2 "Your version of git is out of date. Please update it!" + cd "$UCOIN_DIR" && command git branch -D master >/dev/null 2>&1 + fi fi # Download Nodejs @@ -183,45 +89,13 @@ install_ucoin_from_git() { # Install uCoin dependencies (NPM modules) export PATH=$PATH:$UCOIN_DIR/node/bin/ + npm install -g node-pre-gyp + export PATH=$PATH:$UCOIN_DIR/node/lib/node_modules/node-pre-gyp/bin/ npm install export PATH=$PREVIOUS_PATH return } -install_ucoin_as_script() { - local ARCH="32" - local X64=`uname -a | grep "x86_64"` - if [ ! -z "$X64" ]; then - ARCH="64" - fi - local UCOIN_SOURCE_LOCAL - UCOIN_SOURCE_LOCAL=https://github.com/ucoin-io/ucoin/releases/download/$(ucoin_latest_version)/ucoin-x${ARCH}.tar.gz - local UCOIN_ARCHIVE - UCOIN_ARCHIVE=$UCOIN_DIR/ucoin.tar.gz - - # Downloading to $UCOIN_DIR - mkdir -p "$UCOIN_DIR" - if [ -d "$UCOIN_DIR/ucoin" ]; then - echo "=> ucoin is already installed in $UCOIN_DIR, trying to update" - else - echo "=> Downloading ucoin binary to '$UCOIN_DIR'" - fi - ucoin_download "$UCOIN_SOURCE_LOCAL" -o "$UCOIN_ARCHIVE" || { - echo >&2 "Failed to download '$UCOIN_SOURCE_LOCAL'" - return 1 - } - echo "=> Extracting ucoin sources..." - tar xzf $UCOIN_ARCHIVE -C $UCOIN_DIR || { - echo >&2 "Failed to extract $UCOIN_ARCHIVE to $UCOIN_DIR" - return 2 - } - echo "=> Cleaning..." - rm $UCOIN_ARCHIVE || { - echo >&2 "Failed to remove $UCOIN_ARCHIVE" - return 2 - } -} - # # Detect profile file if not specified as environment variable # (eg: PROFILE=~/.myprofile) @@ -264,46 +138,31 @@ ucoin_detect_profile() { fi } -ucoin_is_available_for_distribution() { - local distribution - local distribution_deb - local distribution_fedora - - distribution=`cat /etc/*-release file 2>/dev/null | grep "Ubuntu"` - distribution_deb=`cat /etc/*-release file 2>/dev/null | grep "Debian"` - distribution_fedora=`cat /etc/*-release file 2>/dev/null | grep "Fedora"` - - if [[ "$distribution" = *Ubuntu\ 14* ]] || [[ "$distribution" = *Ubuntu\ 15* ]] || [[ "$distribution_deb" = *Debian*8*jessie* ]] || [[ "$distribution_fedora" = *Fedora\ 23* ]]; then - local X64=`uname -a | grep "x86_64"` - if [ ! -z "$X64" ]; then - return 0 - fi - echo "=> 32-bit OS, requires to build" - return 1 - else - echo "=> No binary for this system, requires to build" - return 1 - fi -} - ucoin_do_install() { - # Autodetect install method - - if [ "_$1" == "_git" ]; then - install_ucoin_from_git - elif ucoin_is_available_for_distribution; then - install_ucoin_as_script - elif ucoin_has "git"; then - install_ucoin_from_git - elif ucoin_has "curl"; then - install_ucoin_from_git - elif ucoin_has "wget"; then - install_ucoin_from_git - else - echo >&2 "You need git, curl, or wget to install ucoin" + # Check required commands + if ! ucoin_has "git"; then + echo "=> git is not available. You will likely need to install 'git' package." + exit 1 + fi + if ! ucoin_has "curl"; then + echo "=> curl is not available. You will likely need to install 'curl' package." + exit 1 + fi + if ! ucoin_has "make"; then + echo "=> make is not available. You will likely need to install 'build-essential' package." + exit 1 + fi + if ! ucoin_has "g++"; then + echo "=> g++ is not available. You will likely need to install 'build-essential' package." exit 1 fi + if ! ucoin_has "python"; then + echo "=> python is not available. You will likely need to install 'build-essential' package." + exit 1 + fi + + install_ucoin_from_git echo @@ -343,9 +202,8 @@ ucoin_do_install() { # ucoin_reset() { unset -f ucoin_reset ucoin_has ucoin_latest_version \ - ucoin_download install_ucoin_as_script install_ucoin_from_git \ - ucoin_detect_profile ucoin_do_install \ - ucoin_is_available_for_distribution + ucoin_download install_ucoin_from_git \ + ucoin_detect_profile ucoin_do_install } [ "_$UCOIN_ENV" = "_testing" ] || ucoin_do_install $1 -- GitLab