diff --git a/bin/check.sh b/bin/check.sh index 3e491ad0..05095523 100755 --- a/bin/check.sh +++ b/bin/check.sh @@ -87,7 +87,11 @@ _check_POSIX_files() { | grep -Eiqe '^#!/usr/bin/env sh' ; then _check_file "$1" || return 1 + # We only care POSIX issue for files under `lib/` + elif echo "$1" | grep -qs "lib/"; then + >&2 echo ":: WARNING: POSIX help-wanted '$1'" fi + shift done } diff --git a/lib/dpkg.sh b/lib/dpkg.sh index 48064fc2..83bdfb6a 100644 --- a/lib/dpkg.sh +++ b/lib/dpkg.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env sh # Purpose: Debian / Ubuntu support # Author : Anh K. Huynh @@ -20,11 +20,11 @@ _dpkg_init() { # dpkg_Q may _not_implemented # FIXME: Need to support a small list of packages dpkg_Q() { - if [[ "$_TOPT" == "q" ]]; then + if [ "$_TOPT" = "q" ]; then dpkg -l \ | grep -E '^[hi]i' \ | awk '{print $2}' - elif [[ "$_TOPT" == "" ]]; then + elif [ -z "$_TOPT" ]; then dpkg -l "$@" \ | grep -E '^[hi]i' else @@ -45,7 +45,7 @@ dpkg_Qe() { } dpkg_Ql() { - if [[ -n "$*" ]]; then + if [ $# -ge 1 ]; then dpkg-query -L "$@" return fi @@ -54,7 +54,7 @@ dpkg_Ql() { | grep -E '^[hi]i' \ | awk '{print $2}' \ | while read -r _pkg; do - if [[ "$_TOPT" == "q" ]]; then + if [ "$_TOPT" = "q" ]; then dpkg-query -L "$_pkg" else dpkg-query -L "$_pkg" \ @@ -94,7 +94,7 @@ dpkg_Qs() { # dpkg_Rs may _not_implemented dpkg_Rs() { - if [[ "$_TOPT" == "" ]]; then + if [ -z "$_TOPT" ]; then apt-get autoremove "$@" else _not_implemented @@ -140,19 +140,18 @@ dpkg_Sy() { apt-get update "$@" } +# FIXME: A simple implemention for #53 and +# FIXME: https://github.com/icy/pacapt/pull/156 +# FIXME: but I'm not sure there is any issue... dpkg_Ss() { - local IFS=$'\n' - packages=($(apt-cache search "$@")) - for package in ${packages[@]:-} - do - name=${package%% - *} - desc=${package#* - } - dpkg-query -W "$name" > /dev/null 2>&1 - if [[ $? -eq 1 ]]; then - echo -e "package/$name \n $desc" - else - dpkg-query -W -f='package/${binary:Package} ${Version}\t[${Status}]\n ${binary:Summary}\n' "$name" - fi + apt-cache search "${@:-.}" \ + | while read -r name _dash desc; do + if ! dpkg-query -W "$name" > /dev/null 2>&1; then + printf "package/%s \n %s\n" \ + "$name" "$desc" + else + dpkg-query -W -f='package/${binary:Package} ${Version}\n ${binary:Summary}\n' "$name" + fi done } @@ -165,6 +164,7 @@ dpkg_Scc() { } dpkg_S() { + # shellcheck disable=SC2086 apt-get install $_TOPT "$@" } diff --git a/lib/zz_main.sh b/lib/zz_main.sh index e0e9fe82..3617886e 100644 --- a/lib/zz_main.sh +++ b/lib/zz_main.sh @@ -69,26 +69,13 @@ _PACMAN_detect \ # Once we haven't switcher over `bash`, there is great chance # the current system are missing `Bash` ; on these systems # our library are not ready for pure-POSIX features! -# FIXME: Now this list has to be updated manually. if [ -z "${__PACAPT_FORKED__:-}" ]; then case "$_PACMAN" in - "apk") ;; - "conda") ;; - "dnf") ;; - "homebrew") ;; - "macports") ;; - "opkg") ;; - "pkgng") ;; - "pkg_tools") ;; - "portage") ;; - "sun_tools" ) ;; - "swupd" ) ;; - "tazpkg") ;; - "tlmgr" ) ;; - "yum" ) ;; - "zypper" ) ;; - *) + "cave") _die "pacapt($_PACMAN) library is not ready for pure-POSIX features (or your Bash version is not >= 4)." + ;; + *) + ;; esac fi diff --git a/tests/dpkg.txt b/tests/dpkg.txt index 7b3e3e1f..94df8822 100644 --- a/tests/dpkg.txt +++ b/tests/dpkg.txt @@ -7,13 +7,15 @@ # FIXME: debian:squeeze It's unable to run `pacman -Sy` im ubuntu:14.04 ubuntu:16.04 ubuntu:18.04 ubuntu:20.04 ubuntu im debian:jessie debian:stretch debian:buster debian +im debian_bash3 # Remove `docker-clean` because we need *.deb files under /var/cache in ! rm -fv /etc/apt/apt.conf.d/docker-clean ou ^removed .*docker-clean in ! PACAPT_DEBUG=auto pacman -ou debug.*Switching to Bash shell +in ! if bash --version | grep -qs 'version 3'; then echo "Bash3-no-switching"; fi +ou (debug.*Switching to Bash shell)|(Bash3-no-switching) in -P ou available operations:.*( [Q][ ilos])+ @@ -114,7 +116,8 @@ ou ^ Package: screen in -Sc in clear in -sS tmux -ou tmux +ou package/tmux +ou terminal multiplexer # Strong cleaning up in -Sccc