#!/bin/bash

DIST_PACKAGE=/tmp/nutstore_linux_dist.tar.gz

echo "********************************************"
echo "fetching distribution package"
echo ""
echo ""

wget --user-agent=NutstoreLinuxDownloader -O $DIST_PACKAGE http://www.jianguoyun.com/static/exe/installer/nutstore_linux_dist_`uname -m | sed -e 's/i.86/x86/' | sed -e 's/x86_64/x64/'`.tar.gz || exit -1
if [ -a ~/.nutstore/dist ]; then rm -rf ~/.nutstore/dist ; fi
mkdir -p ~/.nutstore/dist && tar xzf $DIST_PACKAGE -C ~/.nutstore/dist || exit -1
mkdir -p ~/.local/share/applications && cp ~/.nutstore/dist/gnome-config/menu/nutstore-menu.desktop ~/.local/share/applications || exit -1

echo ""
echo "********************************************"
echo "Installation is completed succesfully. "

echo ""

echo "Do you wish to start Nutstore now? "
select yn in "Yes" "No"; do
    case $yn in
        Yes ) 
        nohup ~/.nutstore/dist/bin/nutstore-pydaemon.py >/dev/null 2>&1 & 
        break;;
        No ) 
        break;;
    esac
done

echo ""
echo "You can launch nutstore by Gnome menus Applications->Internet->Nutstore. If there is not the entry, you need to restart gnome session by logging out manually"

