-
Notifications
You must be signed in to change notification settings - Fork 15
/
update_functions.sh
executable file
·120 lines (100 loc) · 2.49 KB
/
update_functions.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
function gitcheckout {
dir=$1
branch=$2
remote=$3
if [ ! "$(ls -A "$dir")" ]; then
# Empty directory
update_exec "git submodule sync --recursive"
update_exec "git submodule update --init --recursive"
if [ ! "$(ls -A "$dir")" ]; then
echo "ERROR: el directori $dir no existeix o és buit"
exit 1
fi
fi
echo "Entrant $dir BRANCH $branch REPO $remote ..."
pushd "$dir" > /dev/null || exit 1
if [ -n "$remote" ]; then
update_exec "git remote set-url origin $remote"
update_exec "git fetch"
fi
update_exec "git checkout $branch"
git_pull "$branch"
popd > /dev/null || exit 1
echo 'OK'
}
function git_pull {
branch=$1
if [[ $action == 'stash' ]]
then
update_exec "git stash"
fi
if [[ $action == 'reset' ]]
then
update_exec "git reset --hard origin/$branch"
fi
update_exec "git pull origin $branch --rebase"
if [[ $action == 'stash' ]]
then
if [[ -n $(git stash list) ]]; then
echo ' >>>> Aplicat Stash'
update_exec "git stash pop"
fi
fi
if [[ $action == 'gc' ]]
then
update_exec "git gc"
fi
}
function update_exec {
if ! $1 > /dev/null
then
echo >&2 "ERROR: on $1"
exit 2
fi
}
function get_action {
tempaction=$1
if [[ $tempaction == 'reset' ]]
then
echo 'Demanat RESET'
action=$tempaction
elif [[ $tempaction == 'stash' ]]
then
echo 'Demanat STASH'
action=$tempaction
elif [[ $tempaction == 'gc' ]]
then
echo 'Demanat GC'
action=$tempaction
elif [[ $tempaction == 'onlymoodle' ]]
then
echo 'Demanat actualitzar NOMES MOODLE'
action=$tempaction
elif [[ $tempaction == 'onlywordpress' ]]
then
echo 'Demanat actualitzar NOMES WORDPRESS'
action=$tempaction
elif [[ $tempaction == 'onlyportal' ]]
then
echo 'Demanat actualitzar NOMES PORTAL'
action=$tempaction
else
action=""
fi
}
function pull_submodules {
if [[ $action != 'reset' ]]
then
echo 'Inicialitzant submòduls...'
update_exec "git submodule update --recursive --init"
echo 'Sincronitzant submòduls...'
update_exec "git submodule sync"
fi
./update_submodules.sh "$action"
}
function end_exec {
echo "Garbage collecting..."
git gc
echo "That's all folks!"
}