forked from KanColleTool/KanColleTool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·77 lines (65 loc) · 2.22 KB
/
update.sh
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
SSH_INACCESSIBLE=false
update_repo()
{
# Note: Repos are always fetched from the 'KanColleTool' user on GitHub
REPO="$1"
DEST="$2"
NAME="$3"
if [[ -d $DEST ]]; then
echo -n "$(tput bold)Updating ${NAME}...$(tput sgr0)"
# If the target directory exists, move into it
OLDPWD=$(pwd)
cd ${DEST}
# If there are unstaged changes, we have to stash them to allow a pull
CHANGED=$(git diff-index --name-only HEAD --)
if [ -n "$CHANGED" ]; then
git stash --quiet
fi
# Do a `git pull --rebase` with no progress, and report the status
OUTPUT=$(git pull --no-progress --rebase)
if [[ $? -eq 0 ]]; then
echo "$(tput bold)$(tput setaf 2) Success$(tput sgr0)"
else
echo "$(tput bold)$(tput setaf 1)-> Error:$(tput sgr0)"
echo $OUTPUT
return 1
fi
# Restore the stashed changes, if there are any
if [ -n "$CHANGED" ]; then
git stash pop --quiet
fi
cd $OLDPWD
else
echo -n "$(tput bold)Cloning ${NAME}...$(tput sgr0)"
# Otherwise, try to clone it via git, if that fails, try https instead
# The former will fail if the user doesn't have their SSH key properly
# set up with GitHub, in which case they probably only need readonly
# access anyways.
OUTPUT=$(git clone --no-progress [email protected]:KanColleTool/${REPO}.git ${DEST})
if [[ $? -eq 0 ]]; then
echo "$(tput bold)$(tput setaf 2) Success$(tput sgr0)"
else
OUTPUT2=$(git clone --no-progress https://github.com/KanColleTool/${REPO}.git ${DEST})
if [[ $? -eq 0 ]]; then
echo "$(tput bold)$(tput setaf 3) Success$(tput sgr0)"
SSH_INACCESSIBLE=true
else
echo "$(tput bold)$(tput setaf 1)-> Failed$(tput sgr0)"
exit
fi
fi
fi
}
# Switch to the directory the script is stored in
cd $(dirname "${BASH_SOURCE[0]}")
update_repo KanColleTool . "Main Repo"
update_repo kct-macviewer macviewer "Mac Viewer"
update_repo kct-viewer viewer "Viewer"
update_repo kct-tool tool "Tool"
# If an SSH clone failed, print a notice about it
if $SSH_INACCESSIBLE; then
echo "Note: SSH clones appear to fail, likely because you haven't set up your SSH"
echo " keys (properly). This is probably not a problem, but worth noting."
echo " It's also possible that a firewall of some kind is blocking Port 22."
fi