|
@@ -0,0 +1,112 @@
|
|
|
+#!/usr/bin/env bash
|
|
|
+#
|
|
|
+# Upload changes from inside repository using GIN CLI
|
|
|
+# Works with submodules.
|
|
|
+# needs git config to be set and user should be logged in
|
|
|
+# needs submodules and main repo to be initialised (gin init)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+# Checking synchronisation option and giving feedback
|
|
|
+checkargs() {
|
|
|
+ case "$1" in
|
|
|
+ download)
|
|
|
+ echo "Downloading and keep all large file content"
|
|
|
+ ;;
|
|
|
+ keep)
|
|
|
+ echo "Keeping existing local large file content, do not downlad extra files"
|
|
|
+ ;;
|
|
|
+ remove)
|
|
|
+ echo "Removing all local large file content"
|
|
|
+ ;;
|
|
|
+ *)
|
|
|
+ usage
|
|
|
+ ;;
|
|
|
+ esac
|
|
|
+}
|
|
|
+
|
|
|
+checkargs "${syncopt}"
|
|
|
+
|
|
|
+checkerror() {
|
|
|
+ err=$1
|
|
|
+ msg=$2
|
|
|
+ if [[ ${err} != 0 ]]; then
|
|
|
+ echo "${msg}" >> ./.log/gin.log
|
|
|
+ echo "${err}" >> ./.log/gin.log
|
|
|
+ echo "${msg}"
|
|
|
+ echo "Press [Enter] to close this window"
|
|
|
+ read -r
|
|
|
+ exit 1
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+# Set commit message
|
|
|
+echo "Optionally enter a commit message, and hit return: "
|
|
|
+read commitmessage
|
|
|
+
|
|
|
+if [[ "$commitmessage" == "" ]]; then
|
|
|
+ echo "using date as commit message"
|
|
|
+ commitmessage="commit on $(date +%Y-%m-%d)"
|
|
|
+fi
|
|
|
+
|
|
|
+
|
|
|
+# write log
|
|
|
+mkdir -p ./.log
|
|
|
+echo "$(date +'%Y-%m-%dT%H:%M:%S'): Sync script executed" >> ./.log/gin.log
|
|
|
+
|
|
|
+# create empty .gitmodules if it does not exist
|
|
|
+FILE=.gitmodules
|
|
|
+if [ -f "$FILE" ]; then
|
|
|
+ echo "$FILE already exists."
|
|
|
+else
|
|
|
+ touch "$FILE"
|
|
|
+fi
|
|
|
+
|
|
|
+echo "intialise submodules"
|
|
|
+gin git submodule foreach gin init
|
|
|
+
|
|
|
+echo "Synchronising submodules"
|
|
|
+gin git submodule foreach gin commit . -m "$commitmessage"
|
|
|
+checkerror $? "Error occurred during 'gin commit'"
|
|
|
+gin git submodule foreach gin sync
|
|
|
+checkerror $? "Error occurred during 'gin sync'"
|
|
|
+
|
|
|
+gin git submodule foreach gin upload
|
|
|
+checkerror $? "Error occurred during 'gin upload'"
|
|
|
+
|
|
|
+## remove uploaded (annexed) content
|
|
|
+if [[ "$syncopt" == "remove" ]]; then
|
|
|
+ git submodule foreach gin remove-content
|
|
|
+ checkerror $? "Error occurred during 'gin remove-content'"
|
|
|
+ fi
|
|
|
+# get annexed content
|
|
|
+if [[ "${syncopt}" == "download" ]]; then
|
|
|
+ git submodule foreach gin get-content .
|
|
|
+ checkerror $? "Error occurred during 'gin get-content .'"
|
|
|
+ fi
|
|
|
+
|
|
|
+
|
|
|
+echo "Synchronising main repository"
|
|
|
+
|
|
|
+# add content
|
|
|
+gin commit . -m "$commitmessage"
|
|
|
+# add submodule changes
|
|
|
+gin git commit . --amend -m "$commitmessage"
|
|
|
+# upload files
|
|
|
+gin sync
|
|
|
+gin upload
|
|
|
+
|
|
|
+# remove uploaded (annexed) content
|
|
|
+if [[ "$syncopt" == "remove" ]]; then
|
|
|
+ gin remove-content
|
|
|
+ checkerror $? "Error occurred during 'gin remove-content' in main repo"
|
|
|
+ fi
|
|
|
+# get annexed content
|
|
|
+if [[ "${syncopt}" == "download" ]]; then
|
|
|
+ gin get-content .
|
|
|
+ checkerror $? "Error occurred during 'gin get-content . in main repo'"
|
|
|
+ fi
|