Last active
March 30, 2017 15:44
-
-
Save koter84/2c98922130419f24a689 to your computer and use it in GitHub Desktop.
MongoChef install-updater
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# deprecated MongoChef | |
depr_dir="/opt/$(ls /opt/ | grep mongochef-)" | |
if [ -d "$depr_dir" ] && [ "$depr_dir" != "/opt/" ] | |
then | |
echo "Found deprecated MongoChef [$depr_dir]" | |
rm -rf "$depr_dir" | |
if [ -h /opt/mongochef ] | |
then | |
# remove symlink | |
rm /opt/mongochef | |
fi | |
fi | |
# get current dir | |
prog_dir="/opt/$(ls /opt/ | grep studio-3t-)" | |
echo "Studio 3T DIR: $prog_dir" | |
prog_dir_version=$(echo $prog_dir | awk -F/ '{print $(NF)}' | sed s/'studio-3t-'// | sed s/'-linux-x64'//) | |
echo "Studio 3T DIR Version: $prog_dir_version" | |
# get current url | |
prog_url=$(curl -s https://studio3t.com/download-thank-you/?OS=x64 | sed 's/<a/\n<a/g' | grep '\.tar\.gz' | grep -v META | sed 's/.*http/http/g' | cut -d"\"" -f1) | |
echo "Studio 3T URL: $prog_url" | |
prog_url_version=$(echo $prog_url | awk -F/ '{print $(NF-1)}' | awk -F. '{print $1 "." $2 "." $3}') | |
echo "Studio 3T URL Version: $prog_url_version" | |
# check that a current version is found | |
if [ "$prog_dir_version" == "" ] | |
then | |
echo "New Installation! (no old version found)" | |
new_install="1" | |
fi | |
# check that a new version and url are found | |
if [ "$prog_url" == "" ] || [ "$prog_url_version" == "" ] | |
then | |
echo "couldn't find url for new version" | |
exit | |
fi | |
# check current dir version with current url version | |
if [ "$prog_dir_version" != "$prog_url_version" ] | |
then | |
if [ "$new_install" != "1" ] | |
then | |
echo "New Version Found!" | |
fi | |
cd /opt/ | |
# download | |
wget --quiet --show-progress -O studio3t.new.tar.gz $prog_url | |
# unpack | |
tar -zxf studio3t.new.tar.gz | |
# remove download | |
rm studio3t.new.tar.gz | |
if [ -h studio3t ] | |
then | |
# remove symlink | |
rm studio3t | |
fi | |
# create symlink | |
ln -s studio-3t-${prog_url_version}-linux-x64/bin/studio-3t.sh studio3t | |
if [ "$new_install" != "1" ] | |
then | |
# remove old version | |
rm -rf studio-3t-${prog_dir_version}-linux-x64 | |
fi | |
# get the logo | |
if [ ! -f ~/.local/share/icons/hicolor/128x128/apps/studio3t.png ] | |
then | |
wget -O ~/.local/share/icons/hicolor/128x128/apps/studio3t.png https://cdn-web.studio3t.com/wp-content/uploads/2017/01/cropped-favicon.png | |
fi | |
# create .desktop file | |
echo '[Desktop Entry]' > ~/.local/share/applications/studio3t.desktop | |
echo 'Encoding=UTF-8' >> ~/.local/share/applications/studio3t.desktop | |
echo 'Name=Studio 3T' >> ~/.local/share/applications/studio3t.desktop | |
echo 'GenericName=Mongo' Editor >> ~/.local/share/applications/studio3t.desktop | |
echo 'Exec="/opt/studio3t"' >> ~/.local/share/applications/studio3t.desktop | |
echo "Icon=~/.local/share/icons/hicolor/128x128/apps/studio3t.png" >> ~/.local/share/applications/studio3t.desktop | |
echo 'Terminal=false' >> ~/.local/share/applications/studio3t.desktop | |
echo 'Type=Application' >> ~/.local/share/applications/studio3t.desktop | |
echo 'MimeType=text/plain;' >> ~/.local/share/applications/studio3t.desktop | |
echo 'Categories=Mongo;Application;Development;Editor;Utility;TextEditor;' >> ~/.local/share/applications/studio3t.desktop | |
echo 'StartupWMClass=Studio3T' >> ~/.local/share/applications/studio3t.desktop | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment