1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-19 02:40:11 +01:00

[mod] utils/manage_static.sh: add script to shellcheck

- add script to shellcheck,
- fix error messages from shellcheck and
- moved global variables to local variables (lower case)

No functional change!

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
Markus Heiser 2021-06-24 15:15:34 +02:00
parent 0606cde105
commit 2cb1f35086
2 changed files with 40 additions and 31 deletions

View File

@ -59,7 +59,8 @@ test.shell:
dockerfiles/docker-entrypoint.sh dockerfiles/docker-entrypoint.sh
$(Q)shellcheck -x -s bash \ $(Q)shellcheck -x -s bash \
utils/brand.env \ utils/brand.env \
./manage \ $(MTOOLS) \
$(MSTATIC) \
utils/lib.sh \ utils/lib.sh \
utils/filtron.sh \ utils/filtron.sh \
utils/searx.sh \ utils/searx.sh \
@ -67,7 +68,7 @@ test.shell:
utils/lxc.sh \ utils/lxc.sh \
utils/lxc-searx.env \ utils/lxc-searx.env \
.config.sh .config.sh
$(Q)./manage build_msg TEST "$@ OK" $(Q)$(MTOOLS) build_msg TEST "$@ OK"
# wrap ./manage script # wrap ./manage script

View File

@ -1,8 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# -*- coding: utf-8; mode: sh indent-tabs-mode: nil -*-
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
BUILD_COMMIT_MESSAGE="Static build" BUILD_COMMIT_MESSAGE="[build] /static"
BUILT_PATHS=( BUILT_PATHS=(
searx/static/themes/oscar/css searx/static/themes/oscar/css
@ -14,70 +13,76 @@ BUILT_PATHS=(
searx/static/themes/simple/src/generated/pygments.less searx/static/themes/simple/src/generated/pygments.less
) )
CURRENT_BRANCH="$(git branch --show-current)"
STAGED_FILES=$(git diff --name-only --cached)
git_log_current_branch() { git_log_current_branch() {
git log "heads/${CURRENT_BRANCH}" --not --exclude="${CURRENT_BRANCH}" --branches --remotes --pretty=format:"%h" local branch
branch="$(git branch --show-current)"
git log "${branch}" --pretty=format:'%h' \
--not --exclude="${branch}" --branches --remotes
} }
is.build.commit() { is.build.commit() {
COMMIT_SHA=$1 local commit_sha="$1"
local commit_message
local commit_files
# check commit message # check commit message
COMMIT_MESSAGE=$(git show -s --format=%s ${COMMIT_SHA}) commit_message=$(git show -s --format=%s "${commit_sha}")
if [ "${COMMIT_MESSAGE}" != "${BUILD_COMMIT_MESSAGE}" ]; then if [ "${commit_message}" != "${BUILD_COMMIT_MESSAGE}" ]; then
echo "Commit message of ${COMMIT_SHA} is '${COMMIT_MESSAGE}'" echo "Commit message of ${commit_sha} is '${commit_message}'"
return 1 return 1
fi fi
# check all files of the commit belongs to $BUILT_PATHS # check all files of the commit belongs to $BUILT_PATHS
COMMIT_FILES=$(git diff-tree --no-commit-id --name-only -r "${COMMIT_SHA}") commit_files=$(git diff-tree --no-commit-id --name-only -r "${commit_sha}")
for i in ${BUILT_PATHS[*]}; do for i in ${BUILT_PATHS[*]}; do
# remove files of ${BUILT_PATHS} # remove files of ${BUILT_PATHS}
COMMIT_FILES=$(echo "${COMMIT_FILES}" | grep -v "^${i}") commit_files=$(echo "${commit_files}" | grep -v "^${i}")
done done
if [ -n "${COMMIT_FILES}" ]; then
echo "Commit $1 contains files that were not build: ${COMMIT_FILES}" if [ -n "${commit_files}" ]; then
echo "Commit $1 contains files that were not build: ${commit_files}"
return 2 return 2
fi fi
return 0 return 0
} }
static.build.commit.drop() { static.build.commit.drop() {
LAST_COMMIT_ID=$(git_log_current_branch | head -1) local last_commit_id
last_commit_id=$(git_log_current_branch | head -1)
if [ -z "${LAST_COMMIT_ID}" ]; then if [ -z "${last_commit_id}" ]; then
echo "Empty branch" echo "Empty branch"
return 1 return 1
fi fi
is.build.commit "${LAST_COMMIT_ID}" if ! is.build.commit "${last_commit_id}"; then
if [ $? -ne 0 ]; then
return $? return $?
fi fi
echo "Drop last commit ${LAST_COMMIT_ID}" echo "Drop last commit ${last_commit_id}"
git reset --hard HEAD~1 git reset --hard HEAD~1
} }
static.build.commit() { static.build.commit() {
local staged_files
# check for not commited files # check for not commited files
NOT_COMMITED_FILES="$(git diff --name-only)" if [ -n "$(git diff --name-only)" ]; then
if [ -n "${NOT_COMMITED_FILES}" ]; then
echo "Some files are not commited:" echo "Some files are not commited:"
echo "${NOT_COMMITED_FILES}" echo "${NOT_COMMITED_FILES}"
return 1 return 1
fi fi
staged_files=$(git diff --name-only --cached)
# check for staged files # check for staged files
if [ -n "${STAGED_FILES}" ]; then if [ -n "${staged_files}" ]; then
echo "Some files are staged:" echo "Some files are staged:"
echo "${STAGED_FILES}" echo "${staged_files}"
return 1 return 1
fi fi
# drop existing commit # drop existing commit
static.commit.drop if static.commit.drop; then
if [ $? -ne 0 ]; then
return $? return $?
fi fi
@ -87,7 +92,7 @@ static.build.commit() {
make themes.all make themes.all
# add build files # add build files
for built_path in ${BUILT_PATHS[@]}; do for built_path in "${BUILT_PATHS[@]}"; do
git add -v "${built_path}" git add -v "${built_path}"
done done
@ -96,16 +101,18 @@ static.build.commit() {
echo "make themes.all has created files that are not in BUILT_PATHS" echo "make themes.all has created files that are not in BUILT_PATHS"
return 2 return 2
fi fi
git commit -m "${BUILD_COMMIT_MESSAGE}"
#
git commit -m "Static build"
) )
} }
static.git.restore.staged() { static.git.restore.staged() {
local STAGED_FILES
STAGED_FILES=$(git diff --name-only --cached)
for i in ${BUILT_PATHS[*]}; do for i in ${BUILT_PATHS[*]}; do
STAGED_FILES_FOR_I=$(echo "${STAGED_FILES}" | grep "^${i}") STAGED_FILES_FOR_I=$(echo "${STAGED_FILES}" | grep "^${i}")
if [ -n "${STAGED_FILES_FOR_I}" ]; then if [ -n "${STAGED_FILES_FOR_I}" ]; then
# shellcheck disable=SC2086
git restore --staged ${STAGED_FILES_FOR_I} git restore --staged ${STAGED_FILES_FOR_I}
fi fi
done done
@ -118,6 +125,7 @@ static.git.restore() {
for i in ${BUILT_PATHS[*]}; do for i in ${BUILT_PATHS[*]}; do
NOT_COMMITED_FILES_FOR_I=$(echo "${NOT_COMMITED_FILES}" | grep "^${i}") NOT_COMMITED_FILES_FOR_I=$(echo "${NOT_COMMITED_FILES}" | grep "^${i}")
if [ -n "${NOT_COMMITED_FILES_FOR_I}" ]; then if [ -n "${NOT_COMMITED_FILES_FOR_I}" ]; then
# shellcheck disable=SC2086
git restore ${NOT_COMMITED_FILES_FOR_I} git restore ${NOT_COMMITED_FILES_FOR_I}
fi fi
done done