-
Notifications
You must be signed in to change notification settings - Fork 1
/
github-backup
executable file
·40 lines (31 loc) · 1.31 KB
/
github-backup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh
# Back up Githup repositories for all users with Git::Megapull. The
# canonical version is maintained at http://github.com/avar/github-backup
# Source our configuration file
. /etc/github-backup/github-backup.conf
# Check prerequisites
if [ -z $(which git-megapull) ]; then
echo "You don't have git-megapull installed. Install it as documented at http://github.com/avar/github-backup"
exit 1
fi
# Check configuration
if [ -z $GITHUB_BACKUP_DIRECTORY ]; then
echo "You must set GITHUB_BACKUP_DIRECTORY in /etc/github-backup.conf to use github-backup"
exit 1
fi
if [ ! -d $GITHUB_BACKUP_DIRECTORY ]; then
echo "The GITHUB_BACKUP_DIRECTORY directory you've set ($GITHUB_BACKUP_DIRECTORY) doesn't exist"
exit 1
fi
# Every directory under $GITHUB_BACKUP_DIRECTORY maps to a user on
# this system. We'll run git-megapull as that user to read their
# github.token in their ~/.gitconfig
for user in $(find $GITHUB_BACKUP_DIRECTORY -maxdepth 1 -mindepth 1 -type d -printf "%f\n"); do
cd $GITHUB_BACKUP_DIRECTORY/$user
# Redirect STDERR because git fetch prints non-error output to STDERR
sudo -u $user -H $(which git-megapull) --bare --source Github > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to run git-megapull for user $user, failed with exit code $?"
fi
done
exit 0