on master help sign in
handle input carefully in shell scripts

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

commit076cfe25d778201081972a6848f9173115b530f4 authorThirnearez <thirnearez@localhost> dateFri 6 Oct 2017, 18:24 (9 years ago) parent2790402
2 files changed+21−21
manage.sh+18−18 utils/update-translations.sh+3−3
manage.sh+18−18
@@ -1,11 +1,11 @@
11#!/bin/sh
22
3−BASE_DIR=$(dirname "`readlink -f "$0"`")
4−PYTHONPATH=$BASE_DIR
3+BASE_DIR="$(dirname -- "`readlink -f -- "$0"`")"
4+PYTHONPATH="$BASE_DIR"
55SEARX_DIR="$BASE_DIR/searx"
6−ACTION=$1
6+ACTION="$1"
77
8−cd "$BASE_DIR"
8+cd -- "$BASE_DIR"
99
1010update_packages() {
1111 pip install --upgrade pip
@@ -24,12 +24,12 @@ install_geckodriver() {
2424 set -e
2525 geckodriver -V > /dev/null 2>&1 || NOTFOUND=1
2626 set +e
27− if [ -z $NOTFOUND ]; then
27+ if [ -z "$NOTFOUND" ]; then
2828 return
2929 fi
3030 GECKODRIVER_VERSION="v0.18.0"
31− PLATFORM=`python -c "import six; import platform; six.print_(platform.system().lower(), platform.architecture()[0])"`
32− case $PLATFORM in
31+ PLATFORM="`python -c "import six; import platform; six.print_(platform.system().lower(), platform.architecture()[0])"`"
32+ case "$PLATFORM" in
3333 "linux 32bit" | "linux2 32bit") ARCH="linux32";;
3434 "linux 64bit" | "linux2 64bit") ARCH="linux64";;
3535 "windows 32 bit") ARCH="win32";;
@@ -47,15 +47,15 @@ install_geckodriver() {
4747 fi
4848 else
4949 GECKODRIVER_DIR="$1"
50− mkdir -p "$GECKODRIVER_DIR"
50+ mkdir -p -- "$GECKODRIVER_DIR"
5151 fi
5252
5353 echo "Installing $GECKODRIVER_DIR/geckodriver from\n $GECKODRIVER_URL"
5454
55− FILE=`mktemp`
56− wget "$GECKODRIVER_URL" -qO $FILE && tar xz -C "$GECKODRIVER_DIR" -f $FILE geckodriver
57− rm $FILE
58− chmod 777 "$GECKODRIVER_DIR/geckodriver"
55+ FILE="`mktemp`"
56+ wget -qO "$FILE" -- "$GECKODRIVER_URL" && tar xz -C "$GECKODRIVER_DIR" -f "$FILE" geckodriver
57+ rm -- "$FILE"
58+ chmod 777 -- "$GECKODRIVER_DIR/geckodriver"
5959}
6060
6161pep8_check() {
@@ -73,14 +73,14 @@ unit_tests() {
7373
7474py_test_coverage() {
7575 echo '[!] Running python test coverage'
76− PYTHONPATH=`pwd` python -m nose2 -C --log-capture --with-coverage --coverage "$SEARX_DIR" -s "$BASE_DIR/tests/unit" \
76+ PYTHONPATH="`pwd`" python -m nose2 -C --log-capture --with-coverage --coverage "$SEARX_DIR" -s "$BASE_DIR/tests/unit" \
7777 && coverage report \
7878 && coverage html
7979}
8080
8181robot_tests() {
8282 echo '[!] Running robot tests'
83− PYTHONPATH=`pwd` python "$SEARX_DIR/testing.py" robot
83+ PYTHONPATH="`pwd`" python "$SEARX_DIR/testing.py" robot
8484}
8585
8686tests() {
@@ -113,11 +113,11 @@ styles() {
113113
114114npm_packages() {
115115 echo '[!] install NPM packages for oscar theme'
116− cd $BASE_DIR/searx/static/themes/oscar
116+ cd -- "$BASE_DIR/searx/static/themes/oscar"
117117 npm install
118118
119119 echo '[!] install NPM packages for simple theme'
120− cd $BASE_DIR/searx/static/themes/simple
120+ cd -- "$BASE_DIR/searx/static/themes/simple"
121121 npm install
122122}
123123
@@ -133,7 +133,7 @@ locales() {
133133}
134134
135135help() {
136− [ -z "$1" ] || printf "Error: $1\n"
136+ [ -z "$1" ] || printf 'Error: %s\n' "$1"
137137 echo "Searx manage.sh help
138138
139139Commands
@@ -156,4 +156,4 @@ Commands
156156
157157[ "$(command -V "$ACTION" | grep ' function$')" = "" ] \
158158 && help "action not found" \
159− || $ACTION "$2"
159+ || "$ACTION" "$2"
utils/update-translations.sh+3−3
@@ -7,9 +7,9 @@
77
88SEARX_DIR='searx'
99
10−pybabel extract -F babel.cfg -o messages.pot $SEARX_DIR
11−for f in `ls $SEARX_DIR'/translations/'`; do
12− pybabel update -N -i messages.pot -d $SEARX_DIR'/translations/' -l $f
10+pybabel extract -F babel.cfg -o messages.pot "$SEARX_DIR"
11+for f in `ls "$SEARX_DIR"'/translations/'`; do
12+ pybabel update -N -i messages.pot -d "$SEARX_DIR"'/translations/' -l "$f"
1313done
1414
1515echo '[!] update done, edit .po files if required and run pybabel compile -d searx/translations/'