Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch the requirement for bash to POSIX shell instead #149

Closed
LaszloGombos opened this issue Jun 15, 2021 · 14 comments · Fixed by #161 or #159
Closed

Switch the requirement for bash to POSIX shell instead #149

LaszloGombos opened this issue Jun 15, 2021 · 14 comments · Fixed by #161 or #159

Comments

@LaszloGombos
Copy link

Would it be possible to switch to POSIX shell instead of bash ?

For example alpine linux does not come with bash preinstalled (comes with busybox). This means that the environment needs to be bootstrapped with the native package manager first "apk add bash" before pacapt can be used. Huge fan of the project, just wanted to point out this are for potential improvement.

@cuonglm
Copy link
Collaborator

cuonglm commented Jun 16, 2021

FYI, busybox sh is not a POSIX shell, though.

@icy
Copy link
Owner

icy commented Jun 16, 2021

@LaszloGombos Thanks for using our pacapt and for your suggestion.

I believe the current script has some non-POSIX feature. Porting the script to POSIX shell It's quite possible, though we need to update quite a lot of (its) scripts. The tool also requires grep/awk. I'm not sure about busybox though. I think the need is to address your runtime environment. For that, at the moment, you may want to look at the rust port by @rami3l (https://github.com/rami3l/pacaptr)

@rami3l
Copy link
Collaborator

rami3l commented Jun 16, 2021

@icy Thanks for having mentioned my port!

According to my observation, people seem to go back and forth between pacapt and pacaptr due to the fact that the scopes of the two projects are already slightly different.

Maybe it's time to clarify those differences somewhere, so that people can make a better choice :)

PS: What I have in mind for now:

  • Your version is more of a "minimal" one which only requires bash, a perfect subprocess language, yet my codebase is already quite big for a such a simple util, and the release would be a large binary.
  • Your version still supports more *nix distros than mine, meanwhile mine can be used on Windows.
  • My version has a more complete argument parser, at least that's what it should have in the first place.
  • As for homebrew support, the initial motivation for me to make my own version, actually homebrew itself has been simplified so that your code structure should be able to handle it much better than before.

I'm still bad at bash scripting :(

@icy
Copy link
Owner

icy commented Jun 16, 2021

@rami3l You're welcome. And thanks for your comparison. I'm happy to see your tool has got some success. That's how open source things are working :)

Regarding homebrew I also have seen some new updates, but I don't use them heavily to get them correctly. Do you have a link to the new homebrew features that I can have a look?

I'd like to focus on stability of pacapt and on having more smoke tests for them. I'm a little burnt out today though :(

I'm happy to see you're good (or better) at bash now;) I actually gain a lot of money thanks to bash scripting :D In my current work, I wrote a 600-line tool in Bash + Golang which can have all cool features -for of a very popular 35k-line golang tool , and even more ^.^

@rami3l

This comment has been minimized.

@icy

This comment has been minimized.

@icy
Copy link
Owner

icy commented Jun 18, 2021

`shellcheck` POSIX logs (`pacapt-2.4.4`)

In pacapt line 225:
  local _pacman
  ^-----------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 237:
  [[ "$(uname)" == "SunOS" ]] && _PACMAN="$_pacman" && return
  ^-------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 276:
  [[ -z "$_PACMAN" ]] || return
  ^-----------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 279:
  if [[ -x "/usr/bin/pacman" ]]; then
     ^------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 280:
    $GREP -q "${FUNCNAME[0]}" '/usr/bin/pacman' >/dev/null 2>&1
              ^------------^ SC3028: In POSIX sh, FUNCNAME is undefined.
              ^------------^ SC3054: In POSIX sh, array references are undefined.


In pacapt line 281:
    [[ $? -ge 1 ]] && _PACMAN="pacman" \
    ^------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 285:
  [[ -x "/usr/bin/apt-get" ]] && _PACMAN="dpkg" && return
  ^-------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 286:
  [[ -x "/data/data/com.termux/files/usr/bin/apt-get" ]] && _PACMAN="dpkg" && return
  ^-- SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 287:
  [[ -x "/usr/bin/cave" ]] && _PACMAN="cave" && return
  ^----------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 288:
  [[ -x "/usr/bin/dnf" ]] && _PACMAN="dnf" && return
  ^---------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 289:
  [[ -x "/usr/bin/yum" ]] && _PACMAN="yum" && return
  ^---------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 290:
  [[ -x "/opt/local/bin/port" ]] && _PACMAN="macports" && return
  ^----------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 291:
  [[ -x "/usr/bin/emerge" ]] && _PACMAN="portage" && return
  ^------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 292:
  [[ -x "/usr/bin/zypper" ]] && _PACMAN="zypper" && return
  ^------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 293:
  [[ -x "/usr/sbin/pkg" ]] && _PACMAN="pkgng" && return
  ^----------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 295:
  [[ -x "/usr/sbin/pkg_add" ]] && _PACMAN="pkg_tools" && return
  ^--------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 296:
  [[ -x "/usr/sbin/pkgadd" ]] && _PACMAN="sun_tools" && return
  ^-------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 297:
  [[ -x "/sbin/apk" ]] && _PACMAN="apk" && return
  ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 298:
  [[ -x "/usr/bin/tazpkg" ]] && _PACMAN="tazpkg" && return
  ^------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 299:
  [[ -x "/usr/bin/swupd" ]] && _PACMAN="swupd" && return
  ^-----------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 310:
  local _opt=
  ^--------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 311:
  local _ret=0
  ^--------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 339:
  echo $_opt
       ^---^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
  echo "$_opt"


In pacapt line 360:
  local _opt=
  ^--------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 361:
  local _ret=0
  ^--------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 381:
  echo $_opt
       ^---^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
  echo "$_opt"


In pacapt line 386:
  local _args=""
  ^---------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 387:
  local _debug=
  ^----------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 388:
  local _noconfirm=
  ^--------------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 400:
  local _pacman="$1"
  ^-----------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 401:
  echo -n "pacapt($_pacman): available operations:"
       ^-- SC3037: In POSIX sh, echo flags are undefined.


In pacapt line 407:
      echo -n " $O"
           ^-- SC3037: In POSIX sh, echo flags are undefined.


In pacapt line 424:
  local _tmp_name=
  ^-------------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 425:
  local _pacman=
  ^-----------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 427:
  _tmp_name="${BASH_SOURCE[0]:-?}"
             ^------------------^ SC3028: In POSIX sh, BASH_SOURCE is undefined.


In pacapt line 428:
  if [[ "$_tmp_name" == "?" ]]; then
     ^-----------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 437:
  if grep -Eq -e ":$_pacman[[:space:]]*" <<< "$_SUPPORTED_EXTERNALS"; then
                   ^-- SC1087: Use braces when expanding arrays, e.g. ${array[idx]} (or ${var}[.. to quiet).
                                         ^-^ SC3011: In POSIX sh, here-strings are undefined.


In pacapt line 453:
  if [[ -z "$_TOPT" ]]; then
     ^---------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 501:
          (*) apk add   $_TOPT -- "$@" ;;
                        ^----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
          (*) apk add   "$_TOPT" -- "$@" ;;


In pacapt line 560:
  shopt -u globstar
  ^---------------^ SC3044: In POSIX sh, 'shopt' is undefined.


In pacapt line 564:
  if [[ "$_TOPT" == "q" ]]; then
     ^-------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 577:
  if [[ -n "$*" ]]; then
     ^-----------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 585:
      if [[ "$_TOPT" == "q" ]]; then
         ^-------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 602:
  if [[ -z "$*" ]];then
     ^-----------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 620:
  if [[ "$_TOPT" == "" ]]; then
     ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 688:
  cave resolve $_TOPT "$@" \
               ^----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
  cave resolve "$_TOPT" "$@" \


In pacapt line 691:
  && cave resolve -x $_TOPT "$@"
                     ^----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
  && cave resolve -x "$_TOPT" "$@"


In pacapt line 705:
  if [[ $# -gt 0 ]]; then
     ^------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 729:
  conda search "*$@*"
                 ^-- SC2145: Argument mixes string and array. Use * or separate argument.


In pacapt line 744:
  dnf install $_TOPT "$@"
              ^----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
  dnf install "$_TOPT" "$@"


In pacapt line 764:
  if [[ $# -gt 0 ]]; then
     ^------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 796:
  if [[ "$_TOPT" == "q" ]]; then
     ^-------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 798:
  elif [[ "$_TOPT" == "" ]]; then
       ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 856:
  if [[ "$_TOPT" == "q" ]]; then
     ^-------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 860:
  elif [[ "$_TOPT" == "" ]]; then
       ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 873:
  if [[ -n "$*" ]]; then
     ^-----------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 882:
      if [[ "$_TOPT" == "q" ]]; then
         ^-------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 914:
  if [[ "$_TOPT" == "" ]]; then
     ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 966:
  apt-get install $_TOPT "$@"
                  ^----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
  apt-get install "$_TOPT" "$@"


In pacapt line 999:
  local pkg prefix cellar
  ^---------------------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 1007:
  for package in $cellar/*; do
                 ^-----^ SC2231: Quote expansions in this for loop glob to prevent wordsplitting, e.g. "$dir"/*.txt .


In pacapt line 1008:
    files=(${package}/*/${pkg/#$prefix\//})
          ^-- SC3030: In POSIX sh, arrays are undefined.
           ^--------^ SC2206: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.
                        ^----------------^ SC2206: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.
                        ^----------------^ SC3060: In POSIX sh, string replacement is undefined.


In pacapt line 1009:
    if [[ -e "${files[${#files[@]} - 1]}" ]]; then
       ^-- SC3010: In POSIX sh, [[ ]] is undefined.
              ^------------------------^ SC3054: In POSIX sh, array references are undefined.


In pacapt line 1010:
      echo "${package/#$cellar\//}"
            ^--------------------^ SC3060: In POSIX sh, string replacement is undefined.


In pacapt line 1029:
  if [[ "$_TOPT" == "" ]]; then
     ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1030:
    if [[ "$*" == "" ]]; then
       ^--------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1042:
    if [ $? -ne 0 ]; then
         ^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.


In pacapt line 1047:
    if [ $? -ne 0 ]; then
         ^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.


In pacapt line 1051:
    if [[ "$@" == "" ]]; then
       ^--------------^ SC3010: In POSIX sh, [[ ]] is undefined.
          ^--^ SC2199: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).


In pacapt line 1052:
      _die "pacapt: ${FUNCNAME[0]} requires arguments"
                    ^------------^ SC3028: In POSIX sh, FUNCNAME is undefined.
                    ^------------^ SC3054: In POSIX sh, array references are undefined.


In pacapt line 1055:
    for _target in $@;
                   ^-- SC2068: Double quote array expansions to avoid re-splitting elements.


In pacapt line 1057:
      brew rm $_target
              ^------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
      brew rm "$_target"


In pacapt line 1059:
      while [ "$(join <(sort <(brew leaves)) <(sort <(brew deps $_target)))" != "" ]
                      ^--------------------^ SC3001: In POSIX sh, process substitution is undefined.
                             ^------------^ SC3001: In POSIX sh, process substitution is undefined.
                                             ^---------------------------^ SC3001: In POSIX sh, process substitution is undefined.
                                                    ^-------------------^ SC3001: In POSIX sh, process substitution is undefined.
                                                                ^------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
      while [ "$(join <(sort <(brew leaves)) <(sort <(brew deps "$_target")))" != "" ]


In pacapt line 1061:
        brew rm $(join <(sort <(brew leaves)) <(sort <(brew deps $_target)))
                ^-- SC2046: Quote this to prevent word splitting.
                       ^--------------------^ SC3001: In POSIX sh, process substitution is undefined.
                              ^------------^ SC3001: In POSIX sh, process substitution is undefined.
                                              ^---------------------------^ SC3001: In POSIX sh, process substitution is undefined.
                                                     ^-------------------^ SC3001: In POSIX sh, process substitution is undefined.
                                                                 ^------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
        brew rm $(join <(sort <(brew leaves)) <(sort <(brew deps "$_target")))


In pacapt line 1104:
  local _dcache
  ^-----------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 1109:
    _error "${FUNCNAME[0]}: Unable to delete '$_dcache'."
            ^------------^ SC3028: In POSIX sh, FUNCNAME is undefined.
            ^------------^ SC3054: In POSIX sh, array references are undefined.


In pacapt line 1122:
  2>&1 brew install $_TOPT "$@" \
                    ^----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
  2>&1 brew install "$_TOPT" "$@" \


In pacapt line 1124:
  ret=( ${PIPESTATUS[*]} )
      ^------------------^ SC3030: In POSIX sh, arrays are undefined.
        ^--------------^ SC2206: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.
        ^--------------^ SC3028: In POSIX sh, PIPESTATUS is undefined.
        ^--------------^ SC3054: In POSIX sh, array references are undefined.


In pacapt line 1125:
  if [[ "${ret[1]}" == 126 ]]; then
     ^----------------------^ SC3010: In POSIX sh, [[ ]] is undefined.
         ^-------^ SC3054: In POSIX sh, array references are undefined.


In pacapt line 1127:
    brew cask install $_TOPT "$@"
                      ^----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
    brew cask install "$_TOPT" "$@"


In pacapt line 1129:
    return "${ret[0]}"
            ^-------^ SC3054: In POSIX sh, array references are undefined.


In pacapt line 1156:
  if [[ "$_TOPT" == "" ]]; then
     ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1197:
  if [[ "$_TOPT" == "fetch" ]]; then
     ^-----------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1231:
  if [[ "$_TOPT" == "q" ]]; then
     ^-------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1233:
  elif [[ "$_TOPT" == "" ]]; then
       ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1241:
  if [[ "$_TOPT" == "" ]]; then
     ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1282:
  if [[ "$_TOPT" == "fetch" ]]; then
     ^-----------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1324:
  if [[ "$_TOPT" == "q" && ! -z "$*" ]]; then
     ^-- SC3010: In POSIX sh, [[ ]] is undefined.
                           ^-- SC2236: Use -n instead of ! -z.


In pacapt line 1326:
  elif [[ "$_TOPT" == "q" && -z "$*" ]];then
       ^-- SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1328:
  elif [[ "$_TOPT" == "" && ! -z "$*" ]]; then
       ^-- SC3010: In POSIX sh, [[ ]] is undefined.
                            ^-- SC2236: Use -n instead of ! -z.


In pacapt line 1330:
  elif [[ "$_TOPT" == "" && -z "$*" ]];then
       ^-----------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1338:
  if [[ "$_TOPT" == "" ]]; then
     ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1346:
  if [[ "$_TOPT" == "" ]];then
     ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1387:
  if [[ -z "$*" ]];then
     ^-----------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1396:
  if [[ -z "$PKG_CACHE" ]];then
     ^-------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1398:
  elif [[ ! -d "$PKG_CACHE" ]];then
       ^---------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1424:
  if [[ -x '/usr/bin/qlist' ]]; then
     ^-----------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1426:
  elif [[ -x '/usr/bin/equery' ]]; then
       ^------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1434:
  if [[ -x '/usr/bin/equery' ]]; then
     ^------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1450:
  if [[ "$_TOPT" == "" ]]; then
     ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1451:
    if [[ -x '/usr/bin/eix' ]]; then
       ^---------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1453:
    elif [[ -x '/usr/bin/equery' ]]; then
         ^------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1465:
  if [[ "$_TOPT" == "" ]]; then
     ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1481:
  if [[ -x '/usr/bin/layman' ]]; then
     ^------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1496:
  if [[ -x "/usr/bin/layman" ]]; then
     ^------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1505:
  if [[ -x "/usr/bin/eix" ]]; then
     ^---------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1513:
  if [[ -x "/usr/bin/eclean-dist" ]]; then
     ^-----------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1521:
  if [[ -x "/usr/bin/eclean" ]]; then
     ^------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1541:
  if [[ "$(uname)" == "SunOS" ]]; then
     ^-------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1566:
  if [[ "$_TOPT" == "q" && ! -z "$*" ]]; then
     ^-- SC3010: In POSIX sh, [[ ]] is undefined.
                           ^-- SC2236: Use -n instead of ! -z.


In pacapt line 1568:
  elif [[ "$_TOPT" == "q" && -z "$*" ]]; then
       ^-- SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1632:
  if [[ "$_TOPT" == "q" ]]; then
     ^-------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1635:
  elif [[ "$_TOPT" == "" ]]; then
       ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1647:
  if [[ -z "$*" ]]; then
     ^-----------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1652:
  if [[ "$_TOPT" == "q" ]]; then
     ^-------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1678:
  local _forced=""
  ^-----------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 1680:
  if grep -q -- "--forced" <<<"$*"; then
                           ^-^ SC3011: In POSIX sh, here-strings are undefined.


In pacapt line 1684:
  while (( $# )); do
        ^------^ SC3006: In POSIX sh, standalone ((..)) is undefined.


In pacapt line 1685:
    if [[ "$1" == "--forced" ]]; then
       ^----------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1697:
  local _auto=""
  ^---------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 1699:
  if grep -q -- "--auto" <<<"$*"; then
                         ^-^ SC3011: In POSIX sh, here-strings are undefined.


In pacapt line 1703:
  while (( $# )); do
        ^------^ SC3006: In POSIX sh, standalone ((..)) is undefined.


In pacapt line 1704:
    if [[ "$1" == "--auto" ]]; then
       ^--------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1740:
  local _forced=""
  ^-----------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 1742:
  if grep -q -- "--forced" <<<"$*"; then
                           ^-^ SC3011: In POSIX sh, here-strings are undefined.


In pacapt line 1746:
  while (( $# )); do
        ^------^ SC3006: In POSIX sh, standalone ((..)) is undefined.


In pacapt line 1747:
    if [[ "$1" == "--forced" ]]; then
       ^----------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1811:
  if [[ "$_TOPT" == "q" ]]; then
     ^-------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1813:
  elif [[ "$_TOPT" == "" ]]; then
       ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1853:
  if [[ "$_TOPT" == "" ]]; then
     ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1897:
  yum install $_TOPT "$@"
              ^----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
  yum install "$_TOPT" "$@"


In pacapt line 1948:
  if [[ "$_TOPT" == "q" ]]; then
     ^-------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1952:
  elif [[ "$_TOPT" == "" ]]; then
       ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1960:
  if [[ "$_TOPT" == "s" ]]; then
     ^-------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1974:
    if [[ -f "$file" ]]; then
       ^--------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1977:
  done < <(rpm -ql "$@")
         ^-------------^ SC3001: In POSIX sh, process substitution is undefined.


In pacapt line 1984:
  if [[ "$_TOPT" == "s" ]]; then
     ^-------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1994:
    if [[ -f "$file" ]]; then
       ^--------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 1997:
  done < <(rpm -ql "$@")
         ^-------------^ SC3001: In POSIX sh, process substitution is undefined.


In pacapt line 2011:
  if [[ $# -eq 0 ]]; then
     ^------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 2045:
  local packages=
  ^------------^ SC3043: In POSIX sh, 'local' is undefined.


In pacapt line 2050:
    | grep -q "$@" && echo $package
                           ^------^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
    | grep -q "$@" && echo "$package"


In pacapt line 2055:
  zypper install $_TOPT "$@"
                 ^----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
  zypper install "$_TOPT" "$@"


In pacapt line 2318:
  "zypper_Rs") ;;
  ^---------^ SC2221: This pattern always overrides a later one on line 2321.


In pacapt line 2321:
  "zypper_Rs") ;;
  ^---------^ SC2222: This pattern never matches because of a previous pattern on line 2318.


In pacapt line 2363:
if [[ -z "$PACAPT_DEBUG" ]]; then
   ^----------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 2364:
  [[ "$_PACMAN" != "pacman" ]] \
  ^--------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 2366:
elif [[ "$PACAPT_DEBUG" != "auto" ]]; then
     ^-----------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 2383:
  [[ "${_args:0:1}" == "-" ]] || break
  ^-------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.
      ^----------^ SC3057: In POSIX sh, string indexing is undefined.


In pacapt line 2404:
  while [[ "$i" -lt "${#_args}" ]]; do
        ^------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 2405:
    _opt="${_args:$i:1}"
          ^-----------^ SC3057: In POSIX sh, string indexing is undefined.


In pacapt line 2406:
    (( i ++ ))
    ^--------^ SC3006: In POSIX sh, standalone ((..)) is undefined.
         ^-- SC3018: In POSIX sh, ++ is undefined.


In pacapt line 2423:
      if [[ -n "$_POPT" && "$_POPT" != "$_opt" ]]; then
         ^-- SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 2445:
      if [[ "$_SOPT" == '' ]]; then
         ^------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 2470:
      if [[ "${_SOPT:0:1}" < "$_opt" ]]; then
         ^----------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.
             ^----------^ SC3057: In POSIX sh, string indexing is undefined.


In pacapt line 2471:
        _SOPT="${_SOPT:0:1}$_opt"
               ^----------^ SC3057: In POSIX sh, string indexing is undefined.


In pacapt line 2472:
      elif [[ "${_SOPT:0:1}" == "$_opt" ]]; then
           ^-----------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.
               ^----------^ SC3057: In POSIX sh, string indexing is undefined.


In pacapt line 2475:
        _SOPT="$_opt${_SOPT:0:1}"
                    ^----------^ SC3057: In POSIX sh, string indexing is undefined.


In pacapt line 2484:
      if [[ "${_SOPT:0:1}" == "y" ]]; then
         ^-------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.
             ^----------^ SC3057: In POSIX sh, string indexing is undefined.


In pacapt line 2492:
      if [[ "${_SOPT:0:1}" == "u" ]]; then
         ^-------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.
             ^----------^ SC3057: In POSIX sh, string indexing is undefined.


In pacapt line 2500:
      if [[ "${_SOPT:0:2}" == "cc" ]]; then
         ^--------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.
             ^----------^ SC3057: In POSIX sh, string indexing is undefined.


In pacapt line 2502:
      elif [[ "${_SOPT:0:1}" == "c" ]]; then
           ^-------------------------^ SC3010: In POSIX sh, [[ ]] is undefined.
               ^----------^ SC3057: In POSIX sh, string indexing is undefined.


In pacapt line 2527:
  if [[ -n "$_POPT" && -n "$_SOPT" ]]; then
     ^-- SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 2536:
  elif [[ -z "${_POPT}${_SOPT}${_TOPT}" ]]; then
       ^-- SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 2541:
[[ -n "$_POPT" ]] \
^---------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 2552:
if [[ -n "$*" ]]; then
   ^-----------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 2564:
if [[ -n "$PACAPT_DEBUG" ]]; then
   ^----------------------^ SC3010: In POSIX sh, [[ ]] is undefined.


In pacapt line 2567:
  declare -f "${_PACMAN}_${_POPT}${_SOPT}"
  ^-- SC3044: In POSIX sh, 'declare' is undefined.


In pacapt line 2570:
  "${_PACMAN}_${_POPT}${_SOPT}" $_EOPT "$@"
                                ^----^ SC2086: Double quote to prevent globbing and word splitting.

Did you mean: 
  "${_PACMAN}_${_POPT}${_SOPT}" "$_EOPT" "$@"

For more information:
  https://www.shellcheck.net/wiki/SC1087 -- Use braces when expanding arrays,...
  https://www.shellcheck.net/wiki/SC2068 -- Double quote array expansions to ...
  https://www.shellcheck.net/wiki/SC2145 -- Argument mixes string and array. ...

@icy
Copy link
Owner

icy commented Jun 18, 2021

We don't really need to rewrite all parts using POSIX. We just need POSIX on some restricted environment . e.g OpenWRT (#62). Is that possible to switch the shell at the run-time, @cuonglm ?

@cuonglm
Copy link
Collaborator

cuonglm commented Jun 18, 2021

@icy what do you mean "switch the shell at run-time"?

You can call exec to replace the current process (bash) with the new process (sh), but you still need bash anyway.

@icy
Copy link
Owner

icy commented Jun 18, 2021

Oh, exec is a nice idea. What I would need is to launch bash from sh (not vice-versa). Let's say when user is within openwrt where sh is available (hopefully:D), if we can't see bash there, we continue until it's exhausted; otherwise, we switch over to bash. This is only applicable when the library strictly requires a POSIX shell.

@rami3l
Copy link
Collaborator

rami3l commented Jun 18, 2021

shellcheck POSIX logs (pacapt-2.4.4)

...

@icy Can you use foldable code blocks? That looks like a spam to me otherwise :/

@icy
Copy link
Owner

icy commented Jun 18, 2021

shellcheck POSIX logs (pacapt-2.4.4)
...

@icy Can you use foldable code blocks? That looks like a spam to me otherwise :/

Sorry I thought that's done automatically 🗡️

@icy
Copy link
Owner

icy commented Jun 18, 2021

With recent changes in https://github.com/icy/pacapt/pull/161/files:

  • Yes, we can! We can't mix POSIX and non-POSIX features in the same script: They won't work in strict-POSIX environment
  • (update: Single script, two features). We can generate a POSIX version of pacapt (for now, it only contains apk): That version now can run completely inside an alpine image without bash :)
  • To generate POSIX version, try make pacapt.dev PACAPT_POSIX=yes
  • The script will switch to bash shell (if any) automatically (going to remove this useless feature!)

@icy
Copy link
Owner

icy commented Jun 19, 2021

Great Saturday. I finally can mix up both POSIX and non-POSIX features in the same script. The script detects and loads non-POSIX features dynamically (this was what I couldn't do in any elegant way in my Dlang code :D). Feel free to give a CR on https://github.com/icy/pacapt/pull/161/files . Thanks a lot.

cc: @cuonglm @LaszloGombos @NgoHuy

@icy icy added PR ready and removed In-progress labels Jun 19, 2021
This was linked to pull requests Jun 19, 2021
@icy icy closed this as completed in #161 Jun 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants