summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-opkg/root
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-03-03 15:19:21 +0100
committerJo-Philipp Wich <jo@mein.io>2020-03-03 15:21:48 +0100
commit9b25031cb29bd59561e550daccb69935834d7d63 (patch)
tree28f349f51016e2b95caa64221c8927e4bb034e14 /applications/luci-app-opkg/root
parent95804e5eaf917b2026f50ec262c3bae711a6b317 (diff)
luci-app-opkg: rework backend operations
Introduce a new /usr/libexec/opkg-call helper and invoke it via cgi-io instead of ubus. This is required to be able to reload rpcd without timing out currently running opkg ubus calls. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'applications/luci-app-opkg/root')
-rwxr-xr-xapplications/luci-app-opkg/root/usr/libexec/opkg-call59
-rwxr-xr-xapplications/luci-app-opkg/root/usr/libexec/opkg-list15
-rw-r--r--applications/luci-app-opkg/root/usr/share/rpcd/acl.d/luci-app-opkg.json10
3 files changed, 64 insertions, 20 deletions
diff --git a/applications/luci-app-opkg/root/usr/libexec/opkg-call b/applications/luci-app-opkg/root/usr/libexec/opkg-call
new file mode 100755
index 0000000000..5930977112
--- /dev/null
+++ b/applications/luci-app-opkg/root/usr/libexec/opkg-call
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+. /usr/share/libubox/jshn.sh
+
+action=$1
+shift
+
+case "$action" in
+ list-installed)
+ cat /usr/lib/opkg/status
+ ;;
+ list-available)
+ lists_dir=$(sed -rne 's#^lists_dir \S+ (\S+)#\1#p' /etc/opkg.conf /etc/opkg/*.conf 2>/dev/null | tail -n 1)
+ find "${lists_dir:-/tmp/opkg-lists}" -type f '!' -name '*.sig' | xargs -r gzip -cd
+ ;;
+ install|update|remove)
+ (
+ opkg="opkg"
+
+ while [ -n "$1" ]; do
+ case "$1" in
+ --autoremove|--force-overwrite|--force-removal-of-dependent-packages)
+ opkg="$opkg $1"
+ shift
+ ;;
+ -*)
+ shift
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
+
+ if flock -x 200; then
+ $opkg $action "$@" </dev/null >/tmp/opkg.out 2>/tmp/opkg.err
+ code=$?
+ stdout=$(cat /tmp/opkg.out)
+ stderr=$(cat /tmp/opkg.err)
+ else
+ code=255
+ stderr="Failed to acquire lock"
+ fi
+
+ json_init
+ json_add_int code $code
+ [ -n "$stdout" ] && json_add_string stdout "$stdout"
+ [ -n "$stderr" ] && json_add_string stderr "$stderr"
+ json_dump
+ ) 200>/tmp/opkg.lock
+
+ rm -f /tmp/opkg.lock /tmp/opkg.err /tmp/opkg.out
+ ;;
+ *)
+ echo "Usage: $0 {list-installed|list-available}" >&2
+ echo " $0 {install|upgrade|remove} pkg[ pkg...]" >&2
+ exit 1
+ ;;
+esac
diff --git a/applications/luci-app-opkg/root/usr/libexec/opkg-list b/applications/luci-app-opkg/root/usr/libexec/opkg-list
deleted file mode 100755
index 088bc6339a..0000000000
--- a/applications/luci-app-opkg/root/usr/libexec/opkg-list
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/sh
-
-case "$1" in
- installed)
- cat /usr/lib/opkg/status
- ;;
- available)
- lists_dir=$(sed -rne 's#^lists_dir \S+ (\S+)#\1#p' /etc/opkg.conf /etc/opkg/*.conf 2>/dev/null | tail -n 1)
- find "${lists_dir:-/tmp/opkg-lists}" -type f '!' -name '*.sig' | xargs -r gzip -cd
- ;;
- *)
- echo "Usage: $0 {installed|available}" >&2
- exit 1
- ;;
-esac
diff --git a/applications/luci-app-opkg/root/usr/share/rpcd/acl.d/luci-app-opkg.json b/applications/luci-app-opkg/root/usr/share/rpcd/acl.d/luci-app-opkg.json
index 66ef81f103..37f75fb7c9 100644
--- a/applications/luci-app-opkg/root/usr/share/rpcd/acl.d/luci-app-opkg.json
+++ b/applications/luci-app-opkg/root/usr/share/rpcd/acl.d/luci-app-opkg.json
@@ -4,8 +4,8 @@
"read": {
"cgi-io": [ "exec" ],
"file": {
- "/usr/libexec/opkg-list installed": [ "exec" ],
- "/usr/libexec/opkg-list available": [ "exec" ],
+ "/usr/libexec/opkg-call list-installed": [ "exec" ],
+ "/usr/libexec/opkg-call list-available": [ "exec" ],
"/etc/opkg.conf": [ "read" ],
"/etc/opkg/*.conf": [ "read" ]
},
@@ -15,9 +15,9 @@
},
"write": {
"file": {
- "/bin/opkg * install *": [ "exec" ],
- "/bin/opkg * remove *": [ "exec" ],
- "/bin/opkg * update": [ "exec" ],
+ "/usr/libexec/opkg-call install *": [ "exec" ],
+ "/usr/libexec/opkg-call remove *": [ "exec" ],
+ "/usr/libexec/opkg-call update *": [ "exec" ],
"/etc/opkg.conf": [ "write" ],
"/etc/opkg/*.conf": [ "write" ],
"/tmp/upload.ipk": [ "write" ]