From df2415a53d5604755768f00aad0c640df1ad815c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Otto=20Kek=C3=A4l=C3=A4inen?= Date: Sun, 5 Aug 2018 02:41:20 -0500 Subject: [PATCH] Fix bash syntax issues detected by Shellcheck - Remove unused variable MYADMIN - Correctly execute with $() - Encapsulate variables in double quotes - Use ] && [ instead of -a --- debian/mariadb-server-10.1.postinst | 10 +++++----- debian/mariadb-server-10.1.preinst | 17 ++++++++--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/debian/mariadb-server-10.1.postinst b/debian/mariadb-server-10.1.postinst index 43eed58e..c2424de6 100644 --- a/debian/mariadb-server-10.1.postinst +++ b/debian/mariadb-server-10.1.postinst @@ -45,7 +45,7 @@ case "$1" in mv "$savelink" "$targetdir" else # this should never even happen, but just in case... - mysql_tmp=`mktemp -d -t mysql-symlink-restore-XXXXXX` + mysql_tmp=$(mktemp -d -t mysql-symlink-restore-XXXXXX) echo "this is very strange! see $mysql_tmp/README..." >&2 mv "$targetdir" "$mysql_tmp" cat << EOF > "$mysql_tmp/README" @@ -69,16 +69,16 @@ EOF # Ensure the existence and right permissions for the database and # log files. - if [ ! -d "$mysql_statedir" -a ! -L "$mysql_statedir" ]; then mkdir "$mysql_statedir"; fi - if [ ! -d "$mysql_datadir" -a ! -L "$mysql_datadir" ]; then mkdir "$mysql_datadir" ; fi - if [ ! -d "$mysql_logdir" -a ! -L "$mysql_logdir" ]; then mkdir "$mysql_logdir" ; fi + if [ ! -d "$mysql_statedir" ] && [ ! -L "$mysql_statedir" ]; then mkdir "$mysql_statedir"; fi + if [ ! -d "$mysql_datadir" ] && [ ! -L "$mysql_datadir" ]; then mkdir "$mysql_datadir" ; fi + if [ ! -d "$mysql_logdir" ] && [ ! -L "$mysql_logdir" ]; then mkdir "$mysql_logdir" ; fi # When creating an ext3 jounal on an already mounted filesystem like e.g. # /var/lib/mysql, you get a .journal file that is not modifyable by chown. # The mysql_statedir must not be writable by the mysql user under any # circumstances as it contains scripts that are executed by root. set +e chown -R 0:0 $mysql_statedir - find $mysql_datadir ! -uid $(id -u mysql) -print0 | xargs -0 -r chown mysql + find $mysql_datadir ! -uid "$(id -u mysql)" -print0 | xargs -0 -r chown mysql chown -R mysql:adm $mysql_logdir chmod 2750 $mysql_logdir set -e diff --git a/debian/mariadb-server-10.1.preinst b/debian/mariadb-server-10.1.preinst index 3a762708..2f9c3405 100644 --- a/debian/mariadb-server-10.1.preinst +++ b/debian/mariadb-server-10.1.preinst @@ -18,7 +18,6 @@ if [ -n "$DEBIAN_SCRIPT_DEBUG" ]; then set -v -x; DEBIAN_SCRIPT_TRACE=1; fi ${DEBIAN_SCRIPT_TRACE:+ echo "#42#DEBUG# RUNNING $0 $*" 1>&2 } export PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin -MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf" mysql_datadir=/var/lib/mysql mysql_upgradedir=/var/lib/mysql-upgrade @@ -36,12 +35,12 @@ do # The for loop leaves $flag as the query string if there are no results, # so the check below is needed to stop further processing when there are # no real results. - if [ $flag = "$mysql_datadir/debian-*.flag" ] + if [ "$flag" = "$mysql_datadir/debian-*.flag" ] then break fi - flag_version=`echo $flag | sed 's/.*debian-\([0-9\.]\+\).flag/\1/'` + flag_version=$(echo "$flag" | sed 's/.*debian-\([0-9\.]\+\).flag/\1/') # Initialize value if empty if [ -z "$found_version" ] @@ -95,16 +94,16 @@ then echo "previous data directory will be renamed to $mysql_datadir-$found_version and" 1>&2 echo "a new data directory will be initialized at $mysql_datadir." 1>&2 echo "Please manually export/import your data (e.g. with mysqldump) if needed." 1>&2 - mv -f $mysql_datadir $mysql_datadir-$found_version + mv -f "$mysql_datadir" "$mysql_datadir-$found_version" # Also move away the old debian.cnf file that included credentials that are # no longer valid - mv -f /etc/mysql/debian.cnf /etc/mysql/debian.cnf-$found_version + mv -f /etc/mysql/debian.cnf "/etc/mysql/debian.cnf-$found_version" fi # If we use NIS then errors should be tolerated. It's up to the # user to ensure that the mysql user is correctly setup. # Beware that there are two ypwhich one of them needs the 2>/dev/null! -if test -n "`which ypwhich 2>/dev/null`" && ypwhich >/dev/null 2>&1; then +if test -n "$(which ypwhich 2>/dev/null)" && ypwhich >/dev/null 2>&1; then set +e fi @@ -144,7 +143,7 @@ set -e # if there's a symlink, let's store where it's pointing, because otherwise # it's going to be lost in some situations for dir in DATADIR LOGDIR; do - checkdir=`eval echo "$"$dir` + checkdir=$(eval echo "$"$dir) if [ -L "$checkdir" ]; then mkdir -p "$mysql_upgradedir" cp -dT "$checkdir" "$mysql_upgradedir/$dir.link" @@ -152,7 +151,7 @@ for dir in DATADIR LOGDIR; do done # creating mysql home directory -if [ ! -d $mysql_datadir -a ! -L $mysql_datadir ]; then +if [ ! -d $mysql_datadir ] && [ ! -L $mysql_datadir ]; then mkdir $mysql_datadir fi @@ -171,7 +170,7 @@ fi # The "set +e" is necessary as e.g. a ".journal" of a ext3 partition is # not chgrp'able (#318435). set +e -find $mysql_datadir ! -uid $(id -u mysql) -print0 | xargs -0 -r chown mysql +find $mysql_datadir ! -uid "$(id -u mysql)" -print0 | xargs -0 -r chown mysql find $mysql_datadir -follow -not -group mysql -print0 2>/dev/null \ | xargs -0 --no-run-if-empty chgrp mysql set -e -- GitLab