enhancement: ability to change and revert firmware and package download paths (#490)

replaces #486
fixes #452
This commit is contained in:
Eric 2020-04-03 13:58:30 -07:00 committed by GitHub
parent a3610db810
commit 83675fbd9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 149 additions and 8 deletions

View File

@ -74,4 +74,25 @@ boot() {
usbvalue=$duval
fi
/usr/local/bin/usb_passthrough "${usbvalue}"
# package repositorys
local repos="core base arednpackages packages luci routing telephony"
set -- $repos
while [ -n "$1" ]; do
local ucirepo=$(uci -q get aredn.@downloads[0].pkgs_$1)
local distrepo=$(grep aredn_$1 /etc/opkg/distfeeds.conf | cut -d' ' -f3)
# get the URLs from distfeeds.conf and set the initial UCI values if not present
if [ -z $ucirepo ]; then
uci set aredn.@downloads[0].pkgs_$1=$distrepo
uci commit aredn
uci -c /etc/config.mesh set aredn.@downloads[0].pkgs_$1=$distrepo
uci -c /etc/config.mesh commit aredn
# check values in distfeeds.conf against UCI settings
# and change distfeeds.conf if needed (upgrades?)
## commented for now, may need it later
#elif [ $ucirepo != $distrepo ]; then
# sed -i "s|$distrepo|$ucirepo|g" /etc/opkg/distfeeds.conf
fi
shift
done
}

View File

@ -168,7 +168,7 @@ if(${hardwaretype} eq "nanostation-m")
# refresh fw
if($parms{button_refresh_fw})
{
if(get_default_gw() ne "none")
if((get_default_gw() ne "none") || ($uciserverpath =~ ".local.mesh"))
{
push @fw_output, "Downloading firmware list from $uciserverpath...\n";
unlink "/tmp/web/firmware.list";
@ -184,7 +184,7 @@ if($parms{button_refresh_fw})
}
else
{
push @fw_output, "Error: no route to the Internet\n";
push @fw_output, "Error: no route to Host\n";
unlink "/tmp/web/firmware.list";
}
}
@ -233,7 +233,7 @@ if($parms{button_ul_fw} and -f "/tmp/web/upload/file")
# download fw
if($parms{button_dl_fw} and $parms{dl_fw} ne "default")
{
if(get_default_gw() ne "none")
if((get_default_gw() ne "none") || ($uciserverpath =~ ".local.mesh"))
{
unlink "$tmpdir/firmware";
system("/usr/local/bin/uploadctlservices","upgrade");
@ -298,7 +298,7 @@ if($parms{button_dl_fw} and $parms{dl_fw} ne "default")
}
else
{
push @fw_output, "Error: no route to the Internet\n";
push @fw_output, "Error: no route to Host\n";
unlink "/tmp/web/firmware.list";
}
}
@ -483,9 +483,10 @@ if($parms{button_ul_pkg} and -f "/tmp/web/upload/file")
}
# download package
$meshpkgs = system('grep -q ".local.mesh" /etc/opkg/distfeeds.conf');
if($parms{button_dl_pkg} and $parms{dl_pkg} ne "default")
{
if(get_default_gw() ne "none")
if((get_default_gw() ne "none") || (!$meshpkgs))
{
system("/usr/local/bin/uploadctlservices","opkginstall");
push @pkg_output, `opkg -force-overwrite install $parms{dl_pkg} 2>&1`;
@ -493,21 +494,21 @@ if($parms{button_dl_pkg} and $parms{dl_pkg} ne "default")
}
else
{
push @pkg_output, "Error: no route to the Internet\n";
push @pkg_output, "Error: no route to Host\n";
}
}
# refresh package list
if($parms{button_refresh_pkg})
{
if(get_default_gw() ne "none")
if((get_default_gw() ne "none") || (!$meshpkgs))
{
@pkg_output = `opkg update 2>&1`;
system "opkg list | grep -v '^ ' | cut -f1,3 -d' ' | gzip -c > /etc/opkg.list.gz";
}
else
{
push @pkg_output, "Error: no route to the Internet\n";
push @pkg_output, "Error: no route to Host\n";
}
}

View File

