-
Notifications
You must be signed in to change notification settings - Fork 15
/
upload_iso.sh
executable file
·209 lines (179 loc) · 5.93 KB
/
upload_iso.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
####
# @author stev leibelt <[email protected]>
# @since 2022-03-19
####
####
# @param <string: arch_iso_file_path>
# @param <string: latest_build_date_file_path>
####
function _create_latest_build_date ()
{
local ARCH_ISO_FILE_PATH
local CREATION_DATE_TIME
local LATEST_BUILD_DATE_FILE_PATH
ARCH_ISO_FILE_PATH="${1}"
CREATION_DATE_TIME=""
LATEST_BUILD_DATE_FILE_PATH="${2}"
if [[ ! -f "${ARCH_ISO_FILE_PATH}" ]];
then
echo ":: Error!"
echo " Invalid arch iso file path provided"
echo " >>${ARCH_ISO_FILE_PATH}<< is not a file"
echo ""
exit 20
fi
if [[ -f ${PATH_TO_THE_LATEST_BUILD_DATE} ]];
then
if /usr/bin/rm "${PATH_TO_THE_LATEST_BUILD_DATE}";
then
_echo_if_be_verbose " Removed file: ${PATH_TO_THE_LATEST_BUILD_DATE}"
else
echo ":: Error - Could not remove file"
echo " File path: ${PATH_TO_THE_LATEST_BUILD_DATE}"
exit 21
fi
fi
_echo_if_be_verbose " Creating file >>${LATEST_BUILD_DATE_FILE_PATH}<<"
#add date
CREATION_DATE_TIME=$(stat -c '%w' "${ARCH_ISO_FILE_PATH}" | cut -d ' ' -f 1)
_echo_if_be_verbose " Detected creation date >>${CREATION_DATE_TIME}<<"
#add time
CREATION_DATE_TIME=$(echo -n "${CREATION_DATE_TIME}T"; stat -c '%w' "${ARCH_ISO_FILE_PATH}" | cut -d ' ' -f 2 | cut -d '.' -f 1)
_echo_if_be_verbose " Detected creation date time >>${CREATION_DATE_TIME}<<"
touch "${LATEST_BUILD_DATE_FILE_PATH}"
echo "${CREATION_DATE_TIME}" > "${LATEST_BUILD_DATE_FILE_PATH}"
}
####
# @param <string: output>
####
function _echo_if_be_verbose ()
{
if [[ ${BE_VERBOSE} -eq 1 ]];
then
echo "${1}"
fi
}
function _main ()
{
#bo: variables
local PATH_TO_THE_DISTRIBUTION_ENVIRONMENT_FILE
local PATH_TO_THE_ISO
local PATH_TO_THIS_SCRIPT
local PATH_TO_THE_ISO
local PATH_TO_THE_ISO_SHA512
local PATH_TO_THE_LATEST_BUILD_DATE
local PATH_TO_THE_LOCAL_CONFIGURATION
local PATH_TO_THE_OPTIONAL_ENVIRONMENT_FILE
PATH_TO_THIS_SCRIPT=$(cd $(dirname "${BASH_SOURCE[0]}"); pwd)
PATH_TO_THE_DISTRIBUTION_ENVIRONMENT_FILE="${PATH_TO_THIS_SCRIPT}/.env.dist"
PATH_TO_THE_OPTIONAL_ENVIRONMENT_FILE="${PATH_TO_THIS_SCRIPT}/.env"
#eo: variables
#bo: load environment files
set -a
source "${PATH_TO_THE_DISTRIBUTION_ENVIRONMENT_FILE}"
if [[ -f "${PATH_TO_THE_OPTIONAL_ENVIRONMENT_FILE}" ]];
then
source "${PATH_TO_THE_OPTIONAL_ENVIRONMENT_FILE}"
fi
set +a
#eo: load environment files
#bo: user input
#we are storing all arguments for the case if the script needs to be re-executed as root/system user
local ALL_ARGUMENTS_TO_PASS
local BE_VERBOSE
local IS_DRY_RUN
local IS_LTS_KERNEL
local SHOW_HELP
ALL_ARGUMENTS_TO_PASS="${@}"
BE_VERBOSE=0
IS_DRY_RUN=0
IS_LTS_KERNEL=0
SHOW_HELP=0
while true;
do
case "${1}" in
"-d" | "--dry-run" )
IS_DRY_RUN=1
shift 1
;;
"-h" | "--help" )
SHOW_HELP=1
shift 1
;;
"-l" | "--lts" )
IS_LTS_KERNEL=1
shift 1
;;
"-v" | "--verbose" )
BE_VERBOSE=1
shift 1
;;
* )
break
;;
esac
done
#eo: user input
#bo: help
if [[ ${SHOW_HELP} -eq 1 ]];
then
echo ":: Usage"
echo " ${0} [-d|--dry-run] [-h|--help] [-l|--lts] [-v|--verbose]"
exit 0
fi
#bo: help
if [[ ${IS_LTS_KERNEL} -eq 1 ]];
then
PATH_TO_THE_LATEST_BUILD_DATE="${PATH_TO_THIS_SCRIPT}/last_build_date_lts.txt"
PATH_TO_THE_ISO="${PATH_TO_THIS_SCRIPT}/dynamic_data/out/archlinux-archzfs-linux-lts.iso"
PATH_TO_THE_ISO_SHA512="${PATH_TO_THIS_SCRIPT}/dynamic_data/out/archlinux-archzfs-linux-lts.iso.sha512sum"
else
PATH_TO_THE_LATEST_BUILD_DATE="${PATH_TO_THIS_SCRIPT}/last_build_date.txt"
PATH_TO_THE_ISO="${PATH_TO_THIS_SCRIPT}/dynamic_data/out/archlinux-archzfs-linux.iso"
PATH_TO_THE_ISO_SHA512="${PATH_TO_THIS_SCRIPT}/dynamic_data/out/archlinux-archzfs-linux.iso.sha512sum"
fi
#bo: output used flags
if [[ ${BE_VERBOSE} -eq 1 ]];
then
echo ":: Outputting status of the flags."
echo " BE_VERBOSE >>${BE_VERBOSE}<<."
echo " IS_DRY_RUN >>${IS_DRY_RUN}<<."
echo " IS_LTS_KERNEL >>${IS_LTS_KERNEL}<<."
echo " SHOW_HELP >>${SHOW_HELP}<<."
echo ""
fi
#eo: output used flags
#bo: environment check
if [[ ! -f "${PATH_TO_THE_ISO}" ]];
then
echo ":: ERROR - File does not exist!"
echo " File path >>${PATH_TO_THE_ISO}<< is invalid."
exit 1
fi
if [[ ! -f "${PATH_TO_THE_ISO_SHA512}" ]];
then
_echo_if_be_verbose " File >>${PATH_TO_THE_ISO_SHA512}<< not found. Creating it."
sha512sum "${PATH_TO_THE_ISO}" >> "${PATH_TO_THE_ISO_SHA512}"
fi
#eo: environment check
#bo: create latest build date file
_create_latest_build_date "${PATH_TO_THE_ISO}" "${PATH_TO_THE_LATEST_BUILD_DATE}"
#eo: create latest build date file
#bo: upload
_echo_if_be_verbose " Starting upload using following arguments:"
_echo_if_be_verbose " Files: >>${PATH_TO_THE_LATEST_BUILD_DATE}<<, >>${PATH_TO_THE_ISO_SHA512}<< and >>${PATH_TO_THE_ISO}<<."
_echo_if_be_verbose " Key: >>${PATH_TO_SSH_KEY_FILE}<<."
_echo_if_be_verbose " Hostpath: >>${SCP_HOST_PATH}<<."
if [[ ${IS_DRY_RUN} -eq 0 ]];
then
if [[ ${BE_VERBOSE} -eq 1 ]];
then
scp -v -i "${PATH_TO_SSH_KEY_FILE}" "${PATH_TO_THE_LATEST_BUILD_DATE}" "${PATH_TO_THE_ISO_SHA512}" "${PATH_TO_THE_ISO}" "${SCP_HOST_PATH}"
else
scp -i "${PATH_TO_SSH_KEY_FILE}" "${PATH_TO_THE_LATEST_BUILD_DATE}" "${PATH_TO_THE_ISO_SHA512}" "${PATH_TO_THE_ISO}" "${SCP_HOST_PATH}"
fi
fi
#eo: upload
}
_main "${@}"