Skip to content

Commit bc7e200

Browse files
authored
fix(update-lgsm): cd functionsdir but never back (#4140)
1 parent c6549da commit bc7e200

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
lines changed

lgsm/functions/command_update_linuxgsm.sh

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -182,49 +182,51 @@ fi
182182
# Check and update modules.
183183
if [ -n "${functionsdir}" ]; then
184184
if [ -d "${functionsdir}" ]; then
185-
cd "${functionsdir}" || exit
186-
for functionfile in *; do
187-
# check if module exists in the repo and remove if missing.
188-
# commonly used if module names change.
189-
echo -en "checking ${remotereponame} module ${functionfile}...\c"
190-
github_file_url_dir="lgsm/functions"
191-
if [ "${remotereponame}" == "GitHub" ]; then
192-
curl --connect-timeout 10 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}" 1> /dev/null
193-
else
194-
curl --connect-timeout 10 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${functionfile}" 1> /dev/null
195-
fi
196-
if [ $? != 0 ]; then
197-
fn_print_error_eol_nl
198-
fn_script_log_error "Checking ${remotereponame} module ${functionfile}"
199-
echo -en "removing module ${functionfile}...\c"
200-
if ! rm -f "${functionfile:?}"; then
201-
fn_print_fail_eol_nl
202-
fn_script_log_fatal "Removing module ${functionfile}"
203-
core_exit.sh
204-
else
205-
fn_print_ok_eol_nl
206-
fn_script_log_pass "Removing module ${functionfile}"
207-
fi
208-
else
209-
# compare file
185+
(
186+
cd "${functionsdir}" || exit
187+
for functionfile in *; do
188+
# check if module exists in the repo and remove if missing.
189+
# commonly used if module names change.
190+
echo -en "checking ${remotereponame} module ${functionfile}...\c"
191+
github_file_url_dir="lgsm/functions"
210192
if [ "${remotereponame}" == "GitHub" ]; then
211-
function_file_diff=$(diff "${functionsdir}/${functionfile}" <(curl --connect-timeout 10 -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}"))
193+
curl --connect-timeout 10 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}" 1> /dev/null
212194
else
213-
function_file_diff=$(diff "${functionsdir}/${functionfile}" <(curl --connect-timeout 10 -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${functionfile}"))
195+
curl --connect-timeout 10 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${functionfile}" 1> /dev/null
214196
fi
215-
216-
# results
217-
if [ "${function_file_diff}" != "" ]; then
218-
fn_print_update_eol_nl
219-
fn_script_log_update "Checking ${remotereponame} module ${functionfile}"
220-
rm -rf "${functionsdir:?}/${functionfile}"
221-
fn_update_function
197+
if [ $? != 0 ]; then
198+
fn_print_error_eol_nl
199+
fn_script_log_error "Checking ${remotereponame} module ${functionfile}"
200+
echo -en "removing module ${functionfile}...\c"
201+
if ! rm -f "${functionfile:?}"; then
202+
fn_print_fail_eol_nl
203+
fn_script_log_fatal "Removing module ${functionfile}"
204+
core_exit.sh
205+
else
206+
fn_print_ok_eol_nl
207+
fn_script_log_pass "Removing module ${functionfile}"
208+
fi
222209
else
223-
fn_print_ok_eol_nl
224-
fn_script_log_pass "Checking ${remotereponame} module ${functionfile}"
210+
# compare file
211+
if [ "${remotereponame}" == "GitHub" ]; then
212+
function_file_diff=$(diff "${functionsdir}/${functionfile}" <(curl --connect-timeout 10 -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${functionfile}"))
213+
else
214+
function_file_diff=$(diff "${functionsdir}/${functionfile}" <(curl --connect-timeout 10 -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${functionfile}"))
215+
fi
216+
217+
# results
218+
if [ "${function_file_diff}" != "" ]; then
219+
fn_print_update_eol_nl
220+
fn_script_log_update "Checking ${remotereponame} module ${functionfile}"
221+
rm -rf "${functionsdir:?}/${functionfile}"
222+
fn_update_function
223+
else
224+
fn_print_ok_eol_nl
225+
fn_script_log_pass "Checking ${remotereponame} module ${functionfile}"
226+
fi
225227
fi
226-
fi
227-
done
228+
done
229+
)
228230
fi
229231
fi
230232

0 commit comments

Comments
 (0)