opkg-call 1.2 KB

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