luci-app-opkg: update default opkg list dir
[project/luci.git] / applications / luci-app-opkg / root / usr / libexec / opkg-call
1 #!/bin/sh
2
3 . /usr/share/libubox/jshn.sh
4
5 action=$1
6 shift
7
8 case "$action" in
9 list-installed)
10 cat /usr/lib/opkg/status
11 ;;
12 list-available)
13 lists_dir=$(sed -rne 's#^lists_dir \S+ (\S+)#\1#p' /etc/opkg.conf /etc/opkg/*.conf 2>/dev/null | tail -n 1)
14 find "${lists_dir:-/usr/lib/opkg/lists}" -type f '!' -name '*.sig' | xargs -r gzip -cd
15 ;;
16 install|update|remove)
17 (
18 opkg="opkg"
19
20 while [ -n "$1" ]; do
21 case "$1" in
22 --autoremove|--force-overwrite|--force-removal-of-dependent-packages)
23 opkg="$opkg $1"
24 shift
25 ;;
26 -*)
27 shift
28 ;;
29 *)
30 break
31 ;;
32 esac
33 done
34
35 if flock -x 200; then
36 $opkg $action "$@" </dev/null >/tmp/opkg.out 2>/tmp/opkg.err
37 code=$?
38 stdout=$(cat /tmp/opkg.out)
39 stderr=$(cat /tmp/opkg.err)
40 else
41 code=255
42 stderr="Failed to acquire lock"
43 fi
44
45 json_init
46 json_add_int code $code
47 [ -n "$stdout" ] && json_add_string stdout "$stdout"
48 [ -n "$stderr" ] && json_add_string stderr "$stderr"
49 json_dump
50 ) 200>/tmp/opkg.lock
51
52 rm -f /tmp/opkg.lock /tmp/opkg.err /tmp/opkg.out
53 ;;
54 *)
55 echo "Usage: $0 {list-installed|list-available}" >&2
56 echo " $0 {install|upgrade|remove} pkg[ pkg...]" >&2
57 exit 1
58 ;;
59 esac