diff --git a/install.sh b/install.sh index 3568dc9..33a5cf2 100755 --- a/install.sh +++ b/install.sh @@ -49,7 +49,16 @@ read -i "$COSCALE_APPID" -p "Please enter your application id: " -e -r COSCALE_A read -i "$COSCALE_TOKEN" -p "Please enter your access token: " -e -r COSCALE_TOKEN read -i "$PATH_INSTALL" -p "Installation path: " -e -r PATH_INSTALL -PATH_INSTALL=$(readlink -f $PATH_INSTALL) + +# Create dirs +if [ ! -d "$PATH_INSTALL" ]; then + echo "$PATH_INSTALL does not exist, do you want to create it?" + if ask_yesno "Create directory $PATH_SYMLINK?"; then + mkdir -v -p "$PATH_INSTALL" + else + exit 1 + fi +fi if ask_yesno "Create a symlink [$PATH_SYMLINK]?"; then SYMLINK="true" @@ -58,6 +67,7 @@ echo echo "----------------------------------------------" echo -e "\t Summary" +echo "----------------------------------------------" echo echo -e "Application ID \t\t: $COSCALE_APPID" echo -e "Access token \t\t: $COSCALE_TOKEN" @@ -74,6 +84,8 @@ fi echo "----------------------------------------------" echo -e "Starting installation" +echo "----------------------------------------------" + # Fetch latest release list from Github echo @@ -81,13 +93,6 @@ echo -e "- Getting latest release information" github_data=$(curl -s -L https://api.github.com/repos/CoScale/coscale-cli/releases/latest | grep "browser_download_url" | awk '{ print $2; }' | sed 's/"//g') release=$(echo "$github_data" | grep -v ".exe") -# Create dirs -if [ ! -d "$PATH_INSTALL" ]; then - echo echo -e "- Creating directories $PATH_INSTALL/" - mkdir -v -p "$PATH_INSTALL" - echo -fi - # Install client echo -e "- Downloading client to $PATH_INSTALL/coscale-cli" curl -L "$release" > "$PATH_INSTALL/coscale-cli" @@ -101,25 +106,24 @@ if [ "$SYMLINK" = true ] ; then if [ -f "/usr/bin/coscale-cli" ]; then # Check if symlink is correct if [ "$(readlink /usr/bin/coscale-cli)" = "$PATH_INSTALL/coscale-cli" ]; then - echo -e "\tExisting symlink detected" + echo -e " Existing symlink detected" else - echo -e "\tIncorrect symlink detected, please remove the file /usr/bin/coscale-cli and start again" + echo -e " Incorrect symlink detected, please remove the file /usr/bin/coscale-cli and start again" exit 1 fi else # Symlink does not exist, create ln -v -s "$PATH_INSTALL/coscale-cli" /usr/bin/coscale-cli - echo -e "\tSymlink created" + echo -e " Symlink created" fi echo fi # Create config -if [ ! -f "$PATH_INSTALL/api.conf" ]; then - echo -e "- Generating config file" - echo "{\"baseurl\":\"https://api.coscale.com\", \"appid\":\"$COSCALE_APPID\", \"accesstoken\":\"$COSCALE_TOKEN\"}" | gzip -c > $PATH_INSTALL/api.conf - echo -fi +echo -e "- Generating config file" +echo "{\"baseurl\":\"https://api.coscale.com\", \"appid\":\"$COSCALE_APPID\", \"accesstoken\":\"$COSCALE_TOKEN\"}" | gzip -c > $PATH_INSTALL/api.conf +echo + # Test config echo -e "- Testing configuration"