handle input carefully in shell scripts

- prevent whitespace-splitting of variable expansions
- prevent interpretation of values as flags/options

(mostly)
This commit is contained in:
Thirnearez 2017-10-06 18:24:21 +00:00 committed by Adam Tauber
parent 2790402060
commit 076cfe25d7
2 changed files with 21 additions and 21 deletions

View File

@ -1,11 +1,11 @@
#!/bin/sh #!/bin/sh
BASE_DIR=$(dirname "`readlink -f "$0"`") BASE_DIR="$(dirname -- "`readlink -f -- "$0"`")"
PYTHONPATH=$BASE_DIR PYTHONPATH="$BASE_DIR"
SEARX_DIR="$BASE_DIR/searx" SEARX_DIR="$BASE_DIR/searx"
ACTION=$1 ACTION="$1"
cd "$BASE_DIR" cd -- "$BASE_DIR"
update_packages() { update_packages() {
pip install --upgrade pip pip install --upgrade pip
@ -24,12 +24,12 @@ install_geckodriver() {
set -e set -e
geckodriver -V > /dev/null 2>&1 || NOTFOUND=1 geckodriver -V > /dev/null 2>&1 || NOTFOUND=1
set +e set +e
if [ -z $NOTFOUND ]; then if [ -z "$NOTFOUND" ]; then
return return
fi fi
GECKODRIVER_VERSION="v0.18.0" GECKODRIVER_VERSION="v0.18.0"
PLATFORM=`python -c "import six; import platform; six.print_(platform.system().lower(), platform.architecture()[0])"` PLATFORM="`python -c "import six; import platform; six.print_(platform.system().lower(), platform.architecture()[0])"`"
case $PLATFORM in case "$PLATFORM" in
"linux 32bit" | "linux2 32bit") ARCH="linux32";; "linux 32bit" | "linux2 32bit") ARCH="linux32";;
"linux 64bit" | "linux2 64bit") ARCH="linux64";; "linux 64bit" | "linux2 64bit") ARCH="linux64";;
"windows 32 bit") ARCH="win32";; "windows 32 bit") ARCH="win32";;
@ -47,15 +47,15 @@ install_geckodriver() {
fi fi
else else
GECKODRIVER_DIR="$1" GECKODRIVER_DIR="$1"
mkdir -p "$GECKODRIVER_DIR" mkdir -p -- "$GECKODRIVER_DIR"
fi fi
echo "Installing $GECKODRIVER_DIR/geckodriver from\n $GECKODRIVER_URL" echo "Installing $GECKODRIVER_DIR/geckodriver from\n $GECKODRIVER_URL"
FILE=`mktemp` FILE="`mktemp`"
wget "$GECKODRIVER_URL" -qO $FILE && tar xz -C "$GECKODRIVER_DIR" -f $FILE geckodriver wget -qO "$FILE" -- "$GECKODRIVER_URL" && tar xz -C "$GECKODRIVER_DIR" -f "$FILE" geckodriver
rm $FILE rm -- "$FILE"
chmod 777 "$GECKODRIVER_DIR/geckodriver" chmod 777 -- "$GECKODRIVER_DIR/geckodriver"
} }
pep8_check() { pep8_check() {
@ -73,14 +73,14 @@ unit_tests() {
py_test_coverage() { py_test_coverage() {
echo '[!] Running python test coverage' echo '[!] Running python test coverage'
PYTHONPATH=`pwd` python -m nose2 -C --log-capture --with-coverage --coverage "$SEARX_DIR" -s "$BASE_DIR/tests/unit" \ PYTHONPATH="`pwd`" python -m nose2 -C --log-capture --with-coverage --coverage "$SEARX_DIR" -s "$BASE_DIR/tests/unit" \
&& coverage report \ && coverage report \
&& coverage html && coverage html
} }
robot_tests() { robot_tests() {
echo '[!] Running robot tests' echo '[!] Running robot tests'
PYTHONPATH=`pwd` python "$SEARX_DIR/testing.py" robot PYTHONPATH="`pwd`" python "$SEARX_DIR/testing.py" robot
} }
tests() { tests() {
@ -113,11 +113,11 @@ styles() {
npm_packages() { npm_packages() {
echo '[!] install NPM packages for oscar theme' echo '[!] install NPM packages for oscar theme'
cd $BASE_DIR/searx/static/themes/oscar cd -- "$BASE_DIR/searx/static/themes/oscar"
npm install npm install
echo '[!] install NPM packages for simple theme' echo '[!] install NPM packages for simple theme'
cd $BASE_DIR/searx/static/themes/simple cd -- "$BASE_DIR/searx/static/themes/simple"
npm install npm install
} }
@ -133,7 +133,7 @@ locales() {
} }
help() { help() {
[ -z "$1" ] || printf "Error: $1\n" [ -z "$1" ] || printf 'Error: %s\n' "$1"
echo "Searx manage.sh help echo "Searx manage.sh help
Commands Commands
@ -156,4 +156,4 @@ Commands
[ "$(command -V "$ACTION" | grep ' function$')" = "" ] \ [ "$(command -V "$ACTION" | grep ' function$')" = "" ] \
&& help "action not found" \ && help "action not found" \
|| $ACTION "$2" || "$ACTION" "$2"

View File

@ -7,9 +7,9 @@
SEARX_DIR='searx' SEARX_DIR='searx'
pybabel extract -F babel.cfg -o messages.pot $SEARX_DIR pybabel extract -F babel.cfg -o messages.pot "$SEARX_DIR"
for f in `ls $SEARX_DIR'/translations/'`; do for f in `ls "$SEARX_DIR"'/translations/'`; do
pybabel update -N -i messages.pot -d $SEARX_DIR'/translations/' -l $f pybabel update -N -i messages.pot -d "$SEARX_DIR"'/translations/' -l "$f"
done done
echo '[!] update done, edit .po files if required and run pybabel compile -d searx/translations/' echo '[!] update done, edit .po files if required and run pybabel compile -d searx/translations/'