-
-
Notifications
You must be signed in to change notification settings - Fork 196
/
deploy.sh
executable file
·65 lines (52 loc) · 1.88 KB
/
deploy.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
#!/bin/bash
# Pi-hole: A black hole for Internet advertisements
# (c) 2022 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware.
#
# FTL Engine
# Deploy script for FTL
#
# This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license.
# Transfer Builds to Pi-hole server for pihole checkout
# We use sftp for secure transfer and use the branch name as dir on the server.
# The branch name could contain slashes, creating hierarchical dirs. However,
# this is not supported by sftp's `mkdir` (option -p) is not available. Therefore,
# we need to loop over each dir level and create them one by one.
# Safeguard: do not deploy if TARGET_DIR is empty
if [[ -z ${TARGET_DIR} ]]; then
echo "Error: Empty target dir."
exit 1
fi
IFS='/'
read -r -a path <<<"${TARGET_DIR}"
# Safeguard: do not deploy if more than one subdir (eg. /tweak/feature/subfeature) needs to be created
if [[ "${#path[@]}" -gt 2 ]]; then
echo "Error: Your branch name contains more then one subdir. We won't deploy that."
exit 1
fi
unset IFS
old_path="."
for dir in "${path[@]}"; do
mapfile -t dir_content <<< "$(
sftp -b - "${USER}"@"${HOST}" <<< "cd ${old_path}
ls -1"
)"
# Loop over the dir content and check if this exact dir already exists
path_exists=0
for content in "${dir_content[@]}"; do
if [[ "${content}" == "${dir}" ]]; then
echo "Dir: ${old_path}/${dir} already exists"
path_exists=1
fi
done
# If the dir does not exist, create it
if [[ "${path_exists}" -eq 0 ]]; then
echo "Dir: ${old_path}/${dir} does not exist. Creating it."
sftp -b - "${USER}"@"${HOST}" <<< "cd ${old_path}
-mkdir ${dir}"
fi
old_path="${old_path}/${dir}"
done
sftp -r -b - "${USER}"@"${HOST}" <<< "cd ${old_path}
put ${SOURCE_DIR}/* ./"