Created
January 9, 2019 20:05
-
-
Save valentineus/7ba3058414ffea9631492c7e63dbe3db to your computer and use it in GitHub Desktop.
Synchronization of backup copies of repositories with code.
This file contains hidden or 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 | |
# Author: Valentin Popov | |
# Email: [email protected] | |
# Date: 2018-11-13 | |
# Usage: /bin/bash start-sync.sh /path/to/input | |
# Description: Starting repository synchronization. | |
# Updating the Environment | |
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" | |
export PATH="$PATH:/usr/local/scripts" | |
# Search file sync | |
if [ "$1" ]; then | |
SCRIPT="$(readlink --canonicalize-missing "$1")" | |
if ! [ -f "$SCRIPT" ]; then | |
exit 0 | |
fi | |
else | |
echo "No SCRIPT parameter" | |
exit 1 | |
fi | |
# Search source directory | |
if [ "$2" ]; then | |
INPUT="$(readlink --canonicalize-missing "$2")" | |
if ! [ -d "$INPUT" ]; then | |
exit 0 | |
fi | |
else | |
echo "No INPUT parameter" | |
exit 1 | |
fi | |
# Run synchronizer | |
eval "$SCRIPT" "$INPUT" | |
# End of work | |
exit 0 |
This file contains hidden or 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 | |
# Author: Valentin Popov | |
# Email: [email protected] | |
# Date: 2018-11-13 | |
# Usage: /bin/bash sync-repositories.sh /path/to/input | |
# Description: Update existing users. | |
# Updating the Environment | |
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" | |
export PATH="$PATH:/usr/local/scripts" | |
exec 1> >(logger --stderr --tag "SYNC_REPOSITORIES") 2>&1 | |
echo "Script started" | |
if [ "$1" ]; then | |
INPUT="$(readlink --canonicalize-missing "$1")" | |
if ! [ -d "$INPUT" ]; then | |
echo "Destination directory does not exist" | |
exit 1 | |
fi | |
else | |
echo "No INPUT parameter" | |
exit 1 | |
fi | |
# Processing repositories | |
find "$INPUT" -maxdepth 2 -mindepth 2 -type d -print | while read DIR; do | |
echo "In the process: $(basename "$DIR")" | |
git --git-dir="$DIR" remote update --prune | |
done | |
# End of work | |
echo "Script has been successfully completed" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment