Skip to content

Instantly share code, notes, and snippets.

@sebmaynard
Created June 12, 2013 15:52

Revisions

  1. sebmaynard created this gist Jun 12, 2013.
    55 changes: 55 additions & 0 deletions owncloud-upgrade.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    #!/bin/bash

    # Upgrade an owncloud instance. Makes the following assumptions:
    # 1. you're running this as the same user who owns (and can write to) $OWNCLOUD_FOLDER
    # 2. $TMP_FOLDER is writeable by this user

    # These should be absolute paths
    OWNCLOUD_FOLDER=/var/public_html_ssl/cloud
    TMP_FOLDER=/tmp/owncloud-upgrade

    if [[ "$1" == "" ]] ; then
    echo "Need a version to download (e.g. 5.0.7)"
    exit
    fi
    VERSION=$1


    # make sure the temp directory exists first
    rm -r $TMP_FOLDER
    mkdir -p $TMP_FOLDER

    if [[ ! -d $TMP_FOLDER ]] ; then
    echo "Can't find the temporary folder. "
    exit
    fi

    echo "Backing up existing owncloud"
    rsync -a $OWNCLOUD_FOLDER/ $TMP_FOLDER/owncloud-backup/

    OC_FILENAME=owncloud-$VERSION.tar.bz2

    echo "Fetching new version"
    wget -q http://download.owncloud.org/community/$OC_FILENAME -O $TMP_FOLDER/$OC_FILENAME
    if [[ $? -ne 0 ]] ; then
    echo "Couldn't find that owncloud version to download"
    exit
    fi

    echo "Extracting new version"
    tar -C $TMP_FOLDER -xf $TMP_FOLDER/$OC_FILENAME
    if [[ $? -ne 0 ]] ; then
    echo "Couldn't extract owncloud"
    exit
    fi

    echo "Upgrading!"
    rsync --inplace -rt $TMP_FOLDER/owncloud/ $OWNCLOUD_FOLDER/

    if [[ $? -ne 0 ]] ; then
    echo "The upgrade rsync failed; Be careful..."
    exit
    fi


    echo "Done"