-
Notifications
You must be signed in to change notification settings - Fork 3
/
update.sh
executable file
·123 lines (99 loc) · 2.42 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
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
121
122
123
#!/usr/bin/env bash
VERSION=2024-09-06-07-07
DEBUG=0
GITHUB=https://raw.githubusercontent.com
REPOSITORY=druidfi/tools
BRANCH=main
TARGET=tools/make
PROJECT_MAKEFILE=Makefile.project.dist
REPOSITORY_URL=https://github.com/druidfi/tools
while true; do
case "$1" in
-d | --debug ) DEBUG=1; shift ;;
-b | --branch ) BRANCH="$2"; shift ;;
* ) break ;;
esac
done
RED="[0;31m"
GREEN="[0;32m"
YELLOW="[0;33m"
NORMAL="[0m"
CYAN="[0;36m"
declare -a files=(
"Makefile"
"utils.mk"
"include.mk"
"common.mk"
"docker.mk"
"composer.mk"
"javascript.mk"
"drupal.mk"
"symfony.mk"
"lagoon.mk"
"qa.mk"
"kubectl.mk"
"ansible.mk"
)
declare -a remove_files=(
"druid-cli.mk"
"wordpress.mk"
)
main() {
if [[ ${DEBUG} -eq 1 ]]; then
mkdir -p debug
cd debug || exit
fi
printf "\n\e%s%s updater (version %s)\e%s\n\n" "${YELLOW}" "${REPOSITORY}" "${VERSION}" "${NORMAL}"
info "Download main Makefile..."
if [[ ${DEBUG} -eq 1 ]]; then
debug "curl -LJs -H 'Cache-Control: no-cache' -o Makefile ${GITHUB}/${REPOSITORY}/${BRANCH}/make/${PROJECT_MAKEFILE}"
fi
curl -LJs -H 'Cache-Control: no-cache' -o Makefile ${GITHUB}/${REPOSITORY}/${BRANCH}/make/${PROJECT_MAKEFILE}
if [[ ! -d ${TARGET} ]]; then
info "Folder ${TARGET} does not exist, creating it..."
if [[ ${DEBUG} -eq 1 ]]; then
debug "mkdir -p ${TARGET}"
fi
mkdir -p "${TARGET}"
fi
cd "${TARGET}" || exit
info "Download following files from ${REPOSITORY_URL}:"
printf '%s\n' "${files[@]}"
for i in "${!files[@]}"
do
file=${files[i]}
timestamp=$(date +%s)
urls[${i}]="${GITHUB}/${REPOSITORY}/${BRANCH}/make/${file}?t=${timestamp}"
done
for i in "${!files[@]}"
do
if [[ ${DEBUG} -eq 1 ]]; then
debug "curl -LJs -o ${files[i]} ${urls[i]}"
fi
curl -LJs -o "${files[i]}" "${urls[i]}"
done
for i in "${!remove_files[@]}"
do
if [[ ${DEBUG} -eq 1 ]]; then
debug "Remove ${remove_files[i]}"
fi
if [ -f "${remove_files[i]}" ]; then
rm "${remove_files[i]}"
fi
done
if [[ $? -eq 0 ]]
then
printf "\n\e%s[OK]\e%s Update complete!\e%s\n" "${GREEN}" "${YELLOW}" "${NORMAL}"
exit 0
else
printf "\n\e%s[ERROR]\e%s Check if update.sh has correct settings\n" "${RED}" "${NORMAL}"
exit 1
fi
}
info() {
printf "\e%s[Info]\e%s %s\n" "${YELLOW}" "${NORMAL}" "${1}"
}
debug() {
printf "\e%s[Debug]\e%s %s\n" "${CYAN}" "${NORMAL}" "${1}"
}
main