OPKG in UCI with script or batch

If I run OPKG update command manual and let it load and then install “something” in UCI it works.

But if I run the same commands in UCI with a script or batch run I always get error directly after the update command.

It feels like I need some type of “wait until done” command after each OPKG command. But what is that wait command in UCI?

1 Like

Could you provide a more specific example?

Hello,

In this fresh example I will try to install adblock with batch function and openvpn-openssl by manually copy and paste in UCI.

First a manual opkg update:

root@OpenWrt:~# opkg update
Downloading http://downloads.openwrt.org/releases/19.07.6/targets/mvebu/cortexa9/packages/Packages.gz
Updated list of available packages in /var/opkg-lists/openwrt_core
Downloading http://downloads.openwrt.org/releases/19.07.6/targets/mvebu/cortexa9/packages/Packages.sig
Signature check passed.
Downloading http://downloads.openwrt.org/releases/19.07.6/targets/mvebu/cortexa9/kmods/4.14.215-1-a92a3f5c5bed2671533484c7ace9d5b5/Packages.gz
Updated list of available packages in /var/opkg-lists/openwrt_kmods
Downloading http://downloads.openwrt.org/releases/19.07.6/targets/mvebu/cortexa9/kmods/4.14.215-1-a92a3f5c5bed2671533484c7ace9d5b5/Packages.sig
Signature check passed.
Downloading http://downloads.openwrt.org/releases/19.07.6/packages/arm_cortex-a9_vfpv3-d16/base/Packages.gz
Updated list of available packages in /var/opkg-lists/openwrt_base
Downloading http://downloads.openwrt.org/releases/19.07.6/packages/arm_cortex-a9_vfpv3-d16/base/Packages.sig
Signature check passed.
Downloading http://downloads.openwrt.org/releases/19.07.6/packages/arm_cortex-a9_vfpv3-d16/freifunk/Packages.gz
Updated list of available packages in /var/opkg-lists/openwrt_freifunk
Downloading http://downloads.openwrt.org/releases/19.07.6/packages/arm_cortex-a9_vfpv3-d16/freifunk/Packages.sig
Signature check passed.
Downloading http://downloads.openwrt.org/releases/19.07.6/packages/arm_cortex-a9_vfpv3-d16/luci/Packages.gz
Updated list of available packages in /var/opkg-lists/openwrt_luci
Downloading http://downloads.openwrt.org/releases/19.07.6/packages/arm_cortex-a9_vfpv3-d16/luci/Packages.sig
Signature check passed.
Downloading http://downloads.openwrt.org/releases/19.07.6/packages/arm_cortex-a9_vfpv3-d16/packages/Packages.gz
Updated list of available packages in /var/opkg-lists/openwrt_packages
Downloading http://downloads.openwrt.org/releases/19.07.6/packages/arm_cortex-a9_vfpv3-d16/packages/Packages.sig
Signature check passed.
Downloading http://downloads.openwrt.org/releases/19.07.6/packages/arm_cortex-a9_vfpv3-d16/routing/Packages.gz
Updated list of available packages in /var/opkg-lists/openwrt_routing
Downloading http://downloads.openwrt.org/releases/19.07.6/packages/arm_cortex-a9_vfpv3-d16/routing/Packages.sig
Signature check passed.
Downloading http://downloads.openwrt.org/releases/19.07.6/packages/arm_cortex-a9_vfpv3-d16/telephony/Packages.gz
Updated list of available packages in /var/opkg-lists/openwrt_telephony
Downloading http://downloads.openwrt.org/releases/19.07.6/packages/arm_cortex-a9_vfpv3-d16/telephony/Packages.sig
Signature check passed.

Then manual install of openvpn-openssl:

root@OpenWrt:~# opkg install openvpn-openssl
Installing openvpn-openssl (2.4.7-2) to root...
Downloading http://downloads.openwrt.org/releases/19.07.6/packages/arm_cortex-a9_vfpv3-d16/base/openvpn-openssl_2.4.7-2_arm_cortex-a9_vfpv3-d16.ipk
Installing kmod-tun (4.14.215-1) to root...
Downloading http://downloads.openwrt.org/releases/19.07.6/targets/mvebu/cortexa9/kmods/4.14.215-1-a92a3f5c5bed2671533484c7ace9d5b5/kmod-tun_4.14.215-1_arm_cortex-a9_vfpv3-d16.ipk
Installing liblzo2 (2.10-2) to root...
Downloading http://downloads.openwrt.org/releases/19.07.6/packages/arm_cortex-a9_vfpv3-d16/base/liblzo2_2.10-2_arm_cortex-a9_vfpv3-d16.ipk
Installing libopenssl1.1 (1.1.1i-1) to root...
Downloading http://downloads.openwrt.org/releases/19.07.6/packages/arm_cortex-a9_vfpv3-d16/base/libopenssl1.1_1.1.1i-1_arm_cortex-a9_vfpv3-d16.ipk
Configuring kmod-tun.
Configuring liblzo2.
Configuring libopenssl1.1.
Configuring openvpn-openssl.
root@OpenWrt:~#

Then I try the same concept but with batch command:

root@OpenWrt:~# uci batch << EOF
> opkg update
> opkg install adblock
> EOF
Unknown command
Unknown command
root@OpenWrt:~#

And a little proof of concept of the batch command:

root@OpenWrt:~#  uci batch << EOF
> set network.lan.ipaddr='192.168.1.1'
> commit network
> EOF
root@OpenWrt:~#

I would like to have this automated function for my system update config set script or batch file (I haven't decided which type yet). But I can't get this opkg function to work???

The same concept doesn't work since these tools are entirely different.
They support different features and operate on different objects.

UCI is a configuration manager, while Opkg is a package manager.
UCI operates configurations, while Opkg operates packages.

Opkg can invoke the same operation on multiple packages.
But Opkg doesn't support batch mode for different operations.

You're probably confused by the uci's batch parameter and thinking it's an equivalnt of the batch-file in DOS/Windows. It isn't. The shell-script file is.

opkg update
opkg install adblock

So if run this in a script file it will work?

Yep, it should typically work assuming that:

  • Your device has working internet connectivity.
  • OpenWrt download servers are reachable.
  • You are using a supported OpenWrt release.
  • You have enough memory to run the command.
  • You have enough space to install the packages.
3 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.