Skip to content

Instantly share code, notes, and snippets.

@koter84
Last active July 14, 2017 13:51
Show Gist options
  • Save koter84/7e4eaba426d82ed96e42 to your computer and use it in GitHub Desktop.
Save koter84/7e4eaba426d82ed96e42 to your computer and use it in GitHub Desktop.
update RoboMongo
#!/bin/bash
# get current dir
robomongo_dir="/opt/$(ls /opt/ | grep robomongo-)"
echo "RoboMongo DIR: $robomongo_dir"
robomongo_dir_version=$(echo $robomongo_dir | awk -F/ '{print $(NF)}' | sed s/'robomongo-'//)
echo "RoboMongo DIR Version: $robomongo_dir_version"
# get current url
robomongo_url=$(curl -s https://robomongo.org/download/ | sed 's/<a/\n<a/g' | grep '\.tar\.gz' | grep -v 'days for public availability' | head -n1 | sed 's/.*http/http/g' | cut -d"\"" -f1)
echo "RoboMongo URL: $robomongo_url"
robomongo_url_version=$(echo $robomongo_url | awk -F/ '{print $(NF)}' | sed s/'robo3t-'// | sed s/'.tar.gz'// | cut -d'-' -f1)
echo "RoboMongo URL Version: $robomongo_url_version"
# check that a current version is found
if [ "$robomongo_dir_version" == "" ]
then
echo "New Installation! (no old version found)"
new_install="1"
fi
# check that a new version and url are found
if [ "$robomongo_url" == "" ] || [ "$robomongo_url_version" == "" ]
then
echo "couldn't find url for new version"
exit
fi
# check current dir version with current url version
if [ "$robomongo_dir_version" != "$robomongo_url_version" ]
then
if [ "$new_install" != "1" ]
then
echo "New Version Found!"
fi
cd /opt/
# download
wget --quiet --show-progress -O robomongo.new.tar.gz $robomongo_url
# unpack
tar -zxf robomongo.new.tar.gz
# remove download
rm robomongo.new.tar.gz
# rename the download from robo3t back to robomongo
mv robo3t-${robomongo_url_version}-* robomongo-${robomongo_url_version}
if [ -h robomongo ]
then
# remove symlink
rm robomongo
fi
# create symlink
ln -s robomongo-${robomongo_url_version}/bin/robo3t robomongo
# download logo
wget --quiet -O robomongo-${robomongo_url_version}/logo.png https://raw.githubusercontent.com/paralect/robomongo/master/src/robomongo/gui/resources/icons/logo-256x256.png
# create/update .desktop file
echo -ne "[Desktop Entry]\nEncoding=UTF-8\nName=Robomongo\nGenericName=MongoDB\nComment=MongoDB Administration\nExec=/opt/robomongo\nIcon=/opt/robomongo-${robomongo_url_version}/logo.png\nTerminal=false\nType=Application\nMimeType=text/plain;\nCategories=Robomongo;Application;Development;Utility;" > ${HOME}/.local/share/applications/robomongo.desktop
if [ "$new_install" != "1" ]
then
# remove old version
rm -rf robomongo-${robomongo_dir_version}
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment