Skip to content

Commit

Permalink
Merge pull request #162 from icy/issue-62-openwrt-support
Browse files Browse the repository at this point in the history
lib/opkg: initial support (Fixes #62)
  • Loading branch information
icy authored Jun 21, 2021
2 parents dcb7b08 + e0dfbd2 commit 6234e5a
Show file tree
Hide file tree
Showing 16 changed files with 285 additions and 68 deletions.
13 changes: 9 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
## next

### New features

* Single script can now execute within `POSIX` or `non-POSIX`
environment and it detects/loads features dynamically.
* `lib/opkg`: Add support for `OpenWrt` (and alike)

### Fixes and Updates

* `tests/`: Support new `ubuntu`/`debian` systems
* `lib/yum`, `lib/dpkg`, `lib/apk`: Fix #96, #143
by adding `-q` (quiet) option for `Qs`.
* `tests/`: Support new `ubuntu`/`debian` systems
* `lib/00_core.sh`: POSIX going well
* `lib/zz_main.sh`: POSIX going well

* `lib/apk`:
* Fix many implementation issues.
* `Q` prints version information.
* Fix `--noconfirm` issue (#150)
* Fix many implementation issues.
* POSIX going well
* POSIX version (`pacapt-POSIX` works perfectly without `bash`)
* Remove `{apk,dnf,zypper}_Sw` methods
and fix the `--download-only` for them

## v2.4.4

Expand Down
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ default:
@echo " pacapt : Generate stable script."
@echo ' install : Install stable script into $$BINDIR.'
@echo " clean : (Experimental) Remove git-ignored files."
@echo " shellcheck : Syntax and style checking. Use http://shellcheck.net/."
@echo " docker.i : Launch interactive Docker container which mounts."
@echo ' your local 'pacapt.dev' script to $$BINDIR/pacman.'
@echo ' Please use DISTRO= to specify Docker image'
@echo " shellcheck : It's shellcheck."
@ecoh " POSIX : Use shellcheck with POSIX checks for some scripts."
@echo " docker.i : Launch interactive Docker container which mounts"
@echo ' your local working directory to /src/'
@echo ' and create symlink /bin/pacman to the local pacapt.dev'.
@echo ' Please use DISTRO= to specify Docker image.'
@echo " tests : Run all tests. Please read tests/README.md first."
@echo " Use TESTS= to specify a package. Docker is required."
@echo " stats : Generate table of implemented operations in development branch."
Expand Down Expand Up @@ -75,8 +77,8 @@ $(BINDIR)/pacapt: pacapt
.PHONY: docker.i
docker.i:
@docker run --rm -ti \
-v $(PWD)/pacapt.dev:$(BINDIR)/pacman \
$(DISTRO) /bin/bash
-v $(PWD)/:/src/ \
$(DISTRO) /bin/sh -c 'ln -s /src/pacapt.dev /bin/pacman && exec sh'

.PHONY: update_stats
update_stats:
Expand Down
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

`pacapt` is a wrapper for many package managers.
Simply install package with `pacapt -S htop` or `pacapt install htop`
on any `Linux`, `BSD`, `Mac OS` machines.
on any `Linux`, `BSD`, `OpenWrt` or `Mac OS` machines.
It supports the following package managers:

* `pacman` by `Arch Linux`, `ArchBang`, `Manjaro`, etc.
Expand All @@ -19,6 +19,7 @@ It supports the following package managers:
* `pkg_tools` by `OpenBSD`
* `sun_tools` by `Solaris(SunOS)`
* `apk` by `Alpine Linux`
* `opkg` by `OpenWrt`
* `tazpkg` by `SliTaz Linux`
* `swupd` by `Clear Linux`
* `tlmgr` by `TeX Live`
Expand All @@ -44,7 +45,7 @@ It supports the following package managers:
## Installation

1. This script shouldn't be installed on an Arch-based system;
2. On `FreeBSD` and `Alpine Linux`, please install `bash` package first.
2. On `FreeBSD`, please install `bash` package first.

### Install stable `Bash` script 2.4.x from Github

Expand Down Expand Up @@ -113,23 +114,24 @@ A long list of options and operations can be found from [`ArchLinux`'s wiki](htt
### Implemented operations

```
Q Qc Qe Qi Qk Ql Qm Qo Qp Qs Qu R Rn Rns Rs S Sc Scc Sccc Sg Si Sii Sl Ss Su Suy Sw Sy U
apk ~ * * * * * * * * * * * * * * * * * * * * * *
cave * * * * * * * * * * * * * * x * * * * * x
Q Qc Qe Qi Qk Ql Qm Qo Qp Qs Qu R Rn Rns Rs S Sc Scc Sccc Sg Si Sii Sl Ss Su Suy Sy U
apk ~ * * * * * * * * * * * * * * * * * * * * *
cave * * * * * * * * * * * * * * x * * * * * x
conda * * * * * * *
dnf ~ * * * * * * * * * * * * * * * * * * * * * * *
dpkg ~ * * * * * * * * * ~ * * * * * * * * * * *
homebrew ~ * * * * * * * * * * * * * * * * *
macports * * * * * ~ * * * * * * * *
pkgng * * * * * * * * * * * * * * * *
pkg_tools ~ * * * * * * * * ~ * * x * * ~ * * x
portage * * * * * * * * * * * * * * * * *
sun_tools * * * * * * *
swupd * * * * * * * * *
tazpkg * * * * * * * * * * * * *
tlmgr * * * * * * * * * *
yum * * * * * * * * * * * * * * * * * * * * * *
zypper * * * * * * * * * * * * * * * * * * * * * * * * * *
dnf ~ * * * * * * * * * * * * * * * * * * * * * *
dpkg ~ * * * * * * * * * ~ * * * * * * * * * * *
homebrew ~ * * * * * * * * * * * * * * * * *
macports * * * * * ~ * * * * * * * *
opkg * * * * * * * * * * * * * *
pkgng * * * * * * * * * * * * * * * *
pkg_tools ~ * * * * * * * * ~ * * x * * ~ * * x
portage * * * * * * * * * * * * * * * * *
sun_tools * * * * * * *
swupd * * * * * * * * *
tazpkg * * * * * * * * * * * * *
tlmgr * * * * * * * * * *
yum * * * * * * * * * * * * * * * * * * * * * *
zypper * * * * * * * * * * * * * * * * * * * * * * * * *
```

**Notes:**
Expand Down
29 changes: 13 additions & 16 deletions bin/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,36 +61,33 @@ _has_shellcheck() {
}

_check_file() {
local _file="${1:-/x/x/x/x/x/x/x/}"
local_file="${1:-/x/x/x/x/x/x/x/}"
local_shell="${SHELLCHECK_SHELL:-bash}"

echo >&2 ":: ${FUNCNAME[0]}: $1"
echo >&2 ":: ${FUNCNAME[0]} (${local_shell}): $1"

[[ -f "$_file" ]] \
[[ -f "$local_file" ]] \
|| {
echo >&2 ":: File not found '$_file'"
echo >&2 ":: File not found '$local_file'"
return 1
}

_simple_check "$_file" || return
_simple_check "$local_file" || return

shellcheck -s "${SHELLCHECK_SHELL:-bash}" -f json "$_file" \
| _shellcheck_output_format "$_file"
shellcheck -s "${local_shell}" -f json "$local_file" \
| _shellcheck_output_format "$local_file"

[[ "${PIPESTATUS[0]}" == "0" ]]
}

_check_POSIX_file() {
if ! grep -Eiqe "^# +POSIX.*:.*Ready" -- "$1" ; then
>&2 echo ":: $1: POSIX is not required."
else
_check_file "$1" || return 1
fi
}

_check_POSIX_files() {
export SHELLCHECK_SHELL="sh"
while (( $# )); do
_check_POSIX_file "$1" || return 1
if awk 'NR==1' < "$1" \
| grep -Eiqe '^#!/usr/bin/env sh' ;
then
_check_file "$1" || return 1
fi
shift
done
}
Expand Down
3 changes: 2 additions & 1 deletion bin/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ library_files() {
}

library_POSIX_ready() {
grep -Eqie "^# +POSIX.*:.*Ready" -- "$@"
grep -Eqie '#!/usr/bin/env sh' -- "$@"
}

########################################################################
Expand All @@ -129,6 +129,7 @@ for L in $(library_files); do
|| continue

if library_POSIX_ready "$L"; then
>&2 echo ":: POSIX library '$L'"
$GREP -v '^#' "$L"
else
$GREP -v '^#' "$L" | awk '{printf("#_!_POSIX_# %s\n", $0)}'
Expand Down
7 changes: 5 additions & 2 deletions lib/00_core.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
#!/usr/bin/env sh

# POSIX : Ready
# Purpose: Provide some basic functions
# Author : Anh K. Huynh
# License: Fair license (http://www.opensource.org/licenses/fair)
Expand Down Expand Up @@ -98,6 +97,7 @@ _PACMAN_detect() {
_issue2pacman pkg_tools "OpenBSD" && return
_issue2pacman pkg_tools "Bitrig" && return
_issue2pacman apk "Alpine Linux" && return
_issue2pacman opkg "OpenWrt" && return

[ -z "$_PACMAN" ] || return

Expand All @@ -121,6 +121,7 @@ _PACMAN_detect() {
[ -x "/usr/sbin/pkg_add" ] && _PACMAN="pkg_tools" && return
[ -x "/usr/sbin/pkgadd" ] && _PACMAN="sun_tools" && return
[ -x "/sbin/apk" ] && _PACMAN="apk" && return
[ -x "/bin/opkg" ] && _PACMAN="opkg" && return
[ -x "/usr/bin/tazpkg" ] && _PACMAN="tazpkg" && return
[ -x "/usr/bin/swupd" ] && _PACMAN="swupd" && return

Expand All @@ -141,6 +142,7 @@ _translate_w() {
case "$_PACMAN" in
"dpkg") local_opt="-d";;
"cave") local_opt="-f";;
"dnf") local_opt="--downloadonly";;
"macports") local_opt="fetch";;
"portage") local_opt="--fetchonly";;
"zypper") local_opt="--download-only";;
Expand All @@ -156,6 +158,7 @@ _translate_w() {
local_ret=1
;;
"apk") local_opt="fetch";;
"opkg") local_opt="--download-only";;
*)
local_opt=""
local_ret=1
Expand Down
3 changes: 1 addition & 2 deletions lib/00_external.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