@ -68,6 +68,56 @@ push @setting, {
desc => "Specifies the URL of the location from which firmware files will be downloaded.",
default => "http://downloads.arednmesh.org/firmware"
};
push @setting, {
key => "aredn.\@downloads[0].pkgs_core",
type => "string",
desc => "Specifies the URL for the 'core' packages: kernel modules and the like",
default => defaultPackageRepos('aredn_core'),
postcallback => "writePackageRepo('core')"
};
push @setting, {
key => "aredn.\@downloads[0].pkgs_base",
type => "string",
desc => "Specifies the URL for the 'base' packages: libraries, shells, etc.",
default => defaultPackageRepos('base'),
postcallback => "writePackageRepo('base')"
};
push @setting, {
key => "aredn.\@downloads[0].pkgs_arednpackages",
type => "string",
desc => "Specifies the URL for the 'arednpackages' packages: vtun, etc.",
default => defaultPackageRepos('arednpackages'),
postcallback => "writePackageRepo('arednpackages')"
};
push @setting, {
key => "aredn.\@downloads[0].pkgs_luci",
type => "string",
desc => "Specifies the URL for the 'luci' packages: luci and things needed for luci.",
default => defaultPackageRepos('luci'),
postcallback => "writePackageRepo('luci')"
};
push @setting, {
key => "aredn.\@downloads[0].pkgs_packages",
type => "string",
desc => "Specifies the URL for the 'packages' packages: everything not included in the other dirs.",
default => defaultPackageRepos('packages'),
postcallback => "writePackageRepo('packages')"
};
push @setting, {
key => "aredn.\@downloads[0].pkgs_routing",
type => "string",
desc => "Specifies the URL for the 'routing' packages: olsr, etc.",
default => defaultPackageRepos('routing'),
postcallback => "writePackageRepo('routing')"
};
push @setting, {
key => "aredn.\@downloads[0].pkgs_telephony",
type => "string",
desc => "Specifies the URL for the 'telephony' packages.",
default => defaultPackageRepos('telephony'),
postcallback => "writePackageRepo('telephony')"
};
push @setting, {
key => "aredn.\@poe[0].passthrough",
type => "boolean",
@ -129,6 +179,15 @@ sub olsr_restart()
return $rc;
}
sub writePackageRepo {
my $repo = @_[0];
my $uciurl = `uci get aredn.\@downloads[0].pkgs_$repo`;
chomp($uciurl);
my $file = '/etc/opkg/distfeeds.conf';
my $disturl = `grep aredn_$repo /etc/opkg/distfeeds.conf | cut -d' ' -f3`;
chomp($disturl);
system("sed -i 's|$disturl|$uciurl|g' $file");
}
# ----- CALLBACKS ----------
read_postdata({acceptfile => false});

View File

@ -2047,5 +2047,65 @@ sub tz_names_array {
return \@array;
}
# firmware/packages downloads functions
sub getDistTarget {
# to tell where to download the kernel mod packages (kmod-tun, etc)
my $filename = '/etc/openwrt_release';
open my $fh, '<', $filename or die "Could not open $filename!";
while(my $row = <$fh>) {
if($row =~ /\bDISTRIB_TARGET\b/) {
chomp $row;
my @target = split /'/, $row;
return @target[1];
}
}
}
sub getRelease {
# what firmware are we running?
my $filename = '/etc/openwrt_release';
open my $fh, '<', $filename or die "Could not open $filename!";
while(my $row = <$fh>) {
if($row =~ /\bDISTRIB_RELEASE\b/) {
my @release = split /'/, $row;
return @release[1];
}
}
}
# unused. commented for now.
#sub firmwareDownload {
# my $target = getDistTarget();
# my $release = getRelease();
# if ($release !~ /\./) {
# return "http://downloads.arednmesh.org/snapshots/trunk/" . $target;
# } else {
# return "http://downloads.arednmesh.org/firmware";
# }
#}
sub defaultPackageRepos {
# returns the default package repository URL based on if the running firmware is a "stable release" or not
# send this function a package repo name, ie: "aredn_core", "arednpackages, "base", "packages", "routing", etc...
my $repo = @_[0];
my $target = getDistTarget();
my $release = getRelease();
my $urlprefix = 'http://downloads.arednmesh.org';
my $url = '';
#check release
if ($release =~ /\./) {
my @nums = split /\./, $release;
$urlprefix .= "/releases/" . @nums[0] . "/" . @nums[1] . "/" . $release . "/";
} else {
#nightly build or self built firmware
$urlprefix .= "/snapshots/trunk/";
}
# have prefix (hopefully), now finish the rest of the url
if ($repo =~ "aredn_core") {
$url = $urlprefix . "targets/" . $target . "/packages";
} else {
$url = $urlprefix . "packages/mips_24kc/" . $repo;
}
return $url;
}
#weird uhttpd/busybox error requires a 1 at the end of this file
1