Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to automate the update process more #859

Merged
merged 1 commit into from
Feb 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions update_cloudlog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash
# Cloudlog update script
#
# Pulls changes from Git remote and re-sets appropriate directory ownership.
# Can be run manually or on a schedule using Cron.
#
# Please check the DIR_OWNERSHIP variable carefully to make sure it is
# appropriately set for your system!

# The user and group that own the CLOUDLOG_SUBDIR directories. Passed to 'chown' as-is.
DIR_OWNERSHIP="root:www-data"
# The list of directories that need to have ownership restored after a git pull
declare -a CLOUDLOG_SUBDIRS=("application/config" "assets/qslcard" "backup" "updates" "uploads")
# The name of the Git remote to fetch/pull from
GIT_REMOTE="origin"
# If true, pull from the HEAD of the configured origin, otherwise the latest tag
BLEEDING_EDGE="true"
# If true, restore directory ownership on CLOUDLOG_SUBDIRS after a git pull
RESTORE_OWNERSHIP="true"

check_working_dir() {
# Quick sanity check to make sure that pwd looks like a Cloudlog install
if [[ ! -d "$(pwd)/application" ]]
then
echo "$(pwd) doesn't look like a Cloudlog install directory! Stopping here."
exit 1
fi
}

fast_forward_to_tag() {
# Find the latest tag on the current branch
# See https://git-scm.com/docs/git-describe for details on retrieving tags
LATEST_TAG=$(git describe --tags --abbrev=0)
echo "Fast-forwarding to latest tag: $LATEST_TAG..."
if git pull $GIT_REMOTE $LATEST_TAG ; then
echo "Fast-forward finished successfully."
else
echo "Fast-forward failed; stopping here."
exit 2
fi
}

fast_forward_to_head() {
echo "Fast-forwarding to HEAD (bleeding-edge)..."
if git pull $GIT_REMOTE ; then
echo "Fast-forward finished successfully".
else
echo "Fast-forward failed; stopping here."
exit 3
fi
}

restore_ownership() {
for dir in "${CLOUDLOG_SUBDIRS[@]}"; do
echo "Setting ownership as $DIR_OWNERSHIP on $dir"
chown -R $DIR_OWNERSHIP $(pwd)/$dir
done
}


echo "Cloudlog update started"
echo "-----------------------"
echo "Using $(pwd) as working directory"

check_working_dir

# Fetch the latest changes from the master branch
echo "Fetching changes from remote..."
if git fetch $GIT_REMOTE --tags ; then
echo "Fetched latest changes successfully"
else
echo "Fetch failed; stopping here."
exit 4
fi

if [ "$BLEEDING_EDGE" = true ]; then
fast_forward_to_head
else
fast_forward_to_tag
fi

if [ "$RESTORE_OWNERSHIP" = true ]; then
restore_ownership
fi

echo "Cloudlog update finished"