Skip to content

Instantly share code, notes, and snippets.

@yurenchen000
Last active February 20, 2023 20:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yurenchen000/5f52d0b7c1a0104d1a4fb6f3bf119b35 to your computer and use it in GitHub Desktop.
Save yurenchen000/5f52d0b7c1a0104d1a4fb6f3bf119b35 to your computer and use it in GitHub Desktop.
opkg install specify package version

openwrt opkg install not support specify package version.

ref:
https://stackoverflow.com/a/37938130/4896468
https://forum.openwrt.org/t/opkg-install-a-specific-package-version/33158/21

here is a workgroud to implement install specified version of package with opkg.

principle:

  1. find packge url in package list cache
  2. opkg install $pkg_url

shell code:

1. shell func

find_pkg(){
  local name=$1
  local f
  awk '$1 ~ /^src/' /etc/opkg.conf /etc/opkg/*.conf | while read type repo url pad; do
    f=/var/opkg-lists/$repo
	{
      [ $type == "src/gz" ] && zcat $f || cat $f;
    } | {
      awk -vname="$name" '$1=="Package:" && $2==name {f=1;r=1} $0=="" {f=0} f {print} END{exit 1-r}'
    } | while read key val pad; do
      [ "$key" == "Version:" ] && ver=$val
      [ "$key" == "Filename:" ] && {
        echo found $ver @$repo
        echo $url/$val
      }
    done
  done
}

2. usage

$ find_pkg tree
found 9.9.9-1 @chen_test.txt
http://www.example.com/path/to/file?xxx/aaa/bbb/aa_tree_9.9.9-1_mips_24kc.ipk
found 1.7.0-2 @test_30
http://10.1.1.30/ipk/tree_1.7.0-2_ramips_24kec.ipk
found 1.8.0-1 @packages
http://downloads.openwrt.org/releases/18.06.1/packages/mipsel_24kc/packages/tree_1.8.0-1_mipsel_24kc.ipk

then

$ opkg install $url_of_ipk
@Vir-Dominary
Copy link

Hello.I saw you advise in openwrt wiki.
But I don't know how to use a self-defining function in openwrt.
Could you tell me where should i create it and how can i use it?
thanks a lot!

@yurenchen000
Copy link
Author

Hello.I saw you advise in openwrt wiki. But I don't know how to use a self-defining function in openwrt. Could you tell me where should i create it and how can i use it? thanks a lot!

@Vir-Dominary

if only use in terminal shell, just write func define into ~/.profile, which will auto load when login into shell.

or save them to some file ~/_my_util (for example), then source ~/_my_util (in terminal or in script) when you need them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment