Skip to content

Commit

Permalink
Merge pull request #7 from JaHIY/master
Browse files Browse the repository at this point in the history
Now supports Chromium x64 and fix bugs for new version format
  • Loading branch information
n1k0 committed Oct 19, 2014
2 parents eb738d5 + 49341a1 commit 81d6c2c
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions getchromium.sh
Expand Up @@ -5,29 +5,39 @@
# See README for further informations

die() {
printf "$@ => exiting\n" >&2
exit 1
local format="$1"
shift
printf "${format} => exiting\n" "$@" >&2
exit 1
}

W="$(whoami)"
TMP="${TMPDIR-/tmp}"
BASE_URL='http://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac'
#BASE_URL='https://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac'
BASE_URL='https://storage.googleapis.com/chromium-qa/Chromium_Mac_10_8_x64__experimental_'
ARCHIVE_NAME='chrome-mac.zip'
LATEST_URL="${BASE_URL}/LAST_CHANGE"
LATEST_VERSION="$(curl -s -f "$LATEST_URL")" || die "Unable to fetch latest version number from ${LATEST_URL}"
LATEST_VERSION="$(curl -s -f "$LATEST_URL")" || die 'Unable to fetch latest version number from %s' "$LATEST_URL"
PROC="$(ps aux | grep -i 'Chromium' | grep -iv 'grep' | grep -iv "$0" | wc -l | awk '{print $1}')" || die 'Unable to count running Chromium processes'
INSTALL_DIR='/Applications'
# Using Chromium's Info.plist to get the SCM Revision.
INSTALLED_VERSION="$(defaults read "${INSTALL_DIR}/Chromium.app/Contents/Info" 'SCMRevision' 2> /dev/null)"

if grep -q -v '^[[:digit:]]\+$' <<< "$INSTALLED_VERSION"; then
INSTALLED_VERSION="$({ grep -o '{#[[:digit:]]\+}$' | grep -o '[[:digit:]]\+'; } <<< "$INSTALLED_VERSION")"
fi

printf 'Chromium version installed: %s\n' "$INSTALLED_VERSION"
printf 'Latest Chromium version : %s\n' "$LATEST_VERSION"

# The script should never be run by root
if [ "$W" = 'root' ]; then
die 'This script cannot be run as root'
fi

# Checking if latest available build version number is newer than installed one
if [ "$LATEST_VERSION" = "$INSTALLED_VERSION" ]; then
die "You already have the latest build (${LATEST_VERSION}) installed"
if [ "$LATEST_VERSION" -le "$INSTALLED_VERSION" ]; then
die 'You already have the latest build (%s) installed' "$LATEST_VERSION"
fi

# Testing if Chromium is currently running
Expand All @@ -38,13 +48,13 @@ fi
# Fetching latest archive if not already existing in tmp dir
if [ ! -f "${TMP}/chromium-${LATEST_VERSION}.zip" ]; then
ARCHIVE_URL="${BASE_URL}/${LATEST_VERSION}/${ARCHIVE_NAME}"
printf "Fetching chromium build ${LATEST_VERSION} from ${ARCHIVE_URL}, please wait...\n"
printf 'Fetching chromium build %s from %s, please wait...\n' "$LATEST_VERSION" "$ARCHIVE_URL"
curl -O -L "$ARCHIVE_URL" || die "Unable to fetch version ${LATEST_VERSION} archive"
mv "$ARCHIVE_NAME" "${TMP}/chromium-${LATEST_VERSION}.zip" || die "Unable to move downloaded archive to ${TMP} directory"
mv "$ARCHIVE_NAME" "${TMP}/chromium-${LATEST_VERSION}.zip" || die 'Unable to move downloaded archive to %s directory' "$TMP"
fi

# Unzipping
unzip -qq -u -d "${TMP}/chromium-${LATEST_VERSION}" "${TMP}/chromium-${LATEST_VERSION}.zip" || die "Unable to unzip version ${LATEST_VERSION} archive"
unzip -qq -u -d "${TMP}/chromium-${LATEST_VERSION}" "${TMP}/chromium-${LATEST_VERSION}.zip" || die 'Unable to unzip version %s archive' "$LATEST_VERSION"

# Deleting previously installed version
if [ -d "${INSTALL_DIR}/Chromium.app" ]; then
Expand All @@ -53,10 +63,12 @@ fi

# Installing new version
mv -f "${TMP}/chromium-${LATEST_VERSION}/chrome-mac/Chromium.app" "${INSTALL_DIR}" || die 'Unable to install fetched Chromium version'
printf "Chromium build ${LATEST_VERSION} succesfully installed\n"
printf 'Chromium build %s succesfully installed\n' "$LATEST_VERSION"

# Cleaning
rm "${TMP}/chromium-${LATEST_VERSION}.zip"

# Open Chromium
open "${INSTALL_DIR}/Chromium.app"
if [ "$1" = '--open' ]; then
open "${INSTALL_DIR}/Chromium.app"
fi

0 comments on commit 81d6c2c

Please sign in to comment.