diff options
author | Renato Botelho <renato@netgate.com> | 2016-04-05 19:50:10 -0300 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2016-04-05 19:50:10 -0300 |
commit | a90f1c9b12c4d31ea845fa04188e599ba28dbaf1 (patch) | |
tree | c7332c7aef82031cac8a9ce8d7dea3d1e5bf9611 /src | |
parent | a35bf546b57558535e3fc1958cf3fb2b4d18ade7 (diff) | |
download | pfsense-a90f1c9b12c4d31ea845fa04188e599ba28dbaf1.zip pfsense-a90f1c9b12c4d31ea845fa04188e599ba28dbaf1.tar.gz |
Rework the way repo packages work
- Distribute only a single pfSense-repo package containing all templates
- Create a symlink pointing to selected repo
- Do not limit it only to pfSense-repo and pfSense-repo-devel
Diffstat (limited to 'src')
-rw-r--r-- | src/etc/inc/pkg-utils.inc | 60 | ||||
-rw-r--r-- | src/etc/pfSense.obsoletedfiles | 1 | ||||
-rwxr-xr-x | src/usr/local/sbin/pfSense-upgrade | 26 | ||||
-rw-r--r-- | src/usr/local/www/system_update_settings.php | 53 |
4 files changed, 107 insertions, 33 deletions
diff --git a/src/etc/inc/pkg-utils.inc b/src/etc/inc/pkg-utils.inc index 836e334..48cce82 100644 --- a/src/etc/inc/pkg-utils.inc +++ b/src/etc/inc/pkg-utils.inc @@ -1134,30 +1134,54 @@ function get_system_pkg_version() { ); } -/* Switch between stable and devel repos */ -function pkg_switch_repo($devel = false) { +/* List available repos */ +function pkg_list_repos() { global $g; - $repo_stable = $g['product_name'] . '-repo'; - $repo_devel = $g['product_name'] . '-repo-devel'; + $path = "/usr/local/share/{$g['product_name']}/pkg/repos"; - if ($devel) { - $repo_target = $repo_devel; - } else { - $repo_target = $repo_stable; - } + $default_descr = @file_get_contents($path . "/{$g['product_name']}-repo.descr"); - if (is_pkg_installed($repo_target)) { - /* It's already installed */ - return true; + $default = array( + 'name' => 'Default', + 'path' => $path . "/{$g['product_name']}-repo.conf", + 'descr' => $default_descr + ); + + $result = array($default); + + $conf_files = glob("{$path}/{$g['product_name']}-repo-*.conf"); + foreach ($conf_files as $conf_file) { + $descr_file = preg_replace('/.conf$/', '.descr', $conf_file); + if (file_exists($descr_file)) { + $descr_content = file($descr_file); + $descr = chop($descr_content[0]); + } else { + $descr = 'Unknown'; + } + if (!preg_match('/-repo-(.*).conf/', $conf_file, $matches)) { + continue; + } + $entry = array( + 'name' => ucfirst(strtolower($matches[1])), + 'path' => $conf_file, + 'descr' => $descr + ); + $result[] = $entry; } - /* - * Since both install files in the same place, just - * call pkg_install for target and current one will - * be replaced - */ - return pkg_install($repo_target, true); + return $result; +} + +/* Switch between stable and devel repos */ +function pkg_switch_repo($path) { + global $g; + + safe_mkdir("/usr/local/etc/pkg/repos"); + @unlink("/usr/local/etc/pkg/repos/{$g['product_name']}.conf"); + @symlink($path, "/usr/local/etc/pkg/repos/{$g['product_name']}.conf"); + + return pkg_update(true); } ?> diff --git a/src/etc/pfSense.obsoletedfiles b/src/etc/pfSense.obsoletedfiles index 16854e5..7df07d8 100644 --- a/src/etc/pfSense.obsoletedfiles +++ b/src/etc/pfSense.obsoletedfiles @@ -743,6 +743,7 @@ /usr/local/share/misc /usr/local/share/nls /usr/local/share/pbi-keys +/usr/local/share/pfSense/pfSense-repo-devel.conf /usr/local/share/protocols /usr/local/share/sgml /usr/local/share/skel diff --git a/src/usr/local/sbin/pfSense-upgrade b/src/usr/local/sbin/pfSense-upgrade index e0a0139..de83de1 100755 --- a/src/usr/local/sbin/pfSense-upgrade +++ b/src/usr/local/sbin/pfSense-upgrade @@ -292,11 +292,7 @@ pkg_upgrade() { pkg_update force fi - if is_pkg_installed ${product}-repo-devel; then - local _repo_pkg="${product}-repo-devel" - else - local _repo_pkg="${product}-repo" - fi + local _repo_pkg="${product}-repo" if [ "$(compare_pkg_version ${_repo_pkg})" = "<" ]; then cp /usr/local/etc/pkg/repos/${product}.conf \ @@ -722,6 +718,26 @@ else export HTTP_USER_AGENT="${product}/${product_version}" fi +# Make sure to use default repo conf when it doesn't exist +pkg_repo_conf="/usr/local/etc/pkg/repos/${product}.conf" +default_pkg_repo_conf_path="/usr/local/share/${product}/pkg/repos/${product}-repo.conf" + +pkg_repo_conf_path=$(/usr/local/sbin/read_xml_tag.sh string system/pkg_repo_conf_path \ + ${default_pkg_repo_conf_path}) + +if [ -z "${pkg_repo_conf_path}" -o ! -f "${pkg_repo_conf_path}" ]; then + pkg_repo_conf_path=${default_pkg_repo_conf_path} +fi + +if [ -e "${pkg_repo_conf}" -a ! -L "${pkg_repo_conf}" ]; then + rm -f ${pkg_repo_conf} + ln -sf ${pkg_repo_conf_path} ${pkg_repo_conf} +fi + +if [ "$(readlink ${pkg_repo_conf})" != "${pkg_repo_conf_path}" ]; then + ln -sf ${pkg_repo_conf_path} ${pkg_repo_conf} +fi + # Flags used in _exit export delete_annotation="" export unlock_additional_pkgs="" diff --git a/src/usr/local/www/system_update_settings.php b/src/usr/local/www/system_update_settings.php index d99ea9a..8c7a6f2 100644 --- a/src/usr/local/www/system_update_settings.php +++ b/src/usr/local/www/system_update_settings.php @@ -64,7 +64,10 @@ require("guiconfig.inc"); require("pkg-utils.inc"); +$repos = pkg_list_repos(); + if ($_POST) { + // Set the firmware branch, but only if we are not using it already if ($_POST['fwbranch']) { if (($_POST['fwbranch'] == "development") && !is_pkg_installed($g['product_name'] . "-repo-devel")) { @@ -87,10 +90,21 @@ if ($_POST) { } elseif (isset($config['system']['gitsync']['synconupgrade'])) { unset($config['system']['gitsync']['synconupgrade']); } + $config['system']['gitsync']['repositoryurl'] = $_POST['repositoryurl']; $config['system']['gitsync']['branch'] = $_POST['branch']; + foreach ($repos as $repo) { + if ($repo['name'] == $_POST['fwbranch']) { + $config['system']['pkg_repo_conf_path'] = $repo['path']; + pkg_switch_repo($repo['path']); + break; + } + } + write_config(); + + $savemsg = gettext("Changes have been saved successfully"); } $curcfg = $config['system']['firmware']; @@ -103,6 +117,32 @@ if (file_exists("{$g['tmp_path']}/manifest")) { $preset_urls_split = explode("\n", file_get_contents("{$g['tmp_path']}/manifest")); } +// Create an array of repo names and descriptions to populate the "Branch" selector +function build_repo_list() { + global $repos; + + $list = array(); + + foreach ($repos as $repo) { + $list[$repo['name']] = $repo['descr']; + } + + return($list); +} + +function get_repo_name($path) { + global $repos; + + foreach ($repos as $repo) { + if ($repo['path'] == $path) { + return $repo['name']; + } + } + + /* Default */ + return $repos[0]['name']; +} + include("head.inc"); if ($input_errors) { @@ -125,22 +165,15 @@ $section = new Form_Section('Firmware Branch'); $section->addInput(new Form_Select( fwbranch, 'Branch', - (is_pkg_installed($g['product_name'] . "-repo")) ? "stable":"development", - ["stable" => gettext("Stable"), "development" => gettext("Development")] + get_repo_name($config['system']['pkg_repo_conf_path']), + build_repo_list() ))->setHelp('Please select the stable, or the development branch from which to update the system firmware. ' . ' <br />' . 'Use of the development version is at your own risk!'); $form->add($section); $section = new Form_Section('Updates'); -/* -$section->addInput(new Form_Checkbox( - 'allowinvalidsig', - 'Unsigned images', - 'Allow auto-update firmware images with a missing or invalid digital signature to be used', - isset($curcfg['allowinvalidsig']) - )); -*/ + $section->addInput(new Form_Checkbox( 'disablecheck', 'Dashboard check', |