agherzan / yubikey-full-disk-encryption

Use YubiKey to unlock a LUKS partition
Apache License 2.0
821 stars 51 forks source link

Fix issues detected by shellcheck #12

Closed Vincent43 closed 7 years ago

Vincent43 commented 7 years ago

This PR fixes most issues detected by shellcheck static analysis tool

https://www.shellcheck.net/ https://github.com/koalaman/shellcheck

In ykfde line 11:
  printf "$msg"; #exit 1;
         ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In ykfde line 24:
    [ $YKFDE_CHALLENGE_YUBIKEY_INSERT_TIMEOUT -gt 0 ] && _yubikey_timeout_str="$YKFDE_CHALLENGE_YUBIKEY_INSERT_TIMEOUT seconds"
      ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 31:
      _endtime=$(date +%s); _usedtime=$(( $_endtime - $_starttime ));
                                          ^-- SC2004: $/${} is unnecessary on arithmetic variables.
                                                      ^-- SC2004: $/${} is unnecessary on arithmetic variables.

In ykfde line 36:
      printf "   Enter password: "; if [ $DBG ]; then read _pw; else read -s _pw; fi
                                         ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                      ^-- SC2162: read without -r will mangle backslashes.
                                                                     ^-- SC2162: read without -r will mangle backslashes.

In ykfde line 38:
      [ $DBG ] || echo # if /NOT/ DBG, we need to output \n here.
        ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 41:
      [ $DBG ] && printf "   (used time:$_usedtime, timeout:$_yubikey_timeout) ykinfo -$YKFDE_CHALLENGE_SLOT \"$YKFDE_CHALLENGE\": "
        ^-- SC2086: Double quote to prevent globbing and word splitting.
                         ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In ykfde line 42:
      _tmp="$(ykinfo -$YKFDE_CHALLENGE_SLOT 2>&1)"; _rc=$?;
                      ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 43:
      [ $DBG ] && echo "[$_rc] '$_tmp'"
        ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 45:
      if [ $_yubikey_timeout -eq -1 -o $_usedtime -le $_yubikey_timeout ]; then
           ^-- SC2086: Double quote to prevent globbing and word splitting.
                                    ^-- SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.
                                                      ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 53:
    [ $DBG ] && echo "   Running NOW: ykchalresp -$YKFDE_CHALLENGE_SLOT \"$YKFDE_CHALLENGE\"..."
      ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 54:
    _passphrase="$(ykchalresp -$YKFDE_CHALLENGE_SLOT "$YKFDE_CHALLENGE" 2>/dev/null| tr -d '\n')"
                               ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 57:
      _passphrase="$(ykchalresp -$YKFDE_CHALLENGE_SLOT "$YKFDE_CHALLENGE" 2>/dev/null| tr -d '\n')"
                                 ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 61:
      _passphrase="$(ykchalresp -$YKFDE_CHALLENGE_SLOT "$YKFDE_CHALLENGE" 2>/dev/null| tr -d '\n')"
                                 ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 63:
    [ $DBG ] && printf "\n   Got as response: '$_passphrase'\n"
      ^-- SC2086: Double quote to prevent globbing and word splitting.
                       ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In ykfde line 65:
    if [ -n "$_passphrase" -a "$YKFDE_CHALLENGE_PASSWORD_NEEDED" = "1" ]; then
                           ^-- SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.

In ykfde line 83:
          [ $trial_nr -le $YKFDE_CRYPTSETUP_TRIALS ] && echo "   Just press ENTER to skip and to try Challenge-Response again."
            ^-- SC2086: Double quote to prevent globbing and word splitting.
                          ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 88:
        printf "   Enter passphrase: "; if [ $DBG ]; then read _passphrase; else read -s _passphrase; fi
                                             ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                          ^-- SC2162: read without -r will mangle backslashes.
                                                                                 ^-- SC2162: read without -r will mangle backslashes.

In ykfde line 89:
        [ $DBG ] || echo # if /NOT/ DBG, we need to output \n here.
          ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 94:
    [ $DBG ] && echo " > Using '$_passphrase' with cryptsetup!"
      ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 95:
    [ $DBG ] && echo " > Decrypting (cryptsetup luksOpen "$YKFDE_LUKS_DEV" \"$YKFDE_LUKS_NAME\")..." || echo " > Decrypting (cryptsetup luksOpen)..."
      ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                          ^-- SC2027: The surrounding quotes actually unquote this. Remove or escape them.
                                                          ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 97:
    _tmp="$(printf "$_passphrase"| cryptsetup luksOpen "$YKFDE_LUKS_DEV" "$YKFDE_LUKS_NAME" 2>&1)";
                   ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In ykfde line 102:
        if [ -n "$YKFDE_SLEEP_AFTER_SUCCESSFUL_CRYPTSETUP" ] && [ $YKFDE_SLEEP_AFTER_SUCCESSFUL_CRYPTSETUP -gt 0 ]; then
                                                                  ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 103:
          [ $DBG ] && echo " > Sleeping $YKFDE_SLEEP_AFTER_SUCCESSFUL_CRYPTSETUP bevore moving on..."
            ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 104:
          sleep $YKFDE_SLEEP_AFTER_SUCCESSFUL_CRYPTSETUP
                ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 117:
    [ $DBG ] && echo "$0:"
      ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 119:
    [ $DBG ] && echo " > Reading YKFDE_CONFIG_FILE..."
      ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 120:
    . "$YKFDE_CONFIG_FILE" || { ykfde_err 001 "Failed reading YKFDE_CONFIG_FILE '$YKFDE_CONFIG_FILE'"; return 1; }
    ^-- SC1090: Can't follow non-constant source. Use a directive to specify location.

In ykfde line 122:
    [ -z "$YKFDE_DISK_UUID" -o -z "$YKFDE_LUKS_NAME" ] && { ykfde_err 002 "'$YKFDE_CONFIG_FILE' must provide YKFDE_DISK_UUID /and/ YKFDE_LUKS_NAME."; return 1; }
                            ^-- SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.

In ykfde line 132:
    [ $DBG ] && echo " > udevadm settle..."
      ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 135:
    [ $DBG ] && echo " > modprobe -a -q dm-crypt..."
      ^-- SC2086: Double quote to prevent globbing and word splitting.

In ykfde line 139:
    local what="$YKFDE_DISK_UUID"; [ -n "$YKFDE_LUKS_NAME" ] && s=" $YKFDE_LUKS_NAME";
                                                                ^-- SC2034: s appears unused. Verify it or export it.

In ykfde line 141:
      printf "\nTRIAL #$trial_nr/$YKFDE_CRYPTSETUP_TRIALS: cryptsetup of $what\n"
             ^-- SC2059: Don't use variables in the printf format string. Use printf "..%s.." "$foo".

In ykfde line 143:
      trial_nr=$(( $trial_nr + 1 ));
                   ^-- SC2004: $/${} is unnecessary on arithmetic variables.