Created
September 15, 2014 05:52
-
-
Save zoechi/d240f56a32ed5649797f to your computer and use it in GitHub Desktop.
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 | |
# ~ doesn't work in string resolution use /home/$USER/ instead | |
DOWNLOAD_DIR="/home/$USER/Downloads/Dart" | |
CURRENT_VERSION_FILE="VERSION_current" | |
NEW_VERSION_FILE="VERSION_new" | |
#DOWNLOAD_VERSION_FILE="VERSION_download" | |
#VERSION_URL="http://gsdview.appspot.com/dart-archive/channels/dev/release/latest/VERSION" | |
VERSION_URL="http://gsdview.appspot.com/dart-archive/channels/be/raw/latest/VERSION" | |
#EDITOR_LINUX64_URL="http://gsdview.appspot.com/dart-archive/channels/dev/release/latest/editor/darteditor-linux-x64.zip" | |
EDITOR_LINUX64_URL="http://gsdview.appspot.com/dart-archive/channels/be/raw/latest/editor/darteditor-linux-x64.zip" | |
VERSION_REGEX=" *\"revision\" *: \"([0-9]*)" | |
DARTEDITOR_DEST_DIR="/home/$USER/google/darteditor" | |
DARTEDITOR_BACKUP_DIR="${DARTEDITOR_DEST_DIR}_old" | |
cd $DOWNLOAD_DIR | |
# Download VERSION file | |
# -N: overwrite existing file | |
# -O: specify destination file | |
wget -q -O $NEW_VERSION_FILE $VERSION_URL | |
# read new version number from file | |
if [ ! -f "$NEW_VERSION_FILE" ]; then | |
echo "Download VERSION file failed." | |
exit | |
else | |
# read file content into a variable | |
newVersionContent=$(cat $NEW_VERSION_FILE) | |
# regex matching in bash | |
[[ "$newVersionContent" =~ $VERSION_REGEX ]] | |
newVersion="${BASH_REMATCH[1]}" | |
fi | |
# read version from previous downloaded version file | |
# check if file NOT exists | |
if [ ! -f "$CURRENT_VERSION_FILE" ]; then | |
curVersion=0 | |
else | |
curVersionContent=$(cat $CURRENT_VERSION_FILE) | |
[[ "$curVersionContent" =~ $VERSION_REGEX ]] | |
curVersion="${BASH_REMATCH[1]}" | |
fi | |
destFileName="darteditor-linux-64 ${newVersion}.zip" | |
#echo new: $newVersion | |
#echo cur: $curVersion | |
# compore current and new version | |
# (( )) for integer expression evaluation instead of string evaluation with [[]] | |
if (( $newVersion > $curVersion )); then | |
echo "Newer version available" | |
echo "Downloading version $newVersion." | |
# download new editor version | |
if [ ! -f "$destFileName" ]; then | |
wget -O "$destFileName" "$EDITOR_LINUX64_URL" | |
else | |
echo "$destFileName" already exists. | |
fi | |
fi | |
if (( $newVersion > $curVersion )) || [ ! -d "$DARTEDITOR_DEST_DIR" ]; then | |
# delete old backup directory | |
if [ -d "$DARTEDITOR_BACKUP_DIR" ]; then | |
rm -r "${DARTEDITOR_DEST_DIR}_old" | |
#echo "deleting: ${DARTEDITOR_DEST}_old" | |
fi | |
# move current files to backup directory | |
#echo "$DARTEDITOR_DEST_DIR $DARTEDITOR_BACKUP_DIR" | |
mv "$DARTEDITOR_DEST_DIR" "$DARTEDITOR_BACKUP_DIR" | |
#extract ladownloaded file | |
mkdir "$DARTEDITOR_DEST_DIR" | |
unzip "$destFileName" -d "$DARTEDITOR_DEST_DIR" | |
## remove the unnecessary dart subfolder created from the archive file | |
## mv "${DARTEDITOR_DEST_DIR}/dart/*" "$DARTEDITOR_DEST_DIR" # | |
## hat nicht funktioniert wegen Anführungszeichen - die sind | |
## aber notwendig wenn der Pfad Leerzeichen enthält | |
## daher nachfolgende Lösung. | |
if [ -d "${DARTEDITOR_DEST_DIR}/dart" ]; then | |
ls -A -1 "${DARTEDITOR_DEST_DIR}/dart" | while read FILE; do mv -v "${DARTEDITOR_DEST_DIR}/dart/${FILE}" "${DARTEDITOR_DEST_DIR}" ;done | |
fi | |
#echo "-Dorg.eclipse.swt.browser.DefaultType=mozilla" >> "${DARTEDITOR_DEST_DIR}/DartEditor.ini" | |
# replace current version file with the new one | |
if [ -f "$CURRENT_VERSION_FILE" ]; then | |
rm $CURRENT_VERSION_FILE | |
fi | |
mv "$NEW_VERSION_FILE" "$CURRENT_VERSION_FILE" | |
# download content_shell | |
cd "$DOWNLOAD_DIR" | |
# mv content_shell-linux-x64-release.* "content_shell-linux-x64-release${curVersion}.zip" | |
/bin/bash "${DARTEDITOR_DEST_DIR}/chromium/download_contentshell.sh" | |
unzip "${DOWNLOAD_DIR}/content_shell-linux-x64-release.zip" -d "${DARTEDITOR_DEST_DIR}/chromium/" | |
csDir=$(find ${DARTEDITOR_DEST_DIR}/chromium/ -name drt-lucid64-full-*) | |
ln -s "${csDir}" "${DARTEDITOR_DEST_DIR}/chromium/content_shell" | |
fi | |
echo "current version: $curVersion" | |
echo "new version : $newVersion" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment