Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One-line installer doesn't detect package installation failure #8

Closed
tomusdrw opened this issue Mar 16, 2017 · 3 comments · Fixed by #10
Closed

One-line installer doesn't detect package installation failure #8

tomusdrw opened this issue Mar 16, 2017 · 3 comments · Fixed by #10

Comments

@tomusdrw
Copy link
Contributor

http://pastebin.com/MmmWeyRs

Says Parity has been installed

@tomusdrw
Copy link
Contributor Author

Just checked the code and it will happen if old version was installed correctly.

@5chdn
Copy link
Contributor

5chdn commented Mar 16, 2017

Could use a PARITY_VERSION variable,

PARITY_VERSION=1.6.3
PARITY_DEB_URL=http://d1h4xl4cr1h0mo.cloudfront.net/v${PARITY_VERSION}/x86_64-unknown-linux-gnu/parity_${PARITY_VERSION}_amd64.deb

and later check the installed version, i.e.,

ETH_VERSION=`${ETH_PATH} --version 2>/dev/null | grep -o "[0-9]\.[0-9]\.[0-9]"`

Just a thought, but it's still developing ... comparing version strings with bash is... nasty :)

@5chdn
Copy link
Contributor

5chdn commented Mar 16, 2017

This script compares the versions. Not sure if this is the appropriate way to go.

#!/bin/bash

PARITY_VERSION=$1
PARITY_DEB_URL=http://d1h4xl4cr1h0mo.cloudfront.net/v${PARITY_VERSION}/x86_64-unknown-linux-gnu/parity_${PARITY_VERSION}_amd64.deb

echo "UPDATE VERSION  : ${PARITY_VERSION}"
echo "UPDATE DEB URL  : ${PARITY_DEB_URL}"

ETH_PATH=`which parity 2>/dev/null`
ETH_VERSION=`${ETH_PATH} --version 2>/dev/null | grep -o "[0-9]\.[0-9]\.[0-9]"`

echo "INSTALL BINARY  : ${ETH_PATH}"
echo "INSTALL VERSION : ${ETH_VERSION}"

version_compare () {
    if [[ $1 == $2 ]]
    then
        return 0
    fi
    local IFS=.
    local i ver1=($1) ver2=($2)
    # fill empty fields in ver1 with zeros
    for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
    do
        ver1[i]=0
    done
    for ((i=0; i<${#ver1[@]}; i++))
    do
        if [[ -z ${ver2[i]} ]]
        then
            # fill empty fields in ver2 with zeros
            ver2[i]=0
        fi
        if ((10#${ver1[i]} > 10#${ver2[i]}))
        then
            return 1
        fi
        if ((10#${ver1[i]} < 10#${ver2[i]}))
        then
            return 2
        fi
    done
    return 0
}

version_compare $PARITY_VERSION $ETH_VERSION

case $? in
    0) OPERATOR='=';;
    1) OPERATOR='>';;
    2) OPERATOR='<';;
esac

echo "VERSION MATCH?  : ${PARITY_VERSION} ${OPERATOR} ${ETH_VERSION}"

if [[ $OPERATOR != '=' ]]
then
    echo "FAIL            : VERSIONS DO NOT MATCH!"
else
    echo "SUCCESS         : VERSIONS DO MATCH!"
fi

It figures out the correct installed version:

 $ bash scripts-version.sh 1.6.3
UPDATE VERSION  : 1.6.3
UPDATE DEB URL  : http://d1h4xl4cr1h0mo.cloudfront.net/v1.6.3/x86_64-unknown-linux-gnu/parity_1.6.3_amd64.deb
INSTALL BINARY  : /usr/bin/parity
INSTALL VERSION : 1.6.3
VERSION MATCH?  : 1.6.3 = 1.6.3
SUCCESS         : VERSIONS DO MATCH!
 $ bash scripts-version.sh 1.6.4
UPDATE VERSION  : 1.6.4
UPDATE DEB URL  : http://d1h4xl4cr1h0mo.cloudfront.net/v1.6.4/x86_64-unknown-linux-gnu/parity_1.6.4_amd64.deb
INSTALL BINARY  : /usr/bin/parity
INSTALL VERSION : 1.6.3
VERSION MATCH?  : 1.6.4 > 1.6.3
FAIL            : VERSIONS DO NOT MATCH!

Any comments welcome, could also create a pull request. This, however, is only tested on Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants