-
Notifications
You must be signed in to change notification settings - Fork 10
/
check_update.sh
executable file
·74 lines (62 loc) · 2.09 KB
/
check_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
#!/bin/bash
# Color Constants
RED="0;31"; GREEN="0;32"; BROWN="0;33"; BLUE="0;34"; PURPLE="0;35"; CYAN="0;36"; GRAY="0;37";
PINK="1;31"; LGREEN="1;32"; YELLOW="1;33" LBLUE="1;34"; MAGENTA="1;35"; LCYAN="1;37"; WHITE="1;37"
# Output functions with nice colors
#
function color_echo_nnl {
echo -en "\033[$1m"
echo -n "$2"
echo -en "\033[0;37m"
}
function color_echo {
echo -en "\033[$1m"
echo -n "$2"
echo -e "\033[0;37m"
}
# Check where we are
if [ ! -f 'Vagrantfile.local' ];
then
color_echo $YELLOW "This box has not been configured yet or this command hasn't been ran from the root of the project"
exit 1
fi
# Load the config
BBPATH=$(grep -v "^#" Vagrantfile.local | grep basebox_path | awk {'print $4'})
if [[ $BBPATH -eq '' ]]
then
BBPATH='dev/basebox'
fi
# Check if basebox path exists
if [[ ! -d $BBPATH ]]
then
echo "Unable to find the basebox in $BBPATH"
exit 1
fi
cd $BBPATH
# Checking for local changes
git diff --quiet --exit-code
if [ $? -ne 0 ]; then
color_echo $YELLOW "Your basebox has local changes."
color_echo $YELLOW "Customizations should be done in the Vagrantfile.local and dev/salt folders instead."
color_echo $YELLOW "Please revert these changes where possible or commit them and issue a PR."
exit 0;
fi
git fetch origin master --quiet
if [ $? -ne 0 ]; then
color_echo $PINK "Unable to check for basebox updates."
exit 1
fi
COMMITS_DIFF=$(git rev-list --left-right --count HEAD...origin/master)
COMMITS_AHEAD=$(echo $COMMITS_DIFF | awk '{print $1}')
COMMITS_BEHIND=$(echo $COMMITS_DIFF | awk '{print $2}')
if [ $COMMITS_AHEAD -gt 0 ]; then
color_echo $YELLOW "You made $COMMITS_AHEAD local commit(s) in the basebox."
color_echo $YELLOW "Don't forget to open a Pull Request against the Enrise repo."
exit 0;
fi
if [ $COMMITS_BEHIND -gt 0 ]; then
color_echo $YELLOW "Your basebox is behind by $COMMITS_BEHIND commit(s) and requires an update."
color_echo $YELLOW "Please make sure to update as soon as possible to prevent problems and technical debt."
exit 0;
fi
color_echo $LGREEN "Your basebox is up-to-date."