From a90f1c9b12c4d31ea845fa04188e599ba28dbaf1 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Tue, 5 Apr 2016 19:50:10 -0300 Subject: 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 --- src/etc/inc/pkg-utils.inc | 60 +++++++++++++++++-------- src/etc/pfSense.obsoletedfiles | 1 + src/usr/local/sbin/pfSense-upgrade | 26 ++++++++--- src/usr/local/www/system_update_settings.php | 53 +++++++++++++++++----- tools/builder_common.sh | 67 ++++++++++++---------------- tools/builder_defaults.sh | 3 +- 6 files changed, 136 insertions(+), 74 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. ' . '
' . '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', diff --git a/tools/builder_common.sh b/tools/builder_common.sh index 759a1fc..65635b7 100644 --- a/tools/builder_common.sh +++ b/tools/builder_common.sh @@ -1136,17 +1136,10 @@ clone_to_staging_area() { # Include a sample pkg stable conf to base setup_pkg_repo \ + ${PKG_REPO_DEFAULT} \ ${STAGE_CHROOT_DIR}${PRODUCT_SHARE_DIR}/${PRODUCT_NAME}-repo.conf \ ${TARGET} \ ${TARGET_ARCH} \ - ${PKG_REPO_CONF_BRANCH} \ - "release" - - # Include a sample pkg devel conf to base - setup_pkg_repo \ - ${STAGE_CHROOT_DIR}${PRODUCT_SHARE_DIR}/${PRODUCT_NAME}-repo-devel.conf \ - ${TARGET} \ - ${TARGET_ARCH} \ ${PKG_REPO_CONF_BRANCH} mtree \ @@ -1161,20 +1154,26 @@ clone_to_staging_area() { -X ${_exclude_files} \ . - mkdir -p $(dirname ${STAGE_CHROOT_DIR}${PKG_REPO_PATH}) >/dev/null 2>&1 - - # Create repo and repo-devel packages + local _share_repos_path="${SCRATCHDIR}/repo-tmp/${PRODUCT_SHARE_DIR}/pkg/repos" + rm -rf ${SCRATCHDIR}/repo-tmp >/dev/null 2>&1 + mkdir -p ${_share_repos_path} >/dev/null 2>&1 cp -f ${STAGE_CHROOT_DIR}${PRODUCT_SHARE_DIR}/${PRODUCT_NAME}-repo.conf \ - ${STAGE_CHROOT_DIR}${PKG_REPO_PATH} + ${_share_repos_path} + cp -f ${PKG_REPO_DEFAULT%%.conf}.descr ${_share_repos_path} - core_pkg_create repo "" ${CORE_PKG_VERSION} ${STAGE_CHROOT_DIR} - - cp -f ${STAGE_CHROOT_DIR}${PRODUCT_SHARE_DIR}/${PRODUCT_NAME}-repo-devel.conf \ - ${STAGE_CHROOT_DIR}${PKG_REPO_PATH} - - core_pkg_create repo-devel "" ${CORE_PKG_VERSION} ${STAGE_CHROOT_DIR} + # Add additional repos + for _template in ${PKG_REPO_BASE}/${PRODUCT_NAME}-repo-*.conf; do + _template_filename=$(basename ${_template}) + setup_pkg_repo \ + ${_template} \ + ${_share_repos_path}/${_template_filename} \ + ${TARGET} \ + ${TARGET_ARCH} \ + ${PKG_REPO_CONF_BRANCH} + cp -f ${_template%%.conf}.descr ${_share_repos_path} + done - rm -f ${STAGE_CHROOT_DIR}${PKG_REPO_PATH} + core_pkg_create repo "" ${CORE_PKG_VERSION} ${SCRATCHDIR}/repo-tmp core_pkg_create rc "" ${CORE_PKG_VERSION} ${STAGE_CHROOT_DIR} core_pkg_create base "" ${CORE_PKG_VERSION} ${STAGE_CHROOT_DIR} @@ -1277,11 +1276,7 @@ customize_stagearea_for_image() { pkg_chroot_add ${FINAL_CHROOT_DIR} base fi - if [ -n "${IS_RELEASE}" ]; then - pkg_chroot_add ${FINAL_CHROOT_DIR} repo - else - pkg_chroot_add ${FINAL_CHROOT_DIR} repo-devel - fi + pkg_chroot_add ${FINAL_CHROOT_DIR} repo if [ "${_image_type}" = "iso" -o \ "${_image_type}" = "memstick" -o \ @@ -1510,17 +1505,11 @@ setup_pkg_repo() { return fi - local _target="${1}" - local _arch="${2}" - local _target_arch="${3}" - local _branch="${4}" - local _release="${5}" - - if [ -n "${_release}" ]; then - local _template="${PKG_REPO_TEMPLATE}" - else - local _template="${PKG_REPO_DEVEL_TEMPLATE}" - fi + local _template="${1}" + local _target="${2}" + local _arch="${3}" + local _target_arch="${4}" + local _branch="${5}" if [ -z "${_template}" -o ! -f "${_template}" ]; then echo ">>> ERROR: It was not possible to find pkg conf template ${_template}" @@ -1554,11 +1543,11 @@ builder_setup() { local _arch=$(uname -m) setup_pkg_repo \ + ${PKG_REPO_DEFAULT} \ ${PKG_REPO_PATH} \ ${_arch} \ ${_arch} \ - ${PKG_REPO_CONF_BRANCH} \ - ${IS_RELEASE} + ${PKG_REPO_CONF_BRANCH} # Use fingerprint keys from repo sed -i '' -e "/fingerprints:/ s,\"/,\"${BUILDER_ROOT}/src/," \ @@ -1671,11 +1660,11 @@ pkg_bootstrap() { local _root=${1:-"${STAGE_CHROOT_DIR}"} setup_pkg_repo \ + ${PKG_REPO_DEFAULT} \ ${_root}${PKG_REPO_PATH} \ ${TARGET} \ ${TARGET_ARCH} \ - ${PKG_REPO_CONF_BRANCH} \ - ${IS_RELEASE} + ${PKG_REPO_CONF_BRANCH} pkg_chroot ${_root} bootstrap -f } diff --git a/tools/builder_defaults.sh b/tools/builder_defaults.sh index b8f4bb6..6f32a7c 100644 --- a/tools/builder_defaults.sh +++ b/tools/builder_defaults.sh @@ -312,8 +312,7 @@ export CORE_PKG_REAL_PATH="${CORE_PKG_PATH}/.real_${DATESTRING}" export CORE_PKG_TMP=${CORE_PKG_TMP:-"${SCRATCHDIR}/core_pkg_tmp"} export PKG_REPO_BASE=${PKG_REPO_BASE:-"${FREEBSD_SRC_DIR}/release/pkg_repos"} -export PKG_REPO_TEMPLATE=${PKG_REPO_TEMPLATE:-"${PKG_REPO_BASE}/${PRODUCT_NAME}.conf.template"} -export PKG_REPO_DEVEL_TEMPLATE=${PKG_REPO_DEVEL_TEMPLATE:-"${PKG_REPO_BASE}/${PRODUCT_NAME}-devel.conf.template"} +export PKG_REPO_DEFAULT=${PKG_REPO_DEFAULT:-"${PKG_REPO_BASE}/${PRODUCT_NAME}-repo.conf"} export PKG_REPO_PATH=${PKG_REPO_PATH:-"/usr/local/etc/pkg/repos/${PRODUCT_NAME}.conf"} export PRODUCT_SHARE_DIR=${PRODUCT_SHARE_DIR:-"/usr/local/share/${PRODUCT_NAME}"} -- cgit v1.1