# POSIX : Ready
# Purpose : Provide some basic settings for external package managers
# Author : Ky-Anh Huynh
# License : MIT
Expand Down
9 changes: 2 additions & 7 deletions lib/apk.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
#!/usr/bin/env sh

# POSIX : Ready
# Purpose: Support next-generation Alpine Linux apk package manager
# Author : Carl X. Su <bcbcarl@gmail.com>
# Cuong Manh Le <cuong.manhle.vn@gmail.com>
Expand All @@ -20,6 +19,7 @@ _apk_init() {
}

# apk_Q may _not_implemented
# FIXME: Need to support a small list of packages
apk_Q() {
case "$_TOPT" in
"")
Expand Down Expand Up @@ -162,11 +162,6 @@ apk_Sy() {
apk update
}

apk_Sw() {
# shellcheck disable=2086
apk fetch $_TOPT -- "$@"
}

apk_U() {
# shellcheck disable=2086
apk add --allow-untrusted $_TOPT -- "$@"
Expand Down
4 changes: 0 additions & 4 deletions lib/dnf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ dnf_Suy() {
dnf upgrade "$@"
}

dnf_Sw() {
dnf download "$@"
}

dnf_Sy() {
dnf clean expire-cache && dnf check-update
}
Expand Down
1 change: 1 addition & 0 deletions lib/dpkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _dpkg_init() {
}

# dpkg_Q may _not_implemented
# FIXME: Need to support a small list of packages
dpkg_Q() {
if [[ "$_TOPT" == "q" ]]; then
dpkg -l \
Expand Down
Loading

0 comments on commit 6234e5a

Please sign in to comment.