diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/CHANGELOG b/CHANGELOG index f5d5baa..5a1d487 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,61 @@ -====================== +====================== = Extension Bastille = ====================== Version Description +1.4.04......Dashboard cosmetic changes and fixes, thanks to rucko24. +1.4.03......Cosmetic changes, adjust options row position. +1.4.02......Add resizable columns and auto-refresh option, thanks to rucko24. +1.4.01......Code fixes and improvements, thanks to rucko24. +1.4.00......Performance and code improvements, thanks to rucko24. +1.3.01......Check/update bastille config parameters on runtime. +1.3.00......Code improvements/fixes and dashboard cosmetic changes. +1.2.31......Minor cosmetic/wording changes. +1.2.30......Add auto and live export modes, add ZST compression support. +1.2.29......Fix jail backup. +1.2.28......Minor cosmetic/wording changes. +1.2.27......Minor cosmetic/wording changes. +1.2.26......Minor cosmetic/wording changes. +1.2.25......Add 'etcupdate' missing command, update bundled files. +1.2.24......Minor code changes/improvements. +1.2.23......Check/update bastille config parameters on runtime. +1.2.22......Make sure minor changes are always applied. +1.2.21......Check/update bastille config parameters on runtime. +1.2.20......Allow install in zroot platform with optional zfs dataset. +1.2.19......Fix typo in tarballs page and cleanup, thanks to Lux. +1.2.18......Fix typo in tarballs download page, thanks to Lux. +1.2.17......Check if bastille_zfs_enable is actually set to NO before zfs disable. +1.2.16......Disable zfs activation warnings if bastille_zfs_enable is set to NO. +1.2.15......Minor code changes/improvements. +1.2.14......Make sure bastille-prefix ends with bastille. +1.2.13... ..Fallback for custom bastille prefix name. +1.2.12......Minor code improvements, clean stale pkg files on error. +1.2.11......Add all bastille Linux flavors bootstrap options. +1.2.10......Minor code improvements and cleanup. +1.2.09......Add Debian keyring and minor code changes. +1.2.08......Code cleanup, remove unnecessary statement. +1.2.07......Minor cosmetic/wording changes. +1.2.06......Code changes, symlink bundled files in embedded platforms. +1.2.05......Mount unionfs for pkg while fetching debootstrap packages. +1.2.04......Fix for missing variable affecting embedded platforms, thanks to tga. +1.2.03......Added post upgrade function for convenience, cleanup obsolete code. +1.2.02......Always execute extension script after upgrade from WebGUI, code changes. +1.2.01......Fix extension script missing statement preventing for new installs. +1.2.00......Re-add Linux jail feature, WebGUI fixes and overall improvements. +1.1.53......Code changes, handle osrelease parameter update in bastille-init. +1.1.52......Re-add Thin jail release change and code improvements. +1.1.51......Code update/improvements, update jail config/util pages and bastille-init. +1.1.50......Disable linux_compat due incompatibility with later releases. +1.1.49......Disable basic interface to comply with bastille new syntax. +1.1.48......Add action to set priority value from utilities. +1.1.47......Cosmetic changes and improvements. +1.1.46......Display jail IP using bastille list buil-in command. +1.1.45......Code update for recent bastille boot settings changes. +1.1.44......Fix bastille version display under maintenance tab. +1.1.43......Update: Finish adding support for 14.3 release. +1.1.42......Update: Add support for 14.3 release + add -a option for destroy. +1.1.41......Update: Add support for 14.2 release. +1.1.40......Code fixes/improvements thanks to tschettervictor. 1.1.39......Update release list on bastille_manager_add.php. 1.1.38......Update release list, added new Debian/Ubuntu distros. 1.1.37......Workaround to copy host resolv.conf to jail path. @@ -115,7 +168,7 @@ Version Description 1.0.30......Ability to convert thin jail to thick jail. 1.0.29......Added Chinese (Simplified) translation, thanks to lijinbiao. 1.0.28......Improve fstab utility error handling. -1.0.27......Improved fstab utility, don't allow blank fields. +1.0.27......Improved fstab utility, don't allow blank fields. 1.0.26......Improved jail IP search during import. 1.0.25......Add foreign jail import support, improved fstab utility. 1.0.24......Improved Thick container upgrade process. diff --git a/LICENSE b/LICENSE index 85f2386..5800f1c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ --------------------------------------------------------- - Copyright (c) 2019, José Rivera + Copyright (c) 2019-2026, Jose Rivera All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index 7ccf5da..3b62e15 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,17 @@ **Description:** - This is the XigmaNAS Bastille Extension for quickly create and manage FreeBSD Jails/Containers. + This is the XigmaNAS Bastille Extension to create and manage FreeBSD Jails/Containers. + +**Install** + +``` +mkdir -p /mnt/tank/extensions/bastille +cd /mnt/tank/extensions/bastille +fetch --no-verify-peer https://raw.githubusercontent.com/JRGTH/xigmanas-bastille-extension/master/bastille-init && chmod +x bastille-init && ./bastille-init && echo "=> Done!" +``` **Credits:** - Christer Edwards (cedwards) Bastille, J.M. Rivera (JRGTH) XigmaNAS Add-on. + Christer Edwards (cedwards) Bastille, J.M. Rivera (JRGTH) Bastille and XigmaNAS Add-on. Additional information on Bastille: http://bastillebsd.org/ diff --git a/bastille-init b/bastille-init old mode 100644 new mode 100755 index 4ecd2b2..b86582a --- a/bastille-init +++ b/bastille-init @@ -9,7 +9,7 @@ # Debug script #set -x -# Copyright (c) 2019-2024, José Rivera (joserprg@gmail.com). +# Copyright (c) 2019-2026, José Rivera (joserprg@gmail.com). # All rights reserved. # Redistribution and use in source and binary forms, with or without @@ -43,14 +43,11 @@ PATH=${PATH}:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin CWDIR=$(dirname $(realpath $0)) # Global variables. -CWDIR_TRIM="" -BASTILLE_ZFS_ZPOOL_MOUNTPOINT="" -BASTILLE_ZFS_ZPOOL_MOUNTPOINT_TRIM="" -REQUIRED_UPDATE="" PLATFORM=$(uname -m) PRODUCT=$(uname -i) PRDVERSION=$(uname -r | cut -d '-' -f1 | tr -d '.') HOSTVERSION=$(freebsd-version | cut -d '-' -f1) +BASTILLE_DIR=$(echo "${CWDIR}" | grep -o '[^/]*$') PRDPLATFORM=$(cat /etc/platform) PRDPRODUCT=$(cat /etc/prd.name) SCRIPTNAME=$(basename $0) @@ -58,6 +55,7 @@ CONFIG="/cf/conf/config.xml" PRDNAME="Bastille" APPNAME="bastille" EXTLOGFILE="${CWDIR}/log/bastille_ext.log" +EXTLOCKFILE="/tmp/bastille_ext.lock" FULLAPPNAME="${APPNAME}-dist" WWWPATH="/usr/local/www" PKGCACHE="/var/cache/pkg" @@ -76,33 +74,64 @@ FREEBSD_UPDATE="${INCLUDE_PATH}/freebsd-update/${HOSTVERSION}" SYSTEM_INCLUDE="${INCLUDE_PATH}/include/${HOSTVERSION}" INSTALLPATH="${CWDIR}/${FULLAPPNAME}" BRANCH="master" -BATSILLE_URL="https://github.com/BastilleBSD/${APPNAME}/archive/${BRANCH}.zip" # Official Bastille Repository) -BATSILLE_ALT="https://github.com/JRGTH/${APPNAME}/archive/${BRANCH}.zip" # Alternate Bastille Repository, early updates) -BASTILE_VERSION="https://raw.githubusercontent.com/BastilleBSD/${APPNAME}/${BRANCH}/usr/local/bin/${APPNAME}" +BASTILLE_URL="https://github.com/BastilleBSD/${APPNAME}/archive/${BRANCH}.zip" # Official Bastille Repository) +BASTILLE_ALT="https://github.com/JRGTH/${APPNAME}/archive/${BRANCH}.zip" # Alternate Bastille Repository, early updates) +BASTILLE_VERSION="https://raw.githubusercontent.com/BastilleBSD/${APPNAME}/${BRANCH}/usr/local/bin/${APPNAME}" GITURL="https://github.com/JRGTH/xigmanas-${APPNAME}-extension/archive/${BRANCH}.zip" VERFILE="https://raw.githubusercontent.com/JRGTH/xigmanas-${APPNAME}-extension/${BRANCH}/version" URL_FREEBSD="http://ftp.freebsd.org/pub/FreeBSD/releases/" +URL_FREEBSD_OLD="https://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/" URL_HARDENEDBSD="https://installers.hardenedbsd.org/pub/" URL_MIDNIGHTBSD="https://www.midnightbsd.org/ftp/MidnightBSD/releases/" OPT="${1}" +ARG="${2}" -# Bastille required +# Load bastille configuration file. if [ -f "${BASTILLECONF}" ]; then . /${BASTILLECONF} - if [ "${bastille_zfs_enable}" = "YES" -o "${bastille_zfs_enable}" = "yes" ]; then - if [ -n "${bastille_zfs_prefix}" ] && [ -n "${bastille_zfs_zpool}" ]; then - # Always enforce ZFS activation below "/mnt/" from the extension. - if echo "${CWDIR}" | grep -q '/mnt/'; then - CWDIR_TRIM=$(echo "${CWDIR}" | sed "s|/mnt/||;s|/${bastille_zfs_prefix}||") - fi +elif [ -f "${INSTALLPATH}/${BASTILLECONF}" ]; then + . /${INSTALLPATH}/${BASTILLECONF} +fi - BASTILLE_ZFS_ZPOOL_MOUNTPOINT=$(zfs get -H -o value mountpoint "${bastille_zfs_zpool}") - BASTILLE_ZFS_ZPOOL_MOUNTPOINT_TRIM="" - if echo "${BASTILLE_ZFS_ZPOOL_MOUNTPOINT}" | grep -q '/mnt/'; then - BASTILLE_ZFS_ZPOOL_MOUNTPOINT_TRIM=$(echo "${BASTILLE_ZFS_ZPOOL_MOUNTPOINT}" | sed "s|/mnt/||;s|/${bastille_zfs_prefix}||") +# Unset variables. +REQUIRED_UPDATE= +CWDIR_TRIM= +BASTILLE_ZFS_PREFIX_TRIM= +BASTILLE_ZFS_ZPOOL_MOUNTPOINT= +BASTILLE_ZFS_ZPOOL_MOUNTPOINT_TRIM= + +# Get extension ZFS config info. +if [ "${bastille_zfs_enable}" = "YES" ] || [ "${bastille_zfs_enable}" = "yes" ]; then + if [ -n "${bastille_zfs_prefix}" ] && [ -n "${bastille_zfs_zpool}" ]; then + DAFAULT_BASTILLE_PREFIX="${APPNAME}" + if [ "${CWDIR##*/}" != "${APPNAME}" ]; then + # Assume custom bastille prefix. + DAFAULT_BASTILLE_PREFIX="${CWDIR##*/}" + fi + # Always enforce ZFS activation below "/mnt/" from the extension. + if echo "${CWDIR}" | grep -q '/mnt/'; then + CWDIR_TRIM=$(echo "${CWDIR}" | sed "s|/mnt/||;s|/${bastille_zfs_prefix}||") + fi + BASTILLE_ZFS_ZPOOL_MOUNTPOINT=$(zfs get -H -o value mountpoint "${bastille_zfs_zpool}" 2>/dev/null) + if echo "${BASTILLE_ZFS_ZPOOL_MOUNTPOINT}" | grep -q '/mnt/'; then + BASTILLE_ZFS_ZPOOL_MOUNTPOINT_TRIM=$(echo "${BASTILLE_ZFS_ZPOOL_MOUNTPOINT}" | sed "s|/mnt/||;s|/${bastille_zfs_prefix}||") + fi + # Check if is a zroot install with optional zfs dataset. + if [ -z "${BASTILLE_ZFS_ZPOOL_MOUNTPOINT_TRIM}" ]; then + ZROOT=$(mount | awk -F '/' '/ \/ / {print $1}') + if echo "${BASTILLE_ZFS_ZPOOL_MOUNTPOINT}" | grep -q "/${ZROOT}"; then + BASTILLE_ZFS_ZPOOL_MOUNTPOINT_TRIM="/${ZROOT}" + CWDIR_TRIM=$(echo "${CWDIR}" | sed "s|/mnt/||;s|/${DAFAULT_BASTILLE_PREFIX}||") + if zfs get -H -o value mountpoint "${ZROOT}/${CWDIR_TRIM}" >/dev/null 2>&1; then + CWDIR_TRIM="/${ZROOT}" + fi fi fi + BASTILLE_ZFS_PREFIX_TRIM=$(echo "${bastille_zfs_prefix}" | sed "s|/${DAFAULT_BASTILLE_PREFIX}||") fi + # Check bastille ZFS config match on disk ZFS config. + BASTILLE_CONFIG_DISK=$(zfs list -H "${bastille_prefix}" 2>/dev/null | awk '{print $1}') + BASTILLE_CONFIG_FILE=$(echo "${bastille_zfs_zpool}/${bastille_zfs_prefix}") fi error_notify() @@ -116,68 +145,72 @@ error_notify() runtime_config() { # Run-time configuration and checks. - if [ -f "${INSTALLPATH}/${BASTILLECONF}" ]; then - if ! sysrc -f ${BASTILLECONF} -qn bastille_prefix | grep -q "${CWDIR}"; then - sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_prefix="${CWDIR}" >/dev/null 2>&1 - fi - fi + if [ -d "${INSTALLPATH}" ]; then - # Check for required directories and files. - if [ ! -d "${CWDIR}/backups" ]; then - mkdir -p ${CWDIR}/backups - fi - if [ ! -d "${CWDIR}/conf" ]; then - mkdir -p ${CWDIR}/conf - fi - if [ ! -d "${CWDIR}/log" ]; then - mkdir -p ${CWDIR}/log - fi - if [ ! -d "${CWDIR}/locale-bastille" ]; then - mkdir -p ${CWDIR}/locale-bastille - fi - if [ ! -d "${CWDIR}/freebsd-update" ]; then - mkdir ${CWDIR}/freebsd-update - fi - if [ ! -f "${CWDIR}${BASTILLECONFFILE}" ]; then - touch ${CWDIR}${BASTILLECONFFILE} - fi - if [ ! -d "${CWDIR}/system" ]; then - mkdir -p ${CWDIR}/system - fi - - # Check for permissions. - if [ -f "${FREEBSD_UPDATE}/freebsd-update" ]; then - FREEBSD_UPDATE_PERMS=$(stat -f "%Op" ${FREEBSD_UPDATE}/freebsd-update) - if [ "${FREEBSD_UPDATE_PERMS}" != 100555 ]; then - chmod 0555 ${FREEBSD_UPDATE}/freebsd-update - fi - fi - - # Workaround to check for host /tmp sane permissions. - # This is because after working with Linux jails, this may be changed to 0777 but XigmaNAS wants 1777. - if grep -qw '\"chmod\ 777\ /tmp\"' ${INSTALLPATH}/usr/local/share/bastille/create.sh; then - sed -i '' 's|\"chmod\ 777\ /tmp\"|\"chmod\ 1777\ /tmp\"|g' ${INSTALLPATH}/usr/local/share/bastille/create.sh - else - if [ -d "/tmp" ]; then - TMP_PERMS=$(stat -f "%Op" "/tmp") - if [ "${TMP_PERMS}" != "41777" ]; then - chmod 1777 /tmp + if [ -f "${INSTALLPATH}/${BASTILLECONF}" ]; then + if ! sysrc -f ${BASTILLECONF} -qc bastille_prefix="${CWDIR}"; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_prefix="${CWDIR}" >/dev/null 2>&1 fi fi - fi - # Check and append new config parameters. - update_config + # Check for required directories and files. + if [ ! -d "${CWDIR}/backups" ]; then + mkdir -p ${CWDIR}/backups + fi + if [ ! -d "${CWDIR}/conf" ]; then + mkdir -p ${CWDIR}/conf + fi + if [ ! -d "${CWDIR}/log" ]; then + mkdir -p ${CWDIR}/log + fi + if [ ! -d "${CWDIR}/locale-bastille" ]; then + mkdir -p ${CWDIR}/locale-bastille + fi + if [ ! -d "${CWDIR}/freebsd-update" ]; then + mkdir ${CWDIR}/freebsd-update + fi + if [ ! -f "${CWDIR}${BASTILLECONFFILE}" ]; then + touch ${CWDIR}${BASTILLECONFFILE} + fi + if [ ! -d "${CWDIR}/system" ]; then + mkdir -p ${CWDIR}/system + fi + + # Check for permissions. + if [ -f "${FREEBSD_UPDATE}/freebsd-update" ]; then + FREEBSD_UPDATE_PERMS=$(stat -f "%Op" ${FREEBSD_UPDATE}/freebsd-update) + if [ "${FREEBSD_UPDATE_PERMS}" != 100555 ]; then + chmod 0555 ${FREEBSD_UPDATE}/freebsd-update + fi + fi + + # Workaround to check for host /tmp sane permissions. + # This is because after working with Linux jails, this may be changed to 0777 but XigmaNAS wants 1777. + if grep -qw '\"chmod\ 777\ /tmp\"' ${INSTALLPATH}/usr/local/share/bastille/create.sh; then + sed -i '' 's|\"chmod\ 777\ /tmp\"|\"chmod\ 1777\ /tmp\"|g' ${INSTALLPATH}/usr/local/share/bastille/create.sh + else + if [ -d "/tmp" ]; then + TMP_PERMS=$(stat -f "%Op" "/tmp") + if [ "${TMP_PERMS}" != "41777" ]; then + chmod 1777 /tmp + fi + fi + fi + + # Check and append new config parameters. + update_config + + fi } bastille_initial_download() { # Check if bastille already exist. - + if [ -n "${REQUIRED_UPDATE}" ] || [ ! -f "${CWDIR}/${FULLAPPNAME}${BASTILLEPATH}/${APPNAME}" ]; then # Fetch latest bastille package. echo "Fetching ${APPNAME} files..." - fetch -ao ${CWDIR}/${BRANCH}.zip --no-verify-peer --timeout=30 ${BATSILLE_URL} || \ + fetch -ao ${CWDIR}/${BRANCH}.zip --no-verify-peer --timeout=30 ${BASTILLE_URL} || \ error_notify "Error: A problem has occurred while fetching ${APPNAME}." bastille_pkg_extract fi @@ -205,7 +238,7 @@ bastille_upgrade() DATE=$(date +"%a %b %d %T %Y") echo "Looking for new ${APPNAME} package!" mkdir -p ${CWDIR}/update - fetch -ao ${CWDIR}/update --no-verify-peer --timeout=30 ${BASTILE_VERSION} || \ + fetch -ao ${CWDIR}/update --no-verify-peer --timeout=30 ${BASTILLE_VERSION} || \ error_notify "Error: A problem has occurred while fetching version file." # Compare version files and fetch latest package if available. @@ -214,7 +247,7 @@ bastille_upgrade() CURRENTVER=$(cat ${BASTILLEPATH}/${APPNAME} | grep BASTILLE_VERSION= | egrep -o "([0-9]{1,}\.)+[0-9]{1,}" | tr -d '.') if [ "${UPDATEVER}" -gt "${CURRENTVER}" ]; then echo "New ${APPNAME} package found, performing upgrade..." - fetch -ao ${CWDIR}/update --no-verify-peer --timeout=30 ${BATSILLE_URL} || \ + fetch -ao ${CWDIR}/update --no-verify-peer --timeout=30 ${BASTILLE_URL} || \ error_notify "Error: A problem has occurred while fetching ${APPNAME} package." tar -xf ${CWDIR}/update/${BRANCH}.zip --exclude='.git*' --exclude='docs' --exclude='bastille.conf' --strip-components 1 -C ${CWDIR}/update rm -f ${CWDIR}/update/${BRANCH}.zip @@ -244,11 +277,11 @@ bastille_upgrade() bastille_core_update() { # Check if bastille already exist. - + if [ -f "${CWDIR}/${FULLAPPNAME}${BASTILLEPATH}/${APPNAME}" ]; then # Fetch latest bastille package. echo "Fetching ${APPNAME} files..." - fetch -ao ${CWDIR}/${BRANCH}.zip --no-verify-peer --timeout=30 ${BATSILLE_URL} || \ + fetch -ao ${CWDIR}/${BRANCH}.zip --no-verify-peer --timeout=30 ${BASTILLE_URL} || \ error_notify "Error: A problem has occurred while fetching ${APPNAME}." bastille_pkg_extract fi @@ -295,6 +328,8 @@ extension_upgrade() # Compare version files and fetch latest package if available. if [ -f "${CWDIR}/update/version" ]; then + UPDATEVER_FULL=$(cat ${CWDIR}/update/version) + CURRENTVER_FULL=$(cat ${CWDIR}/version) UPDATEVER=$(cat ${CWDIR}/update/version | tr -d .) CURRENTVER=$(cat ${CWDIR}/version | tr -d .) if [ "${UPDATEVER}" -gt "${CURRENTVER}" ]; then @@ -312,6 +347,13 @@ extension_upgrade() echo "${DATE}: Extension upgraded to ${UPDATEVERSION}" >> ${EXTLOGFILE} echo "Extension upgraded to version ${UPDATEVERSION}" echo "Extension package upgrade completed!" + if [ "${CURRENTVER}" -le "1153" ]; then + echo "***********************************************************************************" + echo "* WARNING: System reboot is required when upgrading from v${CURRENTVER_FULL} to v${UPDATEVER_FULL} *" + echo "***********************************************************************************" + fi + # Tell the extension was upgraded. + sysrc -f ${CWDIR}${EXTCONF} EXTENSION_UPGRADED="1" >/dev/null 2>&1 else echo "Extension is on the latest version!" rm -R ${CWDIR}/update @@ -321,9 +363,13 @@ extension_upgrade() create_addon_env() { - # Set bastille dir required permissions. + # Set bastille dir/files required permissions. chmod 0750 ${CWDIR} + if [ -f "${CWDIR}/unionfs.sh" ]; then + chmod 0755 ${CWDIR}/unionfs.sh + fi + # Create required directories. if [ ! -d "${CWDIR}/backups" ]; then mkdir -p ${CWDIR}/backups @@ -390,7 +436,7 @@ sys_symlinkdir() mkdir -p ${USRLOCAL}/share/licenses fi - # Required symlinks for bastille. + # Required symlinks for bastille. if [ -d "${INSTALLPATH}${USRLOCAL}/share/licenses" ]; then cd ${INSTALLPATH}${USRLOCAL}/share/licenses for file in * @@ -399,24 +445,16 @@ sys_symlinkdir() done fi - # Link bastile config file directory. + # Link bastille config file directory. if [ -d "${INSTALLPATH}${USRLOCAL}/etc/${APPNAME}" ]; then ln -fhs ${INSTALLPATH}${USRLOCAL}/etc/${APPNAME} ${USRLOCAL}/etc/${APPNAME} fi - # Link bastile config file. - #if [ -f "${INSTALLPATH}${USRLOCAL}/etc/${APPNAME}/${APPNAME}.conf.sample" ]; then - # cd ${INSTALLPATH}${USRLOCAL}/etc/${APPNAME} - # if [ ! -f "${APPNAME}.conf" ]; then - # cp ${APPNAME}.conf.sample ${APPNAME}.conf - # fi - #else - if [ -f "${BASTILLECONF_EXT}" ]; then - if [ ! -f "${INSTALLPATH}${USRLOCAL}/etc/${APPNAME}/${APPNAME}.conf" ]; then - cp ${BASTILLECONF_EXT} ${INSTALLPATH}${USRLOCAL}/etc/${APPNAME}/${APPNAME}.conf - fi + if [ -f "${BASTILLECONF_EXT}" ]; then + if [ ! -f "${INSTALLPATH}${USRLOCAL}/etc/${APPNAME}/${APPNAME}.conf" ]; then + cp ${BASTILLECONF_EXT} ${INSTALLPATH}${USRLOCAL}/etc/${APPNAME}/${APPNAME}.conf fi - #fi + fi # Copy bastille shared. if [ -d "${INSTALLPATH}${USRLOCAL}/share/${APPNAME}" ]; then @@ -434,35 +472,55 @@ include_files() if [ "$(freebsd-version | cut -d '.' -f1)" -ge 12 ]; then sysrc -f ${CWDIR}${EXTCONF} VNET_ENABLE="YES" >/dev/null 2>&1 # Include missing system files. - if [ ! -f "/usr/bin/ar" ]; then - if [ -f "${SYSTEM_INCLUDE}/ar" ]; then - install -m 0555 ${SYSTEM_INCLUDE}/ar /usr/bin/ar - fi - fi - if [ ! -f "/usr/local/bin/jib" ]; then - if [ -f "${SYSTEM_INCLUDE}/jib" ]; then - install -m 0544 ${SYSTEM_INCLUDE}/jib /usr/local/bin/jib - fi - fi - if [ ! -f "/usr/sbin/setfib" ]; then - if [ -f "${SYSTEM_INCLUDE}/setfib" ]; then - install -m 0555 ${SYSTEM_INCLUDE}/setfib /usr/sbin/setfib - fi - fi - if [ ! -f "/usr/bin/sum" ]; then - if [ -f "${SYSTEM_INCLUDE}/sum" ]; then - install -m 0555 ${SYSTEM_INCLUDE}/sum /usr/bin/sum - fi - fi - if [ ! -f "/usr/bin/diff3" ]; then - if [ -f "${SYSTEM_INCLUDE}/diff3" ]; then - install -m 0555 ${SYSTEM_INCLUDE}/diff3 /usr/bin/diff3 - fi - fi - if [ ! -f "/usr/bin/makewhatis" ]; then - if [ -f "${SYSTEM_INCLUDE}/makewhatis" ]; then - install -m 0555 ${SYSTEM_INCLUDE}/makewhatis /usr/bin/makewhatis - fi + # Symlink the files in embedded platforms. + USRBIN_FILES="ar diff3 makewhatis setfib sum zstd" + USRSBIN_FILES="etcupdate" + LOCALBIN_FILES="jib" + if [ "${PRDPLATFORM}" = "x64-embedded" ]; then + for _usrbin_file in ${USRBIN_FILES}; do + if [ -f "/usr/bin/${_usrbin_file}" ] && [ ! -L "/usr/bin/${_usrbin_file}" ]; then + rm -r /usr/bin/${_usrbin_file} + fi + if [ ! -f "/usr/bin/${_usrbin_file}" ]; then + chmod 0555 "${SYSTEM_INCLUDE}/${_usrbin_file}" + ln -fhs ${SYSTEM_INCLUDE}/${_usrbin_file} /usr/bin/${_usrbin_file} + fi + done + for _usrsbin_file in ${USRSBIN_FILES}; do + if [ -f "/usr/sbin/${_usrsbin_file}" ] && [ ! -L "/usr/sbin/${_usrsbin_file}" ]; then + rm -r /usr/sbin/${_usrsbin_file} + fi + if [ ! -f "/usr/sbin/${_usrsbin_file}" ]; then + chmod 0555 "${SYSTEM_INCLUDE}/${_usrsbin_file}" + ln -fhs ${SYSTEM_INCLUDE}/${_usrsbin_file} /usr/sbin/${_usrsbin_file} + fi + done + for _localbin_file in ${LOCALBIN_FILES}; do + if [ -f "/usr/local/bin/${_localbin_file}" ] && [ ! -L "/usr/local/bin/${_localbin_file}" ]; then + rm -r /usr/local/bin/${_localbin_file} + fi + if [ ! -f "/usr/bin/${_localbin_file}" ]; then + chmod 0555 "${SYSTEM_INCLUDE}/${_localbin_file}" + ln -fhs ${SYSTEM_INCLUDE}/${_localbin_file} /usr/local/bin/${_localbin_file} + fi + done + else + # Install the files in full platforms natively. + for _usrbin_file in ${USRBIN_FILES}; do + if [ ! -f "/usr/bin/${_usrbin_file}" ]; then + install -m 0555 "${SYSTEM_INCLUDE}/${_usrbin_file}" /usr/bin/${_usrbin_file} + fi + done + for _usrsbin_file in ${USRSBIN_FILES}; do + if [ ! -f "/usr/sbin/${_usrsbin_file}" ]; then + install -m 0555 "${SYSTEM_INCLUDE}/${_usrsbin_file}" /usr/sbin/${_usrsbin_file} + fi + done + for _localbin_file in ${LOCALBIN_FILES}; do + if [ ! -f "/usr/local/bin/${_localbin_file}" ]; then + install -m 0544 ${SYSTEM_INCLUDE}/${_localbin_file} /usr/local/bin/${_localbin_file} + fi + done fi else sysrc -f ${CWDIR}${EXTCONF} VNET_ENABLE="NO" >/dev/null 2>&1 @@ -515,17 +573,15 @@ postinit_cmd() touch ${CWDIR}/postinit || error_notify "Error: A problem has occurred while creating the postinit file." chmod +x ${CWDIR}/postinit if [ "${PRDVERSION}" -ge "110" ]; then - # Generate php script for start/stop commands. + # Generate php script only for start command for extension version 1.2 and later. cat << EOF > ${CWDIR}/postinit EOF fi @@ -616,6 +658,8 @@ gui_enable() else error_notify "Error: Extension gui files not found." fi + + exit 0 } gui_disable() @@ -639,13 +683,15 @@ gui_disable() rm -r ${WWWPATH}/ext fi fi + + exit 0 } jail_update() { # Workaround since XigmaNAS does not ship with freebsd-update command. - if [ "${PRDPRODUCT}" = "XigmaNAS" -o "${PRDPRODUCT}" = "NAS4Free" ]; then + if [ "${PRDPRODUCT}" = "XigmaNAS" ] || [ "${PRDPRODUCT}" = "NAS4Free" ]; then if [ ! -d "${FREEBSD_UPDATE}" ]; then echo "Not supported on ${PRDPRODUCT} platform." exit 1 @@ -659,7 +705,7 @@ jail_update() exit 1 fi - if [ -d "${bastille_jailsdir}/${TARGET}" ]; then + if [ -d "${bastille_jailsdir}/${TARGET}" ]; then if ! cat "${bastille_jailsdir}/${TARGET}/fstab" 2>/dev/null | grep -w "${TARGET}" | grep -qw "/.*/.bastille"; then if [ -f "${bastille_jailsdir}/${TARGET}/root/COPYRIGHT" ]; then if [ "$(jls name | grep -w "${TARGET}")" ]; then @@ -669,10 +715,19 @@ jail_update() echo "Can't determine '${TARGET}' version." exit 1 else - env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \ + if [ -n "${_forceopt}" ]; then + echo "Performing a forced jail update..." + else + echo "Performing a jail update..." + fi + env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update ${_forceopt} --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \ -d ${CWDIR}/freebsd-update -b "${bastille_jailsdir}/${TARGET}/root" fetch --currently-running "${CURRENT_VERSION}" ${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \ -d ${CWDIR}/freebsd-update -b "${bastille_jailsdir}/${TARGET}/root" install --currently-running "${CURRENT_VERSION}" + + echo "Setting OS release for ${TARGET}." + CURRENT_VERSION=$(jexec -l ${TARGET} freebsd-version) + bastille config ${TARGET} set osrelease ${CURRENT_VERSION} fi else echo "Container not running." @@ -689,11 +744,18 @@ jail_update() fi else if [ -d "${bastille_releasesdir}/${TARGET}" ]; then + if [ -n "${_forceopt}" ]; then + echo "Performing a forced base update..." + else + echo "Performing a base update..." + fi # Update container base(affects base child containers). - env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \ + env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update ${_forceopt} --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \ -d ${CWDIR}/freebsd-update -b "${bastille_releasesdir}/${TARGET}" fetch --currently-running "${TARGET}" ${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \ -d ${CWDIR}/freebsd-update -b "${bastille_releasesdir}/${TARGET}" install --currently-running "${TARGET}" + + echo "Please manually set OS release on jail.conf for the required jails." else echo "${TARGET} not found. See bootstrap." exit 1 @@ -711,10 +773,15 @@ release_upgrade() exit 0 fi # Upgrade a release base. + if [ -n "${_forceopt}" ]; then + echo "Performing a forced release upgrade..." + else + echo "Performing a release upgrade..." + fi echo "=> Run the command below several times when asked to finish installing updates." echo "bastille-init install ${TARGET}" echo - env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \ + env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update ${_forceopt} --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \ -d ${CWDIR}/freebsd-update -b "${bastille_releasesdir}/${TARGET}" --currently-running "${TARGET}" -r ${RELEASE} upgrade echo echo "=> Please run: 'bastille-init install ${TARGET}' to finish installing updates." @@ -729,7 +796,7 @@ release_upgrade() release_install() { - if [ -d "${bastille_releasesdir}/${TARGET}" ]; then + if [ -d "${bastille_releasesdir}/${TARGET}" ]; then if [ -f "${bastille_releasesdir}/${TARGET}/COPYRIGHT" ]; then # Finish installing upgrade on a thick container. env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \ @@ -772,6 +839,8 @@ release_change() # If the previous conditions meets, proceed with the container base upgrade. sed -i '' "s/${RELEASE}/${NEWRELEASE}/g" ${bastille_jailsdir}/${TARGET}/fstab echo "${TARGET} release changed to ${NEWRELEASE}." + echo "Setting OS release for ${TARGET}." + bastille config ${TARGET} set osrelease ${NEWRELEASE} elif cat "${bastille_jailsdir}/${TARGET}/fstab" | grep "${NEWRELEASE}" | grep -qw "/.*/.bastille"; then echo "${TARGET} already using ${NEWRELEASE}." exit 0 @@ -811,7 +880,7 @@ thickjail_upgrade() { # Workaround since XigmaNAS does not ship with freebsd-update command. - if [ "${PRDPRODUCT}" = "XigmaNAS" -o "${PRDPRODUCT}" = "NAS4Free" ]; then + if [ "${PRDPRODUCT}" = "XigmaNAS" ] || [ "${PRDPRODUCT}" = "NAS4Free" ]; then if [ ! -d "${FREEBSD_UPDATE}" ]; then echo "Not supported on ${PRDPRODUCT} platform." exit 1 @@ -826,16 +895,21 @@ thickjail_upgrade() fi # Verify for user input and handle some errors. - if [ -d "${bastille_jailsdir}/${TARGET}" ]; then + if [ -d "${bastille_jailsdir}/${TARGET}" ]; then if ! cat "${bastille_jailsdir}/${TARGET}/fstab" 2>/dev/null | grep -w "${TARGET}" | grep -qw "/.*/.bastille"; then if [ -f "${bastille_jailsdir}/${TARGET}/root/COPYRIGHT" ]; then if [ "$(jls name | grep -w "${TARGET}")" ]; then # Upgrade a thick container. + if [ -n "${_forceopt}" ]; then + echo "Performing a forced jail upgrade..." + else + echo "Performing a jail upgrade..." + fi echo "=> Run the command below several times when asked to finish installing updates." echo "bastille-init install ${TARGET}" echo CURRENT_VERSION=$(jexec -l ${TARGET} freebsd-version) - env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \ + env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update ${_forceopt} --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \ -d ${CWDIR}/freebsd-update -b "${bastille_jailsdir}/${TARGET}/root" --currently-running "${CURRENT_VERSION}" -r ${RELEASE} upgrade echo echo "=> Please run: 'bastille-init install ${TARGET}' to finish installing updates." @@ -863,7 +937,7 @@ thickjail_install() { # Workaround since XigmaNAS does not ship with freebsd-update command. - if [ "${PRDPRODUCT}" = "XigmaNAS" -o "${PRDPRODUCT}" = "NAS4Free" ]; then + if [ "${PRDPRODUCT}" = "XigmaNAS" ] || [ "${PRDPRODUCT}" = "NAS4Free" ]; then if [ ! -d "${FREEBSD_UPDATE}" ]; then echo "Not supported on ${PRDPRODUCT} platform." exit 1 @@ -877,7 +951,7 @@ thickjail_install() exit 1 fi - if [ -d "${bastille_jailsdir}/${TARGET}" ]; then + if [ -d "${bastille_jailsdir}/${TARGET}" ]; then if ! cat "${bastille_jailsdir}/${TARGET}/fstab" 2>/dev/null | grep -w "${TARGET}" | grep -qw "/.*/.bastille"; then if [ -f "${bastille_jailsdir}/${TARGET}/root/COPYRIGHT" ]; then if [ "$(jls name | grep -w "${TARGET}")" ]; then @@ -909,12 +983,7 @@ zfs_activate() # Check if ZFS is already configured. # Always enforce ZFS activation below "/mnt/" from the extension. if echo "${BASTILLE_ZFS_ZPOOL_MOUNTPOINT_TRIM}" | grep -qw "${CWDIR_TRIM}$"; then - - BASTILLE_DIR=$(echo "${CWDIR}" | grep -o '[^/]*$') - if [ "${bastille_zfs_prefix}" != "${BASTILLE_DIR}" ]; then - error_notify "Invalid ZFS configuration." - fi - if zfs list "${bastille_zfs_zpool}/${BASTILLE_DIR}" > /dev/null 2>&1; then + if zfs list "${bastille_zfs_zpool}/${bastille_zfs_prefix}" > /dev/null 2>&1; then echo "Bastille ZFS is already configured." sysrc -f ${CWDIR}${EXTCONF} ZFS_ACTIVATED="YES" >/dev/null 2>&1 exit 0 @@ -930,23 +999,26 @@ zfs_activate() echo "Enabling ZFS on ${PRDNAME} Extension..." # Confirm before conversion. - while : - do - read -p "Do you really wish to enable ZFS for ${PRDNAME} Extension? [y/N]:" yn - case ${yn} in - [Yy]) break;; - [Nn]) exit 0;; - esac - done + while :; do + read -p "Do you really want to enable ZFS for ${PRDNAME} Extension? [y/N]:" _yn + case ${_yn} in + [Yy]) + break + ;; + [Nn]) + exit 0 + ;; + esac + done echo "Proceeding..." - if [ "${bastille_zfs_enable}" = "YES" ]; then - if [ ! -z "${bastille_zfs_zpool}" ]; then + if [ "${bastille_zfs_enable}" = "YES" ] || [ "${bastille_zfs_enable}" = "yes" ]; then + if [ -n "${bastille_zfs_zpool}" ]; then if zfs list "${bastille_zfs_zpool}" > /dev/null 2>&1; then - if ! zfs list "${bastille_zfs_zpool}/${BASTILLE_DIR}" > /dev/null 2>&1; then - echo "Renaming existing '${BASTILLE_DIR}' directory" + if ! zfs list "${bastille_zfs_zpool}/${bastille_zfs_prefix}" > /dev/null 2>&1; then + echo "Renaming existing '${BASTILLE_DIR}' directory..." mv ${CWDIR} ${CWDIR}.old - echo "Creating a new ZFS dataset for '${BASTILLE_DIR}'" + echo "Creating a new ZFS dataset for '${BASTILLE_DIR}'..." zfs create ${bastille_zfs_options} ${bastille_zfs_zpool}/${bastille_zfs_prefix} if [ $? -ne 0 ]; then MSG="Failed to enable ZFS, reverting changes." @@ -958,11 +1030,11 @@ zfs_activate() echo "Synchronizing '${BASTILLE_DIR}' data on new dataset" rsync -a ${CWDIR}.old/ ${CWDIR}/ fi - else + else echo "Bastille ZFS is already configured." fi else - error_notify "ERROR: ${bastille_zfs_zpool} is not a ZFS pool/dataset." + error_notify "ERROR: ${bastille_zfs_zpool} is not a ZFS pool." fi else error_notify "Bastille ZPOOL is not set." @@ -974,7 +1046,7 @@ zfs_activate() else error_notify "Invalid ZFS configuration." fi - sysrc -f ${CWDIR}${EXTCONF} ZFS_ACTIVATED="YES" >/dev/null 2>&1 + zfs_support_enabled exit 0 } @@ -993,11 +1065,40 @@ pkg_upgrade() reset_install() { + # Confirm for addon config reset. + while :; do + read -p "Do you really want to proceed with the ${PRDNAME} Extension config reset? [y/N]:" _yn + case ${_yn} in + [Yy]) + break + ;; + [Nn]) + exit 0 + ;; + esac + done + echo "Proceeding..." + + # Check for running jails before config reset. + for _jail in $(bastille list jail); do + if jls -j ${_jail} >/dev/null 2>&1; then + echo "Looks like there are running bastille jails, aborting." + exit 1 + fi + done + # Reset the extension environment. echo "Removing extension files..." + if [ -f "${CWDIR}/conf/bastille_config" ]; then - rm -rf ${CWDIR}/conf/bastille_config + echo "Backup current extension config file." + if [ -f "${CWDIR}/conf/bastille_config.old" ]; then + # Remove previous backup file. + rm -f ${CWDIR}/conf/bastille_config.old + fi + mv -vf ${CWDIR}/conf/bastille_config ${CWDIR}/conf/bastille_config.old fi + if [ -d "${CWDIR}/${FULLAPPNAME}" ]; then rm -rf ${CWDIR}/${FULLAPPNAME} fi @@ -1008,56 +1109,68 @@ reset_install() rm -f ${CWDIR}/version fi + sleep 3 + # Set default config. - sysrc -f ${CWDIR}${EXTCONF} GUI_ENABLE=YES INSTALL_DIR=${CWDIR} >/dev/null 2>&1 + touch ${CWDIR}/conf/bastille_config + sysrc -f ${CWDIR}${EXTCONF} GUI_ENABLE="YES" >/dev/null 2>&1 + sysrc -f ${CWDIR}${EXTCONF} INSTALL_DIR="${CWDIR}" >/dev/null 2>&1 + sysrc -f ${CWDIR}${EXTCONF} BASTILLE_CONFIG="${CWDIR}/${FULLAPPNAME}${BASTILLECONF}" >/dev/null 2>&1 + sysrc -f ${CWDIR}${EXTCONF} BACKUP_DIR="${CWDIR}/backups" >/dev/null 2>&1 + sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="NO" >/dev/null 2>&1 echo "" echo "*************************************************************************************************************" echo "* The configuration was reset, please go to [Extensions > Bastille > Configuration] to configure bastille. *" - echo "* Alternatively you can edit the '/usr/local/etc/bastille/bastille.conf' file manually. *" + echo "* Alternatively you can edit the 'addon/bastille-dist/usr/local/etc/bastille/bastille.conf' file manually. *" echo "*************************************************************************************************************" echo "" - echo "Notice: If Linux Jail support was enabled, please execute the below command to re-enable it:" + echo "Notice: If Linux Jail support was enabled, please execute the below command to manually re-enable it:" echo "==> sysrc -f ${CWDIR}${EXTCONF} LINUX_COMPAT_SUPPORT=\"YES\"" echo "" + + # Tell Bastille Extension that config was reset. + touch ${CWDIR}/conf/config_reset.lock } remove_addon() { # Confirm for addon removal. - while : - do - read -p "Do you wish to proceed with the ${FULLAPPNAME} removal? [y/N]:" yn - case ${yn} in - [Yy]) break;; - [Nn]) exit 0;; - esac - done + while :; do + read -p "Do you want to proceed with the ${FULLAPPNAME} removal? [y/N]:" _yn + case ${_yn} in + [Yy]) break + ;; + [Nn]) exit 0 + ;; + esac + done echo "Proceeding..." - # Check for working platform and remove symlinks. - if [ "${PRDPLATFORM}" = "x64-embedded" ] || [ "${PRDPLATFORM}" = "x64-full" ]; then - if [ -d "${USRLOCAL}/share/licenses/${APPNAME}-*" ]; then - rm -rf ${USRLOCAL}/share/licenses/${APPNAME}-* - fi - if [ -d $"{USRLOCAL}/share/locale-bastille" ]; then - rm -rf ${USRLOCAL}/share/locale-bastille - fi - if [ -f "${USRLOCAL}/etc/rc.d/${APPNAME}" ]; then - rm -f ${USRLOCAL}/etc/rc.d/${APPNAME} - fi - if [ -f "${USRLOCAL}/etc/${APPNAME}.conf" ]; then - rm -f ${USRLOCAL}/etc/${APPNAME}.conf - fi - if [ -f "${BASTILLEPATH}/${APPNAME}" ]; then - rm -f ${BASTILLEPATH}/${APPNAME} - fi - if [ -f "${USRLOCAL}/sbin/${APPNAME}-init" ]; then - rm -rf ${USRLOCAL}/sbin/${APPNAME}-init - fi - if [ -d "${VARLOG}/${APPNAME}" ]; then - rm -rf ${VARLOG}/${APPNAME} - fi + # Check and disable extension unionfs in case it is enabled. + ${CWDIR}/unionfs.sh unionfs_off + + # Check and remove extension files/symlinks. + if [ -d "${USRLOCAL}/share/licenses/${APPNAME}-*" ]; then + rm -rf ${USRLOCAL}/share/licenses/${APPNAME}-* + fi + if [ -d "${USRLOCAL}/share/locale-bastille" ]; then + rm -rf ${USRLOCAL}/share/locale-bastille + fi + if [ -f "${USRLOCAL}/etc/rc.d/${APPNAME}" ]; then + rm -f ${USRLOCAL}/etc/rc.d/${APPNAME} + fi + if [ -f "${USRLOCAL}/etc/${APPNAME}" ]; then + rm -f ${USRLOCAL}/etc/${APPNAME} + fi + if [ -f "${BASTILLEPATH}/${APPNAME}" ]; then + rm -f ${BASTILLEPATH}/${APPNAME} + fi + if [ -f "${BASTILLEPATH}/${APPNAME}-init" ]; then + rm -rf ${BASTILLEPATH}/${APPNAME}-init + fi + if [ -d "${VARLOG}/${APPNAME}" ]; then + rm -rf ${VARLOG}/${APPNAME} fi # Remove extension and GUI components. @@ -1084,21 +1197,22 @@ remove_addon() # Remove addon related files and folders only- # to protect any user-created custom files- # as well as for the containers dirs/files. - FILES="conf download freebsd-update gui locale-bastille log bastille-dist LICENSE README.md postinit CHANGELOG version bastille-init" + FILES="bastille-dist conf download freebsd-update gui locale-bastille log system CHANGELOG LICENSE README.md bastille-init postinit unionfs.sh version" for FILE in ${FILES}; do if [ -f "${CWDIR}/${FILE}" ] || [ -d "${CWDIR}/${FILE}" ]; then rm -rf ${CWDIR}/${FILE} fi done - BIN_FILES="/usr/local/bin/ar /usr/local/bin/jib /usr/sbin/setfib /usr/bin/sum /usr/bin/diff3 /usr/bin/makewhatis" + # Remove this files since they are not part of the base. + BIN_FILES="/usr/bin/ar /usr/local/bin/jib /usr/sbin/setfib /usr/bin/sum /usr/bin/diff3 /usr/bin/makewhatis" for FILE in ${BIN_FILES}; do if [ -f "${FILE}" ]; then rm -rf ${FILE} fi done - # Don't remove this files on 13.x versions since they are part of the base. + # Don't remove this files on 13.x and later versions since they are part of the base. if [ "$(freebsd-version | cut -d '.' -f1)" -le 12 ]; then PF_FILES="/sbin/pfctl /sbin/pfilctl /sbin/pflogd /etc/pf.os" for FILE in ${PF_FILES}; do @@ -1109,7 +1223,7 @@ remove_addon() fi echo "Done!" - echo "Please manually remove the Bastile Extension Command Script from the WebGUI." + echo "Please manually remove the Bastille Extension Command Script from the WebGUI." exit 0 } @@ -1129,30 +1243,44 @@ get_versions() exit 0 } -rcordered_list() { - bastille_ordered_list=$(rcorder -s nostart ${CWDIR}/jails/*/jail.conf | xargs dirname | xargs basename -a | tr "\n" " ") +post_upgrade() +{ + # This function is intended to apply several/temporary changes to the extension once. + if sysrc -f ${CWDIR}${EXTCONF} -qc EXTENSION_UPGRADED=1; then + if [ -f "${CWDIR}/post_upgrade.sh" ]; then + echo "Executing post upgrade file..." + chmod +x ${CWDIR}/post_upgrade.sh && ${CWDIR}/post_upgrade.sh + sleep 3 + fi + sysrc -f ${CWDIR}${EXTCONF} EXTENSION_UPGRADED="0" >/dev/null 2>&1 + fi } ext_start() { - if sysrc -f ${CWDIR}${EXTCONF} -qn LINUX_COMPAT_SUPPORT | grep -q "YES"; then + if sysrc -f ${CWDIR}${EXTCONF} -qc LINUX_COMPAT_SUPPORT=YES; then ${CWDIR}/unionfs.sh load_kmods - ${CWDIR}/unionfs.sh unionfs_on fi # Start bastille jails. if [ -d "${CWDIR}/jails" ]; then - JAIL_LIST=$bastille_ordered_list - for jail in ${JAIL_LIST}; do - if grep -qw "${jail}_AUTO_START=\"YES\"" ${CWDIR}${EXTCONF}; then - if ! jls | sed "1 d" | awk '{print $3}' | grep -qw ${jail}; then - bastille start ${jail} + # Required for embedded platforms due late startup. + if [ "${PRDPLATFORM}" = "x64-embedded" ]; then + if sysrc -qc bastille_enable=YES; then + if [ ! -f "${EXTLOCKFILE}" ]; then + service bastille start fi fi - done + fi + fi + + # Create extension lock file after boot. + if [ ! -f "${EXTLOCKFILE}" ]; then + touch ${EXTLOCKFILE} fi if [ $? -eq 0 ]; then + post_upgrade MSG="script has been started successfully!" logger -t ${SCRIPTNAME} ${MSG} exit 0 @@ -1163,12 +1291,37 @@ ext_start() fi } +zfs_support_enabled() +{ + sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="YES" >/dev/null 2>&1 + sysrc -f ${CWDIR}${EXTCONF} ZFS_ACTIVATED="YES" >/dev/null 2>&1 +} + +zfs_support_error() +{ + echo "WARNING: Invalid ZFS configuration." + sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="ERR" >/dev/null 2>&1 + sysrc -f ${CWDIR}${EXTCONF} -x ZFS_ACTIVATED >/dev/null 2>&1 +} + +zfs_support_avail() +{ + echo "WARNING: ZFS support available but not enabled." + sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="AVA" >/dev/null 2>&1 +} + +zfs_support_disabled() +{ + sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="NO" >/dev/null 2>&1 + sysrc -f ${CWDIR}${EXTCONF} ZFS_ACTIVATED="NO" >/dev/null 2>&1 +} + rc_params() { # Bastille required parameters. # Set bastille prefix. - if ! sysrc -f ${BASTILLECONF} -qn bastille_prefix | grep -q "${CWDIR}"; then + if ! sysrc -f ${BASTILLECONF} -qc bastille_prefix="${CWDIR}"; then sysrc -f ${BASTILLECONF} bastille_prefix="${CWDIR}" >/dev/null 2>&1 fi @@ -1184,13 +1337,13 @@ rc_params() fi # Set bastille.conf location. - if ! sysrc -f ${CWDIR}${EXTCONF} -n BASTILLE_CONFIG 2>/dev/null | grep -q "${CWDIR}/${FULLAPPNAME}${BASTILLECONF}"; then + if ! sysrc -f ${CWDIR}${EXTCONF} -qc BASTILLE_CONFIG="${CWDIR}/${FULLAPPNAME}${BASTILLECONF}"; then sysrc -f ${CWDIR}${EXTCONF} BASTILLE_CONFIG="${CWDIR}/${FULLAPPNAME}${BASTILLECONF}" >/dev/null 2>&1 fi # Default first network interface. ACTIVE_NETIF=$(ifconfig | grep "UP,BROADCAST" | awk -F":" '{print $1}' | sed 1q) - if ! sysrc -f ${BASTILLECONF} -qn bastille_network_shared | grep -q "${ACTIVE_NETIF}" >/dev/null 2>&1; then + if ! sysrc -f ${BASTILLECONF} -qc bastille_network_shared="${ACTIVE_NETIF}" >/dev/null 2>&1; then #echo "" >> ${BASTILLECONF} && echo "## default network interface" >> ${BASTILLECONF} sysrc -f ${BASTILLECONF} bastille_network_shared="${ACTIVE_NETIF}" >/dev/null 2>&1 else @@ -1201,41 +1354,89 @@ rc_params() fi fi - # Do't start containers by default. - if ! sysrc -qn bastille_enable >/dev/null 2>&1; then - sysrc bastille_enable="NO" >/dev/null 2>&1 + # Check if extension config was reset. + if [ -f "${CWDIR}/conf/config_reset.lock" ]; then + zfs_support_error + echo "WARNING: ${PRDNAME} Extension config was reset." + rm ${CWDIR}/conf/config_reset.lock fi - # Check if sane ZFS is enabled in this setup. - if [ "${bastille_zfs_enable}" = "YES" ]; then + # Check for sane ZFS parameters in this setup. + if [ "${bastille_zfs_enable}" = "YES" ] || [ "${bastille_zfs_enable}" = "yes" ]; then if [ -n "${bastille_zfs_zpool}" ]; then - if zfs list "${bastille_zfs_zpool}" > /dev/null 2>&1; then - BASTILLE_DIR=$(echo ${CWDIR} | grep -o '[^/]*$') - if zfs list "${bastille_zfs_zpool}/${BASTILLE_DIR}" > /dev/null 2>&1; then - sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="YES" >/dev/null 2>&1 - else - if echo "${BASTILLE_ZFS_ZPOOL_MOUNTPOINT_TRIM}" | grep -qw "${CWDIR_TRIM}$"; then - sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="AVA" >/dev/null 2>&1 - else - sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="ERR" >/dev/null 2>&1 + if zfs list "${bastille_zfs_zpool}" >/dev/null 2>&1; then + + # Check and don't allow child datasets in bastille_zfs_zpool. + if echo "${bastille_zfs_zpool}" | grep -q '\/'; then + zfs_support_error + exit 1 + fi + + # Check and make sure bastille_zfs_prefix end with "bastille". + if echo "${DAFAULT_BASTILLE_PREFIX}" | ! grep -iq "${APPNAME}"; then + zfs_support_error + exit 1 + elif ! echo "${bastille_zfs_prefix}" | grep -qw "${DAFAULT_BASTILLE_PREFIX}"; then + zfs_support_error + exit 1 + fi + + # Check bastille ZFS config match on disk ZFS config if activation is already enabled in the config file. + if sysrc -f ${CWDIR}${EXTCONF} -qc ZFS_SUPPORT=YES && sysrc -f ${CWDIR}${EXTCONF} -qc ZFS_ACTIVATED=YES; then + if [ "${BASTILLE_CONFIG_DISK}" != "${BASTILLE_CONFIG_FILE}" ]; then + zfs_support_error + exit 1 fi fi + + # Perform some checks against on-disk and file configurations. + if zfs list "${bastille_zfs_zpool}/${BASTILLE_ZFS_PREFIX_TRIM}/${DAFAULT_BASTILLE_PREFIX}" >/dev/null 2>&1; then + # Looks like ZFS support is already configured, then set parameters. + zfs_support_enabled + elif zfs list "${bastille_zfs_zpool}" >/dev/null 2>&1 && \ + [ "${bastille_zfs_prefix}" = "${BASTILLE_ZFS_PREFIX_TRIM}/${DAFAULT_BASTILLE_PREFIX}" ]; then + # Looks like ZFS support is available for activation. + zfs_support_avail + elif zfs list "${bastille_zfs_zpool}/${DAFAULT_BASTILLE_PREFIX}" >/dev/null 2>&1; then + zfs_support_enabled + elif zfs list "${bastille_zfs_zpool}" >/dev/null 2>&1 && \ + [ "${BASTILLE_ZFS_PREFIX_TRIM}" = "${DAFAULT_BASTILLE_PREFIX}" ]; then + # Looks like ZFS support is available for activation. + zfs_support_avail + elif zfs list "${bastille_zfs_zpool}/${DAFAULT_BASTILLE_PREFIX}" >/dev/null 2>&1; then + zfs_support_enabled + else + zfs_support_error + fi else - sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="ERR" >/dev/null 2>&1 + zfs_support_error fi else - sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="ERR" >/dev/null 2>&1 + zfs_support_error fi else - sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="NO" >/dev/null 2>&1 + # Check for orphaned configuration and/or config reset. + if zfs list -H "${CWDIR}" 2>/dev/null | awk '{print $1}' | grep -qw "${DAFAULT_BASTILLE_PREFIX}"; then + zfs_support_error + else + if [ "${bastille_zfs_enable}" = "NO" ] || [ "${bastille_zfs_enable}" = "no" ]; then + zfs_support_disabled + fi + fi fi + + # Enable bastille in /etc/rc.conf + sysrc bastille_enable="YES" >/dev/null 2>&1 } update_config() { # Update config based on minimum version. - # Network parameters. + # Update network parameters. + if grep -qw 'bastille_jail_loopback=' ${INSTALLPATH}/${BASTILLECONF}; then + sed -i '' 's/bastille_jail_loopback=/bastille_network_loopback=/' ${INSTALLPATH}/${BASTILLECONF} + fi if grep -qw 'bastille_jail_loopback=' ${INSTALLPATH}/${BASTILLECONF}; then sed -i '' 's/bastille_jail_loopback=/bastille_network_loopback=/' ${INSTALLPATH}/${BASTILLECONF} fi @@ -1245,6 +1446,8 @@ update_config() if grep -qw 'bastille_jail_gateway=' ${INSTALLPATH}/${BASTILLECONF}; then sed -i '' 's/bastille_jail_gateway=/bastille_network_gateway=/' ${INSTALLPATH}/${BASTILLECONF} fi + + # Fetch parameters. if ! grep -qw 'bastille_url_freebsd=' ${INSTALLPATH}/${BASTILLECONF}; then sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_url_freebsd="${URL_FREEBSD}" fi @@ -1255,17 +1458,34 @@ update_config() sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_url_midnightbsd="${URL_MIDNIGHTBSD}" fi + # Check/append network parameters. + if ! grep -qw 'bastille_network_vnet_type=' ${INSTALLPATH}/${BASTILLECONF}; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_network_vnet_type="if_bridge" + elif ! sysrc -f ${INSTALLPATH}/${BASTILLECONF} -c bastille_network_vnet_type=if_bridge; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_network_vnet_type="if_bridge" + fi + if ! grep -qw 'bastille_network_loopback=' ${INSTALLPATH}/${BASTILLECONF}; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_network_loopback="" + fi if ! grep -qw 'bastille_network_pf_ext_if=' ${INSTALLPATH}/${BASTILLECONF}; then sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_network_pf_ext_if="ext_if" + elif ! sysrc -f ${INSTALLPATH}/${BASTILLECONF} -c bastille_network_pf_ext_if=ext_if; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_network_pf_ext_if="ext_if" fi if ! grep -qw 'bastille_network_pf_table=' ${INSTALLPATH}/${BASTILLECONF}; then sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_network_pf_table="jails" fi + if ! grep -qw 'bastille_network_shared=' ${INSTALLPATH}/${BASTILLECONF}; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_network_shared="" + fi + if ! grep -qw 'bastille_network_gateway=' ${INSTALLPATH}/${BASTILLECONF}; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_network_gateway="" + fi if ! grep -qw 'bastille_network_gateway6=' ${INSTALLPATH}/${BASTILLECONF}; then sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_network_gateway6="" fi - # Template parameters. + # Check/append template parameters. if ! grep -qw 'bastille_template_base=' ${INSTALLPATH}/${BASTILLECONF}; then sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_template_base="default/base" fi @@ -1275,12 +1495,45 @@ update_config() if ! grep -qw 'bastille_template_thick=' ${INSTALLPATH}/${BASTILLECONF}; then sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_template_thick="default/thick" fi + if ! grep -qw 'bastille_template_clone=' ${INSTALLPATH}/${BASTILLECONF}; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_template_clone="default/clone" + fi if ! grep -qw 'bastille_template_thin=' ${INSTALLPATH}/${BASTILLECONF}; then sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_template_thin="default/thin" fi if ! grep -qw 'bastille_template_vnet=' ${INSTALLPATH}/${BASTILLECONF}; then sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_template_vnet="default/vnet" fi + if ! grep -qw 'bastille_template_vlan=' ${INSTALLPATH}/${BASTILLECONF}; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_template_vlan="default/vlan" + fi + + # Compress/Decompress parameters. + if ! grep -qw 'bastille_compress_zst_options=' ${INSTALLPATH}/${BASTILLECONF}; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_compress_zst_options="-3 -v" + fi + if ! grep -qw 'bastille_decompress_zst_options=' ${INSTALLPATH}/${BASTILLECONF}; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_decompress_zst_options="-k -d -c -v" + fi + + # Check/append pkgbase parameters. + if ! grep -qw 'bastille_pkgbase_packages=' ${INSTALLPATH}/${BASTILLECONF}; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_pkgbase_packages="base-jail" + fi + + # Check/append monitor parameters. + if ! grep -qw 'bastille_monitor_cron_path=' ${INSTALLPATH}/${BASTILLECONF}; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_monitor_cron_path="/usr/local/etc/cron.d/bastille-monitor" + fi + if ! grep -qw 'bastille_monitor_cron=' ${INSTALLPATH}/${BASTILLECONF}; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_monitor_cron="*/5 * * * * root /usr/local/bin/bastille monitor ALL >/dev/null 2>&1" + fi + if ! grep -qw 'bastille_monitor_logfile=' ${INSTALLPATH}/${BASTILLECONF}; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_monitor_logfile="\${bastille_logsdir}/monitor.log" + fi + if ! grep -qw 'bastille_monitor_healthchecks=' ${INSTALLPATH}/${BASTILLECONF}; then + sysrc -f ${INSTALLPATH}/${BASTILLECONF} bastille_monitor_healthchecks="" + fi # Remove deprecated parameters based on minimum version. if grep -qw 'bastille_jail_interface' ${INSTALLPATH}/${BASTILLECONF}; then @@ -1337,7 +1590,7 @@ bastille_init() # Check for system compatibility. if [ ! "${PLATFORM}" = "amd64" ]; then echo "Unsupported platform!"; exit 1 - fi + fi # Check for product compatibility. if [ ! "${PRDVERSION}" -ge "112" ]; then echo "Unsupported version!"; exit 1 @@ -1352,17 +1605,18 @@ bastille_init() gui_start rc_params ext_start - } -linux_compat() +linux_compat_enable() { + # Experimental feature. if ping -c1 -t5 freebsd.org > /dev/null; then # Manually enable Linux compatibility(Experimental). - if ! sysrc -f ${CWDIR}${EXTCONF} -qn LINUX_COMPAT_SUPPORT | grep -q "YES"; then - ${CWDIR}/unionfs.sh fetch_pkg && ${CWDIR}/unionfs.sh load_kmods && ${CWDIR}/unionfs.sh unionfs_on && sysrc -f ${CWDIR}${EXTCONF} LINUX_COMPAT_SUPPORT="YES" >/dev/null 2>&1 + if ! sysrc -f ${CWDIR}${EXTCONF} -qc LINUX_COMPAT_SUPPORT=YES; then + echo "Enabling Linux compatibility support..." + ${CWDIR}/unionfs.sh fetch_debootstrap && ${CWDIR}/unionfs.sh load_kmods && sysrc -f ${CWDIR}${EXTCONF} LINUX_COMPAT_SUPPORT="YES" >/dev/null 2>&1 else - echo "Already enabled." + echo "Linux compatibility already enabled." fi exit 0 else @@ -1371,13 +1625,82 @@ linux_compat() fi } +bootstrap_dist() +{ + # Workaround since XigmaNAS does not ship with debootstrap command. + if sysrc -f ${CWDIR}${EXTCONF} -qc LINUX_COMPAT_SUPPORT=YES; then + # List of tested/working Linux distributions on FreeBSD 14.x. + LINUX_FLAVORS="ubuntu-bionic ubuntu-focal ubuntu-jammy ubuntu-noble debian-buster debian-bullseye debian-bookworm" + if [ -n "${LINUX_DIST}" ]; then + for _linux_flavor in ${LINUX_FLAVORS}; do + + if [ "${LINUX_DIST}" = "${_linux_flavor}" ]; then + LINUX_FLAVOR="${_linux_flavor}" + break + fi + + done + fi + + if [ -z "${LINUX_FLAVOR}" ]; then + echo "Available Linux flavors:" + echo "${LINUX_FLAVORS}" + echo -e "\nTo fetch latest debootstrap/keyring packages run 'bastille-init update_debootstrap'" + exit 1 + fi + + # Enable debootstrap environment. + trap "${CWDIR}/unionfs.sh unionfs_off" 0 1 2 5 15 + ${CWDIR}/unionfs.sh unionfs_on + + # Bootstrap Linux flavor using bastille. + bastille bootstrap ${_linux_flavor} + + # Disable debootstrap environment. + ${CWDIR}/unionfs.sh unionfs_off + + else + echo "Linux compatibility disabled." + exit 1 + fi + + exit 0 +} + +update_debootstrap() +{ + # Update debootstrap and dependencies. + if sysrc -f ${CWDIR}${EXTCONF} -qc LINUX_COMPAT_SUPPORT=YES; then + ${CWDIR}/unionfs.sh update_debootstrap + else + echo "Linux compatibility disabled." + exit 1 + fi + + exit 0 +} + linux_compat_disable() { - if sysrc -f ${CWDIR}${EXTCONF} -qn LINUX_COMPAT_SUPPORT | grep -q "YES"; then - echo "Disabling Linux jail compatibility support..." + if sysrc -f ${CWDIR}${EXTCONF} -qc LINUX_COMPAT_SUPPORT=YES; then + echo "Disabling Linux compatibility support..." sysrc -f ${CWDIR}${EXTCONF} -x LINUX_COMPAT_SUPPORT - echo "Done!, server reboot is recommended." + ${CWDIR}/unionfs.sh unionfs_off + ${CWDIR}/unionfs.sh unload_kmods + + if [ -d "${CWDIR}/system/usr" ]; then + echo "Removing debootstrap environment..." + rm -rf ${CWDIR}/system/usr + if [ -d "${CWDIR}/system/var" ]; then + rm -rf ${CWDIR}/system/var + fi + fi + echo "Done!, please reboot server now." + else + echo "Linux compatibility disabled." + exit 1 fi + exit 0 } @@ -1412,12 +1735,39 @@ upgrade|--upgrade) fi release_change fi + _forceopt= + ;; +upgrade_force|--upgrade-force) + # Check container type to upgrade + if [ -z "${NEWRELEASE}" ]; then + if [ $# -gt 3 ] || [ $# -lt 3 ]; then + echo "Usage: ${SCRIPTNAME} [upgrade_force|--upgrade-force] [container|release] [release]" + exit 1 + fi + thickjail_upgrade + else + if [ $# -gt 4 ] || [ $# -lt 4 ]; then + echo "Usage: ${SCRIPTNAME} [upgrade_force|--upgrade-force] [container] [release] [newrelease]" + exit 1 + fi + release_change + fi + _forceopt="-F" ;; update|--update) if [ $# -gt 2 ] || [ $# -lt 2 ]; then echo "Usage: ${SCRIPTNAME} [update|--update] [container] | [release]" exit 1 fi + _forceopt= + jail_update + ;; +update_force|--update-force) + if [ $# -gt 2 ] || [ $# -lt 2 ]; then + echo "Usage: ${SCRIPTNAME} [update_force|--update-force] [container] | [release]" + exit 1 + fi + _forceopt="-F" jail_update ;; clean|--clean) @@ -1427,7 +1777,14 @@ clean|--clean) exit 0 ;; linux_compat) - linux_compat + linux_compat_enable + ;; +bootstrap) + LINUX_DIST="${ARG}" + bootstrap_dist + ;; +update_debootstrap) + update_debootstrap ;; linux_compat_disable) linux_compat_disable @@ -1437,7 +1794,7 @@ bastillebsd_update) ;; esac -while getopts ":ospruxUvgtZh" option; do +while getopts "ospruxUvgtZh" option; do case ${option} in [h]) echo "Usage: ${SCRIPTNAME} -[option] | [container] | [path]"; echo "Options:" @@ -1456,10 +1813,12 @@ while getopts ":ospruxUvgtZh" option; do echo echo "Advanced Usage: ${SCRIPTNAME} [option] [container] [release] | [newrelease]" echo "Options:" - echo " update|--update Update a container/release to base -pX release." - echo " upgrade|--upgrade Upgrade a container/release to X.Y-RELEASE." - echo " install|--install Finish installing pending updates on container/release." - echo " clean|--clean Cleanup the FreeBSD update/upgrade cached files/folders." + echo " update|--update Update a container/release to base -pX release." + echo " update_force|--update-force Update a container/release to base -pX release forcefully." + echo " upgrade|--upgrade Upgrade a container/release to X.Y-RELEASE." + echo " upgrade_force|--upgrade-force Upgrade a container/release to X.Y-RELEASE. forcefully" + echo " install|--install Finish installing pending updates on container/release." + echo " clean|--clean Cleanup the FreeBSD update/upgrade cached files/folders." echo "" echo "" echo "Experimental:" @@ -1469,6 +1828,8 @@ while getopts ":ospruxUvgtZh" option; do echo "" echo "Support:" echo "To update BastilleBSD core files only to the latest patches and fixes, please execute: \"${SCRIPTNAME} bastillebsd_update\"" + echo "To bootstrap a Linux distribution please execute: \"${SCRIPTNAME} bootstrap linux_flavor\"" + echo "To update debootstrap package and dependencies please execute: \"${SCRIPTNAME} update_debootstrap\"" echo ""; exit 0;; [o]) OBI_INSTALL="ON";; # To prevent nested PHP-CGI call for installation with OBI. [s]) bastille_start;; @@ -1478,8 +1839,8 @@ while getopts ":ospruxUvgtZh" option; do [x]) reset_install;; [U]) remove_addon;; [v]) get_versions;; - [g]) gui_enable; exit 0 ;; # For enable the addon gui. - [t]) gui_disable; exit 0 ;; # For disable the addon gui. + [g]) gui_enable;; # Enable the addon gui. + [t]) gui_disable;; # Disable the addon gui. [Z]) zfs_activate;; #[L]) linux_compat;; [?]) echo "Invalid option, -h for usage."; exit 1;; diff --git a/conf/bastille.conf.ext b/conf/bastille.conf.ext index 4ba7c65..8b131f0 100644 --- a/conf/bastille.conf.ext +++ b/conf/bastille.conf.ext @@ -1,5 +1,6 @@ bastille_prefix="/usr/local/bastille" bastille_backupsdir="${bastille_prefix}/backups" +bastille_migratedir="${bastille_prefix}/migrate" bastille_cachedir="${bastille_prefix}/cache" bastille_jailsdir="${bastille_prefix}/jails" bastille_releasesdir="${bastille_prefix}/releases" @@ -8,12 +9,12 @@ bastille_logsdir="${bastille_prefix}/logs" bastille_pf_conf="${bastille_prefix}/pf.conf" bastille_sharedir="/usr/local/share/bastille" bastille_bootstrap_archives="base" +bastille_pkgbase_packages="base-jail" bastille_tzdata="etc/UTC" bastille_resolv_conf="/etc/resolv.conf" bastille_url_freebsd="http://ftp.freebsd.org/pub/FreeBSD/releases/" bastille_url_hardenedbsd="https://installers.hardenedbsd.org/pub/" bastille_url_midnightbsd="https://www.midnightbsd.org/ftp/MidnightBSD/releases/" -bastille_url_midnightbsd="https://www.midnightbsd.org/ftp/MidnightBSD/releases/" bastille_zfs_enable="" bastille_zfs_zpool="" bastille_zfs_prefix="bastille" @@ -22,15 +23,23 @@ bastille_compress_xz_options="-0 -v" bastille_decompress_xz_options="-c -d -v" bastille_compress_gz_options="-1 -v" bastille_decompress_gz_options="-k -d -c -v" +bastille_compress_zst_options="-3 -v" +bastille_decompress_zst_options="-k -d -c -v" +bastille_network_vnet_type="if_bridge" bastille_network_loopback="" bastille_network_pf_ext_if="ext_if" bastille_network_pf_table="jails" bastille_network_shared="" bastille_network_gateway="" -bastille_network_gateway6="" +bastille_network_gateway6="" bastille_template_base="default/base" bastille_template_empty="" bastille_template_thick="default/thick" bastille_template_clone="default/clone" bastille_template_thin="default/thin" bastille_template_vnet="default/vnet" +bastille_template_vlan="default/vlan" +bastille_monitor_cron_path="/usr/local/etc/cron.d/bastille-monitor" +bastille_monitor_cron="*/5 * * * * root /usr/local/bin/bastille monitor ALL >/dev/null 2>&1" +bastille_monitor_logfile="${bastille_logsdir}/monitor.log" +bastille_monitor_healthchecks="" diff --git a/conf/system/freebsd-update/14.2/freebsd-update b/conf/system/freebsd-update/14.2/freebsd-update new file mode 100755 index 0000000..77b12a3 --- /dev/null +++ b/conf/system/freebsd-update/14.2/freebsd-update @@ -0,0 +1,3547 @@ +#!/bin/sh + +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright 2004-2007 Colin Percival +# All rights reserved +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted providing that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +#### Usage function -- called from command-line handling code. + +# Usage instructions. Options not listed: +# --debug -- don't filter output from utilities +# --no-stats -- don't show progress statistics while fetching files +usage () { + cat < ${LINE}" + exit 1 + fi + done < ${CONFFILE} + + # Merge the settings read from the configuration file with those + # provided at the command line. + mergeconfig +} + +# Provide some default parameters +default_params () { + # Save any parameters already configured, and clear the slate + saveconfig + nullconfig + + # Default configurations + config_WorkDir /var/db/freebsd-update + config_MailTo root + config_AllowAdd yes + config_AllowDelete yes + config_KeepModifiedMetadata yes + config_BaseDir / + config_VerboseLevel stats + config_StrictComponents no + config_BackupKernel yes + config_BackupKernelDir /boot/kernel.old + config_BackupKernelSymbolFiles no + config_CreateBootEnv yes + + # Merge these defaults into the earlier-configured settings + mergeconfig +} + +# Set utility output filtering options, based on ${VERBOSELEVEL} +fetch_setup_verboselevel () { + case ${VERBOSELEVEL} in + debug) + QUIETREDIR="/dev/stderr" + QUIETFLAG=" " + STATSREDIR="/dev/stderr" + DDSTATS=".." + XARGST="-t" + NDEBUG=" " + ;; + nostats) + QUIETREDIR="" + QUIETFLAG="" + STATSREDIR="/dev/null" + DDSTATS=".." + XARGST="" + NDEBUG="" + ;; + stats) + QUIETREDIR="/dev/null" + QUIETFLAG="-q" + STATSREDIR="/dev/stdout" + DDSTATS="" + XARGST="" + NDEBUG="-n" + ;; + esac +} + +# Perform sanity checks and set some final parameters +# in preparation for fetching files. Figure out which +# set of updates should be downloaded: If the user is +# running *-p[0-9]+, strip off the last part; if the +# user is running -SECURITY, call it -RELEASE. Chdir +# into the working directory. +fetchupgrade_check_params () { + export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)" + + _SERVERNAME_z=\ +"SERVERNAME must be given via command line or configuration file." + _KEYPRINT_z="Key must be given via -k option or configuration file." + _KEYPRINT_bad="Invalid key fingerprint: " + _WORKDIR_bad="Directory does not exist or is not writable: " + _WORKDIR_bad2="Directory is not on a persistent filesystem: " + + if [ -z "${SERVERNAME}" ]; then + echo -n "`basename $0`: " + echo "${_SERVERNAME_z}" + exit 1 + fi + if [ -z "${KEYPRINT}" ]; then + echo -n "`basename $0`: " + echo "${_KEYPRINT_z}" + exit 1 + fi + if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then + echo -n "`basename $0`: " + echo -n "${_KEYPRINT_bad}" + echo ${KEYPRINT} + exit 1 + fi + if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then + echo -n "`basename $0`: " + echo -n "${_WORKDIR_bad}" + echo ${WORKDIR} + exit 1 + fi + case `df -T ${WORKDIR}` in */dev/md[0-9]* | *tmpfs*) + echo -n "`basename $0`: " + echo -n "${_WORKDIR_bad2}" + echo ${WORKDIR} + exit 1 + ;; + esac + chmod 700 ${WORKDIR} + cd ${WORKDIR} || exit 1 + + # Generate release number. The s/SECURITY/RELEASE/ bit exists + # to provide an upgrade path for FreeBSD Update 1.x users, since + # the kernels provided by FreeBSD Update 1.x are always labelled + # as X.Y-SECURITY. + RELNUM=`uname -r | + sed -E 's,-p[0-9]+,,' | + sed -E 's,-SECURITY,-RELEASE,'` + ARCH=`uname -m` + FETCHDIR=${RELNUM}/${ARCH} + PATCHDIR=${RELNUM}/${ARCH}/bp + + # Disallow upgrade from a version that is not a release + case ${RELNUM} in + *-RELEASE | *-ALPHA* | *-BETA* | *-RC*) + ;; + *) + echo -n "`basename $0`: " + cat <<- EOF + Cannot upgrade from a version that is not a release + (including alpha, beta and release candidates) + using `basename $0`. Instead, FreeBSD can be directly + upgraded by source or upgraded to a RELEASE/RELENG version + prior to running `basename $0`. + Currently running: ${RELNUM} + EOF + exit 1 + ;; + esac + + # Figure out what directory contains the running kernel + BOOTFILE=`sysctl -n kern.bootfile` + KERNELDIR=${BOOTFILE%/kernel} + if ! [ -d ${KERNELDIR} ]; then + echo "Cannot identify running kernel" + exit 1 + fi + + # Figure out what kernel configuration is running. We start with + # the output of `uname -i`, and then make the following adjustments: + # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config + # file says "ident SMP-GENERIC", I don't know... + # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64" + # _and_ `sysctl kern.version` contains a line which ends "/SMP", then + # we're running an SMP kernel. This mis-identification is a bug + # which was fixed in 6.2-STABLE. + KERNCONF=`uname -i` + if [ ${KERNCONF} = "SMP-GENERIC" ]; then + KERNCONF=SMP + fi + if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then + if sysctl kern.version | grep -qE '/SMP$'; then + KERNCONF=SMP + fi + fi + + # Define some paths + BSPATCH=/usr/bin/bspatch + SHA256=/sbin/sha256 + PHTTPGET=/usr/libexec/phttpget + + # Set up variables relating to VERBOSELEVEL + fetch_setup_verboselevel + + # Construct a unique name from ${BASEDIR} + BDHASH=`echo ${BASEDIR} | sha256 -q` +} + +# Perform sanity checks etc. before fetching updates. +fetch_check_params () { + fetchupgrade_check_params + + if ! [ -z "${TARGETRELEASE}" ]; then + echo -n "`basename $0`: " + echo -n "'-r' option is meaningless with 'fetch' command. " + echo "(Did you mean 'upgrade' instead?)" + exit 1 + fi + + # Check that we have updates ready to install + if [ -f ${BDHASH}-install/kerneldone -a $FORCEFETCH -eq 0 ]; then + echo "You have a partially completed upgrade pending" + echo "Run '`basename $0` [options] install' first." + echo "Run '`basename $0` [options] fetch -F' to proceed anyway." + exit 1 + fi +} + +# Perform sanity checks etc. before fetching upgrades. +upgrade_check_params () { + fetchupgrade_check_params + + # Unless set otherwise, we're upgrading to the same kernel config. + NKERNCONF=${KERNCONF} + + # We need TARGETRELEASE set + _TARGETRELEASE_z="Release target must be specified via '-r' option." + if [ -z "${TARGETRELEASE}" ]; then + echo -n "`basename $0`: " + echo "${_TARGETRELEASE_z}" + exit 1 + fi + + # The target release should be != the current release. + if [ "${TARGETRELEASE}" = "${RELNUM}" ]; then + echo -n "`basename $0`: " + echo "Cannot upgrade from ${RELNUM} to itself" + exit 1 + fi + + # Turning off AllowAdd or AllowDelete is a bad idea for upgrades. + if [ "${ALLOWADD}" = "no" ]; then + echo -n "`basename $0`: " + echo -n "WARNING: \"AllowAdd no\" is a bad idea " + echo "when upgrading between releases." + echo + fi + if [ "${ALLOWDELETE}" = "no" ]; then + echo -n "`basename $0`: " + echo -n "WARNING: \"AllowDelete no\" is a bad idea " + echo "when upgrading between releases." + echo + fi + + # Set EDITOR to /usr/bin/vi if it isn't already set + : ${EDITOR:='/usr/bin/vi'} +} + +# Perform sanity checks and set some final parameters in +# preparation for installing updates. +install_check_params () { + # Check that we are root. All sorts of things won't work otherwise. + if [ `id -u` != 0 ]; then + echo "You must be root to run this." + exit 1 + fi + + # Check that securelevel <= 0. Otherwise we can't update schg files. + if [ `sysctl -n kern.securelevel` -gt 0 ]; then + echo "Updates cannot be installed when the system securelevel" + echo "is greater than zero." + exit 1 + fi + + # Check that we have a working directory + _WORKDIR_bad="Directory does not exist or is not writable: " + if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then + echo -n "`basename $0`: " + echo -n "${_WORKDIR_bad}" + echo ${WORKDIR} + exit 1 + fi + cd ${WORKDIR} || exit 1 + + # Construct a unique name from ${BASEDIR} + BDHASH=`echo ${BASEDIR} | sha256 -q` + + # Check that we have updates ready to install + if ! [ -L ${BDHASH}-install ]; then + echo "No updates are available to install." + if [ $ISFETCHED -eq 0 ]; then + echo "Run '`basename $0` [options] fetch' first." + exit 2 + fi + exit 0 + fi + if ! [ -f ${BDHASH}-install/INDEX-OLD ] || + ! [ -f ${BDHASH}-install/INDEX-NEW ]; then + echo "Update manifest is corrupt -- this should never happen." + echo "Re-run '`basename $0` [options] fetch'." + exit 1 + fi + + # Figure out what directory contains the running kernel + BOOTFILE=`sysctl -n kern.bootfile` + KERNELDIR=${BOOTFILE%/kernel} + if ! [ -d ${KERNELDIR} ]; then + echo "Cannot identify running kernel" + exit 1 + fi +} + +# Creates a new boot environment +install_create_be () { + # Figure out if we're running in a jail and return if we are + if [ `sysctl -n security.jail.jailed` = 1 ]; then + return 1 + fi + # Operating on roots that aren't located at / will, more often than not, + # not touch the boot environment. + if [ "$BASEDIR" != "/" ]; then + return 1 + fi + # Create a boot environment if enabled + if [ ${BOOTENV} = yes ]; then + bectl check 2>/dev/null + case $? in + 0) + # Boot environment are supported + CREATEBE=yes + ;; + 255) + # Boot environments are not supported + CREATEBE=no + ;; + *) + # If bectl returns an unexpected exit code, don't create a BE + CREATEBE=no + ;; + esac + if [ ${CREATEBE} = yes ]; then + echo -n "Creating snapshot of existing boot environment... " + VERSION=`freebsd-version -ku | sort -V | tail -n 1` + TIMESTAMP=`date +"%Y-%m-%d_%H%M%S"` + bectl create -r ${VERSION}_${TIMESTAMP} + if [ $? -eq 0 ]; then + echo "done."; + else + echo "failed." + exit 1 + fi + fi + fi +} + +# Perform sanity checks and set some final parameters in +# preparation for UNinstalling updates. +rollback_check_params () { + # Check that we are root. All sorts of things won't work otherwise. + if [ `id -u` != 0 ]; then + echo "You must be root to run this." + exit 1 + fi + + # Check that we have a working directory + _WORKDIR_bad="Directory does not exist or is not writable: " + if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then + echo -n "`basename $0`: " + echo -n "${_WORKDIR_bad}" + echo ${WORKDIR} + exit 1 + fi + cd ${WORKDIR} || exit 1 + + # Construct a unique name from ${BASEDIR} + BDHASH=`echo ${BASEDIR} | sha256 -q` + + # Check that we have updates ready to rollback + if ! [ -L ${BDHASH}-rollback ]; then + echo "No rollback directory found." + exit 1 + fi + if ! [ -f ${BDHASH}-rollback/INDEX-OLD ] || + ! [ -f ${BDHASH}-rollback/INDEX-NEW ]; then + echo "Update manifest is corrupt -- this should never happen." + exit 1 + fi +} + +# Perform sanity checks and set some final parameters +# in preparation for comparing the system against the +# published index. Figure out which index we should +# compare against: If the user is running *-p[0-9]+, +# strip off the last part; if the user is running +# -SECURITY, call it -RELEASE. Chdir into the working +# directory. +IDS_check_params () { + export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)" + + _SERVERNAME_z=\ +"SERVERNAME must be given via command line or configuration file." + _KEYPRINT_z="Key must be given via '-k' option or configuration file." + _KEYPRINT_bad="Invalid key fingerprint: " + _WORKDIR_bad="Directory does not exist or is not writable: " + + if [ -z "${SERVERNAME}" ]; then + echo -n "`basename $0`: " + echo "${_SERVERNAME_z}" + exit 1 + fi + if [ -z "${KEYPRINT}" ]; then + echo -n "`basename $0`: " + echo "${_KEYPRINT_z}" + exit 1 + fi + if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then + echo -n "`basename $0`: " + echo -n "${_KEYPRINT_bad}" + echo ${KEYPRINT} + exit 1 + fi + if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then + echo -n "`basename $0`: " + echo -n "${_WORKDIR_bad}" + echo ${WORKDIR} + exit 1 + fi + cd ${WORKDIR} || exit 1 + + # Generate release number. The s/SECURITY/RELEASE/ bit exists + # to provide an upgrade path for FreeBSD Update 1.x users, since + # the kernels provided by FreeBSD Update 1.x are always labelled + # as X.Y-SECURITY. + RELNUM=`uname -r | + sed -E 's,-p[0-9]+,,' | + sed -E 's,-SECURITY,-RELEASE,'` + ARCH=`uname -m` + FETCHDIR=${RELNUM}/${ARCH} + PATCHDIR=${RELNUM}/${ARCH}/bp + + # Figure out what directory contains the running kernel + BOOTFILE=`sysctl -n kern.bootfile` + KERNELDIR=${BOOTFILE%/kernel} + if ! [ -d ${KERNELDIR} ]; then + echo "Cannot identify running kernel" + exit 1 + fi + + # Figure out what kernel configuration is running. We start with + # the output of `uname -i`, and then make the following adjustments: + # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config + # file says "ident SMP-GENERIC", I don't know... + # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64" + # _and_ `sysctl kern.version` contains a line which ends "/SMP", then + # we're running an SMP kernel. This mis-identification is a bug + # which was fixed in 6.2-STABLE. + KERNCONF=`uname -i` + if [ ${KERNCONF} = "SMP-GENERIC" ]; then + KERNCONF=SMP + fi + if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then + if sysctl kern.version | grep -qE '/SMP$'; then + KERNCONF=SMP + fi + fi + + # Define some paths + SHA256=/sbin/sha256 + PHTTPGET=/usr/libexec/phttpget + + # Set up variables relating to VERBOSELEVEL + fetch_setup_verboselevel +} + +#### Core functionality -- the actual work gets done here + +# Use an SRV query to pick a server. If the SRV query doesn't provide +# a useful answer, use the server name specified by the user. +# Put another way... look up _http._tcp.${SERVERNAME} and pick a server +# from that; or if no servers are returned, use ${SERVERNAME}. +# This allows a user to specify "update.FreeBSD.org" (in which case +# freebsd-update will select one of the mirrors) or "update1.freebsd.org" +# (in which case freebsd-update will use that particular server, since +# there won't be an SRV entry for that name). +# +# We ignore the Port field, since we are always going to use port 80. + +# Fetch the mirror list, but do not pick a mirror yet. Returns 1 if +# no mirrors are available for any reason. +fetch_pick_server_init () { + : > serverlist_tried + +# Check that host(1) exists (i.e., that the system wasn't built with the +# WITHOUT_BIND set) and don't try to find a mirror if it doesn't exist. + if ! which -s host; then + : > serverlist_full + return 1 + fi + + echo -n "Looking up ${SERVERNAME} mirrors... " + +# Issue the SRV query and pull out the Priority, Weight, and Target fields. +# BIND 9 prints "$name has SRV record ..." while BIND 8 prints +# "$name server selection ..."; we allow either format. + MLIST="_http._tcp.${SERVERNAME}" + host -t srv "${MLIST}" | + sed -nE "s/${MLIST} (has SRV record|server selection) //Ip" | + cut -f 1,2,4 -d ' ' | + sed -e 's/\.$//' | + sort > serverlist_full + +# If no records, give up -- we'll just use the server name we were given. + if [ `wc -l < serverlist_full` -eq 0 ]; then + echo "none found." + return 1 + fi + +# Report how many mirrors we found. + echo `wc -l < serverlist_full` "mirrors found." + +# Generate a random seed for use in picking mirrors. If HTTP_PROXY +# is set, this will be used to generate the seed; otherwise, the seed +# will be random. + if [ -n "${HTTP_PROXY}${http_proxy}" ]; then + RANDVALUE=`sha256 -qs "${HTTP_PROXY}${http_proxy}" | + tr -d 'a-f' | + cut -c 1-9` + else + RANDVALUE=`jot -r 1 0 999999999` + fi +} + +# Pick a mirror. Returns 1 if we have run out of mirrors to try. +fetch_pick_server () { +# Generate a list of not-yet-tried mirrors + sort serverlist_tried | + comm -23 serverlist_full - > serverlist + +# Have we run out of mirrors? + if [ `wc -l < serverlist` -eq 0 ]; then + cat <<- EOF + No mirrors remaining, giving up. + + This may be because upgrading from this platform (${ARCH}) + or release (${RELNUM}) is unsupported by `basename $0`. Only + platforms with Tier 1 support can be upgraded by `basename $0`. + See https://www.freebsd.org/platforms/ for more info. + + If unsupported, FreeBSD must be upgraded by source. + EOF + return 1 + fi + +# Find the highest priority level (lowest numeric value). + SRV_PRIORITY=`cut -f 1 -d ' ' serverlist | sort -n | head -1` + +# Add up the weights of the response lines at that priority level. + SRV_WSUM=0; + while read X; do + case "$X" in + ${SRV_PRIORITY}\ *) + SRV_W=`echo $X | cut -f 2 -d ' '` + SRV_WSUM=$(($SRV_WSUM + $SRV_W)) + ;; + esac + done < serverlist + +# If all the weights are 0, pretend that they are all 1 instead. + if [ ${SRV_WSUM} -eq 0 ]; then + SRV_WSUM=`grep -E "^${SRV_PRIORITY} " serverlist | wc -l` + SRV_W_ADD=1 + else + SRV_W_ADD=0 + fi + +# Pick a value between 0 and the sum of the weights - 1 + SRV_RND=`expr ${RANDVALUE} % ${SRV_WSUM}` + +# Read through the list of mirrors and set SERVERNAME. Write the line +# corresponding to the mirror we selected into serverlist_tried so that +# we won't try it again. + while read X; do + case "$X" in + ${SRV_PRIORITY}\ *) + SRV_W=`echo $X | cut -f 2 -d ' '` + SRV_W=$(($SRV_W + $SRV_W_ADD)) + if [ $SRV_RND -lt $SRV_W ]; then + SERVERNAME=`echo $X | cut -f 3 -d ' '` + echo "$X" >> serverlist_tried + break + else + SRV_RND=$(($SRV_RND - $SRV_W)) + fi + ;; + esac + done < serverlist +} + +# Take a list of ${oldhash}|${newhash} and output a list of needed patches, +# i.e., those for which we have ${oldhash} and don't have ${newhash}. +fetch_make_patchlist () { + grep -vE "^([0-9a-f]{64})\|\1$" | + tr '|' ' ' | + while read X Y; do + if [ -f "files/${Y}.gz" ] || + [ ! -f "files/${X}.gz" ]; then + continue + fi + echo "${X}|${Y}" + done | sort -u +} + +# Print user-friendly progress statistics +fetch_progress () { + LNC=0 + while read x; do + LNC=$(($LNC + 1)) + if [ $(($LNC % 10)) = 0 ]; then + echo -n $LNC + elif [ $(($LNC % 2)) = 0 ]; then + echo -n . + fi + done + echo -n " " +} + +# Function for asking the user if everything is ok +continuep () { + while read -p "Does this look reasonable (y/n)? " CONTINUE; do + case "${CONTINUE}" in + [yY]*) + return 0 + ;; + [nN]*) + return 1 + ;; + esac + done +} + +# Initialize the working directory +workdir_init () { + mkdir -p files + touch tINDEX.present +} + +# Check that we have a public key with an appropriate hash, or +# fetch the key if it doesn't exist. Returns 1 if the key has +# not yet been fetched. +fetch_key () { + if [ -r pub.ssl ] && [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then + return 0 + fi + + echo -n "Fetching public key from ${SERVERNAME}... " + rm -f pub.ssl + fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/pub.ssl \ + 2>${QUIETREDIR} || true + if ! [ -r pub.ssl ]; then + echo "failed." + return 1 + fi + if ! [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then + echo "key has incorrect hash." + rm -f pub.ssl + return 1 + fi + echo "done." +} + +# Fetch metadata signature, aka "tag". +fetch_tag () { + echo -n "Fetching metadata signature " + echo ${NDEBUG} "for ${RELNUM} from ${SERVERNAME}... " + rm -f latest.ssl + fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/latest.ssl \ + 2>${QUIETREDIR} || true + if ! [ -r latest.ssl ]; then + echo "failed." + return 1 + fi + + openssl rsautl -pubin -inkey pub.ssl -verify \ + < latest.ssl > tag.new 2>${QUIETREDIR} || true + rm latest.ssl + + if ! [ `wc -l < tag.new` = 1 ] || + ! grep -qE \ + "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \ + tag.new; then + echo "invalid signature." + return 1 + fi + + echo "done." + + RELPATCHNUM=`cut -f 4 -d '|' < tag.new` + TINDEXHASH=`cut -f 5 -d '|' < tag.new` + EOLTIME=`cut -f 6 -d '|' < tag.new` +} + +# Sanity-check the patch number in a tag, to make sure that we're not +# going to "update" backwards and to prevent replay attacks. +fetch_tagsanity () { + # Check that we're not going to move from -pX to -pY with Y < X. + RELPX=`uname -r | sed -E 's,.*-,,'` + if echo ${RELPX} | grep -qE '^p[0-9]+$'; then + RELPX=`echo ${RELPX} | cut -c 2-` + else + RELPX=0 + fi + if [ "${RELPATCHNUM}" -lt "${RELPX}" ]; then + echo + echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})" + echo " appear older than what" + echo "we are currently running (`uname -r`)!" + echo "Cowardly refusing to proceed any further." + return 1 + fi + + # If "tag" exists and corresponds to ${RELNUM}, make sure that + # it contains a patch number <= RELPATCHNUM, in order to protect + # against rollback (replay) attacks. + if [ -f tag ] && + grep -qE \ + "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \ + tag; then + LASTRELPATCHNUM=`cut -f 4 -d '|' < tag` + + if [ "${RELPATCHNUM}" -lt "${LASTRELPATCHNUM}" ]; then + echo + echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})" + echo " are older than the" + echo -n "most recently seen updates" + echo " (${RELNUM}-p${LASTRELPATCHNUM})." + echo "Cowardly refusing to proceed any further." + return 1 + fi + fi +} + +# Fetch metadata index file +fetch_metadata_index () { + echo ${NDEBUG} "Fetching metadata index... " + rm -f ${TINDEXHASH} + fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/t/${TINDEXHASH} + 2>${QUIETREDIR} + if ! [ -f ${TINDEXHASH} ]; then + echo "failed." + return 1 + fi + if [ `${SHA256} -q ${TINDEXHASH}` != ${TINDEXHASH} ]; then + echo "update metadata index corrupt." + return 1 + fi + echo "done." +} + +# Print an error message about signed metadata being bogus. +fetch_metadata_bogus () { + echo + echo "The update metadata$1 is correctly signed, but" + echo "failed an integrity check." + echo "Cowardly refusing to proceed any further." + return 1 +} + +# Construct tINDEX.new by merging the lines named in $1 from ${TINDEXHASH} +# with the lines not named in $@ from tINDEX.present (if that file exists). +fetch_metadata_index_merge () { + for METAFILE in $@; do + if [ `grep -E "^${METAFILE}\|" ${TINDEXHASH} | wc -l` \ + -ne 1 ]; then + fetch_metadata_bogus " index" + return 1 + fi + + grep -E "${METAFILE}\|" ${TINDEXHASH} + done | + sort > tINDEX.wanted + + if [ -f tINDEX.present ]; then + join -t '|' -v 2 tINDEX.wanted tINDEX.present | + sort -m - tINDEX.wanted > tINDEX.new + rm tINDEX.wanted + else + mv tINDEX.wanted tINDEX.new + fi +} + +# Sanity check all the lines of tINDEX.new. Even if more metadata lines +# are added by future versions of the server, this won't cause problems, +# since the only lines which appear in tINDEX.new are the ones which we +# specifically grepped out of ${TINDEXHASH}. +fetch_metadata_index_sanity () { + if grep -qvE '^[0-9A-Z.-]+\|[0-9a-f]{64}$' tINDEX.new; then + fetch_metadata_bogus " index" + return 1 + fi +} + +# Sanity check the metadata file $1. +fetch_metadata_sanity () { + # Some aliases to save space later: ${P} is a character which can + # appear in a path; ${M} is the four numeric metadata fields; and + # ${H} is a sha256 hash. + P="[-+./:=,%@_[~[:alnum:]]" + M="[0-9]+\|[0-9]+\|[0-9]+\|[0-9]+" + H="[0-9a-f]{64}" + + # Check that the first four fields make sense. + if gunzip -c < files/$1.gz | + grep -qvE "^[a-z]+\|[0-9a-z-]+\|${P}+\|[fdL-]\|"; then + fetch_metadata_bogus "" + return 1 + fi + + # Remove the first three fields. + gunzip -c < files/$1.gz | + cut -f 4- -d '|' > sanitycheck.tmp + + # Sanity check entries with type 'f' + if grep -E '^f' sanitycheck.tmp | + grep -qvE "^f\|${M}\|${H}\|${P}*\$"; then + fetch_metadata_bogus "" + return 1 + fi + + # Sanity check entries with type 'd' + if grep -E '^d' sanitycheck.tmp | + grep -qvE "^d\|${M}\|\|\$"; then + fetch_metadata_bogus "" + return 1 + fi + + # Sanity check entries with type 'L' + if grep -E '^L' sanitycheck.tmp | + grep -qvE "^L\|${M}\|${P}*\|\$"; then + fetch_metadata_bogus "" + return 1 + fi + + # Sanity check entries with type '-' + if grep -E '^-' sanitycheck.tmp | + grep -qvE "^-\|\|\|\|\|\|"; then + fetch_metadata_bogus "" + return 1 + fi + + # Clean up + rm sanitycheck.tmp +} + +# Fetch the metadata index and metadata files listed in $@, +# taking advantage of metadata patches where possible. +fetch_metadata () { + fetch_metadata_index || return 1 + fetch_metadata_index_merge $@ || return 1 + fetch_metadata_index_sanity || return 1 + + # Generate a list of wanted metadata patches + join -t '|' -o 1.2,2.2 tINDEX.present tINDEX.new | + fetch_make_patchlist > patchlist + + if [ -s patchlist ]; then + # Attempt to fetch metadata patches + echo -n "Fetching `wc -l < patchlist | tr -d ' '` " + echo ${NDEBUG} "metadata patches.${DDSTATS}" + tr '|' '-' < patchlist | + lam -s "${FETCHDIR}/tp/" - -s ".gz" | + xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ + 2>${STATSREDIR} | fetch_progress + echo "done." + + # Attempt to apply metadata patches + echo -n "Applying metadata patches... " + tr '|' ' ' < patchlist | + while read X Y; do + if [ ! -f "${X}-${Y}.gz" ]; then continue; fi + gunzip -c < ${X}-${Y}.gz > diff + gunzip -c < files/${X}.gz > diff-OLD + + # Figure out which lines are being added and removed + grep -E '^-' diff | + cut -c 2- | + while read PREFIX; do + look "${PREFIX}" diff-OLD + done | + sort > diff-rm + grep -E '^\+' diff | + cut -c 2- > diff-add + + # Generate the new file + comm -23 diff-OLD diff-rm | + sort - diff-add > diff-NEW + + if [ `${SHA256} -q diff-NEW` = ${Y} ]; then + mv diff-NEW files/${Y} + gzip -n files/${Y} + else + mv diff-NEW ${Y}.bad + fi + rm -f ${X}-${Y}.gz diff + rm -f diff-OLD diff-NEW diff-add diff-rm + done 2>${QUIETREDIR} + echo "done." + fi + + # Update metadata without patches + cut -f 2 -d '|' < tINDEX.new | + while read Y; do + if [ ! -f "files/${Y}.gz" ]; then + echo ${Y}; + fi + done | + sort -u > filelist + + if [ -s filelist ]; then + echo -n "Fetching `wc -l < filelist | tr -d ' '` " + echo ${NDEBUG} "metadata files... " + lam -s "${FETCHDIR}/m/" - -s ".gz" < filelist | + xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ + 2>${QUIETREDIR} + + while read Y; do + if ! [ -f ${Y}.gz ]; then + echo "failed." + return 1 + fi + if [ `gunzip -c < ${Y}.gz | + ${SHA256} -q` = ${Y} ]; then + mv ${Y}.gz files/${Y}.gz + else + echo "metadata is corrupt." + return 1 + fi + done < filelist + echo "done." + fi + +# Sanity-check the metadata files. + cut -f 2 -d '|' tINDEX.new > filelist + while read X; do + fetch_metadata_sanity ${X} || return 1 + done < filelist + +# Remove files which are no longer needed + cut -f 2 -d '|' tINDEX.present | + sort > oldfiles + cut -f 2 -d '|' tINDEX.new | + sort | + comm -13 - oldfiles | + lam -s "files/" - -s ".gz" | + xargs rm -f + rm patchlist filelist oldfiles + rm ${TINDEXHASH} + +# We're done! + mv tINDEX.new tINDEX.present + mv tag.new tag + + return 0 +} + +# Extract a subset of a downloaded metadata file containing only the parts +# which are listed in COMPONENTS. +fetch_filter_metadata_components () { + METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'` + gunzip -c < files/${METAHASH}.gz > $1.all + + # Fish out the lines belonging to components we care about. + for C in ${COMPONENTS}; do + look "`echo ${C} | tr '/' '|'`|" $1.all + done > $1 + + # Remove temporary file. + rm $1.all +} + +# Generate a filtered version of the metadata file $1 from the downloaded +# file, by fishing out the lines corresponding to components we're trying +# to keep updated, and then removing lines corresponding to paths we want +# to ignore. +fetch_filter_metadata () { + # Fish out the lines belonging to components we care about. + fetch_filter_metadata_components $1 + + # Canonicalize directory names by removing any trailing / in + # order to avoid listing directories multiple times if they + # belong to multiple components. Turning "/" into "" doesn't + # matter, since we add a leading "/" when we use paths later. + cut -f 3- -d '|' $1 | + sed -e 's,/|d|,|d|,' | + sed -e 's,/|-|,|-|,' | + sort -u > $1.tmp + + # Figure out which lines to ignore and remove them. + for X in ${IGNOREPATHS}; do + grep -E "^${X}" $1.tmp + done | + sort -u | + comm -13 - $1.tmp > $1 + + # Remove temporary files. + rm $1.tmp +} + +# Filter the metadata file $1 by adding lines with "/boot/$2" +# replaced by ${KERNELDIR} (which is `sysctl -n kern.bootfile` minus the +# trailing "/kernel"); and if "/boot/$2" does not exist, remove +# the original lines which start with that. +# Put another way: Deal with the fact that the FOO kernel is sometimes +# installed in /boot/FOO/ and is sometimes installed elsewhere. +fetch_filter_kernel_names () { + grep ^/boot/$2 $1 | + sed -e "s,/boot/$2,${KERNELDIR},g" | + sort - $1 > $1.tmp + mv $1.tmp $1 + + if ! [ -d /boot/$2 ]; then + grep -v ^/boot/$2 $1 > $1.tmp + mv $1.tmp $1 + fi +} + +# For all paths appearing in $1 or $3, inspect the system +# and generate $2 describing what is currently installed. +fetch_inspect_system () { + # No errors yet... + rm -f .err + + # Tell the user why his disk is suddenly making lots of noise + echo -n "Inspecting system... " + + # Generate list of files to inspect + cat $1 $3 | + cut -f 1 -d '|' | + sort -u > filelist + + # Examine each file and output lines of the form + # /path/to/file|type|device-inum|user|group|perm|flags|value + # sorted by device and inode number. + while read F; do + # If the symlink/file/directory does not exist, record this. + if ! [ -e ${BASEDIR}/${F} ]; then + echo "${F}|-||||||" + continue + fi + if ! [ -r ${BASEDIR}/${F} ]; then + echo "Cannot read file: ${BASEDIR}/${F}" \ + >/dev/stderr + touch .err + return 1 + fi + + # Otherwise, output an index line. + if [ -L ${BASEDIR}/${F} ]; then + echo -n "${F}|L|" + stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F}; + readlink ${BASEDIR}/${F}; + elif [ -f ${BASEDIR}/${F} ]; then + echo -n "${F}|f|" + stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F}; + sha256 -q ${BASEDIR}/${F}; + elif [ -d ${BASEDIR}/${F} ]; then + echo -n "${F}|d|" + stat -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F}; + else + echo "Unknown file type: ${BASEDIR}/${F}" \ + >/dev/stderr + touch .err + return 1 + fi + done < filelist | + sort -k 3,3 -t '|' > $2.tmp + rm filelist + + # Check if an error occurred during system inspection + if [ -f .err ]; then + return 1 + fi + + # Convert to the form + # /path/to/file|type|user|group|perm|flags|value|hlink + # by resolving identical device and inode numbers into hard links. + cut -f 1,3 -d '|' $2.tmp | + sort -k 1,1 -t '|' | + sort -s -u -k 2,2 -t '|' | + join -1 2 -2 3 -t '|' - $2.tmp | + awk -F \| -v OFS=\| \ + '{ + if (($2 == $3) || ($4 == "-")) + print $3,$4,$5,$6,$7,$8,$9,"" + else + print $3,$4,$5,$6,$7,$8,$9,$2 + }' | + sort > $2 + rm $2.tmp + + # We're finished looking around + echo "done." +} + +# For any paths matching ${MERGECHANGES}, compare $2 against $1 and $3 and +# find any files with values unique to $2; generate $4 containing these paths +# and their corresponding hashes from $1. +fetch_filter_mergechanges () { + # Pull out the paths and hashes of the files matching ${MERGECHANGES}. + for F in $1 $2 $3; do + for X in ${MERGECHANGES}; do + grep -E "^${X}" ${F} + done | + cut -f 1,2,7 -d '|' | + sort > ${F}-values + done + + # Any line in $2-values which doesn't appear in $1-values or $3-values + # and is a file means that we should list the path in $3. + sort $1-values $3-values | + comm -13 - $2-values | + fgrep '|f|' | + cut -f 1 -d '|' > $2-paths + + # For each path, pull out one (and only one!) entry from $1-values. + # Note that we cannot distinguish which "old" version the user made + # changes to; but hopefully any changes which occur due to security + # updates will exist in both the "new" version and the version which + # the user has installed, so the merging will still work. + while read X; do + look "${X}|" $1-values | + head -1 + done < $2-paths > $4 + + # Clean up + rm $1-values $2-values $3-values $2-paths +} + +# For any paths matching ${UPDATEIFUNMODIFIED}, remove lines from $[123] +# which correspond to lines in $2 with hashes not matching $1 or $3, unless +# the paths are listed in $4. For entries in $2 marked "not present" +# (aka. type -), remove lines from $[123] unless there is a corresponding +# entry in $1. +fetch_filter_unmodified_notpresent () { + # Figure out which lines of $1 and $3 correspond to bits which + # should only be updated if they haven't changed, and fish out + # the (path, type, value) tuples. + # NOTE: We don't consider a file to be "modified" if it matches + # the hash from $3. + for X in ${UPDATEIFUNMODIFIED}; do + grep -E "^${X}" $1 + grep -E "^${X}" $3 + done | + cut -f 1,2,7 -d '|' | + sort > $1-values + + # Do the same for $2. + for X in ${UPDATEIFUNMODIFIED}; do + grep -E "^${X}" $2 + done | + cut -f 1,2,7 -d '|' | + sort > $2-values + + # Any entry in $2-values which is not in $1-values corresponds to + # a path which we need to remove from $1, $2, and $3, unless it + # that path appears in $4. + comm -13 $1-values $2-values | + sort -t '|' -k 1,1 > mlines.tmp + cut -f 1 -d '|' $4 | + sort | + join -v 2 -t '|' - mlines.tmp | + sort > mlines + rm $1-values $2-values mlines.tmp + + # Any lines in $2 which are not in $1 AND are "not present" lines + # also belong in mlines. + comm -13 $1 $2 | + cut -f 1,2,7 -d '|' | + fgrep '|-|' >> mlines + + # Remove lines from $1, $2, and $3 + for X in $1 $2 $3; do + sort -t '|' -k 1,1 ${X} > ${X}.tmp + cut -f 1 -d '|' < mlines | + sort | + join -v 2 -t '|' - ${X}.tmp | + sort > ${X} + rm ${X}.tmp + done + + # Store a list of the modified files, for future reference + fgrep -v '|-|' mlines | + cut -f 1 -d '|' > modifiedfiles + rm mlines +} + +# For each entry in $1 of type -, remove any corresponding +# entry from $2 if ${ALLOWADD} != "yes". Remove all entries +# of type - from $1. +fetch_filter_allowadd () { + cut -f 1,2 -d '|' < $1 | + fgrep '|-' | + cut -f 1 -d '|' > filesnotpresent + + if [ ${ALLOWADD} != "yes" ]; then + sort < $2 | + join -v 1 -t '|' - filesnotpresent | + sort > $2.tmp + mv $2.tmp $2 + fi + + sort < $1 | + join -v 1 -t '|' - filesnotpresent | + sort > $1.tmp + mv $1.tmp $1 + rm filesnotpresent +} + +# If ${ALLOWDELETE} != "yes", then remove any entries from $1 +# which don't correspond to entries in $2. +fetch_filter_allowdelete () { + # Produce a lists ${PATH}|${TYPE} + for X in $1 $2; do + cut -f 1-2 -d '|' < ${X} | + sort -u > ${X}.nodes + done + + # Figure out which lines need to be removed from $1. + if [ ${ALLOWDELETE} != "yes" ]; then + comm -23 $1.nodes $2.nodes > $1.badnodes + else + : > $1.badnodes + fi + + # Remove the relevant lines from $1 + while read X; do + look "${X}|" $1 + done < $1.badnodes | + comm -13 - $1 > $1.tmp + mv $1.tmp $1 + + rm $1.badnodes $1.nodes $2.nodes +} + +# If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in $2 +# with metadata not matching any entry in $1, replace the corresponding +# line of $3 with one having the same metadata as the entry in $2. +fetch_filter_modified_metadata () { + # Fish out the metadata from $1 and $2 + for X in $1 $2; do + cut -f 1-6 -d '|' < ${X} > ${X}.metadata + done + + # Find the metadata we need to keep + if [ ${KEEPMODIFIEDMETADATA} = "yes" ]; then + comm -13 $1.metadata $2.metadata > keepmeta + else + : > keepmeta + fi + + # Extract the lines which we need to remove from $3, and + # construct the lines which we need to add to $3. + : > $3.remove + : > $3.add + while read LINE; do + NODE=`echo "${LINE}" | cut -f 1-2 -d '|'` + look "${NODE}|" $3 >> $3.remove + look "${NODE}|" $3 | + cut -f 7- -d '|' | + lam -s "${LINE}|" - >> $3.add + done < keepmeta + + # Remove the specified lines and add the new lines. + sort $3.remove | + comm -13 - $3 | + sort -u - $3.add > $3.tmp + mv $3.tmp $3 + + rm keepmeta $1.metadata $2.metadata $3.add $3.remove +} + +# Remove lines from $1 and $2 which are identical; +# no need to update a file if it isn't changing. +fetch_filter_uptodate () { + comm -23 $1 $2 > $1.tmp + comm -13 $1 $2 > $2.tmp + + mv $1.tmp $1 + mv $2.tmp $2 +} + +# Fetch any "clean" old versions of files we need for merging changes. +fetch_files_premerge () { + # We only need to do anything if $1 is non-empty. + if [ -s $1 ]; then + # Tell the user what we're doing + echo -n "Fetching files from ${OLDRELNUM} for merging... " + + # List of files wanted + fgrep '|f|' < $1 | + cut -f 3 -d '|' | + sort -u > files.wanted + + # Only fetch the files we don't already have + while read Y; do + if [ ! -f "files/${Y}.gz" ]; then + echo ${Y}; + fi + done < files.wanted > filelist + + # Actually fetch them + lam -s "${OLDFETCHDIR}/f/" - -s ".gz" < filelist | + xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ + 2>${QUIETREDIR} + + # Make sure we got them all, and move them into /files/ + while read Y; do + if ! [ -f ${Y}.gz ]; then + echo "failed." + return 1 + fi + if [ `gunzip -c < ${Y}.gz | + ${SHA256} -q` = ${Y} ]; then + mv ${Y}.gz files/${Y}.gz + else + echo "${Y} has incorrect hash." + return 1 + fi + done < filelist + echo "done." + + # Clean up + rm filelist files.wanted + fi +} + +# Prepare to fetch files: Generate a list of the files we need, +# copy the unmodified files we have into /files/, and generate +# a list of patches to download. +fetch_files_prepare () { + # Tell the user why his disk is suddenly making lots of noise + echo -n "Preparing to download files... " + + # Reduce indices to ${PATH}|${HASH} pairs + for X in $1 $2 $3; do + cut -f 1,2,7 -d '|' < ${X} | + fgrep '|f|' | + cut -f 1,3 -d '|' | + sort > ${X}.hashes + done + + # List of files wanted + cut -f 2 -d '|' < $3.hashes | + sort -u | + while read HASH; do + if ! [ -f files/${HASH}.gz ]; then + echo ${HASH} + fi + done > files.wanted + + # Generate a list of unmodified files + comm -12 $1.hashes $2.hashes | + sort -k 1,1 -t '|' > unmodified.files + + # Copy all files into /files/. We only need the unmodified files + # for use in patching; but we'll want all of them if the user asks + # to rollback the updates later. + while read LINE; do + F=`echo "${LINE}" | cut -f 1 -d '|'` + HASH=`echo "${LINE}" | cut -f 2 -d '|'` + + # Skip files we already have. + if [ -f files/${HASH}.gz ]; then + continue + fi + + # Make sure the file hasn't changed. + cp "${BASEDIR}/${F}" tmpfile + if [ `sha256 -q tmpfile` != ${HASH} ]; then + echo + echo "File changed while FreeBSD Update running: ${F}" + return 1 + fi + + # Place the file into storage. + gzip -c < tmpfile > files/${HASH}.gz + rm tmpfile + done < $2.hashes + + # Produce a list of patches to download + sort -k 1,1 -t '|' $3.hashes | + join -t '|' -o 2.2,1.2 - unmodified.files | + fetch_make_patchlist > patchlist + + # Garbage collect + rm unmodified.files $1.hashes $2.hashes $3.hashes + + # We don't need the list of possible old files any more. + rm $1 + + # We're finished making noise + echo "done." +} + +# Fetch files. +fetch_files () { + # Attempt to fetch patches + if [ -s patchlist ]; then + echo -n "Fetching `wc -l < patchlist | tr -d ' '` " + echo ${NDEBUG} "patches.${DDSTATS}" + tr '|' '-' < patchlist | + lam -s "${PATCHDIR}/" - | + xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ + 2>${STATSREDIR} | fetch_progress + echo "done." + + # Attempt to apply patches + echo -n "Applying patches... " + tr '|' ' ' < patchlist | + while read X Y; do + if [ ! -f "${X}-${Y}" ]; then continue; fi + gunzip -c < files/${X}.gz > OLD + + bspatch OLD NEW ${X}-${Y} + + if [ `${SHA256} -q NEW` = ${Y} ]; then + mv NEW files/${Y} + gzip -n files/${Y} + fi + rm -f diff OLD NEW ${X}-${Y} + done 2>${QUIETREDIR} + echo "done." + fi + + # Download files which couldn't be generate via patching + while read Y; do + if [ ! -f "files/${Y}.gz" ]; then + echo ${Y}; + fi + done < files.wanted > filelist + + if [ -s filelist ]; then + echo -n "Fetching `wc -l < filelist | tr -d ' '` " + echo ${NDEBUG} "files... " + lam -s "${FETCHDIR}/f/" - -s ".gz" < filelist | + xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ + 2>${STATSREDIR} | fetch_progress + + while read Y; do + if ! [ -f ${Y}.gz ]; then + echo "failed." + return 1 + fi + if [ `gunzip -c < ${Y}.gz | + ${SHA256} -q` = ${Y} ]; then + mv ${Y}.gz files/${Y}.gz + else + echo "${Y} has incorrect hash." + return 1 + fi + done < filelist + echo "done." + fi + + # Clean up + rm files.wanted filelist patchlist +} + +# Create and populate install manifest directory; and report what updates +# are available. +fetch_create_manifest () { + # If we have an existing install manifest, nuke it. + if [ -L "${BDHASH}-install" ]; then + rm -r ${BDHASH}-install/ + rm ${BDHASH}-install + fi + + # Report to the user if any updates were avoided due to local changes + if [ -s modifiedfiles ]; then + cat - modifiedfiles <<- EOF | ${PAGER} + The following files are affected by updates. No changes have + been downloaded, however, because the files have been modified + locally: + EOF + fi + rm modifiedfiles + + # If no files will be updated, tell the user and exit + if ! [ -s INDEX-PRESENT ] && + ! [ -s INDEX-NEW ]; then + rm INDEX-PRESENT INDEX-NEW + echo + echo -n "No updates needed to update system to " + echo "${RELNUM}-p${RELPATCHNUM}." + return + fi + + # Divide files into (a) removed files, (b) added files, and + # (c) updated files. + cut -f 1 -d '|' < INDEX-PRESENT | + sort > INDEX-PRESENT.flist + cut -f 1 -d '|' < INDEX-NEW | + sort > INDEX-NEW.flist + comm -23 INDEX-PRESENT.flist INDEX-NEW.flist > files.removed + comm -13 INDEX-PRESENT.flist INDEX-NEW.flist > files.added + comm -12 INDEX-PRESENT.flist INDEX-NEW.flist > files.updated + rm INDEX-PRESENT.flist INDEX-NEW.flist + + # Report removed files, if any + if [ -s files.removed ]; then + cat - files.removed <<- EOF | ${PAGER} + The following files will be removed as part of updating to + ${RELNUM}-p${RELPATCHNUM}: + EOF + fi + rm files.removed + + # Report added files, if any + if [ -s files.added ]; then + cat - files.added <<- EOF | ${PAGER} + The following files will be added as part of updating to + ${RELNUM}-p${RELPATCHNUM}: + EOF + fi + rm files.added + + # Report updated files, if any + if [ -s files.updated ]; then + cat - files.updated <<- EOF | ${PAGER} + The following files will be updated as part of updating to + ${RELNUM}-p${RELPATCHNUM}: + EOF + fi + rm files.updated + + # Create a directory for the install manifest. + MDIR=`mktemp -d install.XXXXXX` || return 1 + + # Populate it + mv INDEX-PRESENT ${MDIR}/INDEX-OLD + mv INDEX-NEW ${MDIR}/INDEX-NEW + + # Link it into place + ln -s ${MDIR} ${BDHASH}-install +} + +# Warn about any upcoming EoL +fetch_warn_eol () { + # What's the current time? + NOWTIME=`date "+%s"` + + # When did we last warn about the EoL date? + if [ -f lasteolwarn ]; then + LASTWARN=`cat lasteolwarn` + else + LASTWARN=`expr ${NOWTIME} - 63072000` + fi + + # If the EoL time is past, warn. + if [ ${EOLTIME} -lt ${NOWTIME} ]; then + echo + cat <<-EOF + WARNING: `uname -sr` HAS PASSED ITS END-OF-LIFE DATE. + Any security issues discovered after `date -r ${EOLTIME}` + will not have been corrected. + EOF + return 1 + fi + + # Figure out how long it has been since we last warned about the + # upcoming EoL, and how much longer we have left. + SINCEWARN=`expr ${NOWTIME} - ${LASTWARN}` + TIMELEFT=`expr ${EOLTIME} - ${NOWTIME}` + + # Don't warn if the EoL is more than 3 months away + if [ ${TIMELEFT} -gt 7884000 ]; then + return 0 + fi + + # Don't warn if the time remaining is more than 3 times the time + # since the last warning. + if [ ${TIMELEFT} -gt `expr ${SINCEWARN} \* 3` ]; then + return 0 + fi + + # Figure out what time units to use. + if [ ${TIMELEFT} -lt 604800 ]; then + UNIT="day" + SIZE=86400 + elif [ ${TIMELEFT} -lt 2678400 ]; then + UNIT="week" + SIZE=604800 + else + UNIT="month" + SIZE=2678400 + fi + + # Compute the right number of units + NUM=`expr ${TIMELEFT} / ${SIZE}` + if [ ${NUM} != 1 ]; then + UNIT="${UNIT}s" + fi + + # Print the warning + echo + cat <<-EOF + WARNING: `uname -sr` is approaching its End-of-Life date. + It is strongly recommended that you upgrade to a newer + release within the next ${NUM} ${UNIT}. + EOF + + # Update the stored time of last warning + echo ${NOWTIME} > lasteolwarn +} + +# Do the actual work involved in "fetch" / "cron". +fetch_run () { + workdir_init || return 1 + + # Prepare the mirror list. + fetch_pick_server_init && fetch_pick_server + + # Try to fetch the public key until we run out of servers. + while ! fetch_key; do + fetch_pick_server || return 1 + done + + # Try to fetch the metadata index signature ("tag") until we run + # out of available servers; and sanity check the downloaded tag. + while ! fetch_tag; do + fetch_pick_server || return 1 + done + fetch_tagsanity || return 1 + + # Fetch the latest INDEX-NEW and INDEX-OLD files. + fetch_metadata INDEX-NEW INDEX-OLD || return 1 + + # Generate filtered INDEX-NEW and INDEX-OLD files containing only + # the lines which (a) belong to components we care about, and (b) + # don't correspond to paths we're explicitly ignoring. + fetch_filter_metadata INDEX-NEW || return 1 + fetch_filter_metadata INDEX-OLD || return 1 + + # Translate /boot/${KERNCONF} into ${KERNELDIR} + fetch_filter_kernel_names INDEX-NEW ${KERNCONF} + fetch_filter_kernel_names INDEX-OLD ${KERNCONF} + + # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the + # system and generate an INDEX-PRESENT file. + fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1 + + # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which + # correspond to lines in INDEX-PRESENT with hashes not appearing + # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in + # INDEX-PRESENT has type - and there isn't a corresponding entry in + # INDEX-OLD with type -. + fetch_filter_unmodified_notpresent \ + INDEX-OLD INDEX-PRESENT INDEX-NEW /dev/null + + # For each entry in INDEX-PRESENT of type -, remove any corresponding + # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries + # of type - from INDEX-PRESENT. + fetch_filter_allowadd INDEX-PRESENT INDEX-NEW + + # If ${ALLOWDELETE} != "yes", then remove any entries from + # INDEX-PRESENT which don't correspond to entries in INDEX-NEW. + fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW + + # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in + # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD, + # replace the corresponding line of INDEX-NEW with one having the + # same metadata as the entry in INDEX-PRESENT. + fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW + + # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical; + # no need to update a file if it isn't changing. + fetch_filter_uptodate INDEX-PRESENT INDEX-NEW + + # Prepare to fetch files: Generate a list of the files we need, + # copy the unmodified files we have into /files/, and generate + # a list of patches to download. + fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1 + + # Fetch files. + fetch_files || return 1 + + # Create and populate install manifest directory; and report what + # updates are available. + fetch_create_manifest || return 1 + + # Warn about any upcoming EoL + fetch_warn_eol || return 1 +} + +# If StrictComponents is not "yes", generate a new components list +# with only the components which appear to be installed. +upgrade_guess_components () { + if [ "${STRICTCOMPONENTS}" = "no" ]; then + # Generate filtered INDEX-ALL with only the components listed + # in COMPONENTS. + fetch_filter_metadata_components $1 || return 1 + + # Tell the user why his disk is suddenly making lots of noise + echo -n "Inspecting system... " + + # Look at the files on disk, and assume that a component is + # supposed to be present if it is more than half-present. + cut -f 1-3 -d '|' < INDEX-ALL | + tr '|' ' ' | + while read C S F; do + if [ -e ${BASEDIR}/${F} ]; then + echo "+ ${C}|${S}" + fi + echo "= ${C}|${S}" + done | + sort | + uniq -c | + sed -E 's,^ +,,' > compfreq + grep ' = ' compfreq | + cut -f 1,3 -d ' ' | + sort -k 2,2 -t ' ' > compfreq.total + grep ' + ' compfreq | + cut -f 1,3 -d ' ' | + sort -k 2,2 -t ' ' > compfreq.present + join -t ' ' -1 2 -2 2 compfreq.present compfreq.total | + while read S P T; do + if [ ${T} -ne 0 -a ${P} -gt `expr ${T} / 2` ]; then + echo ${S} + fi + done > comp.present + cut -f 2 -d ' ' < compfreq.total > comp.total + rm INDEX-ALL compfreq compfreq.total compfreq.present + + # We're done making noise. + echo "done." + + # Sometimes the kernel isn't installed where INDEX-ALL + # thinks that it should be: In particular, it is often in + # /boot/kernel instead of /boot/GENERIC or /boot/SMP. To + # deal with this, if "kernel|X" is listed in comp.total + # (i.e., is a component which would be upgraded if it is + # found to be present) we will add it to comp.present. + # If "kernel|" is in comp.total but "kernel|X" is + # not, we print a warning -- the user is running a kernel + # which isn't part of the release. + KCOMP=`echo ${KERNCONF} | tr 'A-Z' 'a-z'` + grep -E "^kernel\|${KCOMP}\$" comp.total >> comp.present + + if grep -qE "^kernel\|" comp.total && + ! grep -qE "^kernel\|${KCOMP}\$" comp.total; then + cat <<-EOF + +WARNING: This system is running a "${KCOMP}" kernel, which is not a +kernel configuration distributed as part of FreeBSD ${RELNUM}. +This kernel will not be updated: you MUST update the kernel manually +before running '`basename $0` [options] install'. + EOF + fi + + # Re-sort the list of installed components and generate + # the list of non-installed components. + sort -u < comp.present > comp.present.tmp + mv comp.present.tmp comp.present + comm -13 comp.present comp.total > comp.absent + + # Ask the user to confirm that what we have is correct. To + # reduce user confusion, translate "X|Y" back to "X/Y" (as + # subcomponents must be listed in the configuration file). + echo + echo -n "The following components of FreeBSD " + echo "seem to be installed:" + tr '|' '/' < comp.present | + fmt -72 + echo + echo -n "The following components of FreeBSD " + echo "do not seem to be installed:" + tr '|' '/' < comp.absent | + fmt -72 + echo + continuep || return 1 + echo + + # Suck the generated list of components into ${COMPONENTS}. + # Note that comp.present.tmp is used due to issues with + # pipelines and setting variables. + COMPONENTS="" + tr '|' '/' < comp.present > comp.present.tmp + while read C; do + COMPONENTS="${COMPONENTS} ${C}" + done < comp.present.tmp + + # Delete temporary files + rm comp.present comp.present.tmp comp.absent comp.total + fi +} + +# If StrictComponents is not "yes", COMPONENTS contains an entry +# corresponding to the currently running kernel, and said kernel +# does not exist in the new release, add "kernel/generic" to the +# list of components. +upgrade_guess_new_kernel () { + if [ "${STRICTCOMPONENTS}" = "no" ]; then + # Grab the unfiltered metadata file. + METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'` + gunzip -c < files/${METAHASH}.gz > $1.all + + # If "kernel/${KCOMP}" is in ${COMPONENTS} and that component + # isn't in $1.all, we need to add kernel/generic. + for C in ${COMPONENTS}; do + if [ ${C} = "kernel/${KCOMP}" ] && + ! grep -qE "^kernel\|${KCOMP}\|" $1.all; then + COMPONENTS="${COMPONENTS} kernel/generic" + NKERNCONF="GENERIC" + cat <<-EOF + +WARNING: This system is running a "${KCOMP}" kernel, which is not a +kernel configuration distributed as part of FreeBSD ${RELNUM}. +As part of upgrading to FreeBSD ${RELNUM}, this kernel will be +replaced with a "generic" kernel. + EOF + continuep || return 1 + fi + done + + # Don't need this any more... + rm $1.all + fi +} + +# Convert INDEX-OLD (last release) and INDEX-ALL (new release) into +# INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades). +upgrade_oldall_to_oldnew () { + # For each ${F}|... which appears in INDEX-ALL but does not appear + # in INDEX-OLD, add ${F}|-|||||| to INDEX-OLD. + cut -f 1 -d '|' < $1 | + sort -u > $1.paths + cut -f 1 -d '|' < $2 | + sort -u | + comm -13 $1.paths - | + lam - -s "|-||||||" | + sort - $1 > $1.tmp + mv $1.tmp $1 + + # Remove lines from INDEX-OLD which also appear in INDEX-ALL + comm -23 $1 $2 > $1.tmp + mv $1.tmp $1 + + # Remove lines from INDEX-ALL which have a file name not appearing + # anywhere in INDEX-OLD (since these must be files which haven't + # changed -- if they were new, there would be an entry of type "-"). + cut -f 1 -d '|' < $1 | + sort -u > $1.paths + sort -k 1,1 -t '|' < $2 | + join -t '|' - $1.paths | + sort > $2.tmp + rm $1.paths + mv $2.tmp $2 + + # Rename INDEX-ALL to INDEX-NEW. + mv $2 $3 +} + +# Helper for upgrade_merge: Return zero true iff the two files differ only +# in the contents of their RCS tags. +samef () { + X=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $1 | ${SHA256}` + Y=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $2 | ${SHA256}` + + if [ $X = $Y ]; then + return 0; + else + return 1; + fi +} + +# From the list of "old" files in $1, merge changes in $2 with those in $3, +# and update $3 to reflect the hashes of merged files. +upgrade_merge () { + # We only need to do anything if $1 is non-empty. + if [ -s $1 ]; then + cut -f 1 -d '|' $1 | + sort > $1-paths + + # Create staging area for merging files + rm -rf merge/ + while read F; do + D=`dirname ${F}` + mkdir -p merge/old/${D} + mkdir -p merge/${OLDRELNUM}/${D} + mkdir -p merge/${RELNUM}/${D} + mkdir -p merge/new/${D} + done < $1-paths + + # Copy in files + while read F; do + # Currently installed file + V=`look "${F}|" $2 | cut -f 7 -d '|'` + gunzip < files/${V}.gz > merge/old/${F} + + # Old release + if look "${F}|" $1 | fgrep -q "|f|"; then + V=`look "${F}|" $1 | cut -f 3 -d '|'` + gunzip < files/${V}.gz \ + > merge/${OLDRELNUM}/${F} + fi + + # New release + if look "${F}|" $3 | cut -f 1,2,7 -d '|' | + fgrep -q "|f|"; then + V=`look "${F}|" $3 | cut -f 7 -d '|'` + gunzip < files/${V}.gz \ + > merge/${RELNUM}/${F} + fi + done < $1-paths + + # Attempt to automatically merge changes + echo -n "Attempting to automatically merge " + echo -n "changes in files..." + : > failed.merges + while read F; do + # If the file doesn't exist in the new release, + # the result of "merging changes" is having the file + # not exist. + if ! [ -f merge/${RELNUM}/${F} ]; then + continue + fi + + # If the file didn't exist in the old release, we're + # going to throw away the existing file and hope that + # the version from the new release is what we want. + if ! [ -f merge/${OLDRELNUM}/${F} ]; then + cp merge/${RELNUM}/${F} merge/new/${F} + continue + fi + + # Some files need special treatment. + case ${F} in + /etc/spwd.db | /etc/pwd.db | /etc/login.conf.db) + # Don't merge these -- we're rebuild them + # after updates are installed. + cp merge/old/${F} merge/new/${F} + ;; + *) + if ! diff3 -E -m -L "current version" \ + -L "${OLDRELNUM}" -L "${RELNUM}" \ + merge/old/${F} \ + merge/${OLDRELNUM}/${F} \ + merge/${RELNUM}/${F} \ + > merge/new/${F} 2>/dev/null; then + echo ${F} >> failed.merges + fi + ;; + esac + done < $1-paths + echo " done." + + # Ask the user to handle any files which didn't merge. + while read F; do + # If the installed file differs from the version in + # the old release only due to RCS tag expansion + # then just use the version in the new release. + if samef merge/old/${F} merge/${OLDRELNUM}/${F}; then + cp merge/${RELNUM}/${F} merge/new/${F} + continue + fi + + cat <<-EOF + +The following file could not be merged automatically: ${F} +Press Enter to edit this file in ${EDITOR} and resolve the conflicts +manually... + EOF + while true; do + read response /dev/null; then + echo + break + fi + ${EDITOR} `pwd`/merge/new/${F} < /dev/tty + + if ! grep -qE '^(<<<<<<<|=======|>>>>>>>)([[:space:]].*)?$' $(pwd)/merge/new/${F} ; then + break + fi + cat <<-EOF + +Merge conflict markers remain in: ${F} +These must be resolved for the system to be functional. + +Press Enter to return to editing this file, or type "ACCEPT" to carry on with +these lines remaining in the file. + EOF + done + done < failed.merges + rm failed.merges + + # Ask the user to confirm that he likes how the result + # of merging files. + while read F; do + # Skip files which haven't changed except possibly + # in their RCS tags. + if [ -f merge/old/${F} ] && [ -f merge/new/${F} ] && + samef merge/old/${F} merge/new/${F}; then + continue + fi + + # Skip files where the installed file differs from + # the old file only due to RCS tags. + if [ -f merge/old/${F} ] && + [ -f merge/${OLDRELNUM}/${F} ] && + samef merge/old/${F} merge/${OLDRELNUM}/${F}; then + continue + fi + + # Warn about files which are ceasing to exist. + if ! [ -f merge/new/${F} ]; then + cat <<-EOF + +The following file will be removed, as it no longer exists in +FreeBSD ${RELNUM}: ${F} + EOF + continuep < /dev/tty || return 1 + continue + fi + + # Print changes for the user's approval. + cat <<-EOF + +The following changes, which occurred between FreeBSD ${OLDRELNUM} and +FreeBSD ${RELNUM} have been merged into ${F}: +EOF + diff -U 5 -L "current version" -L "new version" \ + merge/old/${F} merge/new/${F} || true + continuep < /dev/tty || return 1 + done < $1-paths + + # Store merged files. + while read F; do + if [ -f merge/new/${F} ]; then + V=`${SHA256} -q merge/new/${F}` + + gzip -c < merge/new/${F} > files/${V}.gz + echo "${F}|${V}" + fi + done < $1-paths > newhashes + + # Pull lines out from $3 which need to be updated to + # reflect merged files. + while read F; do + look "${F}|" $3 + done < $1-paths > $3-oldlines + + # Update lines to reflect merged files + join -t '|' -o 1.1,1.2,1.3,1.4,1.5,1.6,2.2,1.8 \ + $3-oldlines newhashes > $3-newlines + + # Remove old lines from $3 and add new lines. + sort $3-oldlines | + comm -13 - $3 | + sort - $3-newlines > $3.tmp + mv $3.tmp $3 + + # Clean up + rm $1-paths newhashes $3-oldlines $3-newlines + rm -rf merge/ + fi + + # We're done with merging files. + rm $1 +} + +# Do the work involved in fetching upgrades to a new release +upgrade_run () { + workdir_init || return 1 + + # Prepare the mirror list. + fetch_pick_server_init && fetch_pick_server + + # Try to fetch the public key until we run out of servers. + while ! fetch_key; do + fetch_pick_server || return 1 + done + + # Try to fetch the metadata index signature ("tag") until we run + # out of available servers; and sanity check the downloaded tag. + while ! fetch_tag; do + fetch_pick_server || return 1 + done + fetch_tagsanity || return 1 + + # Fetch the INDEX-OLD and INDEX-ALL. + fetch_metadata INDEX-OLD INDEX-ALL || return 1 + + # If StrictComponents is not "yes", generate a new components list + # with only the components which appear to be installed. + upgrade_guess_components INDEX-ALL || return 1 + + # Generate filtered INDEX-OLD and INDEX-ALL files containing only + # the components we want and without anything marked as "Ignore". + fetch_filter_metadata INDEX-OLD || return 1 + fetch_filter_metadata INDEX-ALL || return 1 + + # Merge the INDEX-OLD and INDEX-ALL files into INDEX-OLD. + sort INDEX-OLD INDEX-ALL > INDEX-OLD.tmp + mv INDEX-OLD.tmp INDEX-OLD + rm INDEX-ALL + + # Adjust variables for fetching files from the new release. + OLDRELNUM=${RELNUM} + RELNUM=${TARGETRELEASE} + OLDFETCHDIR=${FETCHDIR} + FETCHDIR=${RELNUM}/${ARCH} + + # Try to fetch the NEW metadata index signature ("tag") until we run + # out of available servers; and sanity check the downloaded tag. + while ! fetch_tag; do + fetch_pick_server || return 1 + done + + # Fetch the new INDEX-ALL. + fetch_metadata INDEX-ALL || return 1 + + # If StrictComponents is not "yes", COMPONENTS contains an entry + # corresponding to the currently running kernel, and said kernel + # does not exist in the new release, add "kernel/generic" to the + # list of components. + upgrade_guess_new_kernel INDEX-ALL || return 1 + + # Filter INDEX-ALL to contain only the components we want and without + # anything marked as "Ignore". + fetch_filter_metadata INDEX-ALL || return 1 + + # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into + # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades). + upgrade_oldall_to_oldnew INDEX-OLD INDEX-ALL INDEX-NEW + + # Translate /boot/${KERNCONF} or /boot/${NKERNCONF} into ${KERNELDIR} + fetch_filter_kernel_names INDEX-NEW ${NKERNCONF} + fetch_filter_kernel_names INDEX-OLD ${KERNCONF} + + # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the + # system and generate an INDEX-PRESENT file. + fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1 + + # Based on ${MERGECHANGES}, generate a file tomerge-old with the + # paths and hashes of old versions of files to merge. + fetch_filter_mergechanges INDEX-OLD INDEX-PRESENT INDEX-NEW tomerge-old + + # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which + # correspond to lines in INDEX-PRESENT with hashes not appearing + # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in + # INDEX-PRESENT has type - and there isn't a corresponding entry in + # INDEX-OLD with type -. + fetch_filter_unmodified_notpresent \ + INDEX-OLD INDEX-PRESENT INDEX-NEW tomerge-old + + # For each entry in INDEX-PRESENT of type -, remove any corresponding + # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries + # of type - from INDEX-PRESENT. + fetch_filter_allowadd INDEX-PRESENT INDEX-NEW + + # If ${ALLOWDELETE} != "yes", then remove any entries from + # INDEX-PRESENT which don't correspond to entries in INDEX-NEW. + fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW + + # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in + # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD, + # replace the corresponding line of INDEX-NEW with one having the + # same metadata as the entry in INDEX-PRESENT. + fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW + + # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical; + # no need to update a file if it isn't changing. + fetch_filter_uptodate INDEX-PRESENT INDEX-NEW + + # Fetch "clean" files from the old release for merging changes. + fetch_files_premerge tomerge-old + + # Prepare to fetch files: Generate a list of the files we need, + # copy the unmodified files we have into /files/, and generate + # a list of patches to download. + fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1 + + # Fetch patches from to-${RELNUM}/${ARCH}/bp/ + PATCHDIR=to-${RELNUM}/${ARCH}/bp + fetch_files || return 1 + + # Merge configuration file changes. + upgrade_merge tomerge-old INDEX-PRESENT INDEX-NEW || return 1 + + # Create and populate install manifest directory; and report what + # updates are available. + fetch_create_manifest || return 1 + + # Leave a note behind to tell the "install" command that the kernel + # needs to be installed before the world. + touch ${BDHASH}-install/kernelfirst + + # Remind the user that they need to run "freebsd-update install" + # to install the downloaded bits, in case they didn't RTFM. + echo "To install the downloaded upgrades, run '`basename $0` [options] install'." +} + +# Make sure that all the file hashes mentioned in $@ have corresponding +# gzipped files stored in /files/. +install_verify () { + # Generate a list of hashes + cat $@ | + cut -f 2,7 -d '|' | + grep -E '^f' | + cut -f 2 -d '|' | + sort -u > filelist + + # Make sure all the hashes exist + while read HASH; do + if ! [ -f files/${HASH}.gz ]; then + echo -n "Update files missing -- " + echo "this should never happen." + echo "Re-run '`basename $0` [options] fetch'." + return 1 + fi + done < filelist + + # Clean up + rm filelist +} + +# Remove the system immutable flag from files +install_unschg () { + # Generate file list + cat $@ | + cut -f 1 -d '|' > filelist + + # Remove flags + while read F; do + if ! [ -e ${BASEDIR}/${F} ]; then + continue + else + echo ${BASEDIR}/${F} + fi + done < filelist | xargs chflags noschg || return 1 + + # Clean up + rm filelist +} + +# Decide which directory name to use for kernel backups. +backup_kernel_finddir () { + CNT=0 + while true ; do + # Pathname does not exist, so it is OK use that name + # for backup directory. + if [ ! -e $BASEDIR/$BACKUPKERNELDIR ]; then + return 0 + fi + + # If directory do exist, we only use if it has our + # marker file. + if [ -d $BASEDIR/$BACKUPKERNELDIR -a \ + -e $BASEDIR/$BACKUPKERNELDIR/.freebsd-update ]; then + return 0 + fi + + # We could not use current directory name, so add counter to + # the end and try again. + CNT=$((CNT + 1)) + if [ $CNT -gt 9 ]; then + echo "Could not find valid backup dir ($BASEDIR/$BACKUPKERNELDIR)" + exit 1 + fi + BACKUPKERNELDIR="`echo $BACKUPKERNELDIR | sed -Ee 's/[0-9]\$//'`" + BACKUPKERNELDIR="${BACKUPKERNELDIR}${CNT}" + done +} + +# Backup the current kernel using hardlinks, if not disabled by user. +# Since we delete all files in the directory used for previous backups +# we create a marker file called ".freebsd-update" in the directory so +# we can determine on the next run that the directory was created by +# freebsd-update and we then do not accidentally remove user files in +# the unlikely case that the user has created a directory with a +# conflicting name. +backup_kernel () { + # Only make kernel backup is so configured. + if [ $BACKUPKERNEL != yes ]; then + return 0 + fi + + # Decide which directory name to use for kernel backups. + backup_kernel_finddir + + # Remove old kernel backup files. If $BACKUPKERNELDIR was + # "not ours", backup_kernel_finddir would have exited, so + # deleting the directory content is as safe as we can make it. + if [ -d $BASEDIR/$BACKUPKERNELDIR ]; then + rm -fr $BASEDIR/$BACKUPKERNELDIR + fi + + # Create directories for backup. + mkdir -p $BASEDIR/$BACKUPKERNELDIR + mtree -cdn -p "${BASEDIR}/${KERNELDIR}" | \ + mtree -Ue -p "${BASEDIR}/${BACKUPKERNELDIR}" > /dev/null + + # Mark the directory as having been created by freebsd-update. + touch $BASEDIR/$BACKUPKERNELDIR/.freebsd-update + if [ $? -ne 0 ]; then + echo "Could not create kernel backup directory" + exit 1 + fi + + # Disable pathname expansion to be sure *.symbols is not + # expanded. + set -f + + # Use find to ignore symbol files, unless disabled by user. + if [ $BACKUPKERNELSYMBOLFILES = yes ]; then + FINDFILTER="" + else + FINDFILTER="-a ! -name *.debug -a ! -name *.symbols" + fi + + # Backup all the kernel files using hardlinks. + (cd ${BASEDIR}/${KERNELDIR} && find . -type f $FINDFILTER -exec \ + cp -pl '{}' ${BASEDIR}/${BACKUPKERNELDIR}/'{}' \;) + + # Re-enable pathname expansion. + set +f +} + +# Check for and remove an existing directory that conflicts with the file or +# symlink that we are going to install. +dir_conflict () { + if [ -d "$1" ]; then + echo "Removing conflicting directory $1" + rm -rf -- "$1" + fi +} + +# Install new files +install_from_index () { + # First pass: Do everything apart from setting file flags. We + # can't set flags yet, because schg inhibits hard linking. + sort -k 1,1 -t '|' $1 | + tr '|' ' ' | + while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do + case ${TYPE} in + d) + # Create a directory. A file may change to a directory + # on upgrade (PR273661). If that happens, remove the + # file first. + if [ -e "${BASEDIR}/${FPATH}" ] && \ + ! [ -d "${BASEDIR}/${FPATH}" ]; then + rm -f -- "${BASEDIR}/${FPATH}" + fi + install -d -o ${OWNER} -g ${GROUP} \ + -m ${PERM} ${BASEDIR}/${FPATH} + ;; + f) + dir_conflict "${BASEDIR}/${FPATH}" + if [ -z "${LINK}" ]; then + # Create a file, without setting flags. + gunzip < files/${HASH}.gz > ${HASH} + install -S -o ${OWNER} -g ${GROUP} \ + -m ${PERM} ${HASH} ${BASEDIR}/${FPATH} + rm ${HASH} + else + # Create a hard link. + ln -f ${BASEDIR}/${LINK} ${BASEDIR}/${FPATH} + fi + ;; + L) + dir_conflict "${BASEDIR}/${FPATH}" + # Create a symlink + ln -sfh ${HASH} ${BASEDIR}/${FPATH} + ;; + esac + done + + # Perform a second pass, adding file flags. + tr '|' ' ' < $1 | + while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do + if [ ${TYPE} = "f" ] && + ! [ ${FLAGS} = "0" ]; then + chflags ${FLAGS} ${BASEDIR}/${FPATH} + fi + done +} + +# Remove files which we want to delete +install_delete () { + # Generate list of new files + cut -f 1 -d '|' < $2 | + sort > newfiles + + # Generate subindex of old files we want to nuke + sort -k 1,1 -t '|' $1 | + join -t '|' -v 1 - newfiles | + sort -r -k 1,1 -t '|' | + cut -f 1,2 -d '|' | + tr '|' ' ' > killfiles + + # Remove the offending bits + while read FPATH TYPE; do + case ${TYPE} in + d) + rmdir ${BASEDIR}/${FPATH} + ;; + f) + if [ -f "${BASEDIR}/${FPATH}" ]; then + rm "${BASEDIR}/${FPATH}" + fi + ;; + L) + if [ -L "${BASEDIR}/${FPATH}" ]; then + rm "${BASEDIR}/${FPATH}" + fi + ;; + esac + done < killfiles + + # Clean up + rm newfiles killfiles +} + +# Install new files, delete old files, and update generated files +install_files () { + # If we haven't already dealt with the kernel, deal with it. + if ! [ -f $1/kerneldone ]; then + grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD + grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW + + # Backup current kernel before installing a new one + backup_kernel || return 1 + + # Install new files + install_from_index INDEX-NEW || return 1 + + # Remove files which need to be deleted + install_delete INDEX-OLD INDEX-NEW || return 1 + + # Update linker.hints if necessary + if [ -s INDEX-OLD -o -s INDEX-NEW ]; then + kldxref -R ${BASEDIR}/boot/ 2>/dev/null + fi + + # We've finished updating the kernel. + touch $1/kerneldone + + # Do we need to ask for a reboot now? + if [ -f $1/kernelfirst ] && + [ -s INDEX-OLD -o -s INDEX-NEW ]; then + cat <<-EOF + +Kernel updates have been installed. Please reboot and run +'`basename $0` [options] install' again to finish installing updates. + EOF + exit 0 + fi + fi + + # If we haven't already dealt with the world, deal with it. + if ! [ -f $1/worlddone ]; then + # Create any necessary directories first + grep -vE '^/boot/' $1/INDEX-NEW | + grep -E '^[^|]+\|d\|' > INDEX-NEW + install_from_index INDEX-NEW || return 1 + + # Install new runtime linker + grep -vE '^/boot/' $1/INDEX-NEW | + grep -vE '^[^|]+\|d\|' | + grep -E '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' > INDEX-NEW + install_from_index INDEX-NEW || return 1 + + # Install new shared libraries next + grep -vE '^/boot/' $1/INDEX-NEW | + grep -vE '^[^|]+\|d\|' | + grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' | + grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW + install_from_index INDEX-NEW || return 1 + + # Deal with everything else + grep -vE '^/boot/' $1/INDEX-OLD | + grep -vE '^[^|]+\|d\|' | + grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' | + grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD + grep -vE '^/boot/' $1/INDEX-NEW | + grep -vE '^[^|]+\|d\|' | + grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' | + grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW + install_from_index INDEX-NEW || return 1 + install_delete INDEX-OLD INDEX-NEW || return 1 + + # Restart host sshd if running (PR263489). Note that this does + # not affect child sshd processes handling existing sessions. + if [ "$BASEDIR" = / ] && \ + service sshd status >/dev/null 2>/dev/null; then + echo + echo "Restarting sshd after upgrade" + service sshd restart + fi + + # Rehash certs if we actually have certctl installed. + if which certctl>/dev/null; then + env DESTDIR=${BASEDIR} certctl rehash + fi + + # Rebuild generated pwd files and /etc/login.conf.db. + pwd_mkdb -d ${BASEDIR}/etc -p ${BASEDIR}/etc/master.passwd + cap_mkdb ${BASEDIR}/etc/login.conf + + # Rebuild man page databases, if necessary. + for D in /usr/share/man /usr/share/openssl/man; do + if [ ! -d ${BASEDIR}/$D ]; then + continue + fi + if [ -f ${BASEDIR}/$D/mandoc.db ] && \ + [ -z "$(find ${BASEDIR}/$D -type f -newer ${BASEDIR}/$D/mandoc.db)" ]; then + continue; + fi + makewhatis ${BASEDIR}/$D + done + + # We've finished installing the world and deleting old files + # which are not shared libraries. + touch $1/worlddone + + # Do we need to ask the user to portupgrade now? + grep -vE '^/boot/' $1/INDEX-NEW | + grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' | + cut -f 1 -d '|' | + sort > newfiles + if grep -vE '^/boot/' $1/INDEX-OLD | + grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' | + cut -f 1 -d '|' | + sort | + join -v 1 - newfiles | + grep -q .; then + cat <<-EOF + +Completing this upgrade requires removing old shared object files. +Please rebuild all installed 3rd party software (e.g., programs +installed from the ports tree) and then run +'`basename $0` [options] install' again to finish installing updates. + EOF + rm newfiles + exit 0 + fi + rm newfiles + fi + + # Remove old shared libraries + grep -vE '^/boot/' $1/INDEX-NEW | + grep -vE '^[^|]+\|d\|' | + grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW + grep -vE '^/boot/' $1/INDEX-OLD | + grep -vE '^[^|]+\|d\|' | + grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD + install_delete INDEX-OLD INDEX-NEW || return 1 + + # Remove old directories + grep -vE '^/boot/' $1/INDEX-NEW | + grep -E '^[^|]+\|d\|' > INDEX-NEW + grep -vE '^/boot/' $1/INDEX-OLD | + grep -E '^[^|]+\|d\|' > INDEX-OLD + install_delete INDEX-OLD INDEX-NEW || return 1 + + # Remove temporary files + rm INDEX-OLD INDEX-NEW +} + +# Rearrange bits to allow the installed updates to be rolled back +install_setup_rollback () { + # Remove the "reboot after installing kernel", "kernel updated", and + # "finished installing the world" flags if present -- they are + # irrelevant when rolling back updates. + if [ -f ${BDHASH}-install/kernelfirst ]; then + rm ${BDHASH}-install/kernelfirst + rm ${BDHASH}-install/kerneldone + fi + if [ -f ${BDHASH}-install/worlddone ]; then + rm ${BDHASH}-install/worlddone + fi + + if [ -L ${BDHASH}-rollback ]; then + mv ${BDHASH}-rollback ${BDHASH}-install/rollback + fi + + mv ${BDHASH}-install ${BDHASH}-rollback +} + +# Actually install updates +install_run () { + echo -n "Installing updates..." + + # Make sure we have all the files we should have + install_verify ${BDHASH}-install/INDEX-OLD \ + ${BDHASH}-install/INDEX-NEW || return 1 + + # Remove system immutable flag from files + install_unschg ${BDHASH}-install/INDEX-OLD \ + ${BDHASH}-install/INDEX-NEW || return 1 + + # Install new files, delete old files, and update linker.hints + install_files ${BDHASH}-install || return 1 + + # Rearrange bits to allow the installed updates to be rolled back + install_setup_rollback + + echo " done." +} + +# Rearrange bits to allow the previous set of updates to be rolled back next. +rollback_setup_rollback () { + if [ -L ${BDHASH}-rollback/rollback ]; then + mv ${BDHASH}-rollback/rollback rollback-tmp + rm -r ${BDHASH}-rollback/ + rm ${BDHASH}-rollback + mv rollback-tmp ${BDHASH}-rollback + else + rm -r ${BDHASH}-rollback/ + rm ${BDHASH}-rollback + fi +} + +# Install old files, delete new files, and update linker.hints +rollback_files () { + # Create directories first. They may be needed by files we will + # install in subsequent steps (PR273950). + awk -F \| '{if ($2 == "d") print }' $1/INDEX-OLD > INDEX-OLD + install_from_index INDEX-OLD || return 1 + + # Install old shared library files which don't have the same path as + # a new shared library file. + grep -vE '^/boot/' $1/INDEX-NEW | + grep -E '/lib/.*\.so\.[0-9]+\|' | + cut -f 1 -d '|' | + sort > INDEX-NEW.libs.flist + grep -vE '^/boot/' $1/INDEX-OLD | + grep -E '/lib/.*\.so\.[0-9]+\|' | + sort -k 1,1 -t '|' - | + join -t '|' -v 1 - INDEX-NEW.libs.flist > INDEX-OLD + install_from_index INDEX-OLD || return 1 + + # Deal with files which are neither kernel nor shared library + grep -vE '^/boot/' $1/INDEX-OLD | + grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD + grep -vE '^/boot/' $1/INDEX-NEW | + grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW + install_from_index INDEX-OLD || return 1 + install_delete INDEX-NEW INDEX-OLD || return 1 + + # Install any old shared library files which we didn't install above. + grep -vE '^/boot/' $1/INDEX-OLD | + grep -E '/lib/.*\.so\.[0-9]+\|' | + sort -k 1,1 -t '|' - | + join -t '|' - INDEX-NEW.libs.flist > INDEX-OLD + install_from_index INDEX-OLD || return 1 + + # Delete unneeded shared library files + grep -vE '^/boot/' $1/INDEX-OLD | + grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD + grep -vE '^/boot/' $1/INDEX-NEW | + grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW + install_delete INDEX-NEW INDEX-OLD || return 1 + + # Deal with kernel files + grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD + grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW + install_from_index INDEX-OLD || return 1 + install_delete INDEX-NEW INDEX-OLD || return 1 + if [ -s INDEX-OLD -o -s INDEX-NEW ]; then + kldxref -R /boot/ 2>/dev/null + fi + + # Remove temporary files + rm INDEX-OLD INDEX-NEW INDEX-NEW.libs.flist +} + +# Actually rollback updates +rollback_run () { + echo -n "Uninstalling updates..." + + # If there are updates waiting to be installed, remove them; we + # want the user to re-run 'fetch' after rolling back updates. + if [ -L ${BDHASH}-install ]; then + rm -r ${BDHASH}-install/ + rm ${BDHASH}-install + fi + + # Make sure we have all the files we should have + install_verify ${BDHASH}-rollback/INDEX-NEW \ + ${BDHASH}-rollback/INDEX-OLD || return 1 + + # Remove system immutable flag from files + install_unschg ${BDHASH}-rollback/INDEX-NEW \ + ${BDHASH}-rollback/INDEX-OLD || return 1 + + # Install old files, delete new files, and update linker.hints + rollback_files ${BDHASH}-rollback || return 1 + + # Remove the rollback directory and the symlink pointing to it; and + # rearrange bits to allow the previous set of updates to be rolled + # back next. + rollback_setup_rollback + + echo " done." +} + +# Compare INDEX-ALL and INDEX-PRESENT and print warnings about differences. +IDS_compare () { + # Get all the lines which mismatch in something other than file + # flags. We ignore file flags because sysinstall doesn't seem to + # set them when it installs FreeBSD; warning about these adds a + # very large amount of noise. + cut -f 1-5,7-8 -d '|' $1 > $1.noflags + sort -k 1,1 -t '|' $1.noflags > $1.sorted + cut -f 1-5,7-8 -d '|' $2 | + comm -13 $1.noflags - | + fgrep -v '|-|||||' | + sort -k 1,1 -t '|' | + join -t '|' $1.sorted - > INDEX-NOTMATCHING + + # Ignore files which match IDSIGNOREPATHS. + for X in ${IDSIGNOREPATHS}; do + grep -E "^${X}" INDEX-NOTMATCHING + done | + sort -u | + comm -13 - INDEX-NOTMATCHING > INDEX-NOTMATCHING.tmp + mv INDEX-NOTMATCHING.tmp INDEX-NOTMATCHING + + # Go through the lines and print warnings. + local IFS='|' + while read FPATH TYPE OWNER GROUP PERM HASH LINK P_TYPE P_OWNER P_GROUP P_PERM P_HASH P_LINK; do + # Warn about different object types. + if ! [ "${TYPE}" = "${P_TYPE}" ]; then + echo -n "${FPATH} is a " + case "${P_TYPE}" in + f) echo -n "regular file, " + ;; + d) echo -n "directory, " + ;; + L) echo -n "symlink, " + ;; + esac + echo -n "but should be a " + case "${TYPE}" in + f) echo -n "regular file." + ;; + d) echo -n "directory." + ;; + L) echo -n "symlink." + ;; + esac + echo + + # Skip other tests, since they don't make sense if + # we're comparing different object types. + continue + fi + + # Warn about different owners. + if ! [ "${OWNER}" = "${P_OWNER}" ]; then + echo -n "${FPATH} is owned by user id ${P_OWNER}, " + echo "but should be owned by user id ${OWNER}." + fi + + # Warn about different groups. + if ! [ "${GROUP}" = "${P_GROUP}" ]; then + echo -n "${FPATH} is owned by group id ${P_GROUP}, " + echo "but should be owned by group id ${GROUP}." + fi + + # Warn about different permissions. We do not warn about + # different permissions on symlinks, since some archivers + # don't extract symlink permissions correctly and they are + # ignored anyway. + if ! [ "${PERM}" = "${P_PERM}" ] && + ! [ "${TYPE}" = "L" ]; then + echo -n "${FPATH} has ${P_PERM} permissions, " + echo "but should have ${PERM} permissions." + fi + + # Warn about different file hashes / symlink destinations. + if ! [ "${HASH}" = "${P_HASH}" ]; then + if [ "${TYPE}" = "L" ]; then + echo -n "${FPATH} is a symlink to ${P_HASH}, " + echo "but should be a symlink to ${HASH}." + fi + if [ "${TYPE}" = "f" ]; then + echo -n "${FPATH} has SHA256 hash ${P_HASH}, " + echo "but should have SHA256 hash ${HASH}." + fi + fi + + # We don't warn about different hard links, since some + # some archivers break hard links, and as long as the + # underlying data is correct they really don't matter. + done < INDEX-NOTMATCHING + + # Clean up + rm $1 $1.noflags $1.sorted $2 INDEX-NOTMATCHING +} + +# Do the work involved in comparing the system to a "known good" index +IDS_run () { + workdir_init || return 1 + + # Prepare the mirror list. + fetch_pick_server_init && fetch_pick_server + + # Try to fetch the public key until we run out of servers. + while ! fetch_key; do + fetch_pick_server || return 1 + done + + # Try to fetch the metadata index signature ("tag") until we run + # out of available servers; and sanity check the downloaded tag. + while ! fetch_tag; do + fetch_pick_server || return 1 + done + fetch_tagsanity || return 1 + + # Fetch INDEX-OLD and INDEX-ALL. + fetch_metadata INDEX-OLD INDEX-ALL || return 1 + + # Generate filtered INDEX-OLD and INDEX-ALL files containing only + # the components we want and without anything marked as "Ignore". + fetch_filter_metadata INDEX-OLD || return 1 + fetch_filter_metadata INDEX-ALL || return 1 + + # Merge the INDEX-OLD and INDEX-ALL files into INDEX-ALL. + sort INDEX-OLD INDEX-ALL > INDEX-ALL.tmp + mv INDEX-ALL.tmp INDEX-ALL + rm INDEX-OLD + + # Translate /boot/${KERNCONF} to ${KERNELDIR} + fetch_filter_kernel_names INDEX-ALL ${KERNCONF} + + # Inspect the system and generate an INDEX-PRESENT file. + fetch_inspect_system INDEX-ALL INDEX-PRESENT /dev/null || return 1 + + # Compare INDEX-ALL and INDEX-PRESENT and print warnings about any + # differences. + IDS_compare INDEX-ALL INDEX-PRESENT +} + +#### Main functions -- call parameter-handling and core functions + +# Using the command line, configuration file, and defaults, +# set all the parameters which are needed later. +get_params () { + init_params + parse_cmdline $@ + parse_conffile + default_params +} + +# Fetch command. Make sure that we're being called +# interactively, then run fetch_check_params and fetch_run +cmd_fetch () { + finalize_components_config ${COMPONENTS} + if [ ! -t 0 -a $NOTTYOK -eq 0 ]; then + echo -n "`basename $0` fetch should not " + echo "be run non-interactively." + echo "Run `basename $0` cron instead." + exit 1 + fi + fetch_check_params + fetch_run || exit 1 + ISFETCHED=1 +} + +# Cron command. Make sure the parameters are sensible; wait +# rand(3600) seconds; then fetch updates. While fetching updates, +# send output to a temporary file; only print that file if the +# fetching failed. +cmd_cron () { + fetch_check_params + sleep `jot -r 1 0 3600` + + TMPFILE=`mktemp /tmp/freebsd-update.XXXXXX` || exit 1 + finalize_components_config ${COMPONENTS} >> ${TMPFILE} + if ! fetch_run >> ${TMPFILE} || + ! grep -q "No updates needed" ${TMPFILE} || + [ ${VERBOSELEVEL} = "debug" ]; then + mail -s "`hostname` security updates" ${MAILTO} < ${TMPFILE} + fi + ISFETCHED=1 + + rm ${TMPFILE} +} + +# Fetch files for upgrading to a new release. +cmd_upgrade () { + finalize_components_config ${COMPONENTS} + upgrade_check_params + upgrade_run || exit 1 +} + +# Check if there are fetched updates ready to install. +# Chdir into the working directory. +cmd_updatesready () { + finalize_components_config ${COMPONENTS} + # Check if working directory exists (if not, no updates pending) + if ! [ -e "${WORKDIR}" ]; then + echo "No updates are available to install." + exit 2 + fi + + # Change into working directory (fail if no permission/directory etc.) + cd ${WORKDIR} || exit 1 + + # Construct a unique name from ${BASEDIR} + BDHASH=`echo ${BASEDIR} | sha256 -q` + + # Check that we have updates ready to install + if ! [ -L ${BDHASH}-install ]; then + echo "No updates are available to install." + exit 2 + fi + + echo "There are updates available to install." + echo "Run '`basename $0` [options] install' to proceed." +} + +# Install downloaded updates. +cmd_install () { + finalize_components_config ${COMPONENTS} + install_check_params + install_create_be + install_run || exit 1 +} + +# Rollback most recently installed updates. +cmd_rollback () { + finalize_components_config ${COMPONENTS} + rollback_check_params + rollback_run || exit 1 +} + +# Compare system against a "known good" index. +cmd_IDS () { + finalize_components_config ${COMPONENTS} + IDS_check_params + IDS_run || exit 1 +} + +# Output configuration. +cmd_showconfig () { + finalize_components_config ${COMPONENTS} + for X in ${CONFIGOPTIONS}; do + echo $X=$(eval echo \$${X}) + done +} + +#### Entry point + +# Make sure we find utilities from the base system +export PATH=/sbin:/bin:/usr/sbin:/usr/bin:${PATH} + +# Set a pager if the user doesn't +if [ -z "$PAGER" ]; then + PAGER=/usr/bin/less +fi + +# Set LC_ALL in order to avoid problems with character ranges like [A-Z]. +export LC_ALL=C + +# Clear environment variables that may affect operation of tools that we use. +unset GREP_OPTIONS + +get_params $@ +for COMMAND in ${COMMANDS}; do + cmd_${COMMAND} +done diff --git a/conf/system/freebsd-update/14.2/freebsd-update.conf b/conf/system/freebsd-update/14.2/freebsd-update.conf new file mode 100644 index 0000000..08cf512 --- /dev/null +++ b/conf/system/freebsd-update/14.2/freebsd-update.conf @@ -0,0 +1,78 @@ + +# Trusted keyprint. Changing this is a Bad Idea unless you've received +# a PGP-signed email from telling you to +# change it and explaining why. +KeyPrint 800651ef4b4c71c27e60786d7b487188970f4b4169cc055784e21eb71d410cc5 + +# Server or server pool from which to fetch updates. You can change +# this to point at a specific server if you want, but in most cases +# using a "nearby" server won't provide a measurable improvement in +# performance. +ServerName update.FreeBSD.org + +# Components of the base system which should be kept updated. +Components src world kernel + +# Example for updating the userland and the kernel source code only: +# Components src/base src/sys world + +# Paths which start with anything matching an entry in an IgnorePaths +# statement will be ignored. +IgnorePaths + +# Paths which start with anything matching an entry in an IDSIgnorePaths +# statement will be ignored by "freebsd-update IDS". +IDSIgnorePaths /usr/share/man/cat +IDSIgnorePaths /usr/share/man/whatis +IDSIgnorePaths /var/db/locate.database +IDSIgnorePaths /var/log + +# Paths which start with anything matching an entry in an UpdateIfUnmodified +# statement will only be updated if the contents of the file have not been +# modified by the user (unless changes are merged; see below). +UpdateIfUnmodified /etc/ /var/ /root/ /.cshrc /.profile + +# When upgrading to a new FreeBSD release, files which match MergeChanges +# will have any local changes merged into the version from the new release. +MergeChanges /etc/ /boot/device.hints + +### Default configuration options: + +# Directory in which to store downloaded updates and temporary +# files used by FreeBSD Update. +# WorkDir /var/db/freebsd-update + +# Destination to send output of "freebsd-update cron" if an error +# occurs or updates have been downloaded. +# MailTo root + +# Is FreeBSD Update allowed to create new files? +# AllowAdd yes + +# Is FreeBSD Update allowed to delete files? +# AllowDelete yes + +# If the user has modified file ownership, permissions, or flags, should +# FreeBSD Update retain this modified metadata when installing a new version +# of that file? +# KeepModifiedMetadata yes + +# When upgrading between releases, should the list of Components be +# read strictly (StrictComponents yes) or merely as a list of components +# which *might* be installed of which FreeBSD Update should figure out +# which actually are installed and upgrade those (StrictComponents no)? +# StrictComponents no + +# When installing a new kernel perform a backup of the old one first +# so it is possible to boot the old kernel in case of problems. +# BackupKernel yes + +# If BackupKernel is enabled, the backup kernel is saved to this +# directory. +# BackupKernelDir /boot/kernel.old + +# When backing up a kernel also back up debug symbol files? +# BackupKernelSymbolFiles no + +# Create a new boot environment when installing patches +# CreateBootEnv yes diff --git a/conf/system/freebsd-update/14.3/freebsd-update b/conf/system/freebsd-update/14.3/freebsd-update new file mode 100755 index 0000000..cf314a2 --- /dev/null +++ b/conf/system/freebsd-update/14.3/freebsd-update @@ -0,0 +1,3588 @@ +#!/bin/sh + +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright 2004-2007 Colin Percival +# All rights reserved +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted providing that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +#### Usage function -- called from command-line handling code. + +# Usage instructions. Options not listed: +# --debug -- don't filter output from utilities +# --no-stats -- don't show progress statistics while fetching files +usage () { + cat < ${LINE}" + exit 1 + fi + done < ${CONFFILE} + + # Merge the settings read from the configuration file with those + # provided at the command line. + mergeconfig +} + +# Provide some default parameters +default_params () { + # Save any parameters already configured, and clear the slate + saveconfig + nullconfig + + # Default configurations + config_WorkDir /var/db/freebsd-update + config_MailTo root + config_AllowAdd yes + config_AllowDelete yes + config_KeepModifiedMetadata yes + config_BaseDir / + config_VerboseLevel stats + config_StrictComponents no + config_BackupKernel yes + config_BackupKernelDir /boot/kernel.old + config_BackupKernelSymbolFiles no + config_CreateBootEnv yes + + # Merge these defaults into the earlier-configured settings + mergeconfig +} + +# Set utility output filtering options, based on ${VERBOSELEVEL} +fetch_setup_verboselevel () { + case ${VERBOSELEVEL} in + debug) + QUIETREDIR="/dev/stderr" + QUIETFLAG=" " + STATSREDIR="/dev/stderr" + DDSTATS=".." + XARGST="-t" + NDEBUG=" " + ;; + nostats) + QUIETREDIR="" + QUIETFLAG="" + STATSREDIR="/dev/null" + DDSTATS=".." + XARGST="" + NDEBUG="" + ;; + stats) + QUIETREDIR="/dev/null" + QUIETFLAG="-q" + STATSREDIR="/dev/stdout" + DDSTATS="" + XARGST="" + NDEBUG="-n" + ;; + esac +} + +# Perform sanity checks and set some final parameters +# in preparation for fetching files. Figure out which +# set of updates should be downloaded: If the user is +# running *-p[0-9]+, strip off the last part; if the +# user is running -SECURITY, call it -RELEASE. Chdir +# into the working directory. +fetchupgrade_check_params () { + export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)" + + _SERVERNAME_z=\ +"SERVERNAME must be given via command line or configuration file." + _KEYPRINT_z="Key must be given via -k option or configuration file." + _KEYPRINT_bad="Invalid key fingerprint: " + _WORKDIR_bad="Directory does not exist or is not writable: " + _WORKDIR_bad2="Directory is not on a persistent filesystem: " + + if [ -z "${SERVERNAME}" ]; then + echo -n "`basename $0`: " + echo "${_SERVERNAME_z}" + exit 1 + fi + if [ -z "${KEYPRINT}" ]; then + echo -n "`basename $0`: " + echo "${_KEYPRINT_z}" + exit 1 + fi + if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then + echo -n "`basename $0`: " + echo -n "${_KEYPRINT_bad}" + echo ${KEYPRINT} + exit 1 + fi + if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then + echo -n "`basename $0`: " + echo -n "${_WORKDIR_bad}" + echo ${WORKDIR} + exit 1 + fi + case `df -T ${WORKDIR}` in */dev/md[0-9]* | *tmpfs*) + echo -n "`basename $0`: " + echo -n "${_WORKDIR_bad2}" + echo ${WORKDIR} + exit 1 + ;; + esac + chmod 700 ${WORKDIR} + cd ${WORKDIR} || exit 1 + + # Generate release number. The s/SECURITY/RELEASE/ bit exists + # to provide an upgrade path for FreeBSD Update 1.x users, since + # the kernels provided by FreeBSD Update 1.x are always labelled + # as X.Y-SECURITY. + RELNUM=`uname -r | + sed -E 's,-p[0-9]+,,' | + sed -E 's,-SECURITY,-RELEASE,'` + ARCH=`uname -m` + FETCHDIR=${RELNUM}/${ARCH} + PATCHDIR=${RELNUM}/${ARCH}/bp + + # Disallow upgrade from a version that is not a release + case ${RELNUM} in + *-RELEASE | *-ALPHA* | *-BETA* | *-RC*) + ;; + *) + echo -n "`basename $0`: " + cat <<- EOF + Cannot upgrade from a version that is not a release + (including alpha, beta and release candidates) + using `basename $0`. Instead, FreeBSD can be directly + upgraded by source or upgraded to a RELEASE/RELENG version + prior to running `basename $0`. + Currently running: ${RELNUM} + EOF + exit 1 + ;; + esac + + # Figure out what directory contains the running kernel + BOOTFILE=`sysctl -n kern.bootfile` + KERNELDIR=${BOOTFILE%/kernel} + if ! [ -d ${KERNELDIR} ]; then + echo "Cannot identify running kernel" + exit 1 + fi + + # Figure out what kernel configuration is running. We start with + # the output of `uname -i`, and then make the following adjustments: + # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config + # file says "ident SMP-GENERIC", I don't know... + # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64" + # _and_ `sysctl kern.version` contains a line which ends "/SMP", then + # we're running an SMP kernel. This mis-identification is a bug + # which was fixed in 6.2-STABLE. + KERNCONF=`uname -i` + if [ ${KERNCONF} = "SMP-GENERIC" ]; then + KERNCONF=SMP + fi + if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then + if sysctl kern.version | grep -qE '/SMP$'; then + KERNCONF=SMP + fi + fi + + # Define some paths + BSPATCH=/usr/bin/bspatch + SHA256=/sbin/sha256 + PHTTPGET=/usr/libexec/phttpget + + # Set up variables relating to VERBOSELEVEL + fetch_setup_verboselevel + + # Construct a unique name from ${BASEDIR} + BDHASH=`echo ${BASEDIR} | sha256 -q` +} + +# Perform sanity checks etc. before fetching updates. +fetch_check_params () { + fetchupgrade_check_params + + if ! [ -z "${TARGETRELEASE}" ]; then + echo -n "`basename $0`: " + echo -n "'-r' option is meaningless with 'fetch' command. " + echo "(Did you mean 'upgrade' instead?)" + exit 1 + fi + + # Check that we have updates ready to install + if [ -f ${BDHASH}-install/kerneldone -a $FORCEFETCH -eq 0 ]; then + echo "You have a partially completed upgrade pending" + echo "Run '`basename $0` [options] install' first." + echo "Run '`basename $0` [options] fetch -F' to proceed anyway." + exit 1 + fi +} + +# Perform sanity checks etc. before fetching upgrades. +upgrade_check_params () { + fetchupgrade_check_params + + # Unless set otherwise, we're upgrading to the same kernel config. + NKERNCONF=${KERNCONF} + + # We need TARGETRELEASE set + _TARGETRELEASE_z="Release target must be specified via '-r' option." + if [ -z "${TARGETRELEASE}" ]; then + echo -n "`basename $0`: " + echo "${_TARGETRELEASE_z}" + exit 1 + fi + + # The target release should be != the current release. + if [ "${TARGETRELEASE}" = "${RELNUM}" ]; then + echo -n "`basename $0`: " + echo "Cannot upgrade from ${RELNUM} to itself" + exit 1 + fi + + # Turning off AllowAdd or AllowDelete is a bad idea for upgrades. + if [ "${ALLOWADD}" = "no" ]; then + echo -n "`basename $0`: " + echo -n "WARNING: \"AllowAdd no\" is a bad idea " + echo "when upgrading between releases." + echo + fi + if [ "${ALLOWDELETE}" = "no" ]; then + echo -n "`basename $0`: " + echo -n "WARNING: \"AllowDelete no\" is a bad idea " + echo "when upgrading between releases." + echo + fi + + # Set EDITOR to /usr/bin/vi if it isn't already set + : ${EDITOR:='/usr/bin/vi'} +} + +# Perform sanity checks and set some final parameters in +# preparation for installing updates. +install_check_params () { + # Check that we are root. All sorts of things won't work otherwise. + if [ `id -u` != 0 ]; then + echo "You must be root to run this." + exit 1 + fi + + # Check that securelevel <= 0. Otherwise we can't update schg files. + if [ `sysctl -n kern.securelevel` -gt 0 ]; then + echo "Updates cannot be installed when the system securelevel" + echo "is greater than zero." + exit 1 + fi + + # Check that we have a working directory + _WORKDIR_bad="Directory does not exist or is not writable: " + if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then + echo -n "`basename $0`: " + echo -n "${_WORKDIR_bad}" + echo ${WORKDIR} + exit 1 + fi + cd ${WORKDIR} || exit 1 + + # Construct a unique name from ${BASEDIR} + BDHASH=`echo ${BASEDIR} | sha256 -q` + + # Check that we have updates ready to install + if ! [ -L ${BDHASH}-install ]; then + echo "No updates are available to install." + if [ $ISFETCHED -eq 0 ]; then + echo "Run '`basename $0` [options] fetch' first." + exit 2 + fi + exit 0 + fi + if ! [ -f ${BDHASH}-install/INDEX-OLD ] || + ! [ -f ${BDHASH}-install/INDEX-NEW ]; then + echo "Update manifest is corrupt -- this should never happen." + echo "Re-run '`basename $0` [options] fetch'." + exit 1 + fi + + # Figure out what directory contains the running kernel + BOOTFILE=`sysctl -n kern.bootfile` + KERNELDIR=${BOOTFILE%/kernel} + if ! [ -d ${KERNELDIR} ]; then + echo "Cannot identify running kernel" + exit 1 + fi +} + +# Creates a new boot environment +install_create_be () { + # Figure out if we're running in a jail and return if we are + if [ `sysctl -n security.jail.jailed` = 1 ]; then + return 1 + fi + # Operating on roots that aren't located at / will, more often than not, + # not touch the boot environment. + if [ "$BASEDIR" != "/" ]; then + return 1 + fi + # Create a boot environment if enabled + if [ ${BOOTENV} = yes ]; then + bectl check 2>/dev/null + case $? in + 0) + # Boot environment are supported + CREATEBE=yes + ;; + 255) + # Boot environments are not supported + CREATEBE=no + ;; + *) + # If bectl returns an unexpected exit code, don't create a BE + CREATEBE=no + ;; + esac + if [ ${CREATEBE} = yes ]; then + echo -n "Creating snapshot of existing boot environment... " + VERSION=`freebsd-version -ku | sort -V | tail -n 1` + TIMESTAMP=`date +"%Y-%m-%d_%H%M%S"` + bectl create -r ${VERSION}_${TIMESTAMP} + if [ $? -eq 0 ]; then + echo "done."; + else + echo "failed." + exit 1 + fi + fi + fi +} + +# Perform sanity checks and set some final parameters in +# preparation for UNinstalling updates. +rollback_check_params () { + # Check that we are root. All sorts of things won't work otherwise. + if [ `id -u` != 0 ]; then + echo "You must be root to run this." + exit 1 + fi + + # Check that we have a working directory + _WORKDIR_bad="Directory does not exist or is not writable: " + if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then + echo -n "`basename $0`: " + echo -n "${_WORKDIR_bad}" + echo ${WORKDIR} + exit 1 + fi + cd ${WORKDIR} || exit 1 + + # Construct a unique name from ${BASEDIR} + BDHASH=`echo ${BASEDIR} | sha256 -q` + + # Check that we have updates ready to rollback + if ! [ -L ${BDHASH}-rollback ]; then + echo "No rollback directory found." + exit 1 + fi + if ! [ -f ${BDHASH}-rollback/INDEX-OLD ] || + ! [ -f ${BDHASH}-rollback/INDEX-NEW ]; then + echo "Update manifest is corrupt -- this should never happen." + exit 1 + fi +} + +# Perform sanity checks and set some final parameters +# in preparation for comparing the system against the +# published index. Figure out which index we should +# compare against: If the user is running *-p[0-9]+, +# strip off the last part; if the user is running +# -SECURITY, call it -RELEASE. Chdir into the working +# directory. +IDS_check_params () { + export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)" + + _SERVERNAME_z=\ +"SERVERNAME must be given via command line or configuration file." + _KEYPRINT_z="Key must be given via '-k' option or configuration file." + _KEYPRINT_bad="Invalid key fingerprint: " + _WORKDIR_bad="Directory does not exist or is not writable: " + + if [ -z "${SERVERNAME}" ]; then + echo -n "`basename $0`: " + echo "${_SERVERNAME_z}" + exit 1 + fi + if [ -z "${KEYPRINT}" ]; then + echo -n "`basename $0`: " + echo "${_KEYPRINT_z}" + exit 1 + fi + if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then + echo -n "`basename $0`: " + echo -n "${_KEYPRINT_bad}" + echo ${KEYPRINT} + exit 1 + fi + if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then + echo -n "`basename $0`: " + echo -n "${_WORKDIR_bad}" + echo ${WORKDIR} + exit 1 + fi + cd ${WORKDIR} || exit 1 + + # Generate release number. The s/SECURITY/RELEASE/ bit exists + # to provide an upgrade path for FreeBSD Update 1.x users, since + # the kernels provided by FreeBSD Update 1.x are always labelled + # as X.Y-SECURITY. + RELNUM=`uname -r | + sed -E 's,-p[0-9]+,,' | + sed -E 's,-SECURITY,-RELEASE,'` + ARCH=`uname -m` + FETCHDIR=${RELNUM}/${ARCH} + PATCHDIR=${RELNUM}/${ARCH}/bp + + # Figure out what directory contains the running kernel + BOOTFILE=`sysctl -n kern.bootfile` + KERNELDIR=${BOOTFILE%/kernel} + if ! [ -d ${KERNELDIR} ]; then + echo "Cannot identify running kernel" + exit 1 + fi + + # Figure out what kernel configuration is running. We start with + # the output of `uname -i`, and then make the following adjustments: + # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config + # file says "ident SMP-GENERIC", I don't know... + # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64" + # _and_ `sysctl kern.version` contains a line which ends "/SMP", then + # we're running an SMP kernel. This mis-identification is a bug + # which was fixed in 6.2-STABLE. + KERNCONF=`uname -i` + if [ ${KERNCONF} = "SMP-GENERIC" ]; then + KERNCONF=SMP + fi + if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then + if sysctl kern.version | grep -qE '/SMP$'; then + KERNCONF=SMP + fi + fi + + # Define some paths + SHA256=/sbin/sha256 + PHTTPGET=/usr/libexec/phttpget + + # Set up variables relating to VERBOSELEVEL + fetch_setup_verboselevel +} + +# Packaged base and freebsd-update are incompatible. Exit with an error if +# packaged base is in use. +check_pkgbase() +{ + # Packaged base requires that pkg is bootstrapped. + if ! pkg -c ${BASEDIR} -N >/dev/null 2>/dev/null; then + return + fi + # uname(1) is used by pkg to determine ABI, so it should exist. + # If it comes from a package then this system uses packaged base. + if ! pkg -c ${BASEDIR} which /usr/bin/uname >/dev/null; then + return + fi + cat < serverlist_tried + +# Check that host(1) exists (i.e., that the system wasn't built with the +# WITHOUT_BIND set) and don't try to find a mirror if it doesn't exist. + if ! which -s host; then + : > serverlist_full + return 1 + fi + + echo -n "Looking up ${SERVERNAME} mirrors... " + +# Issue the SRV query and pull out the Priority, Weight, and Target fields. +# BIND 9 prints "$name has SRV record ..." while BIND 8 prints +# "$name server selection ..."; we allow either format. + MLIST="_http._tcp.${SERVERNAME}" + host -t srv "${MLIST}" | + sed -nE "s/${MLIST} (has SRV record|server selection) //Ip" | + cut -f 1,2,4 -d ' ' | + sed -e 's/\.$//' | + sort > serverlist_full + +# If no records, give up -- we'll just use the server name we were given. + if [ `wc -l < serverlist_full` -eq 0 ]; then + echo "none found." + return 1 + fi + +# Report how many mirrors we found. + echo `wc -l < serverlist_full` "mirrors found." + +# Generate a random seed for use in picking mirrors. If HTTP_PROXY +# is set, this will be used to generate the seed; otherwise, the seed +# will be random. + if [ -n "${HTTP_PROXY}${http_proxy}" ]; then + RANDVALUE=`sha256 -qs "${HTTP_PROXY}${http_proxy}" | + tr -d 'a-f' | + cut -c 1-9` + else + RANDVALUE=`jot -r 1 0 999999999` + fi +} + +# Pick a mirror. Returns 1 if we have run out of mirrors to try. +fetch_pick_server () { +# Generate a list of not-yet-tried mirrors + sort serverlist_tried | + comm -23 serverlist_full - > serverlist + +# Have we run out of mirrors? + if [ `wc -l < serverlist` -eq 0 ]; then + cat <<- EOF + No mirrors remaining, giving up. + + This may be because upgrading from this platform (${ARCH}) + or release (${RELNUM}) is unsupported by `basename $0`. Only + platforms with Tier 1 support can be upgraded by `basename $0`. + See https://www.freebsd.org/platforms/ for more info. + + If unsupported, FreeBSD must be upgraded by source. + EOF + return 1 + fi + +# Find the highest priority level (lowest numeric value). + SRV_PRIORITY=`cut -f 1 -d ' ' serverlist | sort -n | head -1` + +# Add up the weights of the response lines at that priority level. + SRV_WSUM=0; + while read X; do + case "$X" in + ${SRV_PRIORITY}\ *) + SRV_W=`echo $X | cut -f 2 -d ' '` + SRV_WSUM=$(($SRV_WSUM + $SRV_W)) + ;; + esac + done < serverlist + +# If all the weights are 0, pretend that they are all 1 instead. + if [ ${SRV_WSUM} -eq 0 ]; then + SRV_WSUM=`grep -E "^${SRV_PRIORITY} " serverlist | wc -l` + SRV_W_ADD=1 + else + SRV_W_ADD=0 + fi + +# Pick a value between 0 and the sum of the weights - 1 + SRV_RND=`expr ${RANDVALUE} % ${SRV_WSUM}` + +# Read through the list of mirrors and set SERVERNAME. Write the line +# corresponding to the mirror we selected into serverlist_tried so that +# we won't try it again. + while read X; do + case "$X" in + ${SRV_PRIORITY}\ *) + SRV_W=`echo $X | cut -f 2 -d ' '` + SRV_W=$(($SRV_W + $SRV_W_ADD)) + if [ $SRV_RND -lt $SRV_W ]; then + SERVERNAME=`echo $X | cut -f 3 -d ' '` + echo "$X" >> serverlist_tried + break + else + SRV_RND=$(($SRV_RND - $SRV_W)) + fi + ;; + esac + done < serverlist +} + +# Take a list of ${oldhash}|${newhash} and output a list of needed patches, +# i.e., those for which we have ${oldhash} and don't have ${newhash}. +fetch_make_patchlist () { + grep -vE "^([0-9a-f]{64})\|\1$" | + tr '|' ' ' | + while read X Y; do + if [ -f "files/${Y}.gz" ] || + [ ! -f "files/${X}.gz" ]; then + continue + fi + echo "${X}|${Y}" + done | sort -u +} + +# Print user-friendly progress statistics +fetch_progress () { + LNC=0 + while read x; do + LNC=$(($LNC + 1)) + if [ $(($LNC % 10)) = 0 ]; then + echo -n $LNC + elif [ $(($LNC % 2)) = 0 ]; then + echo -n . + fi + done + echo -n " " +} + +# Function for asking the user if everything is ok +continuep () { + while read -p "Does this look reasonable (y/n)? " CONTINUE; do + case "${CONTINUE}" in + [yY]*) + return 0 + ;; + [nN]*) + return 1 + ;; + esac + done +} + +# Initialize the working directory +workdir_init () { + mkdir -p files + touch tINDEX.present +} + +# Check that we have a public key with an appropriate hash, or +# fetch the key if it doesn't exist. Returns 1 if the key has +# not yet been fetched. +fetch_key () { + if [ -r pub.ssl ] && [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then + return 0 + fi + + echo -n "Fetching public key from ${SERVERNAME}... " + rm -f pub.ssl + fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/pub.ssl \ + 2>${QUIETREDIR} || true + if ! [ -r pub.ssl ]; then + echo "failed." + return 1 + fi + if ! [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then + echo "key has incorrect hash." + rm -f pub.ssl + return 1 + fi + echo "done." +} + +# Fetch metadata signature, aka "tag". +fetch_tag () { + echo -n "Fetching metadata signature " + echo ${NDEBUG} "for ${RELNUM} from ${SERVERNAME}... " + rm -f latest.ssl + fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/latest.ssl \ + 2>${QUIETREDIR} || true + if ! [ -r latest.ssl ]; then + echo "failed." + return 1 + fi + + openssl rsautl -pubin -inkey pub.ssl -verify \ + < latest.ssl > tag.new 2>${QUIETREDIR} || true + rm latest.ssl + + if ! [ `wc -l < tag.new` = 1 ] || + ! grep -qE \ + "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \ + tag.new; then + echo "invalid signature." + return 1 + fi + + echo "done." + + RELPATCHNUM=`cut -f 4 -d '|' < tag.new` + TINDEXHASH=`cut -f 5 -d '|' < tag.new` + EOLTIME=`cut -f 6 -d '|' < tag.new` +} + +# Sanity-check the patch number in a tag, to make sure that we're not +# going to "update" backwards and to prevent replay attacks. +fetch_tagsanity () { + # Check that we're not going to move from -pX to -pY with Y < X. + RELPX=`uname -r | sed -E 's,.*-,,'` + if echo ${RELPX} | grep -qE '^p[0-9]+$'; then + RELPX=`echo ${RELPX} | cut -c 2-` + else + RELPX=0 + fi + if [ "${RELPATCHNUM}" -lt "${RELPX}" ]; then + echo + echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})" + echo " appear older than what" + echo "we are currently running (`uname -r`)!" + echo "Cowardly refusing to proceed any further." + return 1 + fi + + # If "tag" exists and corresponds to ${RELNUM}, make sure that + # it contains a patch number <= RELPATCHNUM, in order to protect + # against rollback (replay) attacks. + if [ -f tag ] && + grep -qE \ + "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \ + tag; then + LASTRELPATCHNUM=`cut -f 4 -d '|' < tag` + + if [ "${RELPATCHNUM}" -lt "${LASTRELPATCHNUM}" ]; then + echo + echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})" + echo " are older than the" + echo -n "most recently seen updates" + echo " (${RELNUM}-p${LASTRELPATCHNUM})." + echo "Cowardly refusing to proceed any further." + return 1 + fi + fi +} + +# Fetch metadata index file +fetch_metadata_index () { + echo ${NDEBUG} "Fetching metadata index... " + rm -f ${TINDEXHASH} + fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/t/${TINDEXHASH} + 2>${QUIETREDIR} + if ! [ -f ${TINDEXHASH} ]; then + echo "failed." + return 1 + fi + if [ `${SHA256} -q ${TINDEXHASH}` != ${TINDEXHASH} ]; then + echo "update metadata index corrupt." + return 1 + fi + echo "done." +} + +# Print an error message about signed metadata being bogus. +fetch_metadata_bogus () { + echo + echo "The update metadata$1 is correctly signed, but" + echo "failed an integrity check." + echo "Cowardly refusing to proceed any further." + return 1 +} + +# Construct tINDEX.new by merging the lines named in $1 from ${TINDEXHASH} +# with the lines not named in $@ from tINDEX.present (if that file exists). +fetch_metadata_index_merge () { + for METAFILE in $@; do + if [ `grep -E "^${METAFILE}\|" ${TINDEXHASH} | wc -l` \ + -ne 1 ]; then + fetch_metadata_bogus " index" + return 1 + fi + + grep -E "${METAFILE}\|" ${TINDEXHASH} + done | + sort > tINDEX.wanted + + if [ -f tINDEX.present ]; then + join -t '|' -v 2 tINDEX.wanted tINDEX.present | + sort -m - tINDEX.wanted > tINDEX.new + rm tINDEX.wanted + else + mv tINDEX.wanted tINDEX.new + fi +} + +# Sanity check all the lines of tINDEX.new. Even if more metadata lines +# are added by future versions of the server, this won't cause problems, +# since the only lines which appear in tINDEX.new are the ones which we +# specifically grepped out of ${TINDEXHASH}. +fetch_metadata_index_sanity () { + if grep -qvE '^[0-9A-Z.-]+\|[0-9a-f]{64}$' tINDEX.new; then + fetch_metadata_bogus " index" + return 1 + fi +} + +# Sanity check the metadata file $1. +fetch_metadata_sanity () { + # Some aliases to save space later: ${P} is a character which can + # appear in a path; ${M} is the four numeric metadata fields; and + # ${H} is a sha256 hash. + P="[-+./:=,%@_[~[:alnum:]]" + M="[0-9]+\|[0-9]+\|[0-9]+\|[0-9]+" + H="[0-9a-f]{64}" + + # Check that the first four fields make sense. + if gunzip -c < files/$1.gz | + grep -qvE "^[a-z]+\|[0-9a-z-]+\|${P}+\|[fdL-]\|"; then + fetch_metadata_bogus "" + return 1 + fi + + # Remove the first three fields. + gunzip -c < files/$1.gz | + cut -f 4- -d '|' > sanitycheck.tmp + + # Sanity check entries with type 'f' + if grep -E '^f' sanitycheck.tmp | + grep -qvE "^f\|${M}\|${H}\|${P}*\$"; then + fetch_metadata_bogus "" + return 1 + fi + + # Sanity check entries with type 'd' + if grep -E '^d' sanitycheck.tmp | + grep -qvE "^d\|${M}\|\|\$"; then + fetch_metadata_bogus "" + return 1 + fi + + # Sanity check entries with type 'L' + if grep -E '^L' sanitycheck.tmp | + grep -qvE "^L\|${M}\|${P}*\|\$"; then + fetch_metadata_bogus "" + return 1 + fi + + # Sanity check entries with type '-' + if grep -E '^-' sanitycheck.tmp | + grep -qvE "^-\|\|\|\|\|\|"; then + fetch_metadata_bogus "" + return 1 + fi + + # Clean up + rm sanitycheck.tmp +} + +# Fetch the metadata index and metadata files listed in $@, +# taking advantage of metadata patches where possible. +fetch_metadata () { + fetch_metadata_index || return 1 + fetch_metadata_index_merge $@ || return 1 + fetch_metadata_index_sanity || return 1 + + # Generate a list of wanted metadata patches + join -t '|' -o 1.2,2.2 tINDEX.present tINDEX.new | + fetch_make_patchlist > patchlist + + if [ -s patchlist ]; then + # Attempt to fetch metadata patches + echo -n "Fetching `wc -l < patchlist | tr -d ' '` " + echo ${NDEBUG} "metadata patches.${DDSTATS}" + tr '|' '-' < patchlist | + lam -s "${FETCHDIR}/tp/" - -s ".gz" | + xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ + 2>${STATSREDIR} | fetch_progress + echo "done." + + # Attempt to apply metadata patches + echo -n "Applying metadata patches... " + tr '|' ' ' < patchlist | + while read X Y; do + if [ ! -f "${X}-${Y}.gz" ]; then continue; fi + gunzip -c < ${X}-${Y}.gz > diff + gunzip -c < files/${X}.gz > diff-OLD + + # Figure out which lines are being added and removed + grep -E '^-' diff | + cut -c 2- | + while read PREFIX; do + look "${PREFIX}" diff-OLD + done | + sort > diff-rm + grep -E '^\+' diff | + cut -c 2- > diff-add + + # Generate the new file + comm -23 diff-OLD diff-rm | + sort - diff-add > diff-NEW + + if [ `${SHA256} -q diff-NEW` = ${Y} ]; then + mv diff-NEW files/${Y} + gzip -n files/${Y} + else + mv diff-NEW ${Y}.bad + fi + rm -f ${X}-${Y}.gz diff + rm -f diff-OLD diff-NEW diff-add diff-rm + done 2>${QUIETREDIR} + echo "done." + fi + + # Update metadata without patches + cut -f 2 -d '|' < tINDEX.new | + while read Y; do + if [ ! -f "files/${Y}.gz" ]; then + echo ${Y}; + fi + done | + sort -u > filelist + + if [ -s filelist ]; then + echo -n "Fetching `wc -l < filelist | tr -d ' '` " + echo ${NDEBUG} "metadata files... " + lam -s "${FETCHDIR}/m/" - -s ".gz" < filelist | + xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ + 2>${QUIETREDIR} + + while read Y; do + if ! [ -f ${Y}.gz ]; then + echo "failed." + return 1 + fi + if [ `gunzip -c < ${Y}.gz | + ${SHA256} -q` = ${Y} ]; then + mv ${Y}.gz files/${Y}.gz + else + echo "metadata is corrupt." + return 1 + fi + done < filelist + echo "done." + fi + +# Sanity-check the metadata files. + cut -f 2 -d '|' tINDEX.new > filelist + while read X; do + fetch_metadata_sanity ${X} || return 1 + done < filelist + +# Remove files which are no longer needed + cut -f 2 -d '|' tINDEX.present | + sort > oldfiles + cut -f 2 -d '|' tINDEX.new | + sort | + comm -13 - oldfiles | + lam -s "files/" - -s ".gz" | + xargs rm -f + rm patchlist filelist oldfiles + rm ${TINDEXHASH} + +# We're done! + mv tINDEX.new tINDEX.present + mv tag.new tag + + return 0 +} + +# Extract a subset of a downloaded metadata file containing only the parts +# which are listed in COMPONENTS. +fetch_filter_metadata_components () { + METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'` + gunzip -c < files/${METAHASH}.gz > $1.all + + # Fish out the lines belonging to components we care about. + for C in ${COMPONENTS}; do + look "`echo ${C} | tr '/' '|'`|" $1.all + done > $1 + + # Remove temporary file. + rm $1.all +} + +# Generate a filtered version of the metadata file $1 from the downloaded +# file, by fishing out the lines corresponding to components we're trying +# to keep updated, and then removing lines corresponding to paths we want +# to ignore. +fetch_filter_metadata () { + # Fish out the lines belonging to components we care about. + fetch_filter_metadata_components $1 + + # Canonicalize directory names by removing any trailing / in + # order to avoid listing directories multiple times if they + # belong to multiple components. Turning "/" into "" doesn't + # matter, since we add a leading "/" when we use paths later. + cut -f 3- -d '|' $1 | + sed -e 's,/|d|,|d|,' | + sed -e 's,/|-|,|-|,' | + sort -u > $1.tmp + + # Figure out which lines to ignore and remove them. + for X in ${IGNOREPATHS}; do + grep -E "^${X}" $1.tmp + done | + sort -u | + comm -13 - $1.tmp > $1 + + # Remove temporary files. + rm $1.tmp +} + +# Filter the metadata file $1 by adding lines with "/boot/$2" +# replaced by ${KERNELDIR} (which is `sysctl -n kern.bootfile` minus the +# trailing "/kernel"); and if "/boot/$2" does not exist, remove +# the original lines which start with that. +# Put another way: Deal with the fact that the FOO kernel is sometimes +# installed in /boot/FOO/ and is sometimes installed elsewhere. +fetch_filter_kernel_names () { + grep ^/boot/$2 $1 | + sed -e "s,/boot/$2,${KERNELDIR},g" | + sort - $1 > $1.tmp + mv $1.tmp $1 + + if ! [ -d /boot/$2 ]; then + grep -v ^/boot/$2 $1 > $1.tmp + mv $1.tmp $1 + fi +} + +# For all paths appearing in $1 or $3, inspect the system +# and generate $2 describing what is currently installed. +fetch_inspect_system () { + # No errors yet... + rm -f .err + + # Tell the user why his disk is suddenly making lots of noise + echo -n "Inspecting system... " + + # Generate list of files to inspect + cat $1 $3 | + cut -f 1 -d '|' | + sort -u > filelist + + # Examine each file and output lines of the form + # /path/to/file|type|device-inum|user|group|perm|flags|value + # sorted by device and inode number. + while read F; do + # If the symlink/file/directory does not exist, record this. + if ! [ -e ${BASEDIR}/${F} ]; then + echo "${F}|-||||||" + continue + fi + if ! [ -r ${BASEDIR}/${F} ]; then + echo "Cannot read file: ${BASEDIR}/${F}" \ + >/dev/stderr + touch .err + return 1 + fi + + # Otherwise, output an index line. + if [ -L ${BASEDIR}/${F} ]; then + echo -n "${F}|L|" + stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F}; + readlink ${BASEDIR}/${F}; + elif [ -f ${BASEDIR}/${F} ]; then + echo -n "${F}|f|" + stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F}; + sha256 -q ${BASEDIR}/${F}; + elif [ -d ${BASEDIR}/${F} ]; then + echo -n "${F}|d|" + stat -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F}; + else + echo "Unknown file type: ${BASEDIR}/${F}" \ + >/dev/stderr + touch .err + return 1 + fi + done < filelist | + sort -k 3,3 -t '|' > $2.tmp + rm filelist + + # Check if an error occurred during system inspection + if [ -f .err ]; then + return 1 + fi + + # Convert to the form + # /path/to/file|type|user|group|perm|flags|value|hlink + # by resolving identical device and inode numbers into hard links. + cut -f 1,3 -d '|' $2.tmp | + sort -k 1,1 -t '|' | + sort -s -u -k 2,2 -t '|' | + join -1 2 -2 3 -t '|' - $2.tmp | + awk -F \| -v OFS=\| \ + '{ + if (($2 == $3) || ($4 == "-")) + print $3,$4,$5,$6,$7,$8,$9,"" + else + print $3,$4,$5,$6,$7,$8,$9,$2 + }' | + sort > $2 + rm $2.tmp + + # We're finished looking around + echo "done." +} + +# For any paths matching ${MERGECHANGES}, compare $2 against $1 and $3 and +# find any files with values unique to $2; generate $4 containing these paths +# and their corresponding hashes from $1. +fetch_filter_mergechanges () { + # Pull out the paths and hashes of the files matching ${MERGECHANGES}. + for F in $1 $2 $3; do + for X in ${MERGECHANGES}; do + grep -E "^${X}" ${F} + done | + cut -f 1,2,7 -d '|' | + sort > ${F}-values + done + + # Any line in $2-values which doesn't appear in $1-values or $3-values + # and is a file means that we should list the path in $3. + sort $1-values $3-values | + comm -13 - $2-values | + fgrep '|f|' | + cut -f 1 -d '|' > $2-paths + + # For each path, pull out one (and only one!) entry from $1-values. + # Note that we cannot distinguish which "old" version the user made + # changes to; but hopefully any changes which occur due to security + # updates will exist in both the "new" version and the version which + # the user has installed, so the merging will still work. + while read X; do + look "${X}|" $1-values | + head -1 + done < $2-paths > $4 + + # Clean up + rm $1-values $2-values $3-values $2-paths +} + +# For any paths matching ${UPDATEIFUNMODIFIED}, remove lines from $[123] +# which correspond to lines in $2 with hashes not matching $1 or $3, unless +# the paths are listed in $4. For entries in $2 marked "not present" +# (aka. type -), remove lines from $[123] unless there is a corresponding +# entry in $1. +fetch_filter_unmodified_notpresent () { + # Figure out which lines of $1 and $3 correspond to bits which + # should only be updated if they haven't changed, and fish out + # the (path, type, value) tuples. + # NOTE: We don't consider a file to be "modified" if it matches + # the hash from $3. + for X in ${UPDATEIFUNMODIFIED}; do + grep -E "^${X}" $1 + grep -E "^${X}" $3 + done | + cut -f 1,2,7 -d '|' | + sort > $1-values + + # Do the same for $2. + for X in ${UPDATEIFUNMODIFIED}; do + grep -E "^${X}" $2 + done | + cut -f 1,2,7 -d '|' | + sort > $2-values + + # Any entry in $2-values which is not in $1-values corresponds to + # a path which we need to remove from $1, $2, and $3, unless it + # that path appears in $4. + comm -13 $1-values $2-values | + sort -t '|' -k 1,1 > mlines.tmp + cut -f 1 -d '|' $4 | + sort | + join -v 2 -t '|' - mlines.tmp | + sort > mlines + rm $1-values $2-values mlines.tmp + + # Any lines in $2 which are not in $1 AND are "not present" lines + # also belong in mlines. + comm -13 $1 $2 | + cut -f 1,2,7 -d '|' | + fgrep '|-|' >> mlines + + # Remove lines from $1, $2, and $3 + for X in $1 $2 $3; do + sort -t '|' -k 1,1 ${X} > ${X}.tmp + cut -f 1 -d '|' < mlines | + sort | + join -v 2 -t '|' - ${X}.tmp | + sort > ${X} + rm ${X}.tmp + done + + # Store a list of the modified files, for future reference + fgrep -v '|-|' mlines | + cut -f 1 -d '|' > modifiedfiles + rm mlines +} + +# For each entry in $1 of type -, remove any corresponding +# entry from $2 if ${ALLOWADD} != "yes". Remove all entries +# of type - from $1. +fetch_filter_allowadd () { + cut -f 1,2 -d '|' < $1 | + fgrep '|-' | + cut -f 1 -d '|' > filesnotpresent + + if [ ${ALLOWADD} != "yes" ]; then + sort < $2 | + join -v 1 -t '|' - filesnotpresent | + sort > $2.tmp + mv $2.tmp $2 + fi + + sort < $1 | + join -v 1 -t '|' - filesnotpresent | + sort > $1.tmp + mv $1.tmp $1 + rm filesnotpresent +} + +# If ${ALLOWDELETE} != "yes", then remove any entries from $1 +# which don't correspond to entries in $2. +fetch_filter_allowdelete () { + # Produce a lists ${PATH}|${TYPE} + for X in $1 $2; do + cut -f 1-2 -d '|' < ${X} | + sort -u > ${X}.nodes + done + + # Figure out which lines need to be removed from $1. + if [ ${ALLOWDELETE} != "yes" ]; then + comm -23 $1.nodes $2.nodes > $1.badnodes + else + : > $1.badnodes + fi + + # Remove the relevant lines from $1 + while read X; do + look "${X}|" $1 + done < $1.badnodes | + comm -13 - $1 > $1.tmp + mv $1.tmp $1 + + rm $1.badnodes $1.nodes $2.nodes +} + +# If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in $2 +# with metadata not matching any entry in $1, replace the corresponding +# line of $3 with one having the same metadata as the entry in $2. +fetch_filter_modified_metadata () { + # Fish out the metadata from $1 and $2 + for X in $1 $2; do + cut -f 1-6 -d '|' < ${X} > ${X}.metadata + done + + # Find the metadata we need to keep + if [ ${KEEPMODIFIEDMETADATA} = "yes" ]; then + comm -13 $1.metadata $2.metadata > keepmeta + else + : > keepmeta + fi + + # Extract the lines which we need to remove from $3, and + # construct the lines which we need to add to $3. + : > $3.remove + : > $3.add + while read LINE; do + NODE=`echo "${LINE}" | cut -f 1-2 -d '|'` + look "${NODE}|" $3 >> $3.remove + look "${NODE}|" $3 | + cut -f 7- -d '|' | + lam -s "${LINE}|" - >> $3.add + done < keepmeta + + # Remove the specified lines and add the new lines. + sort $3.remove | + comm -13 - $3 | + sort -u - $3.add > $3.tmp + mv $3.tmp $3 + + rm keepmeta $1.metadata $2.metadata $3.add $3.remove +} + +# Remove lines from $1 and $2 which are identical; +# no need to update a file if it isn't changing. +fetch_filter_uptodate () { + comm -23 $1 $2 > $1.tmp + comm -13 $1 $2 > $2.tmp + + mv $1.tmp $1 + mv $2.tmp $2 +} + +# Fetch any "clean" old versions of files we need for merging changes. +fetch_files_premerge () { + # We only need to do anything if $1 is non-empty. + if [ -s $1 ]; then + # Tell the user what we're doing + echo -n "Fetching files from ${OLDRELNUM} for merging... " + + # List of files wanted + fgrep '|f|' < $1 | + cut -f 3 -d '|' | + sort -u > files.wanted + + # Only fetch the files we don't already have + while read Y; do + if [ ! -f "files/${Y}.gz" ]; then + echo ${Y}; + fi + done < files.wanted > filelist + + # Actually fetch them + lam -s "${OLDFETCHDIR}/f/" - -s ".gz" < filelist | + xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ + 2>${QUIETREDIR} + + # Make sure we got them all, and move them into /files/ + while read Y; do + if ! [ -f ${Y}.gz ]; then + echo "failed." + return 1 + fi + if [ `gunzip -c < ${Y}.gz | + ${SHA256} -q` = ${Y} ]; then + mv ${Y}.gz files/${Y}.gz + else + echo "${Y} has incorrect hash." + return 1 + fi + done < filelist + echo "done." + + # Clean up + rm filelist files.wanted + fi +} + +# Prepare to fetch files: Generate a list of the files we need, +# copy the unmodified files we have into /files/, and generate +# a list of patches to download. +fetch_files_prepare () { + # Tell the user why his disk is suddenly making lots of noise + echo -n "Preparing to download files... " + + # Reduce indices to ${PATH}|${HASH} pairs + for X in $1 $2 $3; do + cut -f 1,2,7 -d '|' < ${X} | + fgrep '|f|' | + cut -f 1,3 -d '|' | + sort > ${X}.hashes + done + + # List of files wanted + cut -f 2 -d '|' < $3.hashes | + sort -u | + while read HASH; do + if ! [ -f files/${HASH}.gz ]; then + echo ${HASH} + fi + done > files.wanted + + # Generate a list of unmodified files + comm -12 $1.hashes $2.hashes | + sort -k 1,1 -t '|' > unmodified.files + + # Copy all files into /files/. We only need the unmodified files + # for use in patching; but we'll want all of them if the user asks + # to rollback the updates later. + while read LINE; do + F=`echo "${LINE}" | cut -f 1 -d '|'` + HASH=`echo "${LINE}" | cut -f 2 -d '|'` + + # Skip files we already have. + if [ -f files/${HASH}.gz ]; then + continue + fi + + # Make sure the file hasn't changed. + cp "${BASEDIR}/${F}" tmpfile + if [ `sha256 -q tmpfile` != ${HASH} ]; then + echo + echo "File changed while FreeBSD Update running: ${F}" + return 1 + fi + + # Place the file into storage. + gzip -c < tmpfile > files/${HASH}.gz + rm tmpfile + done < $2.hashes + + # Produce a list of patches to download + sort -k 1,1 -t '|' $3.hashes | + join -t '|' -o 2.2,1.2 - unmodified.files | + fetch_make_patchlist > patchlist + + # Garbage collect + rm unmodified.files $1.hashes $2.hashes $3.hashes + + # We don't need the list of possible old files any more. + rm $1 + + # We're finished making noise + echo "done." +} + +# Fetch files. +fetch_files () { + # Attempt to fetch patches + if [ -s patchlist ]; then + echo -n "Fetching `wc -l < patchlist | tr -d ' '` " + echo ${NDEBUG} "patches.${DDSTATS}" + tr '|' '-' < patchlist | + lam -s "${PATCHDIR}/" - | + xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ + 2>${STATSREDIR} | fetch_progress + echo "done." + + # Attempt to apply patches + echo -n "Applying patches... " + tr '|' ' ' < patchlist | + while read X Y; do + if [ ! -f "${X}-${Y}" ]; then continue; fi + gunzip -c < files/${X}.gz > OLD + + bspatch OLD NEW ${X}-${Y} + + if [ `${SHA256} -q NEW` = ${Y} ]; then + mv NEW files/${Y} + gzip -n files/${Y} + fi + rm -f diff OLD NEW ${X}-${Y} + done 2>${QUIETREDIR} + echo "done." + fi + + # Download files which couldn't be generate via patching + while read Y; do + if [ ! -f "files/${Y}.gz" ]; then + echo ${Y}; + fi + done < files.wanted > filelist + + if [ -s filelist ]; then + echo -n "Fetching `wc -l < filelist | tr -d ' '` " + echo ${NDEBUG} "files... " + lam -s "${FETCHDIR}/f/" - -s ".gz" < filelist | + xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ + 2>${STATSREDIR} | fetch_progress + + while read Y; do + if ! [ -f ${Y}.gz ]; then + echo "failed." + return 1 + fi + if [ `gunzip -c < ${Y}.gz | + ${SHA256} -q` = ${Y} ]; then + mv ${Y}.gz files/${Y}.gz + else + echo "${Y} has incorrect hash." + return 1 + fi + done < filelist + echo "done." + fi + + # Clean up + rm files.wanted filelist patchlist +} + +# Create and populate install manifest directory; and report what updates +# are available. +fetch_create_manifest () { + # If we have an existing install manifest, nuke it. + if [ -L "${BDHASH}-install" ]; then + rm -r ${BDHASH}-install/ + rm ${BDHASH}-install + fi + + # Report to the user if any updates were avoided due to local changes + if [ -s modifiedfiles ]; then + cat - modifiedfiles <<- EOF | ${PAGER} + The following files are affected by updates. No changes have + been downloaded, however, because the files have been modified + locally: + EOF + fi + rm modifiedfiles + + # If no files will be updated, tell the user and exit + if ! [ -s INDEX-PRESENT ] && + ! [ -s INDEX-NEW ]; then + rm INDEX-PRESENT INDEX-NEW + echo + echo -n "No updates needed to update system to " + echo "${RELNUM}-p${RELPATCHNUM}." + return + fi + + # Divide files into (a) removed files, (b) added files, and + # (c) updated files. + cut -f 1 -d '|' < INDEX-PRESENT | + sort > INDEX-PRESENT.flist + cut -f 1 -d '|' < INDEX-NEW | + sort > INDEX-NEW.flist + comm -23 INDEX-PRESENT.flist INDEX-NEW.flist > files.removed + comm -13 INDEX-PRESENT.flist INDEX-NEW.flist > files.added + comm -12 INDEX-PRESENT.flist INDEX-NEW.flist > files.updated + rm INDEX-PRESENT.flist INDEX-NEW.flist + + # Report removed files, if any + if [ -s files.removed ]; then + cat - files.removed <<- EOF | ${PAGER} + The following files will be removed as part of updating to + ${RELNUM}-p${RELPATCHNUM}: + EOF + fi + rm files.removed + + # Report added files, if any + if [ -s files.added ]; then + cat - files.added <<- EOF | ${PAGER} + The following files will be added as part of updating to + ${RELNUM}-p${RELPATCHNUM}: + EOF + fi + rm files.added + + # Report updated files, if any + if [ -s files.updated ]; then + cat - files.updated <<- EOF | ${PAGER} + The following files will be updated as part of updating to + ${RELNUM}-p${RELPATCHNUM}: + EOF + fi + rm files.updated + + # Create a directory for the install manifest. + MDIR=`mktemp -d install.XXXXXX` || return 1 + + # Populate it + mv INDEX-PRESENT ${MDIR}/INDEX-OLD + mv INDEX-NEW ${MDIR}/INDEX-NEW + + # Link it into place + ln -s ${MDIR} ${BDHASH}-install +} + +# Warn about any upcoming EoL +fetch_warn_eol () { + # What's the current time? + NOWTIME=`date "+%s"` + + # When did we last warn about the EoL date? + if [ -f lasteolwarn ]; then + LASTWARN=`cat lasteolwarn` + else + LASTWARN=`expr ${NOWTIME} - 63072000` + fi + + # If the EoL time is past, warn. + if [ ${EOLTIME} -lt ${NOWTIME} ]; then + echo + cat <<-EOF + WARNING: `uname -sr` HAS PASSED ITS END-OF-LIFE DATE. + Any security issues discovered after `date -r ${EOLTIME}` + will not have been corrected. + EOF + return 1 + fi + + # Figure out how long it has been since we last warned about the + # upcoming EoL, and how much longer we have left. + SINCEWARN=`expr ${NOWTIME} - ${LASTWARN}` + TIMELEFT=`expr ${EOLTIME} - ${NOWTIME}` + + # Don't warn if the EoL is more than 3 months away + if [ ${TIMELEFT} -gt 7884000 ]; then + return 0 + fi + + # Don't warn if the time remaining is more than 3 times the time + # since the last warning. + if [ ${TIMELEFT} -gt `expr ${SINCEWARN} \* 3` ]; then + return 0 + fi + + # Figure out what time units to use. + if [ ${TIMELEFT} -lt 604800 ]; then + UNIT="day" + SIZE=86400 + elif [ ${TIMELEFT} -lt 2678400 ]; then + UNIT="week" + SIZE=604800 + else + UNIT="month" + SIZE=2678400 + fi + + # Compute the right number of units + NUM=`expr ${TIMELEFT} / ${SIZE}` + if [ ${NUM} != 1 ]; then + UNIT="${UNIT}s" + fi + + # Print the warning + echo + cat <<-EOF + WARNING: `uname -sr` is approaching its End-of-Life date. + It is strongly recommended that you upgrade to a newer + release within the next ${NUM} ${UNIT}. + EOF + + # Update the stored time of last warning + echo ${NOWTIME} > lasteolwarn +} + +# Do the actual work involved in "fetch" / "cron". +fetch_run () { + workdir_init || return 1 + + # Prepare the mirror list. + fetch_pick_server_init && fetch_pick_server + + # Try to fetch the public key until we run out of servers. + while ! fetch_key; do + fetch_pick_server || return 1 + done + + # Try to fetch the metadata index signature ("tag") until we run + # out of available servers; and sanity check the downloaded tag. + while ! fetch_tag; do + fetch_pick_server || return 1 + done + fetch_tagsanity || return 1 + + # Fetch the latest INDEX-NEW and INDEX-OLD files. + fetch_metadata INDEX-NEW INDEX-OLD || return 1 + + # Generate filtered INDEX-NEW and INDEX-OLD files containing only + # the lines which (a) belong to components we care about, and (b) + # don't correspond to paths we're explicitly ignoring. + fetch_filter_metadata INDEX-NEW || return 1 + fetch_filter_metadata INDEX-OLD || return 1 + + # Translate /boot/${KERNCONF} into ${KERNELDIR} + fetch_filter_kernel_names INDEX-NEW ${KERNCONF} + fetch_filter_kernel_names INDEX-OLD ${KERNCONF} + + # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the + # system and generate an INDEX-PRESENT file. + fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1 + + # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which + # correspond to lines in INDEX-PRESENT with hashes not appearing + # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in + # INDEX-PRESENT has type - and there isn't a corresponding entry in + # INDEX-OLD with type -. + fetch_filter_unmodified_notpresent \ + INDEX-OLD INDEX-PRESENT INDEX-NEW /dev/null + + # For each entry in INDEX-PRESENT of type -, remove any corresponding + # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries + # of type - from INDEX-PRESENT. + fetch_filter_allowadd INDEX-PRESENT INDEX-NEW + + # If ${ALLOWDELETE} != "yes", then remove any entries from + # INDEX-PRESENT which don't correspond to entries in INDEX-NEW. + fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW + + # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in + # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD, + # replace the corresponding line of INDEX-NEW with one having the + # same metadata as the entry in INDEX-PRESENT. + fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW + + # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical; + # no need to update a file if it isn't changing. + fetch_filter_uptodate INDEX-PRESENT INDEX-NEW + + # Prepare to fetch files: Generate a list of the files we need, + # copy the unmodified files we have into /files/, and generate + # a list of patches to download. + fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1 + + # Fetch files. + fetch_files || return 1 + + # Create and populate install manifest directory; and report what + # updates are available. + fetch_create_manifest || return 1 + + # Warn about any upcoming EoL + fetch_warn_eol || return 1 +} + +# If StrictComponents is not "yes", generate a new components list +# with only the components which appear to be installed. +upgrade_guess_components () { + if [ "${STRICTCOMPONENTS}" = "no" ]; then + # Generate filtered INDEX-ALL with only the components listed + # in COMPONENTS. + fetch_filter_metadata_components $1 || return 1 + + # Tell the user why his disk is suddenly making lots of noise + echo -n "Inspecting system... " + + # Look at the files on disk, and assume that a component is + # supposed to be present if it is more than half-present. + cut -f 1-3 -d '|' < INDEX-ALL | + tr '|' ' ' | + while read C S F; do + if [ -e ${BASEDIR}/${F} ]; then + echo "+ ${C}|${S}" + fi + echo "= ${C}|${S}" + done | + sort | + uniq -c | + sed -E 's,^ +,,' > compfreq + grep ' = ' compfreq | + cut -f 1,3 -d ' ' | + sort -k 2,2 -t ' ' > compfreq.total + grep ' + ' compfreq | + cut -f 1,3 -d ' ' | + sort -k 2,2 -t ' ' > compfreq.present + join -t ' ' -1 2 -2 2 compfreq.present compfreq.total | + while read S P T; do + if [ ${T} -ne 0 -a ${P} -gt `expr ${T} / 2` ]; then + echo ${S} + fi + done > comp.present + cut -f 2 -d ' ' < compfreq.total > comp.total + rm INDEX-ALL compfreq compfreq.total compfreq.present + + # We're done making noise. + echo "done." + + # Sometimes the kernel isn't installed where INDEX-ALL + # thinks that it should be: In particular, it is often in + # /boot/kernel instead of /boot/GENERIC or /boot/SMP. To + # deal with this, if "kernel|X" is listed in comp.total + # (i.e., is a component which would be upgraded if it is + # found to be present) we will add it to comp.present. + # If "kernel|" is in comp.total but "kernel|X" is + # not, we print a warning -- the user is running a kernel + # which isn't part of the release. + KCOMP=`echo ${KERNCONF} | tr 'A-Z' 'a-z'` + grep -E "^kernel\|${KCOMP}\$" comp.total >> comp.present + + if grep -qE "^kernel\|" comp.total && + ! grep -qE "^kernel\|${KCOMP}\$" comp.total; then + cat <<-EOF + +WARNING: This system is running a "${KCOMP}" kernel, which is not a +kernel configuration distributed as part of FreeBSD ${RELNUM}. +This kernel will not be updated: you MUST update the kernel manually +before running '`basename $0` [options] install'. + EOF + fi + + # Re-sort the list of installed components and generate + # the list of non-installed components. + sort -u < comp.present > comp.present.tmp + mv comp.present.tmp comp.present + comm -13 comp.present comp.total > comp.absent + + # Ask the user to confirm that what we have is correct. To + # reduce user confusion, translate "X|Y" back to "X/Y" (as + # subcomponents must be listed in the configuration file). + echo + echo -n "The following components of FreeBSD " + echo "seem to be installed:" + tr '|' '/' < comp.present | + fmt -72 + echo + echo -n "The following components of FreeBSD " + echo "do not seem to be installed:" + tr '|' '/' < comp.absent | + fmt -72 + echo + continuep || return 1 + echo + + # Suck the generated list of components into ${COMPONENTS}. + # Note that comp.present.tmp is used due to issues with + # pipelines and setting variables. + COMPONENTS="" + tr '|' '/' < comp.present > comp.present.tmp + while read C; do + COMPONENTS="${COMPONENTS} ${C}" + done < comp.present.tmp + + # Delete temporary files + rm comp.present comp.present.tmp comp.absent comp.total + fi +} + +# If StrictComponents is not "yes", COMPONENTS contains an entry +# corresponding to the currently running kernel, and said kernel +# does not exist in the new release, add "kernel/generic" to the +# list of components. +upgrade_guess_new_kernel () { + if [ "${STRICTCOMPONENTS}" = "no" ]; then + # Grab the unfiltered metadata file. + METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'` + gunzip -c < files/${METAHASH}.gz > $1.all + + # If "kernel/${KCOMP}" is in ${COMPONENTS} and that component + # isn't in $1.all, we need to add kernel/generic. + for C in ${COMPONENTS}; do + if [ ${C} = "kernel/${KCOMP}" ] && + ! grep -qE "^kernel\|${KCOMP}\|" $1.all; then + COMPONENTS="${COMPONENTS} kernel/generic" + NKERNCONF="GENERIC" + cat <<-EOF + +WARNING: This system is running a "${KCOMP}" kernel, which is not a +kernel configuration distributed as part of FreeBSD ${RELNUM}. +As part of upgrading to FreeBSD ${RELNUM}, this kernel will be +replaced with a "generic" kernel. + EOF + continuep || return 1 + fi + done + + # Don't need this any more... + rm $1.all + fi +} + +# Convert INDEX-OLD (last release) and INDEX-ALL (new release) into +# INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades). +upgrade_oldall_to_oldnew () { + # For each ${F}|... which appears in INDEX-ALL but does not appear + # in INDEX-OLD, add ${F}|-|||||| to INDEX-OLD. + cut -f 1 -d '|' < $1 | + sort -u > $1.paths + cut -f 1 -d '|' < $2 | + sort -u | + comm -13 $1.paths - | + lam - -s "|-||||||" | + sort - $1 > $1.tmp + mv $1.tmp $1 + + # Remove lines from INDEX-OLD which also appear in INDEX-ALL + comm -23 $1 $2 > $1.tmp + mv $1.tmp $1 + + # Remove lines from INDEX-ALL which have a file name not appearing + # anywhere in INDEX-OLD (since these must be files which haven't + # changed -- if they were new, there would be an entry of type "-"). + cut -f 1 -d '|' < $1 | + sort -u > $1.paths + sort -k 1,1 -t '|' < $2 | + join -t '|' - $1.paths | + sort > $2.tmp + rm $1.paths + mv $2.tmp $2 + + # Rename INDEX-ALL to INDEX-NEW. + mv $2 $3 +} + +# Helper for upgrade_merge: Return zero true iff the two files differ only +# in the contents of their RCS tags. +samef () { + X=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $1 | ${SHA256}` + Y=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $2 | ${SHA256}` + + if [ $X = $Y ]; then + return 0; + else + return 1; + fi +} + +# From the list of "old" files in $1, merge changes in $2 with those in $3, +# and update $3 to reflect the hashes of merged files. +upgrade_merge () { + # We only need to do anything if $1 is non-empty. + if [ -s $1 ]; then + cut -f 1 -d '|' $1 | + sort > $1-paths + + # Create staging area for merging files + rm -rf merge/ + while read F; do + D=`dirname ${F}` + mkdir -p merge/old/${D} + mkdir -p merge/${OLDRELNUM}/${D} + mkdir -p merge/${RELNUM}/${D} + mkdir -p merge/new/${D} + done < $1-paths + + # Copy in files + while read F; do + # Currently installed file + V=`look "${F}|" $2 | cut -f 7 -d '|'` + gunzip < files/${V}.gz > merge/old/${F} + + # Old release + if look "${F}|" $1 | fgrep -q "|f|"; then + V=`look "${F}|" $1 | cut -f 3 -d '|'` + gunzip < files/${V}.gz \ + > merge/${OLDRELNUM}/${F} + fi + + # New release + if look "${F}|" $3 | cut -f 1,2,7 -d '|' | + fgrep -q "|f|"; then + V=`look "${F}|" $3 | cut -f 7 -d '|'` + gunzip < files/${V}.gz \ + > merge/${RELNUM}/${F} + fi + done < $1-paths + + # Attempt to automatically merge changes + echo -n "Attempting to automatically merge " + echo -n "changes in files..." + : > failed.merges + while read F; do + # If the file doesn't exist in the new release, + # the result of "merging changes" is having the file + # not exist. + if ! [ -f merge/${RELNUM}/${F} ]; then + continue + fi + + # If the file didn't exist in the old release, we're + # going to throw away the existing file and hope that + # the version from the new release is what we want. + if ! [ -f merge/${OLDRELNUM}/${F} ]; then + cp merge/${RELNUM}/${F} merge/new/${F} + continue + fi + + # Some files need special treatment. + case ${F} in + /etc/spwd.db | /etc/pwd.db | /etc/login.conf.db) + # Don't merge these -- we're rebuild them + # after updates are installed. + cp merge/old/${F} merge/new/${F} + ;; + *) + if ! diff3 -E -m -L "current version" \ + -L "${OLDRELNUM}" -L "${RELNUM}" \ + merge/old/${F} \ + merge/${OLDRELNUM}/${F} \ + merge/${RELNUM}/${F} \ + > merge/new/${F} 2>/dev/null; then + echo ${F} >> failed.merges + fi + ;; + esac + done < $1-paths + echo " done." + + # Ask the user to handle any files which didn't merge. + while read F; do + # If the installed file differs from the version in + # the old release only due to RCS tag expansion + # then just use the version in the new release. + if samef merge/old/${F} merge/${OLDRELNUM}/${F}; then + cp merge/${RELNUM}/${F} merge/new/${F} + continue + fi + + cat <<-EOF + +The following file could not be merged automatically: ${F} +Press Enter to edit this file in ${EDITOR} and resolve the conflicts +manually... + EOF + while true; do + read response /dev/null; then + echo + break + fi + ${EDITOR} `pwd`/merge/new/${F} < /dev/tty + + if ! grep -qE '^(<<<<<<<|=======|>>>>>>>)([[:space:]].*)?$' $(pwd)/merge/new/${F} ; then + break + fi + cat <<-EOF + +Merge conflict markers remain in: ${F} +These must be resolved for the system to be functional. + +Press Enter to return to editing this file, or type "ACCEPT" to carry on with +these lines remaining in the file. + EOF + done + done < failed.merges + rm failed.merges + + # Ask the user to confirm that he likes how the result + # of merging files. + while read F; do + # Skip files which haven't changed except possibly + # in their RCS tags. + if [ -f merge/old/${F} ] && [ -f merge/new/${F} ] && + samef merge/old/${F} merge/new/${F}; then + continue + fi + + # Skip files where the installed file differs from + # the old file only due to RCS tags. + if [ -f merge/old/${F} ] && + [ -f merge/${OLDRELNUM}/${F} ] && + samef merge/old/${F} merge/${OLDRELNUM}/${F}; then + continue + fi + + # Warn about files which are ceasing to exist. + if ! [ -f merge/new/${F} ]; then + cat <<-EOF + +The following file will be removed, as it no longer exists in +FreeBSD ${RELNUM}: ${F} + EOF + continuep < /dev/tty || return 1 + continue + fi + + # Print changes for the user's approval. + cat <<-EOF + +The following changes, which occurred between FreeBSD ${OLDRELNUM} and +FreeBSD ${RELNUM} have been merged into ${F}: +EOF + diff -U 5 -L "current version" -L "new version" \ + merge/old/${F} merge/new/${F} || true + continuep < /dev/tty || return 1 + done < $1-paths + + # Store merged files. + while read F; do + if [ -f merge/new/${F} ]; then + V=`${SHA256} -q merge/new/${F}` + + gzip -c < merge/new/${F} > files/${V}.gz + echo "${F}|${V}" + fi + done < $1-paths > newhashes + + # Pull lines out from $3 which need to be updated to + # reflect merged files. + while read F; do + look "${F}|" $3 + done < $1-paths > $3-oldlines + + # Update lines to reflect merged files + join -t '|' -o 1.1,1.2,1.3,1.4,1.5,1.6,2.2,1.8 \ + $3-oldlines newhashes > $3-newlines + + # Remove old lines from $3 and add new lines. + sort $3-oldlines | + comm -13 - $3 | + sort - $3-newlines > $3.tmp + mv $3.tmp $3 + + # Clean up + rm $1-paths newhashes $3-oldlines $3-newlines + rm -rf merge/ + fi + + # We're done with merging files. + rm $1 +} + +# Do the work involved in fetching upgrades to a new release +upgrade_run () { + workdir_init || return 1 + + # Prepare the mirror list. + fetch_pick_server_init && fetch_pick_server + + # Try to fetch the public key until we run out of servers. + while ! fetch_key; do + fetch_pick_server || return 1 + done + + # Try to fetch the metadata index signature ("tag") until we run + # out of available servers; and sanity check the downloaded tag. + while ! fetch_tag; do + fetch_pick_server || return 1 + done + fetch_tagsanity || return 1 + + # Fetch the INDEX-OLD and INDEX-ALL. + fetch_metadata INDEX-OLD INDEX-ALL || return 1 + + # If StrictComponents is not "yes", generate a new components list + # with only the components which appear to be installed. + upgrade_guess_components INDEX-ALL || return 1 + + # Generate filtered INDEX-OLD and INDEX-ALL files containing only + # the components we want and without anything marked as "Ignore". + fetch_filter_metadata INDEX-OLD || return 1 + fetch_filter_metadata INDEX-ALL || return 1 + + # Merge the INDEX-OLD and INDEX-ALL files into INDEX-OLD. + sort INDEX-OLD INDEX-ALL > INDEX-OLD.tmp + mv INDEX-OLD.tmp INDEX-OLD + rm INDEX-ALL + + # Adjust variables for fetching files from the new release. + OLDRELNUM=${RELNUM} + RELNUM=${TARGETRELEASE} + OLDFETCHDIR=${FETCHDIR} + FETCHDIR=${RELNUM}/${ARCH} + + # Try to fetch the NEW metadata index signature ("tag") until we run + # out of available servers; and sanity check the downloaded tag. + while ! fetch_tag; do + fetch_pick_server || return 1 + done + + # Fetch the new INDEX-ALL. + fetch_metadata INDEX-ALL || return 1 + + # If StrictComponents is not "yes", COMPONENTS contains an entry + # corresponding to the currently running kernel, and said kernel + # does not exist in the new release, add "kernel/generic" to the + # list of components. + upgrade_guess_new_kernel INDEX-ALL || return 1 + + # Filter INDEX-ALL to contain only the components we want and without + # anything marked as "Ignore". + fetch_filter_metadata INDEX-ALL || return 1 + + # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into + # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades). + upgrade_oldall_to_oldnew INDEX-OLD INDEX-ALL INDEX-NEW + + # Translate /boot/${KERNCONF} or /boot/${NKERNCONF} into ${KERNELDIR} + fetch_filter_kernel_names INDEX-NEW ${NKERNCONF} + fetch_filter_kernel_names INDEX-OLD ${KERNCONF} + + # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the + # system and generate an INDEX-PRESENT file. + fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1 + + # Based on ${MERGECHANGES}, generate a file tomerge-old with the + # paths and hashes of old versions of files to merge. + fetch_filter_mergechanges INDEX-OLD INDEX-PRESENT INDEX-NEW tomerge-old + + # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which + # correspond to lines in INDEX-PRESENT with hashes not appearing + # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in + # INDEX-PRESENT has type - and there isn't a corresponding entry in + # INDEX-OLD with type -. + fetch_filter_unmodified_notpresent \ + INDEX-OLD INDEX-PRESENT INDEX-NEW tomerge-old + + # For each entry in INDEX-PRESENT of type -, remove any corresponding + # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries + # of type - from INDEX-PRESENT. + fetch_filter_allowadd INDEX-PRESENT INDEX-NEW + + # If ${ALLOWDELETE} != "yes", then remove any entries from + # INDEX-PRESENT which don't correspond to entries in INDEX-NEW. + fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW + + # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in + # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD, + # replace the corresponding line of INDEX-NEW with one having the + # same metadata as the entry in INDEX-PRESENT. + fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW + + # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical; + # no need to update a file if it isn't changing. + fetch_filter_uptodate INDEX-PRESENT INDEX-NEW + + # Fetch "clean" files from the old release for merging changes. + fetch_files_premerge tomerge-old + + # Prepare to fetch files: Generate a list of the files we need, + # copy the unmodified files we have into /files/, and generate + # a list of patches to download. + fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1 + + # Fetch patches from to-${RELNUM}/${ARCH}/bp/ + PATCHDIR=to-${RELNUM}/${ARCH}/bp + fetch_files || return 1 + + # Merge configuration file changes. + upgrade_merge tomerge-old INDEX-PRESENT INDEX-NEW || return 1 + + # Create and populate install manifest directory; and report what + # updates are available. + fetch_create_manifest || return 1 + + # Leave a note behind to tell the "install" command that the kernel + # needs to be installed before the world. + touch ${BDHASH}-install/kernelfirst + + # Remind the user that they need to run "freebsd-update install" + # to install the downloaded bits, in case they didn't RTFM. + echo "To install the downloaded upgrades, run '`basename $0` [options] install'." +} + +# Make sure that all the file hashes mentioned in $@ have corresponding +# gzipped files stored in /files/. +install_verify () { + # Generate a list of hashes + cat $@ | + cut -f 2,7 -d '|' | + grep -E '^f' | + cut -f 2 -d '|' | + sort -u > filelist + + # Make sure all the hashes exist + while read HASH; do + if ! [ -f files/${HASH}.gz ]; then + echo -n "Update files missing -- " + echo "this should never happen." + echo "Re-run '`basename $0` [options] fetch'." + return 1 + fi + done < filelist + + # Clean up + rm filelist +} + +# Remove the system immutable flag from files +install_unschg () { + # Generate file list + cat $@ | + cut -f 1 -d '|' > filelist + + # Remove flags + while read F; do + if ! [ -e ${BASEDIR}/${F} ]; then + continue + else + echo ${BASEDIR}/${F} + fi + done < filelist | xargs chflags noschg || return 1 + + # Clean up + rm filelist +} + +# Decide which directory name to use for kernel backups. +backup_kernel_finddir () { + CNT=0 + while true ; do + # Pathname does not exist, so it is OK use that name + # for backup directory. + if [ ! -e $BASEDIR/$BACKUPKERNELDIR ]; then + return 0 + fi + + # If directory do exist, we only use if it has our + # marker file. + if [ -d $BASEDIR/$BACKUPKERNELDIR -a \ + -e $BASEDIR/$BACKUPKERNELDIR/.freebsd-update ]; then + return 0 + fi + + # We could not use current directory name, so add counter to + # the end and try again. + CNT=$((CNT + 1)) + if [ $CNT -gt 9 ]; then + echo "Could not find valid backup dir ($BASEDIR/$BACKUPKERNELDIR)" + exit 1 + fi + BACKUPKERNELDIR="`echo $BACKUPKERNELDIR | sed -Ee 's/[0-9]\$//'`" + BACKUPKERNELDIR="${BACKUPKERNELDIR}${CNT}" + done +} + +# Backup the current kernel using hardlinks, if not disabled by user. +# Since we delete all files in the directory used for previous backups +# we create a marker file called ".freebsd-update" in the directory so +# we can determine on the next run that the directory was created by +# freebsd-update and we then do not accidentally remove user files in +# the unlikely case that the user has created a directory with a +# conflicting name. +backup_kernel () { + # Only make kernel backup is so configured. + if [ $BACKUPKERNEL != yes ]; then + return 0 + fi + + # Decide which directory name to use for kernel backups. + backup_kernel_finddir + + # Remove old kernel backup files. If $BACKUPKERNELDIR was + # "not ours", backup_kernel_finddir would have exited, so + # deleting the directory content is as safe as we can make it. + if [ -d $BASEDIR/$BACKUPKERNELDIR ]; then + rm -fr $BASEDIR/$BACKUPKERNELDIR + fi + + # Create directories for backup. + mkdir -p $BASEDIR/$BACKUPKERNELDIR + mtree -cdn -p "${BASEDIR}/${KERNELDIR}" | \ + mtree -Ue -p "${BASEDIR}/${BACKUPKERNELDIR}" > /dev/null + + # Mark the directory as having been created by freebsd-update. + touch $BASEDIR/$BACKUPKERNELDIR/.freebsd-update + if [ $? -ne 0 ]; then + echo "Could not create kernel backup directory" + exit 1 + fi + + # Disable pathname expansion to be sure *.symbols is not + # expanded. + set -f + + # Use find to ignore symbol files, unless disabled by user. + if [ $BACKUPKERNELSYMBOLFILES = yes ]; then + FINDFILTER="" + else + FINDFILTER="-a ! -name *.debug -a ! -name *.symbols" + fi + + # Backup all the kernel files using hardlinks. + (cd ${BASEDIR}/${KERNELDIR} && find . -type f $FINDFILTER -exec \ + cp -pl '{}' ${BASEDIR}/${BACKUPKERNELDIR}/'{}' \;) + + # Re-enable pathname expansion. + set +f +} + +# Check for and remove an existing directory that conflicts with the file or +# symlink that we are going to install. +dir_conflict () { + if [ -d "$1" ]; then + echo "Removing conflicting directory $1" + rm -rf -- "$1" + fi +} + +# Install new files +install_from_index () { + # First pass: Do everything apart from setting file flags. We + # can't set flags yet, because schg inhibits hard linking. + sort -k 1,1 -t '|' $1 | + tr '|' ' ' | + while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do + case ${TYPE} in + d) + # Create a directory. A file may change to a directory + # on upgrade (PR273661). If that happens, remove the + # file first. + if [ -e "${BASEDIR}/${FPATH}" ] && \ + ! [ -d "${BASEDIR}/${FPATH}" ]; then + rm -f -- "${BASEDIR}/${FPATH}" + fi + install -d -o ${OWNER} -g ${GROUP} \ + -m ${PERM} ${BASEDIR}/${FPATH} + ;; + f) + dir_conflict "${BASEDIR}/${FPATH}" + if [ -z "${LINK}" ]; then + # Create a file, without setting flags. + gunzip < files/${HASH}.gz > ${HASH} + install -S -o ${OWNER} -g ${GROUP} \ + -m ${PERM} ${HASH} ${BASEDIR}/${FPATH} + rm ${HASH} + else + # Create a hard link. + ln -f ${BASEDIR}/${LINK} ${BASEDIR}/${FPATH} + fi + ;; + L) + dir_conflict "${BASEDIR}/${FPATH}" + # Create a symlink + ln -sfh ${HASH} ${BASEDIR}/${FPATH} + ;; + esac + done + + # Perform a second pass, adding file flags. + tr '|' ' ' < $1 | + while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do + if [ ${TYPE} = "f" ] && + ! [ ${FLAGS} = "0" ]; then + chflags ${FLAGS} ${BASEDIR}/${FPATH} + fi + done +} + +# Remove files which we want to delete +install_delete () { + # Generate list of new files + cut -f 1 -d '|' < $2 | + sort > newfiles + + # Generate subindex of old files we want to nuke + sort -k 1,1 -t '|' $1 | + join -t '|' -v 1 - newfiles | + sort -r -k 1,1 -t '|' | + cut -f 1,2 -d '|' | + tr '|' ' ' > killfiles + + # Remove the offending bits + while read FPATH TYPE; do + case ${TYPE} in + d) + rmdir ${BASEDIR}/${FPATH} + ;; + f) + if [ -f "${BASEDIR}/${FPATH}" ]; then + rm "${BASEDIR}/${FPATH}" + fi + ;; + L) + if [ -L "${BASEDIR}/${FPATH}" ]; then + rm "${BASEDIR}/${FPATH}" + fi + ;; + esac + done < killfiles + + # Clean up + rm newfiles killfiles +} + +# Install new files, delete old files, and update generated files +install_files () { + # If we haven't already dealt with the kernel, deal with it. + if ! [ -f $1/kerneldone ]; then + grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD + grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW + + # Backup current kernel before installing a new one + backup_kernel || return 1 + + # Install new files + install_from_index INDEX-NEW || return 1 + + # Remove files which need to be deleted + install_delete INDEX-OLD INDEX-NEW || return 1 + + # Update linker.hints if necessary + if [ -s INDEX-OLD -o -s INDEX-NEW ]; then + kldxref -R ${BASEDIR}/boot/ 2>/dev/null + fi + + # We've finished updating the kernel. + touch $1/kerneldone + + # Do we need to ask for a reboot now? + if [ -f $1/kernelfirst ] && + [ -s INDEX-OLD -o -s INDEX-NEW ]; then + cat <<-EOF + +Kernel updates have been installed. Please reboot and run +'`basename $0` [options] install' again to finish installing updates. + EOF + exit 0 + fi + fi + + # If we haven't already dealt with the world, deal with it. + if ! [ -f $1/worlddone ]; then + # Create any necessary directories first + grep -vE '^/boot/' $1/INDEX-NEW | + grep -E '^[^|]+\|d\|' > INDEX-NEW + install_from_index INDEX-NEW || return 1 + + # Install new runtime linker + grep -vE '^/boot/' $1/INDEX-NEW | + grep -vE '^[^|]+\|d\|' | + grep -E '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' > INDEX-NEW + install_from_index INDEX-NEW || return 1 + + # Next, in order, libsys, libc, and libthr. + grep -vE '^/boot/' $1/INDEX-NEW | + grep -vE '^[^|]+\|d\|' | + grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' | + grep -E '^[^|]*/lib/libsys\.so\.[0-9]+\|' > INDEX-NEW + install_from_index INDEX-NEW || return 1 + grep -vE '^/boot/' $1/INDEX-NEW | + grep -vE '^[^|]+\|d\|' | + grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' | + grep -E '^[^|]*/lib/libc\.so\.[0-9]+\|' > INDEX-NEW + install_from_index INDEX-NEW || return 1 + grep -vE '^/boot/' $1/INDEX-NEW | + grep -vE '^[^|]+\|d\|' | + grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' | + grep -E '^[^|]*/lib/libthr\.so\.[0-9]+\|' > INDEX-NEW + install_from_index INDEX-NEW || return 1 + + # Install the rest of the shared libraries next + grep -vE '^/boot/' $1/INDEX-NEW | + grep -vE '^[^|]+\|d\|' | + grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' | + grep -vE '^[^|]*/lib/(libsys|libc|libthr)\.so\.[0-9]+\|' | + grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW + install_from_index INDEX-NEW || return 1 + + # Deal with everything else + grep -vE '^/boot/' $1/INDEX-OLD | + grep -vE '^[^|]+\|d\|' | + grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' | + grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD + grep -vE '^/boot/' $1/INDEX-NEW | + grep -vE '^[^|]+\|d\|' | + grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' | + grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW + install_from_index INDEX-NEW || return 1 + install_delete INDEX-OLD INDEX-NEW || return 1 + + # Restart host sshd if running (PR263489). Note that this does + # not affect child sshd processes handling existing sessions. + if [ "$BASEDIR" = / ] && \ + service sshd status >/dev/null 2>/dev/null; then + echo + echo "Restarting sshd after upgrade" + service sshd restart + fi + + # Rehash certs if we actually have certctl installed. + if which certctl>/dev/null; then + env DESTDIR=${BASEDIR} certctl rehash + fi + + # Rebuild generated pwd files and /etc/login.conf.db. + pwd_mkdb -d ${BASEDIR}/etc -p ${BASEDIR}/etc/master.passwd + cap_mkdb ${BASEDIR}/etc/login.conf + + # Rebuild man page databases, if necessary. + for D in /usr/share/man /usr/share/openssl/man; do + if [ ! -d ${BASEDIR}/$D ]; then + continue + fi + if [ -f ${BASEDIR}/$D/mandoc.db ] && \ + [ -z "$(find ${BASEDIR}/$D -type f -newer ${BASEDIR}/$D/mandoc.db)" ]; then + continue; + fi + makewhatis ${BASEDIR}/$D + done + + # We've finished installing the world and deleting old files + # which are not shared libraries. + touch $1/worlddone + + # Do we need to ask the user to portupgrade now? + grep -vE '^/boot/' $1/INDEX-NEW | + grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' | + cut -f 1 -d '|' | + sort > newfiles + if grep -vE '^/boot/' $1/INDEX-OLD | + grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' | + cut -f 1 -d '|' | + sort | + join -v 1 - newfiles | + grep -q .; then + cat <<-EOF + +Completing this upgrade requires removing old shared object files. +Please rebuild all installed 3rd party software (e.g., programs +installed from the ports tree) and then run +'`basename $0` [options] install' again to finish installing updates. + EOF + rm newfiles + exit 0 + fi + rm newfiles + fi + + # Remove old shared libraries + grep -vE '^/boot/' $1/INDEX-NEW | + grep -vE '^[^|]+\|d\|' | + grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW + grep -vE '^/boot/' $1/INDEX-OLD | + grep -vE '^[^|]+\|d\|' | + grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD + install_delete INDEX-OLD INDEX-NEW || return 1 + + # Remove old directories + grep -vE '^/boot/' $1/INDEX-NEW | + grep -E '^[^|]+\|d\|' > INDEX-NEW + grep -vE '^/boot/' $1/INDEX-OLD | + grep -E '^[^|]+\|d\|' > INDEX-OLD + install_delete INDEX-OLD INDEX-NEW || return 1 + + # Remove temporary files + rm INDEX-OLD INDEX-NEW +} + +# Rearrange bits to allow the installed updates to be rolled back +install_setup_rollback () { + # Remove the "reboot after installing kernel", "kernel updated", and + # "finished installing the world" flags if present -- they are + # irrelevant when rolling back updates. + if [ -f ${BDHASH}-install/kernelfirst ]; then + rm ${BDHASH}-install/kernelfirst + rm ${BDHASH}-install/kerneldone + fi + if [ -f ${BDHASH}-install/worlddone ]; then + rm ${BDHASH}-install/worlddone + fi + + if [ -L ${BDHASH}-rollback ]; then + mv ${BDHASH}-rollback ${BDHASH}-install/rollback + fi + + mv ${BDHASH}-install ${BDHASH}-rollback +} + +# Actually install updates +install_run () { + echo -n "Installing updates..." + + # Make sure we have all the files we should have + install_verify ${BDHASH}-install/INDEX-OLD \ + ${BDHASH}-install/INDEX-NEW || return 1 + + # Remove system immutable flag from files + install_unschg ${BDHASH}-install/INDEX-OLD \ + ${BDHASH}-install/INDEX-NEW || return 1 + + # Install new files, delete old files, and update linker.hints + install_files ${BDHASH}-install || return 1 + + # Rearrange bits to allow the installed updates to be rolled back + install_setup_rollback + + echo " done." +} + +# Rearrange bits to allow the previous set of updates to be rolled back next. +rollback_setup_rollback () { + if [ -L ${BDHASH}-rollback/rollback ]; then + mv ${BDHASH}-rollback/rollback rollback-tmp + rm -r ${BDHASH}-rollback/ + rm ${BDHASH}-rollback + mv rollback-tmp ${BDHASH}-rollback + else + rm -r ${BDHASH}-rollback/ + rm ${BDHASH}-rollback + fi +} + +# Install old files, delete new files, and update linker.hints +rollback_files () { + # Create directories first. They may be needed by files we will + # install in subsequent steps (PR273950). + awk -F \| '{if ($2 == "d") print }' $1/INDEX-OLD > INDEX-OLD + install_from_index INDEX-OLD || return 1 + + # Install old shared library files which don't have the same path as + # a new shared library file. + grep -vE '^/boot/' $1/INDEX-NEW | + grep -E '/lib/.*\.so\.[0-9]+\|' | + cut -f 1 -d '|' | + sort > INDEX-NEW.libs.flist + grep -vE '^/boot/' $1/INDEX-OLD | + grep -E '/lib/.*\.so\.[0-9]+\|' | + sort -k 1,1 -t '|' - | + join -t '|' -v 1 - INDEX-NEW.libs.flist > INDEX-OLD + install_from_index INDEX-OLD || return 1 + + # Deal with files which are neither kernel nor shared library + grep -vE '^/boot/' $1/INDEX-OLD | + grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD + grep -vE '^/boot/' $1/INDEX-NEW | + grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW + install_from_index INDEX-OLD || return 1 + install_delete INDEX-NEW INDEX-OLD || return 1 + + # Install any old shared library files which we didn't install above. + grep -vE '^/boot/' $1/INDEX-OLD | + grep -E '/lib/.*\.so\.[0-9]+\|' | + sort -k 1,1 -t '|' - | + join -t '|' - INDEX-NEW.libs.flist > INDEX-OLD + install_from_index INDEX-OLD || return 1 + + # Delete unneeded shared library files + grep -vE '^/boot/' $1/INDEX-OLD | + grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD + grep -vE '^/boot/' $1/INDEX-NEW | + grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW + install_delete INDEX-NEW INDEX-OLD || return 1 + + # Deal with kernel files + grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD + grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW + install_from_index INDEX-OLD || return 1 + install_delete INDEX-NEW INDEX-OLD || return 1 + if [ -s INDEX-OLD -o -s INDEX-NEW ]; then + kldxref -R /boot/ 2>/dev/null + fi + + # Remove temporary files + rm INDEX-OLD INDEX-NEW INDEX-NEW.libs.flist +} + +# Actually rollback updates +rollback_run () { + echo -n "Uninstalling updates..." + + # If there are updates waiting to be installed, remove them; we + # want the user to re-run 'fetch' after rolling back updates. + if [ -L ${BDHASH}-install ]; then + rm -r ${BDHASH}-install/ + rm ${BDHASH}-install + fi + + # Make sure we have all the files we should have + install_verify ${BDHASH}-rollback/INDEX-NEW \ + ${BDHASH}-rollback/INDEX-OLD || return 1 + + # Remove system immutable flag from files + install_unschg ${BDHASH}-rollback/INDEX-NEW \ + ${BDHASH}-rollback/INDEX-OLD || return 1 + + # Install old files, delete new files, and update linker.hints + rollback_files ${BDHASH}-rollback || return 1 + + # Remove the rollback directory and the symlink pointing to it; and + # rearrange bits to allow the previous set of updates to be rolled + # back next. + rollback_setup_rollback + + echo " done." +} + +# Compare INDEX-ALL and INDEX-PRESENT and print warnings about differences. +IDS_compare () { + # Get all the lines which mismatch in something other than file + # flags. We ignore file flags because sysinstall doesn't seem to + # set them when it installs FreeBSD; warning about these adds a + # very large amount of noise. + cut -f 1-5,7-8 -d '|' $1 > $1.noflags + sort -k 1,1 -t '|' $1.noflags > $1.sorted + cut -f 1-5,7-8 -d '|' $2 | + comm -13 $1.noflags - | + fgrep -v '|-|||||' | + sort -k 1,1 -t '|' | + join -t '|' $1.sorted - > INDEX-NOTMATCHING + + # Ignore files which match IDSIGNOREPATHS. + for X in ${IDSIGNOREPATHS}; do + grep -E "^${X}" INDEX-NOTMATCHING + done | + sort -u | + comm -13 - INDEX-NOTMATCHING > INDEX-NOTMATCHING.tmp + mv INDEX-NOTMATCHING.tmp INDEX-NOTMATCHING + + # Go through the lines and print warnings. + local IFS='|' + while read FPATH TYPE OWNER GROUP PERM HASH LINK P_TYPE P_OWNER P_GROUP P_PERM P_HASH P_LINK; do + # Warn about different object types. + if ! [ "${TYPE}" = "${P_TYPE}" ]; then + echo -n "${FPATH} is a " + case "${P_TYPE}" in + f) echo -n "regular file, " + ;; + d) echo -n "directory, " + ;; + L) echo -n "symlink, " + ;; + esac + echo -n "but should be a " + case "${TYPE}" in + f) echo -n "regular file." + ;; + d) echo -n "directory." + ;; + L) echo -n "symlink." + ;; + esac + echo + + # Skip other tests, since they don't make sense if + # we're comparing different object types. + continue + fi + + # Warn about different owners. + if ! [ "${OWNER}" = "${P_OWNER}" ]; then + echo -n "${FPATH} is owned by user id ${P_OWNER}, " + echo "but should be owned by user id ${OWNER}." + fi + + # Warn about different groups. + if ! [ "${GROUP}" = "${P_GROUP}" ]; then + echo -n "${FPATH} is owned by group id ${P_GROUP}, " + echo "but should be owned by group id ${GROUP}." + fi + + # Warn about different permissions. We do not warn about + # different permissions on symlinks, since some archivers + # don't extract symlink permissions correctly and they are + # ignored anyway. + if ! [ "${PERM}" = "${P_PERM}" ] && + ! [ "${TYPE}" = "L" ]; then + echo -n "${FPATH} has ${P_PERM} permissions, " + echo "but should have ${PERM} permissions." + fi + + # Warn about different file hashes / symlink destinations. + if ! [ "${HASH}" = "${P_HASH}" ]; then + if [ "${TYPE}" = "L" ]; then + echo -n "${FPATH} is a symlink to ${P_HASH}, " + echo "but should be a symlink to ${HASH}." + fi + if [ "${TYPE}" = "f" ]; then + echo -n "${FPATH} has SHA256 hash ${P_HASH}, " + echo "but should have SHA256 hash ${HASH}." + fi + fi + + # We don't warn about different hard links, since some + # some archivers break hard links, and as long as the + # underlying data is correct they really don't matter. + done < INDEX-NOTMATCHING + + # Clean up + rm $1 $1.noflags $1.sorted $2 INDEX-NOTMATCHING +} + +# Do the work involved in comparing the system to a "known good" index +IDS_run () { + workdir_init || return 1 + + # Prepare the mirror list. + fetch_pick_server_init && fetch_pick_server + + # Try to fetch the public key until we run out of servers. + while ! fetch_key; do + fetch_pick_server || return 1 + done + + # Try to fetch the metadata index signature ("tag") until we run + # out of available servers; and sanity check the downloaded tag. + while ! fetch_tag; do + fetch_pick_server || return 1 + done + fetch_tagsanity || return 1 + + # Fetch INDEX-OLD and INDEX-ALL. + fetch_metadata INDEX-OLD INDEX-ALL || return 1 + + # Generate filtered INDEX-OLD and INDEX-ALL files containing only + # the components we want and without anything marked as "Ignore". + fetch_filter_metadata INDEX-OLD || return 1 + fetch_filter_metadata INDEX-ALL || return 1 + + # Merge the INDEX-OLD and INDEX-ALL files into INDEX-ALL. + sort INDEX-OLD INDEX-ALL > INDEX-ALL.tmp + mv INDEX-ALL.tmp INDEX-ALL + rm INDEX-OLD + + # Translate /boot/${KERNCONF} to ${KERNELDIR} + fetch_filter_kernel_names INDEX-ALL ${KERNCONF} + + # Inspect the system and generate an INDEX-PRESENT file. + fetch_inspect_system INDEX-ALL INDEX-PRESENT /dev/null || return 1 + + # Compare INDEX-ALL and INDEX-PRESENT and print warnings about any + # differences. + IDS_compare INDEX-ALL INDEX-PRESENT +} + +#### Main functions -- call parameter-handling and core functions + +# Using the command line, configuration file, and defaults, +# set all the parameters which are needed later. +get_params () { + init_params + parse_cmdline $@ + parse_conffile + default_params +} + +# Fetch command. Make sure that we're being called +# interactively, then run fetch_check_params and fetch_run +cmd_fetch () { + finalize_components_config ${COMPONENTS} + if [ ! -t 0 -a $NOTTYOK -eq 0 ]; then + echo -n "`basename $0` fetch should not " + echo "be run non-interactively." + echo "Run `basename $0` cron instead." + exit 1 + fi + fetch_check_params + fetch_run || exit 1 + ISFETCHED=1 +} + +# Cron command. Make sure the parameters are sensible; wait +# rand(3600) seconds; then fetch updates. While fetching updates, +# send output to a temporary file; only print that file if the +# fetching failed. +cmd_cron () { + fetch_check_params + sleep `jot -r 1 0 3600` + + TMPFILE=`mktemp /tmp/freebsd-update.XXXXXX` || exit 1 + finalize_components_config ${COMPONENTS} >> ${TMPFILE} + if ! fetch_run >> ${TMPFILE} || + ! grep -q "No updates needed" ${TMPFILE} || + [ ${VERBOSELEVEL} = "debug" ]; then + mail -s "`hostname` security updates" ${MAILTO} < ${TMPFILE} + fi + ISFETCHED=1 + + rm ${TMPFILE} +} + +# Fetch files for upgrading to a new release. +cmd_upgrade () { + finalize_components_config ${COMPONENTS} + upgrade_check_params + upgrade_run || exit 1 +} + +# Check if there are fetched updates ready to install. +# Chdir into the working directory. +cmd_updatesready () { + finalize_components_config ${COMPONENTS} + # Check if working directory exists (if not, no updates pending) + if ! [ -e "${WORKDIR}" ]; then + echo "No updates are available to install." + exit 2 + fi + + # Change into working directory (fail if no permission/directory etc.) + cd ${WORKDIR} || exit 1 + + # Construct a unique name from ${BASEDIR} + BDHASH=`echo ${BASEDIR} | sha256 -q` + + # Check that we have updates ready to install + if ! [ -L ${BDHASH}-install ]; then + echo "No updates are available to install." + exit 2 + fi + + echo "There are updates available to install." + echo "Run '`basename $0` [options] install' to proceed." +} + +# Install downloaded updates. +cmd_install () { + finalize_components_config ${COMPONENTS} + install_check_params + install_create_be + install_run || exit 1 +} + +# Rollback most recently installed updates. +cmd_rollback () { + finalize_components_config ${COMPONENTS} + rollback_check_params + rollback_run || exit 1 +} + +# Compare system against a "known good" index. +cmd_IDS () { + finalize_components_config ${COMPONENTS} + IDS_check_params + IDS_run || exit 1 +} + +# Output configuration. +cmd_showconfig () { + finalize_components_config ${COMPONENTS} + for X in ${CONFIGOPTIONS}; do + echo $X=$(eval echo \$${X}) + done +} + +#### Entry point + +# Make sure we find utilities from the base system +export PATH=/sbin:/bin:/usr/sbin:/usr/bin:${PATH} + +# Set a pager if the user doesn't +if [ -z "$PAGER" ]; then + PAGER=/usr/bin/less +fi + +# Set LC_ALL in order to avoid problems with character ranges like [A-Z]. +export LC_ALL=C + +# Clear environment variables that may affect operation of tools that we use. +unset GREP_OPTIONS + +# Disallow use with packaged base. +check_pkgbase + +get_params $@ +for COMMAND in ${COMMANDS}; do + cmd_${COMMAND} +done diff --git a/conf/system/freebsd-update/14.3/freebsd-update.conf b/conf/system/freebsd-update/14.3/freebsd-update.conf new file mode 100644 index 0000000..08cf512 --- /dev/null +++ b/conf/system/freebsd-update/14.3/freebsd-update.conf @@ -0,0 +1,78 @@ + +# Trusted keyprint. Changing this is a Bad Idea unless you've received +# a PGP-signed email from telling you to +# change it and explaining why. +KeyPrint 800651ef4b4c71c27e60786d7b487188970f4b4169cc055784e21eb71d410cc5 + +# Server or server pool from which to fetch updates. You can change +# this to point at a specific server if you want, but in most cases +# using a "nearby" server won't provide a measurable improvement in +# performance. +ServerName update.FreeBSD.org + +# Components of the base system which should be kept updated. +Components src world kernel + +# Example for updating the userland and the kernel source code only: +# Components src/base src/sys world + +# Paths which start with anything matching an entry in an IgnorePaths +# statement will be ignored. +IgnorePaths + +# Paths which start with anything matching an entry in an IDSIgnorePaths +# statement will be ignored by "freebsd-update IDS". +IDSIgnorePaths /usr/share/man/cat +IDSIgnorePaths /usr/share/man/whatis +IDSIgnorePaths /var/db/locate.database +IDSIgnorePaths /var/log + +# Paths which start with anything matching an entry in an UpdateIfUnmodified +# statement will only be updated if the contents of the file have not been +# modified by the user (unless changes are merged; see below). +UpdateIfUnmodified /etc/ /var/ /root/ /.cshrc /.profile + +# When upgrading to a new FreeBSD release, files which match MergeChanges +# will have any local changes merged into the version from the new release. +MergeChanges /etc/ /boot/device.hints + +### Default configuration options: + +# Directory in which to store downloaded updates and temporary +# files used by FreeBSD Update. +# WorkDir /var/db/freebsd-update + +# Destination to send output of "freebsd-update cron" if an error +# occurs or updates have been downloaded. +# MailTo root + +# Is FreeBSD Update allowed to create new files? +# AllowAdd yes + +# Is FreeBSD Update allowed to delete files? +# AllowDelete yes + +# If the user has modified file ownership, permissions, or flags, should +# FreeBSD Update retain this modified metadata when installing a new version +# of that file? +# KeepModifiedMetadata yes + +# When upgrading between releases, should the list of Components be +# read strictly (StrictComponents yes) or merely as a list of components +# which *might* be installed of which FreeBSD Update should figure out +# which actually are installed and upgrade those (StrictComponents no)? +# StrictComponents no + +# When installing a new kernel perform a backup of the old one first +# so it is possible to boot the old kernel in case of problems. +# BackupKernel yes + +# If BackupKernel is enabled, the backup kernel is saved to this +# directory. +# BackupKernelDir /boot/kernel.old + +# When backing up a kernel also back up debug symbol files? +# BackupKernelSymbolFiles no + +# Create a new boot environment when installing patches +# CreateBootEnv yes diff --git a/conf/system/include/14.2/ar b/conf/system/include/14.2/ar new file mode 100755 index 0000000..5d7523b Binary files /dev/null and b/conf/system/include/14.2/ar differ diff --git a/conf/system/include/14.2/diff3 b/conf/system/include/14.2/diff3 new file mode 100755 index 0000000..72f3413 Binary files /dev/null and b/conf/system/include/14.2/diff3 differ diff --git a/conf/system/include/14.2/jib b/conf/system/include/14.2/jib new file mode 100755 index 0000000..55d9084 --- /dev/null +++ b/conf/system/include/14.2/jib @@ -0,0 +1,417 @@ +#!/bin/sh +#- +# Copyright (c) 2016 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +############################################################ IDENT(1) +# +# $Title: if_bridge(4) management script for vnet jails $ +# +############################################################ INFORMATION +# +# Use this tool with jail.conf(5) (or rc.conf(5) ``legacy'' configuration) to +# manage `vnet' interfaces for jails. Designed to automate the creation of vnet +# interface(s) during jail `prestart' and destroy said interface(s) during jail +# `poststop'. +# +# In jail.conf(5) format: +# +# ### BEGIN EXCERPT ### +# +# xxx { +# host.hostname = "xxx.yyy"; +# path = "/vm/xxx"; +# +# # +# # NB: Below 2-lines required +# # NB: The number of eNb_xxx interfaces should match the number of +# # arguments given to `jib addm xxx' in exec.prestart value. +# # +# vnet; +# vnet.interface = e0b_xxx, e1b_xxx, ...; +# +# exec.clean; +# exec.system_user = "root"; +# exec.jail_user = "root"; +# +# # +# # NB: Below 2-lines required +# # NB: The number of arguments after `jib addm xxx' should match +# # the number of eNb_xxx arguments in vnet.interface value. +# # +# exec.prestart += "jib addm xxx em0 em1 ..."; +# exec.poststop += "jib destroy xxx"; +# +# # Standard recipe +# exec.start += "/bin/sh /etc/rc"; +# exec.stop = "/bin/sh /etc/rc.shutdown jail"; +# exec.consolelog = "/var/log/jail_xxx_console.log"; +# mount.devfs; +# +# # Optional (default off) +# #allow.mount; +# #allow.set_hostname = 1; +# #allow.sysvipc = 1; +# #devfs_ruleset = "11"; # rule to unhide bpf for DHCP +# } +# +# ### END EXCERPT ### +# +# In rc.conf(5) ``legacy'' format (used when /etc/jail.conf does not exist): +# +# ### BEGIN EXCERPT ### +# +# jail_enable="YES" +# jail_list="xxx" +# +# # +# # Global presets for all jails +# # +# jail_devfs_enable="YES" # mount devfs +# +# # +# # Global options (default off) +# # +# #jail_mount_enable="YES" # mount /etc/fstab.{name} +# #jail_set_hostname_allow="YES" # Allow hostname to change +# #jail_sysvipc_allow="YES" # Allow SysV Interprocess Comm. +# +# # xxx +# jail_xxx_hostname="xxx.shxd.cx" # hostname +# jail_xxx_rootdir="/vm/xxx" # root directory +# jail_xxx_vnet_interfaces="e0b_xxx e1bxxx ..." # vnet interface(s) +# jail_xxx_exec_prestart0="jib addm xxx em0 em1 ..." # bridge interface(s) +# jail_xxx_exec_poststop0="jib destroy xxx" # destroy interface(s) +# #jail_xxx_mount_enable="YES" # mount /etc/fstab.xxx +# #jail_xxx_devfs_ruleset="11" # rule to unhide bpf for DHCP +# +# ### END EXCERPT ### +# +# Note that the legacy rc.conf(5) format is converted to +# /var/run/jail.{name}.conf by /etc/rc.d/jail if jail.conf(5) is missing. +# +# ASIDE: dhclient(8) inside a vnet jail... +# +# To allow dhclient(8) to work inside a vnet jail, make sure the following +# appears in /etc/devfs.rules (which should be created if it doesn't exist): +# +# [devfsrules_jail=11] +# add include $devfsrules_hide_all +# add include $devfsrules_unhide_basic +# add include $devfsrules_unhide_login +# add path 'bpf*' unhide +# +# And set ether devfs.ruleset="11" (jail.conf(5)) or +# jail_{name}_devfs_ruleset="11" (rc.conf(5)). +# +# NB: While this tool can't create every type of desirable topology, it should +# handle most setups, minus some which considered exotic or purpose-built. +# +############################################################ GLOBALS + +pgm="${0##*/}" # Program basename + +# +# Global exit status +# +SUCCESS=0 +FAILURE=1 + +############################################################ FUNCTIONS + +usage() +{ + local action usage descr + exec >&2 + echo "Usage: $pgm action [arguments]" + echo "Actions:" + for action in \ + addm \ + show \ + show1 \ + destroy \ + ; do + eval usage=\"\$jib_${action}_usage\" + [ "$usage" ] || continue + eval descr=\"\$jib_${action}_descr\" + printf "\t%s\n\t\t%s\n" "$usage" "$descr" + done + exit $FAILURE +} + +action_usage() +{ + local usage descr action="$1" + eval usage=\"\$jib_${action}_usage\" + echo "Usage: $pgm $usage" >&2 + eval descr=\"\$jib_${action}_descr\" + printf "\t%s\n" "$descr" + exit $FAILURE +} + +derive_mac() +{ + local OPTIND=1 OPTARG __flag + local __mac_num= __make_pair= + while getopts 2n: __flag; do + case "$__flag" in + 2) __make_pair=1 ;; + n) __mac_num=${OPTARG%%[^0-9]*} ;; + esac + done + shift $(( $OPTIND - 1 )) + + if [ ! "$__mac_num" ]; then + eval __mac_num=\${_${iface}_num:--1} + __mac_num=$(( $__mac_num + 1 )) + eval _${iface}_num=\$__mac_num + fi + + local __iface="$1" __name="$2" __var_to_set="$3" __var_to_set_b="$4" + local __iface_devid __new_devid __num __new_devid_b + # + # Calculate MAC address derived from given iface. + # + # The formula I'm using is ``NP:SS:SS:II:II:II'' where: + # + N denotes 4 bits used as a counter to support branching + # each parent interface up to 15 times under the same jail + # name (see S below). + # + P denotes the special nibble whose value, if one of + # 2, 6, A, or E (but usually 2) denotes a privately + # administered MAC address (while remaining routable). + # + S denotes 16 bits, the sum(1) value of the jail name. + # + I denotes bits that are inherited from parent interface. + # + # The S bits are a CRC-16 checksum of NAME, allowing the jail + # to change link numbers in ng_bridge(4) without affecting the + # MAC address. Meanwhile, if... + # + the jail NAME changes (e.g., it was duplicated and given + # a new name with no other changes) + # + the underlying network interface changes + # + the jail is moved to another host + # the MAC address will be recalculated to a new, similarly + # unique value preventing conflict. + # + __iface_devid=$( ifconfig $__iface ether | awk '/ether/,$0=$2' ) + # ??:??:??:II:II:II + __new_devid=${__iface_devid#??:??:??} # => :II:II:II + # => :SS:SS:II:II:II + __num=$( set -- `echo -n "$__name" | sum` && echo $1 ) + __new_devid=$( printf :%02x:%02x \ + $(( $__num >> 8 & 255 )) $(( $__num & 255 )) )$__new_devid + # => P:SS:SS:II:II:II + case "$__iface_devid" in + ?2:*) __new_devid=a$__new_devid __new_devid_b=e$__new_devid ;; + ?[Ee]:*) __new_devid=2$__new_devid __new_devid_b=6$__new_devid ;; + *) __new_devid=2$__new_devid __new_devid_b=e$__new_devid + esac + # => NP:SS:SS:II:II:II + __new_devid=$( printf %x $(( $__mac_num & 15 )) )$__new_devid + __new_devid_b=$( printf %x $(( $__mac_num & 15 )) )$__new_devid_b + + # + # Return derivative MAC address(es) + # + if [ "$__make_pair" ]; then + if [ "$__var_to_set" -a "$__var_to_set_b" ]; then + eval $__var_to_set=\$__new_devid + eval $__var_to_set_b=\$__new_devid_b + else + echo $__new_devid $__new_devid_b + fi + else + if [ "$__var_to_set" ]; then + eval $__var_to_set=\$__new_devid + else + echo $__new_devid + fi + fi +} + +mustberoot_to_continue() +{ + if [ "$( id -u )" -ne 0 ]; then + echo "Must run as root!" >&2 + exit $FAILURE + fi +} + +jib_addm_usage="addm [-b BRIDGE_NAME] NAME [!]iface0 [[!]iface1 ...]" +jib_addm_descr="Creates e0b_NAME [e1b_NAME ...]" +jib_addm() +{ + local OPTIND=1 OPTARG flag bridge=bridge + while getopts b: flag; do + case "$flag" in + b) bridge="${OPTARG:-bridge}" ;; + *) action_usage addm # NOTREACHED + esac + done + shift $(( $OPTIND - 1 )) + + local name="$1" + [ "${name:-x}" = "${name#*[!0-9a-zA-Z_]}" -a $# -gt 1 ] || + action_usage addm # NOTREACHED + shift 1 # name + + mustberoot_to_continue + + local iface eiface_devid_a eiface_devid_b + local new no_derive num quad i=0 + for iface in $*; do + + no_derive= + case "$iface" in + !*) iface=${iface#!} no_derive=1 ;; + esac + + # Make sure the interface doesn't exist already + if ifconfig "e${i}a_$name" > /dev/null 2>&1; then + i=$(( $i + 1 )) + continue + fi + + # Bring the interface up + ifconfig $iface up || return + + # Make sure the interface has been bridged + if ! ifconfig "$iface$bridge" > /dev/null 2>&1; then + new=$( ifconfig bridge create ) || return + ifconfig $new addm $iface || return + ifconfig $new name "$iface$bridge" || return + ifconfig "$iface$bridge" up || return + fi + + # Create a new interface to the bridge + new=$( ifconfig epair create ) || return + ifconfig "$iface$bridge" addm $new || return + + # Rename the new interface + ifconfig $new name "e${i}a_$name" || return + ifconfig ${new%a}b name "e${i}b_$name" || return + ifconfig "e${i}a_$name" up || return + ifconfig "e${i}b_$name" up || return + + # + # Set the MAC address of the new interface using a sensible + # algorithm to prevent conflicts on the network. + # + eiface_devid_a= eiface_devid_b= + [ "$no_derive" ] || derive_mac -2 $iface "$name" \ + eiface_devid_a eiface_devid_b + if [ "$eiface_devid_a" -a "$eiface_devid_b" ]; then + ifconfig "e${i}a_$name" ether $eiface_devid_a + ifconfig "e${i}b_$name" ether $eiface_devid_b + fi > /dev/null 2>&1 + + i=$(( $i + 1 )) + done # for iface +} + +jib_show_usage="show" +jib_show_descr="List possible NAME values for \`show NAME'" +jib_show1_usage="show NAME" +jib_show1_descr="Lists e0b_NAME [e1b_NAME ...]" +jib_show2_usage="show [NAME]" +jib_show() +{ + local OPTIND=1 OPTARG flag + while getopts "" flag; do + case "$flag" in + *) action_usage show2 # NOTREACHED + esac + done + shift $(( $OPTIND - 1 )) + if [ $# -eq 0 ]; then + ifconfig | awk ' + /^[^:[:space:]]+:/ { + iface = $1 + sub(/:.*/, "", iface) + next + } + $1 == "groups:" { + for (n = split($0, group); n > 1; n--) { + if (group[n] != "bridge") continue + print iface + next + } + }' | + xargs -rn1 ifconfig | + awk '$1 == "member:" && + sub(/^e[[:digit:]]+a_/, "", $2), $0 = $2' | + sort -u + return + fi + ifconfig | awk -v name="$1" ' + match($0, /^e[[:digit:]]+a_/) && sub(/:.*/, "") && + substr($1, RSTART + RLENGTH) == name + ' | sort +} + +jib_destroy_usage="destroy NAME" +jib_destroy_descr="Destroy e0b_NAME [e1b_NAME ...]" +jib_destroy() +{ + local OPTIND=1 OPTARG flag + while getopts "" flag; do + case "$flag" in + *) action_usage destroy # NOTREACHED + esac + done + shift $(( $OPTIND -1 )) + local name="$1" + [ "${name:-x}" = "${name#*[!0-9a-zA-Z_]}" -a $# -eq 1 ] || + action_usage destroy # NOTREACHED + mustberoot_to_continue + jib_show "$name" | xargs -rn1 -I eiface ifconfig eiface destroy +} + +############################################################ MAIN + +# +# Command-line arguments +# +action="$1" +[ "$action" ] || usage # NOTREACHED + +# +# Validate action argument +# +if [ "$BASH_VERSION" ]; then + type="$( type -t "jib_$action" )" || usage # NOTREACHED +else + type="$( type "jib_$action" 2> /dev/null )" || usage # NOTREACHED +fi +case "$type" in +*function) + shift 1 # action + eval "jib_$action" \"\$@\" + ;; +*) usage # NOTREACHED +esac + +################################################################################ +# END +################################################################################ diff --git a/conf/system/include/14.2/makewhatis b/conf/system/include/14.2/makewhatis new file mode 100755 index 0000000..6fe3ca8 Binary files /dev/null and b/conf/system/include/14.2/makewhatis differ diff --git a/conf/system/include/14.2/pf.os b/conf/system/include/14.2/pf.os new file mode 100644 index 0000000..e131d1b --- /dev/null +++ b/conf/system/include/14.2/pf.os @@ -0,0 +1,708 @@ +# $OpenBSD: pf.os,v 1.27 2016/09/03 17:08:57 sthen Exp $ +# passive OS fingerprinting +# ------------------------- +# +# SYN signatures. Those signatures work for SYN packets only (duh!). +# +# (C) Copyright 2000-2003 by Michal Zalewski +# (C) Copyright 2003 by Mike Frantzen +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +# This fingerprint database is adapted from Michal Zalewski's p0f passive +# operating system package. The last database sync was from a Nov 3 2003 +# p0f.fp. +# +# +# Each line in this file specifies a single fingerprint. Please read the +# information below carefully before attempting to append any signatures +# reported as UNKNOWN to this file to avoid mistakes. +# +# We use the following set metrics for fingerprinting: +# +# - Window size (WSS) - a highly OS dependent setting used for TCP/IP +# performance control (max. amount of data to be sent without ACK). +# Some systems use a fixed value for initial packets. On other +# systems, it is a multiple of MSS or MTU (MSS+40). In some rare +# cases, the value is just arbitrary. +# +# NEW SIGNATURE: if p0f reported a special value of 'Snn', the number +# appears to be a multiple of MSS (MSS*nn); a special value of 'Tnn' +# means it is a multiple of MTU ((MSS+40)*nn). Unless you notice the +# value of nn is not fixed (unlikely), just copy the Snn or Tnn token +# literally. If you know this device has a simple stack and a fixed +# MTU, you can however multiply S value by MSS, or T value by MSS+40, +# and put it instead of Snn or Tnn. +# +# If WSS otherwise looks like a fixed value (for example a multiple +# of two), or if you can confirm the value is fixed, please quote +# it literally. If there's no apparent pattern in WSS chosen, you +# should consider wildcarding this value. +# +# - Overall packet size - a function of all IP and TCP options and bugs. +# +# NEW SIGNATURE: Copy this value literally. +# +# - Initial TTL - We check the actual TTL of a received packet. It can't +# be higher than the initial TTL, and also shouldn't be dramatically +# lower (maximum distance is defined as 40 hops). +# +# NEW SIGNATURE: *Never* copy TTL from a p0f-reported signature literally. +# You need to determine the initial TTL. The best way to do it is to +# check the documentation for a remote system, or check its settings. +# A fairly good method is to simply round the observed TTL up to +# 32, 64, 128, or 255, but it should be noted that some obscure devices +# might not use round TTLs (in particular, some shoddy appliances use +# "original" initial TTL settings). If not sure, you can see how many +# hops you're away from the remote party with traceroute or mtr. +# +# - Don't fragment flag (DF) - some modern OSes set this to implement PMTU +# discovery. Others do not bother. +# +# NEW SIGNATURE: Copy this value literally. +# +# - Maximum segment size (MSS) - this setting is usually link-dependent. P0f +# uses it to determine link type of the remote host. +# +# NEW SIGNATURE: Always wildcard this value, except for rare cases when +# you have an appliance with a fixed value, know the system supports only +# a very limited number of network interface types, or know the system +# is using a value it pulled out of nowhere. Specific unique MSS +# can be used to tell Google crawlbots from the rest of the population. +# +# - Window scaling (WSCALE) - this feature is used to scale WSS. +# It extends the size of a TCP/IP window to 32 bits. Some modern +# systems implement this feature. +# +# NEW SIGNATURE: Observe several signatures. Initial WSCALE is often set +# to zero or other low value. There's usually no need to wildcard this +# parameter. +# +# - Timestamp - some systems that implement timestamps set them to +# zero in the initial SYN. This case is detected and handled appropriately. +# +# - Selective ACK permitted - a flag set by systems that implement +# selective ACK functionality. +# +# - The sequence of TCP all options (MSS, window scaling, selective ACK +# permitted, timestamp, NOP). Other than the options previously +# discussed, p0f also checks for timestamp option (a silly +# extension to broadcast your uptime ;-), NOP options (used for +# header padding) and sackOK option (selective ACK feature). +# +# NEW SIGNATURE: Copy the sequence literally. +# +# To wildcard any value (except for initial TTL or TCP options), replace +# it with '*'. You can also use a modulo operator to match any values +# that divide by nnn - '%nnn'. +# +# Fingerprint entry format: +# +# wwww:ttt:D:ss:OOO...:OS:Version:Subtype:Details +# +# wwww - window size (can be *, %nnn, Snn or Tnn). The special values +# "S" and "T" which are a multiple of MSS or a multiple of MTU +# respectively. +# ttt - initial TTL +# D - don't fragment bit (0 - not set, 1 - set) +# ss - overall SYN packet size +# OOO - option value and order specification (see below) +# OS - OS genre (Linux, Solaris, Windows) +# Version - OS Version (2.0.27 on x86, etc) +# Subtype - OS subtype or patchlevel (SP3, lo0) +# details - Generic OS details +# +# If OS genre starts with '*', p0f will not show distance, link type +# and timestamp data. It is useful for userland TCP/IP stacks of +# network scanners and so on, where many settings are randomized or +# bogus. +# +# If OS genre starts with @, it denotes an approximate hit for a group +# of operating systems (signature reporting still enabled in this case). +# Use this feature at the end of this file to catch cases for which +# you don't have a precise match, but can tell it's Windows or FreeBSD +# or whatnot by looking at, say, flag layout alone. +# +# Option block description is a list of comma or space separated +# options in the order they appear in the packet: +# +# N - NOP option +# Wnnn - window scaling option, value nnn (or * or %nnn) +# Mnnn - maximum segment size option, value nnn (or * or %nnn) +# S - selective ACK OK +# T - timestamp +# T0 - timestamp with a zero value +# +# To denote no TCP options, use a single '.'. +# +# Please report any additions to this file, or any inaccuracies or +# problems spotted, to the maintainers: lcamtuf@coredump.cx, +# frantzen@openbsd.org and bugs@openbsd.org with a tcpdump packet +# capture of the relevant SYN packet(s) +# +# A test and submission page is available at +# http://lcamtuf.coredump.cx/p0f-help/ +# +# +# WARNING WARNING WARNING +# ----------------------- +# +# Do not add a system X as OS Y just because NMAP says so. It is often +# the case that X is a NAT firewall. While nmap is talking to the +# device itself, p0f is fingerprinting the guy behind the firewall +# instead. +# +# When in doubt, use common sense, don't add something that looks like +# a completely different system as Linux or FreeBSD or LinkSys router. +# Check DNS name, establish a connection to the remote host and look +# at SYN+ACK - does it look similar? +# +# Some users tweak their TCP/IP settings - enable or disable RFC1323 +# functionality, enable or disable timestamps or selective ACK, +# disable PMTU discovery, change MTU and so on. Always compare a new rule +# to other fingerprints for this system, and verify the system isn't +# "customized" before adding it. It is OK to add signature variants +# caused by a commonly used software (personal firewalls, security +# packages, etc), but it makes no sense to try to add every single +# possible /proc/sys/net/ipv4 tweak on Linux or so. +# +# KEEP IN MIND: Some packet firewalls configured to normalize outgoing +# traffic (OpenBSD pf with "scrub" enabled, for example) will, well, +# normalize packets. Signatures will not correspond to the originating +# system (and probably not quite to the firewall either). +# +# NOTE: Try to keep this file in some reasonable order, from most to +# least likely systems. This will speed up operation. Also keep most +# generic and broad rules near the end. +# + +########################## +# Standard OS signatures # +########################## + +# ----------------- AIX --------------------- + +# AIX is first because its signatures are close to NetBSD, MacOS X and +# Linux 2.0, but it uses a fairly rare MSSes, at least sometimes... +# This is a shoddy hack, though. + +45046:64:0:44:M*: AIX:4.3::AIX 4.3 +16384:64:0:44:M512: AIX:4.3:2-3:AIX 4.3.2 and earlier + +16384:64:0:60:M512,N,W%2,N,N,T: AIX:4.3:3:AIX 4.3.3-5.2 +16384:64:0:60:M512,N,W%2,N,N,T: AIX:5.1-5.2::AIX 4.3.3-5.2 +32768:64:0:60:M512,N,W%2,N,N,T: AIX:4.3:3:AIX 4.3.3-5.2 +32768:64:0:60:M512,N,W%2,N,N,T: AIX:5.1-5.2::AIX 4.3.3-5.2 +65535:64:0:60:M512,N,W%2,N,N,T: AIX:4.3:3:AIX 4.3.3-5.2 +65535:64:0:60:M512,N,W%2,N,N,T: AIX:5.1-5.2::AIX 4.3.3-5.2 +65535:64:0:64:M*,N,W1,N,N,T,N,N,S: AIX:5.3:ML1:AIX 5.3 ML1 + +# ----------------- Linux ------------------- + +# S1:64:0:44:M*:A: Linux:1.2::Linux 1.2.x (XXX quirks support) +512:64:0:44:M*: Linux:2.0:3x:Linux 2.0.3x +16384:64:0:44:M*: Linux:2.0:3x:Linux 2.0.3x + +# Endian snafu! Nelson says "ha-ha": +2:64:0:44:M*: Linux:2.0:3x:Linux 2.0.3x (MkLinux) on Mac +64:64:0:44:M*: Linux:2.0:3x:Linux 2.0.3x (MkLinux) on Mac + + +S4:64:1:60:M1360,S,T,N,W0: Linux:google::Linux (Google crawlbot) + +S2:64:1:60:M*,S,T,N,W0: Linux:2.4::Linux 2.4 (big boy) +S3:64:1:60:M*,S,T,N,W0: Linux:2.4:.18-21:Linux 2.4.18 and newer +S4:64:1:60:M*,S,T,N,W0: Linux:2.4::Linux 2.4/2.6 <= 2.6.7 +S4:64:1:60:M*,S,T,N,W0: Linux:2.6:.1-7:Linux 2.4/2.6 <= 2.6.7 + +S4:64:1:60:M*,S,T,N,W5: Linux:2.6::Linux 2.6 (newer, 1) +S4:64:1:60:M*,S,T,N,W6: Linux:2.6::Linux 2.6 (newer, 2) +S4:64:1:60:M*,S,T,N,W7: Linux:2.6::Linux 2.6 (newer, 3) +T4:64:1:60:M*,S,T,N,W7: Linux:2.6::Linux 2.6 (newer, 4) + +S10:64:1:60:M*,S,T,N,W4: Linux:3.0::Linux 3.0 + +S3:64:1:60:M*,S,T,N,W1: Linux:2.5::Linux 2.5 (sometimes 2.4) +S4:64:1:60:M*,S,T,N,W1: Linux:2.5-2.6::Linux 2.5/2.6 +S3:64:1:60:M*,S,T,N,W2: Linux:2.5::Linux 2.5 (sometimes 2.4) +S4:64:1:60:M*,S,T,N,W2: Linux:2.5::Linux 2.5 (sometimes 2.4) + +S20:64:1:60:M*,S,T,N,W0: Linux:2.2:20-25:Linux 2.2.20 and newer +S22:64:1:60:M*,S,T,N,W0: Linux:2.2::Linux 2.2 +S11:64:1:60:M*,S,T,N,W0: Linux:2.2::Linux 2.2 + +# Popular cluster config scripts disable timestamps and +# selective ACK: +S4:64:1:48:M1460,N,W0: Linux:2.4:cluster:Linux 2.4 in cluster + +# This needs to be investigated. On some systems, WSS +# is selected as a multiple of MTU instead of MSS. I got +# many submissions for this for many late versions of 2.4: +T4:64:1:60:M1412,S,T,N,W0: Linux:2.4::Linux 2.4 (late, uncommon) + +# This happens only over loopback, but let's make folks happy: +32767:64:1:60:M16396,S,T,N,W0: Linux:2.4:lo0:Linux 2.4 (local) +S8:64:1:60:M3884,S,T,N,W0: Linux:2.2:lo0:Linux 2.2 (local) + +# Opera visitors: +16384:64:1:60:M*,S,T,N,W0: Linux:2.2:Opera:Linux 2.2 (Opera?) +32767:64:1:60:M*,S,T,N,W0: Linux:2.4:Opera:Linux 2.4 (Opera?) + +# Some fairly common mods: +S4:64:1:52:M*,N,N,S,N,W0: Linux:2.4:ts:Linux 2.4 w/o timestamps +S22:64:1:52:M*,N,N,S,N,W0: Linux:2.2:ts:Linux 2.2 w/o timestamps + + +# ----------------- FreeBSD ----------------- + +16384:64:1:44:M*: FreeBSD:2.0-2.2::FreeBSD 2.0-4.2 +16384:64:1:44:M*: FreeBSD:3.0-3.5::FreeBSD 2.0-4.2 +16384:64:1:44:M*: FreeBSD:4.0-4.2::FreeBSD 2.0-4.2 +16384:64:1:60:M*,N,W0,N,N,T: FreeBSD:4.4::FreeBSD 4.4 + +1024:64:1:60:M*,N,W0,N,N,T: FreeBSD:4.4::FreeBSD 4.4 + +57344:64:1:44:M*: FreeBSD:4.6-4.8:noRFC1323:FreeBSD 4.6-4.8 (no RFC1323) +57344:64:1:60:M*,N,W0,N,N,T: FreeBSD:4.6-4.9::FreeBSD 4.6-4.9 + +32768:64:1:60:M*,N,W0,N,N,T: FreeBSD:4.8-4.11::FreeBSD 4.8-5.1 (or MacOS X) +32768:64:1:60:M*,N,W0,N,N,T: FreeBSD:5.0-5.1::FreeBSD 4.8-5.1 (or MacOS X) +65535:64:1:60:M*,N,W0,N,N,T: FreeBSD:4.8-4.11::FreeBSD 4.8-5.2 (or MacOS X) +65535:64:1:60:M*,N,W0,N,N,T: FreeBSD:5.0-5.2::FreeBSD 4.8-5.2 (or MacOS X) +65535:64:1:60:M*,N,W1,N,N,T: FreeBSD:4.7-4.11::FreeBSD 4.7-5.2 +65535:64:1:60:M*,N,W1,N,N,T: FreeBSD:5.0-5.2::FreeBSD 4.7-5.2 + +# XXX need quirks support +# 65535:64:1:60:M*,N,W0,N,N,T:Z:FreeBSD:5.1-5.4::5.1-current (1) +# 65535:64:1:60:M*,N,W1,N,N,T:Z:FreeBSD:5.1-5.4::5.1-current (2) +# 65535:64:1:60:M*,N,W2,N,N,T:Z:FreeBSD:5.1-5.4::5.1-current (3) +# 65535:64:1:44:M*:Z:FreeBSD:5.2::FreeBSD 5.2 (no RFC1323) + +# 16384:64:1:60:M*,N,N,N,N,N,N,T:FreeBSD:4.4:noTS:FreeBSD 4.4 (w/o timestamps) + +# ----------------- NetBSD ------------------ + +16384:64:0:60:M*,N,W0,N,N,T: NetBSD:1.3::NetBSD 1.3 +65535:64:0:60:M*,N,W0,N,N,T0: NetBSD:1.6:opera:NetBSD 1.6 (Opera) +16384:64:0:60:M*,N,W0,N,N,T0: NetBSD:1.6::NetBSD 1.6 +16384:64:1:60:M*,N,W0,N,N,T0: NetBSD:1.6:df:NetBSD 1.6 (DF) +65535:64:1:60:M*,N,W1,N,N,T0: NetBSD:1.6::NetBSD 1.6W-current (DF) +65535:64:1:60:M*,N,W0,N,N,T0: NetBSD:1.6::NetBSD 1.6X (DF) +32768:64:1:60:M*,N,W0,N,N,T0: NetBSD:1.6:randomization:NetBSD 1.6ZH-current (w/ ip_id randomization) + +# ----------------- OpenBSD ----------------- + +16384:64:0:60:M*,N,W0,N,N,T: OpenBSD:2.6::NetBSD 1.3 (or OpenBSD 2.6) +16384:64:1:64:M*,N,N,S,N,W0,N,N,T: OpenBSD:3.0-4.8::OpenBSD 3.0-4.8 +16384:64:0:64:M*,N,N,S,N,W0,N,N,T: OpenBSD:3.0-4.8:no-df:OpenBSD 3.0-4.8 (scrub no-df) +57344:64:1:64:M*,N,N,S,N,W0,N,N,T: OpenBSD:3.3-4.0::OpenBSD 3.3-4.0 +57344:64:0:64:M*,N,N,S,N,W0,N,N,T: OpenBSD:3.3-4.0:no-df:OpenBSD 3.3-4.0 (scrub no-df) + +65535:64:1:64:M*,N,N,S,N,W0,N,N,T: OpenBSD:3.0-4.0:opera:OpenBSD 3.0-4.0 (Opera) + +16384:64:1:64:M*,N,N,S,N,W3,N,N,T: OpenBSD:4.9::OpenBSD 4.9 +16384:64:0:64:M*,N,N,S,N,W3,N,N,T: OpenBSD:4.9:no-df:OpenBSD 4.9 (scrub no-df) + +16384:64:1:64:M*,N,N,S,N,W6,N,N,T: OpenBSD:6.1::OpenBSD 6.1 +16384:64:0:64:M*,N,N,S,N,W6,N,N,T: OpenBSD:6.1:no-df:OpenBSD 6.1 (scrub no-df) + +# ----------------- DragonFly BSD ----------------- + +57344:64:1:60:M*,N,W0,N,N,T: DragonFly:1.0:A:DragonFly 1.0A +57344:64:0:64:M*,N,W0,N,N,S,N,N,T: DragonFly:1.2-1.12::DragonFly 1.2-1.12 +5840:64:1:60:M*,S,T,N,W4: DragonFly:2.0-2.1::DragonFly 2.0-2.1 +57344:64:0:64:M*,N,W0,N,N,S,N,N,T: DragonFly:2.2-2.3::DragonFly 2.2-2.3 +57344:64:0:64:M*,N,W5,N,N,S,N,N,T: DragonFly:2.4-2.7::DragonFly 2.4-2.7 + +# ----------------- Solaris ----------------- + +S17:64:1:64:N,W3,N,N,T0,N,N,S,M*: Solaris:8:RFC1323:Solaris 8 RFC1323 +S17:64:1:48:N,N,S,M*: Solaris:8::Solaris 8 +S17:255:1:44:M*: Solaris:2.5-2.7::Solaris 2.5 to 7 + +S6:255:1:44:M*: Solaris:2.6-2.7::Solaris 2.6 to 7 +S23:255:1:44:M*: Solaris:2.5:1:Solaris 2.5.1 +S34:64:1:48:M*,N,N,S: Solaris:2.9::Solaris 9 +S44:255:1:44:M*: Solaris:2.7::Solaris 7 + +4096:64:0:44:M1460: SunOS:4.1::SunOS 4.1.x + +S34:64:1:52:M*,N,W0,N,N,S: Solaris:10:beta:Solaris 10 (beta) +32850:64:1:64:M*,N,N,T,N,W1,N,N,S: Solaris:10::Solaris 10 1203 + +# ----------------- IRIX -------------------- + +49152:64:0:44:M*: IRIX:6.4::IRIX 6.4 +61440:64:0:44:M*: IRIX:6.2-6.5::IRIX 6.2-6.5 +49152:64:0:52:M*,N,W2,N,N,S: IRIX:6.5:RFC1323:IRIX 6.5 (RFC1323) +49152:64:0:52:M*,N,W3,N,N,S: IRIX:6.5:RFC1323:IRIX 6.5 (RFC1323) + +61440:64:0:48:M*,N,N,S: IRIX:6.5:12-21:IRIX 6.5.12 - 6.5.21 +49152:64:0:48:M*,N,N,S: IRIX:6.5:15-21:IRIX 6.5.15 - 6.5.21 + +49152:60:0:64:M*,N,W2,N,N,T,N,N,S: IRIX:6.5:IP27:IRIX 6.5 IP27 + + +# ----------------- Tru64 ------------------- + +32768:64:1:48:M*,N,W0: Tru64:4.0::Tru64 4.0 (or OS/2 Warp 4) +32768:64:0:48:M*,N,W0: Tru64:5.0::Tru64 5.0 +8192:64:0:44:M1460: Tru64:5.1:noRFC1323:Tru64 6.1 (no RFC1323) (or QNX 6) +61440:64:0:48:M*,N,W0: Tru64:5.1a:JP4:Tru64 v5.1a JP4 (or OpenVMS 7.x on Compaq 5.x stack) + +# ----------------- OpenVMS ----------------- + +6144:64:1:60:M*,N,W0,N,N,T: OpenVMS:7.2::OpenVMS 7.2 (Multinet 4.4 stack) + +# ----------------- MacOS ------------------- + +# XXX Need EOL tcp opt support +# S2:255:1:48:M*,W0,E:.:MacOS:8.6 classic + +# XXX some of these use EOL too +16616:255:1:48:M*,W0: MacOS:7.3-7.6:OTTCP:MacOS 7.3-8.6 (OTTCP) +16616:255:1:48:M*,W0: MacOS:8.0-8.6:OTTCP:MacOS 7.3-8.6 (OTTCP) +16616:255:1:48:M*,N,N,N: MacOS:8.1-8.6:OTTCP:MacOS 8.1-8.6 (OTTCP) +32768:255:1:48:M*,W0,N: MacOS:9.0-9.2::MacOS 9.0-9.2 +65535:255:1:48:M*,N,N,N,N: MacOS:9.1::MacOS 9.1 (OT 2.7.4) + + +# ----------------- Windows ----------------- + +# Windows TCP/IP stack is a mess. For most recent XP, 2000 and +# even 98, the patchlevel, not the actual OS version, is more +# relevant to the signature. They share the same code, so it would +# seem. Luckily for us, almost all Windows 9x boxes have an +# awkward MSS of 536, which I use to tell one from another +# in most difficult cases. + +8192:32:1:44:M*: Windows:3.11::Windows 3.11 (Tucows) +S44:64:1:64:M*,N,W0,N,N,T0,N,N,S: Windows:95::Windows 95 +8192:128:1:64:M*,N,W0,N,N,T0,N,N,S: Windows:95:b:Windows 95b + +# There were so many tweaking tools and so many stack versions for +# Windows 98 it is no longer possible to tell them from each other +# without some very serious research. Until then, there's an insane +# number of signatures, for your amusement: + +S44:32:1:48:M*,N,N,S: Windows:98:lowTTL:Windows 98 (low TTL) +8192:32:1:48:M*,N,N,S: Windows:98:lowTTL:Windows 98 (low TTL) +%8192:64:1:48:M536,N,N,S: Windows:98::Windows 98 +%8192:128:1:48:M536,N,N,S: Windows:98::Windows 98 +S4:64:1:48:M*,N,N,S: Windows:98::Windows 98 +S6:64:1:48:M*,N,N,S: Windows:98::Windows 98 +S12:64:1:48:M*,N,N,S: Windows:98::Windows 98 +T30:64:1:64:M1460,N,W0,N,N,T0,N,N,S: Windows:98::Windows 98 +32767:64:1:48:M*,N,N,S: Windows:98::Windows 98 +37300:64:1:48:M*,N,N,S: Windows:98::Windows 98 +46080:64:1:52:M*,N,W3,N,N,S: Windows:98:RFC1323:Windows 98 (RFC1323) +65535:64:1:44:M*: Windows:98:noSack:Windows 98 (no sack) +S16:128:1:48:M*,N,N,S: Windows:98::Windows 98 +S16:128:1:64:M*,N,W0,N,N,T0,N,N,S: Windows:98::Windows 98 +S26:128:1:48:M*,N,N,S: Windows:98::Windows 98 +T30:128:1:48:M*,N,N,S: Windows:98::Windows 98 +32767:128:1:52:M*,N,W0,N,N,S: Windows:98::Windows 98 +60352:128:1:48:M*,N,N,S: Windows:98::Windows 98 +60352:128:1:64:M*,N,W2,N,N,T0,N,N,S: Windows:98::Windows 98 + +# What's with 1414 on NT? +T31:128:1:44:M1414: Windows:NT:4.0:Windows NT 4.0 SP6a +64512:128:1:44:M1414: Windows:NT:4.0:Windows NT 4.0 SP6a +8192:128:1:44:M*: Windows:NT:4.0:Windows NT 4.0 (older) + +# Windows XP and 2000. Most of the signatures that were +# either dubious or non-specific (no service pack data) +# were deleted and replaced with generics at the end. + +65535:128:1:48:M*,N,N,S: Windows:2000:SP4:Windows 2000 SP4, XP SP1 +65535:128:1:48:M*,N,N,S: Windows:XP:SP1:Windows 2000 SP4, XP SP1 +%8192:128:1:48:M*,N,N,S: Windows:2000:SP2+:Windows 2000 SP2, XP SP1 (seldom 98 4.10.2222) +%8192:128:1:48:M*,N,N,S: Windows:XP:SP1:Windows 2000 SP2, XP SP1 (seldom 98 4.10.2222) +S20:128:1:48:M*,N,N,S: Windows:2000::Windows 2000/XP SP3 +S20:128:1:48:M*,N,N,S: Windows:XP:SP3:Windows 2000/XP SP3 +S45:128:1:48:M*,N,N,S: Windows:2000:SP4:Windows 2000 SP4, XP SP 1 +S45:128:1:48:M*,N,N,S: Windows:XP:SP1:Windows 2000 SP4, XP SP 1 +40320:128:1:48:M*,N,N,S: Windows:2000:SP4:Windows 2000 SP4 + +S6:128:1:48:M*,N,N,S: Windows:2000:SP2:Windows XP, 2000 SP2+ +S6:128:1:48:M*,N,N,S: Windows:XP::Windows XP, 2000 SP2+ +S12:128:1:48:M*,N,N,S: Windows:XP:SP1:Windows XP SP1 +S44:128:1:48:M*,N,N,S: Windows:2000:SP3:Windows Pro SP1, 2000 SP3 +S44:128:1:48:M*,N,N,S: Windows:XP:SP1:Windows Pro SP1, 2000 SP3 +64512:128:1:48:M*,N,N,S: Windows:2000:SP3:Windows SP1, 2000 SP3 +64512:128:1:48:M*,N,N,S: Windows:XP:SP1:Windows SP1, 2000 SP3 +32767:128:1:48:M*,N,N,S: Windows:2000:SP4:Windows SP1, 2000 SP4 +32767:128:1:48:M*,N,N,S: Windows:XP:SP1:Windows SP1, 2000 SP4 + +8192:128:1:52:M*,N,W2,N,N,S: Windows:Vista::Windows Vista/7 + +# Odds, ends, mods: + +S52:128:1:48:M1260,N,N,S: Windows:2000:cisco:Windows XP/2000 via Cisco +S52:128:1:48:M1260,N,N,S: Windows:XP:cisco:Windows XP/2000 via Cisco +65520:128:1:48:M*,N,N,S: Windows:XP::Windows XP bare-bone +16384:128:1:52:M536,N,W0,N,N,S: Windows:2000:ZoneAlarm:Windows 2000 w/ZoneAlarm? +2048:255:0:40:.: Windows:.NET::Windows .NET Enterprise Server + +44620:64:0:48:M*,N,N,S: Windows:ME::Windows ME no SP (?) +S6:255:1:48:M536,N,N,S: Windows:95:winsock2:Windows 95 winsock 2 +32768:32:1:52:M1460,N,W0,N,N,S: Windows:2003:AS:Windows 2003 AS + + +# No need to be more specific, it passes: +# *:128:1:48:M*,N,N,S:U:-Windows:XP/2000 while downloading (leak!) XXX quirk +# there is an equiv similar generic sig w/o the quirk + +# ----------------- HP/UX ------------------- + +32768:64:1:44:M*: HP-UX:B.10.20::HP-UX B.10.20 +32768:64:0:48:M*,W0,N: HP-UX:11.0::HP-UX 11.0 +32768:64:1:48:M*,W0,N: HP-UX:11.10::HP-UX 11.0 or 11.11 +32768:64:1:48:M*,W0,N: HP-UX:11.11::HP-UX 11.0 or 11.11 + +# Whoa. Hardcore WSS. +0:64:0:48:M*,W0,N: HP-UX:B.11.00:A:HP-UX B.11.00 A (RFC1323) + +# ----------------- RiscOS ------------------ + +# We don't yet support the ?12 TCP option +#16384:64:1:68:M1460,N,W0,N,N,T,N,N,?12: RISCOS:3.70-4.36::RISC OS 3.70-4.36 +12288:32:0:44:M536: RISC OS:3.70:4.10:RISC OS 3.70 inet 4.10 + +# XXX quirk +# 4096:64:1:56:M1460,N,N,T:T: RISC OS:3.70:freenet:RISC OS 3.70 freenet 2.00 + + + +# ----------------- BSD/OS ------------------ + +# Once again, power of two WSS is also shared by MacOS X with DF set +8192:64:1:60:M1460,N,W0,N,N,T: BSD/OS:3.1::BSD/OS 3.1-4.3 (or MacOS X 10.2 w/DF) +8192:64:1:60:M1460,N,W0,N,N,T: BSD/OS:4.0-4.3::BSD/OS 3.1-4.3 (or MacOS X 10.2) + + +# ---------------- NewtonOS ----------------- + +4096:64:0:44:M1420: NewtonOS:2.1::NewtonOS 2.1 + +# ---------------- NeXTSTEP ----------------- + +S4:64:0:44:M1024: NeXTSTEP:3.3::NeXTSTEP 3.3 +S8:64:0:44:M512: NeXTSTEP:3.3::NeXTSTEP 3.3 + +# ------------------ BeOS ------------------- + +1024:255:0:48:M*,N,W0: BeOS:5.0-5.1::BeOS 5.0-5.1 +12288:255:0:44:M1402: BeOS:5.0::BeOS 5.0.x + +# ------------------ OS/400 ----------------- + +8192:64:1:60:M1440,N,W0,N,N,T: OS/400:VR4::OS/400 VR4/R5 +8192:64:1:60:M1440,N,W0,N,N,T: OS/400:VR5::OS/400 VR4/R5 +4096:64:1:60:M1440,N,W0,N,N,T: OS/400:V4R5:CF67032:OS/400 V4R5 + CF67032 + +# XXX quirk +# 28672:64:0:44:M1460:A:OS/390:? + +# ------------------ ULTRIX ----------------- + +16384:64:0:40:.: ULTRIX:4.5::ULTRIX 4.5 + +# ------------------- QNX ------------------- + +S16:64:0:44:M512: QNX:::QNX demodisk + +# ------------------ Novell ----------------- + +16384:128:1:44:M1460: Novell:NetWare:5.0:Novel Netware 5.0 +6144:128:1:44:M1460: Novell:IntranetWare:4.11:Novell IntranetWare 4.11 +6144:128:1:44:M1368: Novell:BorderManager::Novell BorderManager ? + +6144:128:1:52:M*,W0,N,S,N,N: Novell:Netware:6:Novell Netware 6 SP3 + + +# ----------------- SCO ------------------ +S3:64:1:60:M1460,N,W0,N,N,T: SCO:UnixWare:7.1:SCO UnixWare 7.1 +S17:64:1:60:M1380,N,W0,N,N,T: SCO:UnixWare:7.1:SCO UnixWare 7.1.3 MP3 +S23:64:1:44:M1380: SCO:OpenServer:5.0:SCO OpenServer 5.0 + +# ------------------- DOS ------------------- + +2048:255:0:44:M536: DOS:WATTCP:1.05:DOS Arachne via WATTCP/1.05 +T2:255:0:44:M984: DOS:WATTCP:1.05Arachne:Arachne via WATTCP/1.05 (eepro) + +# ------------------ OS/2 ------------------- + +S56:64:0:44:M512: OS/2:4::OS/2 4 +28672:64:0:44:M1460: OS/2:4::OS/2 Warp 4.0 + +# ----------------- TOPS-20 ----------------- + +# Another hardcore MSS, one of the ACK leakers hunted down. +# XXX QUIRK 0:64:0:44:M1460:A:TOPS-20:version 7 +0:64:0:44:M1460: TOPS-20:7::TOPS-20 version 7 + +# ----------------- FreeMiNT ---------------- + +S44:255:0:44:M536: FreeMiNT:1:16A:FreeMiNT 1 patch 16A (Atari) + +# ------------------ AMIGA ------------------ + +# XXX TCP option 12 +# S32:64:1:56:M*,N,N,S,N,N,?12:.:AMIGA:3.9 BB2 with Miami stack + +# ------------------ Plan9 ------------------ + +65535:255:0:48:M1460,W0,N: Plan9:4::Plan9 edition 4 + +# ----------------- AMIGAOS ----------------- + +16384:64:1:48:M1560,N,N,S: AMIGAOS:3.9::AMIGAOS 3.9 BB2 MiamiDX + +########################################### +# Appliance / embedded / other signatures # +########################################### + +# ---------- Firewalls / routers ------------ + +S12:64:1:44:M1460: @Checkpoint:::Checkpoint (unknown 1) +S12:64:1:48:N,N,S,M1460: @Checkpoint:::Checkpoint (unknown 2) +4096:32:0:44:M1460: ExtremeWare:4.x::ExtremeWare 4.x + +# XXX TCP option 12 +# S32:64:0:68:M512,N,W0,N,N,T,N,N,?12:.:Nokia:IPSO w/Checkpoint NG FP3 +# S16:64:0:68:M1024,N,W0,N,N,T,N,N,?12:.:Nokia:IPSO 3.7 build 026 + +S4:64:1:60:W0,N,S,T,M1460: FortiNet:FortiGate:50:FortiNet FortiGate 50 + +8192:64:1:44:M1460: Eagle:::Eagle Secure Gateway + +S52:128:1:48:M1260,N,N,N,N: LinkSys:WRV54G::LinkSys WRV54G VPN router + + + +# ------- Switches and other stuff ---------- + +4128:255:0:44:M*: Cisco:::Cisco Catalyst 3500, 7500 etc +S8:255:0:44:M*: Cisco:12008::Cisco 12008 +60352:128:1:64:M1460,N,W2,N,N,T,N,N,S: Alteon:ACEswitch::Alteon ACEswitch +64512:128:1:44:M1370: Nortel:Contivity Client::Nortel Conectivity Client + + +# ---------- Caches and whatnots ------------ + +S4:64:1:52:M1460,N,N,S,N,W0: AOL:web cache::AOL web cache + +32850:64:1:64:N,W1,N,N,T,N,N,S,M*: NetApp:5.x::NetApp Data OnTap 5.x +16384:64:1:64:M1460,N,N,S,N,W0,N: NetApp:5.3:1:NetApp 5.3.1 +65535:64:0:64:M1460,N,N,S,N,W*,N,N,T: NetApp:5.3-5.5::NetApp 5.3-5.5 +65535:64:0:60:M1460,N,W0,N,N,T: NetApp:CacheFlow::NetApp CacheFlow +8192:64:1:64:M1460,N,N,S,N,W0,N,N,T: NetApp:5.2:1:NetApp NetCache 5.2.1 +20480:64:1:64:M1460,N,N,S,N,W0,N,N,T: NetApp:4.1::NetApp NetCache4.1 + +65535:64:0:60:M1460,N,W0,N,N,T: CacheFlow:4.1::CacheFlow CacheOS 4.1 +8192:64:0:60:M1380,N,N,N,N,N,N,T: CacheFlow:1.1::CacheFlow CacheOS 1.1 + +S4:64:0:48:M1460,N,N,S: Cisco:Content Engine::Cisco Content Engine + +27085:128:0:40:.: Dell:PowerApp cache::Dell PowerApp (Linux-based) + +65535:255:1:48:N,W1,M1460: Inktomi:crawler::Inktomi crawler +S1:255:1:60:M1460,S,T,N,W0: LookSmart:ZyBorg::LookSmart ZyBorg + +16384:255:0:40:.: Proxyblocker:::Proxyblocker (what's this?) + +65535:255:0:48:M*,N,N,S: Redline:::Redline T|X 2200 + +32696:128:0:40:M1460: Spirent:Avalanche::Spirent Web Avalanche HTTP benchmarking engine + +# ----------- Embedded systems -------------- + +S9:255:0:44:M536: PalmOS:Tungsten:C:PalmOS Tungsten C +S5:255:0:44:M536: PalmOS:3::PalmOS 3/4 +S5:255:0:44:M536: PalmOS:4::PalmOS 3/4 +S4:255:0:44:M536: PalmOS:3:5:PalmOS 3.5 +2948:255:0:44:M536: PalmOS:3:5:PalmOS 3.5.3 (Handera) +S29:255:0:44:M536: PalmOS:5::PalmOS 5.0 +16384:255:0:44:M1398: PalmOS:5.2:Clie:PalmOS 5.2 (Clie) +S14:255:0:44:M1350: PalmOS:5.2:Treo:PalmOS 5.2.1 (Treo) + +S23:64:1:64:N,W1,N,N,T,N,N,S,M1460: SymbianOS:7::SymbianOS 7 + +8192:255:0:44:M1460: SymbianOS:6048::Symbian OS 6048 (Nokia 7650?) +8192:255:0:44:M536: SymbianOS:9210::Symbian OS (Nokia 9210?) +S22:64:1:56:M1460,T,S: SymbianOS:P800::Symbian OS ? (SE P800?) +S36:64:1:56:M1360,T,S: SymbianOS:6600::Symbian OS 60xx (Nokia 6600?) + + +# Perhaps S4? +5840:64:1:60:M1452,S,T,N,W1: Zaurus:3.10::Zaurus 3.10 + +32768:128:1:64:M1460,N,W0,N,N,T0,N,N,S: PocketPC:2002::PocketPC 2002 + +S1:255:0:44:M346: Contiki:1.1:rc0:Contiki 1.1-rc0 + +4096:128:0:44:M1460: Sega:Dreamcast:3.0:Sega Dreamcast Dreamkey 3.0 +T5:64:0:44:M536: Sega:Dreamcast:HKT-3020:Sega Dreamcast HKT-3020 (browser disc 51027) +S22:64:1:44:M1460: Sony:PS2::Sony Playstation 2 (SOCOM?) + +S12:64:0:44:M1452: AXIS:5600:v5.64:AXIS Printer Server 5600 v5.64 + +3100:32:1:44:M1460: Windows:CE:2.0:Windows CE 2.0 + +#################### +# Fancy signatures # +#################### + +1024:64:0:40:.: *NMAP:syn scan:1:NMAP syn scan (1) +2048:64:0:40:.: *NMAP:syn scan:2:NMAP syn scan (2) +3072:64:0:40:.: *NMAP:syn scan:3:NMAP syn scan (3) +4096:64:0:40:.: *NMAP:syn scan:4:NMAP syn scan (4) + +# Requires quirks support +# 1024:64:0:40:.:A:*NMAP:TCP sweep probe (1) +# 2048:64:0:40:.:A:*NMAP:TCP sweep probe (2) +# 3072:64:0:40:.:A:*NMAP:TCP sweep probe (3) +# 4096:64:0:40:.:A:*NMAP:TCP sweep probe (4) + +1024:64:0:60:W10,N,M265,T: *NMAP:OS:1:NMAP OS detection probe (1) +2048:64:0:60:W10,N,M265,T: *NMAP:OS:2:NMAP OS detection probe (2) +3072:64:0:60:W10,N,M265,T: *NMAP:OS:3:NMAP OS detection probe (3) +4096:64:0:60:W10,N,M265,T: *NMAP:OS:4:NMAP OS detection probe (4) + +32767:64:0:40:.: *NAST:::NASTsyn scan + +# Requires quirks support +# 12345:255:0:40:.:A:-p0f:sendsyn utility + + +##################################### +# Generic signatures - just in case # +##################################### + +#*:64:1:60:M*,N,W*,N,N,T: @FreeBSD:4.0-4.9::FreeBSD 4.x/5.x +#*:64:1:60:M*,N,W*,N,N,T: @FreeBSD:5.0-5.1::FreeBSD 4.x/5.x + +*:128:1:52:M*,N,W0,N,N,S: @Windows:XP:RFC1323:Windows XP/2000 (RFC1323 no tstamp) +*:128:1:52:M*,N,W0,N,N,S: @Windows:2000:RFC1323:Windows XP/2000 (RFC1323 no tstamp) +*:128:1:52:M*,N,W*,N,N,S: @Windows:XP:RFC1323:Windows XP/2000 (RFC1323 no tstamp) +*:128:1:52:M*,N,W*,N,N,S: @Windows:2000:RFC1323:Windows XP/2000 (RFC1323 no tstamp) +*:128:1:64:M*,N,W0,N,N,T0,N,N,S: @Windows:XP:RFC1323:Windows XP/2000 (RFC1323) +*:128:1:64:M*,N,W0,N,N,T0,N,N,S: @Windows:2000:RFC1323:Windows XP/2000 (RFC1323) +*:128:1:64:M*,N,W*,N,N,T0,N,N,S: @Windows:XP:RFC1323:Windows XP (RFC1323, w+) +*:128:1:48:M536,N,N,S: @Windows:98::Windows 98 +*:128:1:48:M*,N,N,S: @Windows:XP::Windows XP/2000 +*:128:1:48:M*,N,N,S: @Windows:2000::Windows XP/2000 + + diff --git a/conf/system/include/14.2/pfctl b/conf/system/include/14.2/pfctl new file mode 100755 index 0000000..475c7a8 Binary files /dev/null and b/conf/system/include/14.2/pfctl differ diff --git a/conf/system/include/14.2/pfilctl b/conf/system/include/14.2/pfilctl new file mode 100755 index 0000000..5011f3a Binary files /dev/null and b/conf/system/include/14.2/pfilctl differ diff --git a/conf/system/include/14.2/pflogd b/conf/system/include/14.2/pflogd new file mode 100755 index 0000000..fb6e935 Binary files /dev/null and b/conf/system/include/14.2/pflogd differ diff --git a/conf/system/include/14.2/setfib b/conf/system/include/14.2/setfib new file mode 100755 index 0000000..9111e41 Binary files /dev/null and b/conf/system/include/14.2/setfib differ diff --git a/conf/system/include/14.2/sum b/conf/system/include/14.2/sum new file mode 100755 index 0000000..5179839 Binary files /dev/null and b/conf/system/include/14.2/sum differ diff --git a/conf/system/include/14.3/ar b/conf/system/include/14.3/ar new file mode 100644 index 0000000..36c141a Binary files /dev/null and b/conf/system/include/14.3/ar differ diff --git a/conf/system/include/14.3/diff3 b/conf/system/include/14.3/diff3 new file mode 100644 index 0000000..4095513 Binary files /dev/null and b/conf/system/include/14.3/diff3 differ diff --git a/conf/system/include/14.3/etcupdate b/conf/system/include/14.3/etcupdate new file mode 100644 index 0000000..7bddd65 --- /dev/null +++ b/conf/system/include/14.3/etcupdate @@ -0,0 +1,1963 @@ +#!/bin/sh +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2010-2013 Hudson River Trading LLC +# Written by: John H. Baldwin +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +# This is a tool to manage updating files that are not updated as part +# of 'make installworld' such as files in /etc. Unlike other tools, +# this one is specifically tailored to assisting with mass upgrades. +# To that end it does not require user intervention while running. +# +# Theory of operation: +# +# The most reliable way to update changes to files that have local +# modifications is to perform a three-way merge between the original +# unmodified file, the new version of the file, and the modified file. +# This requires having all three versions of the file available when +# performing an update. +# +# To that end, etcupdate uses a strategy where the current unmodified +# tree is kept in WORKDIR/current and the previous unmodified tree is +# kept in WORKDIR/old. When performing a merge, a new tree is built +# if needed and then the changes are merged into DESTDIR. Any files +# with unresolved conflicts after the merge are left in a tree rooted +# at WORKDIR/conflicts. +# +# To provide extra flexibility, etcupdate can also build tarballs of +# root trees that can later be used. It can also use a tarball as the +# source of a new tree instead of building it from /usr/src. + +# Global settings. These can be adjusted by config files and in some +# cases by command line options. + +# TODO: +# - automatable conflict resolution + +usage() +{ + cat < + etcupdate diff [-d workdir] [-D destdir] [-I patterns] [-L logfile] + etcupdate extract [-BN] [-d workdir] [-s source | -t tarball] + [-D destdir] [-L logfile] [-M options] [-m make] + etcupdate resolve [-p] [-d workdir] [-D destdir] [-L logfile] + etcupdate revert [-d workdir] [-D destdir] [-L logfile] file ... + etcupdate status [-d workdir] [-D destdir] +EOF + exit 1 +} + +# Used to write a message prepended with '>>>' to the logfile. +log() +{ + echo ">>>" "$@" >&3 +} + +# Used for assertion conditions that should never happen. +panic() +{ + echo "PANIC:" "$@" + exit 10 +} + +# Used to write a warning message. These are saved to the WARNINGS +# file with " " prepended. +warn() +{ + echo -n " " >> $WARNINGS + echo "$@" >> $WARNINGS +} + +# Output a horizontal rule using the passed-in character. Matches the +# length used for Index lines in CVS and SVN diffs. +# +# $1 - character +rule() +{ + jot -b "$1" -s "" 67 +} + +# Output a text description of a specified file's type. +# +# $1 - file pathname. +file_type() +{ + stat -f "%HT" $1 | tr "[:upper:]" "[:lower:]" +} + +# Returns true (0) if a file exists +# +# $1 - file pathname. +exists() +{ + [ -e $1 -o -L $1 ] +} + +# Returns true (0) if a file should be ignored, false otherwise. +# +# $1 - file pathname +ignore() +{ + local pattern - + + set -o noglob + for pattern in $IGNORE_FILES; do + set +o noglob + case $1 in + $pattern) + return 0 + ;; + esac + set -o noglob + done + + # Ignore /.cshrc and /.profile if they are hardlinked to the + # same file in /root. This ensures we only compare those + # files once in that case. + case $1 in + /.cshrc|/.profile) + if [ ${DESTDIR}$1 -ef ${DESTDIR}/root$1 ]; then + return 0 + fi + ;; + *) + ;; + esac + + return 1 +} + +# Returns true (0) if the new version of a file should always be +# installed rather than attempting to do a merge. +# +# $1 - file pathname +always_install() +{ + local pattern - + + set -o noglob + for pattern in $ALWAYS_INSTALL; do + set +o noglob + case $1 in + $pattern) + return 0 + ;; + esac + set -o noglob + done + + return 1 +} + +# Build a new tree. This runs inside a subshell to trap SIGINT. +# +# $1 - directory to store new tree in +build_tree() +( + local destdir dir file make autogenfiles metatmp + + make="$MAKE_CMD $MAKE_OPTIONS -DNO_FILEMON" + + if [ -n "$noroot" ]; then + make="$make -DNO_ROOT" + metatmp=`mktemp $WORKDIR/etcupdate-XXXXXXX` + : > $metatmp + trap "rm -f $metatmp; trap '' EXIT; return 1" INT + trap "rm -f $metatmp" EXIT + else + metatmp="/dev/null" + trap "return 1" INT + fi + + log "Building tree at $1 with $make" + + exec >&3 2>&1 + + mkdir -p $1/usr/obj + destdir=`realpath $1` + + if [ -n "$preworld" ]; then + # Build a limited tree that only contains files that are + # crucial to installworld. + for file in $PREWORLD_FILES; do + name=$(basename $file) + mkdir -p $1/etc || return 1 + cp -p $SRCDIR/$file $1/etc/$name || return 1 + done + else + ( + cd $SRCDIR || exit 1 + if ! [ -n "$nobuild" ]; then + export MAKEOBJDIRPREFIX=$destdir/usr/obj + if [ -n "$($make -V.ALLTARGETS:Mbuildetc)" ]; then + $make buildetc || exit 1 + else + $make _obj SUBDIR_OVERRIDE=etc || exit 1 + $make everything SUBDIR_OVERRIDE=etc || exit 1 + fi + fi + if [ -n "$($make -V.ALLTARGETS:Minstalletc)" ]; then + $make DESTDIR=$destdir installetc || exit 1 + else + $make DESTDIR=$destdir distrib-dirs || exit 1 + $make DESTDIR=$destdir distribution || exit 1 + fi + ) || return 1 + fi + chflags -R noschg $1 || return 1 + rm -rf $1/usr/obj || return 1 + + # Purge auto-generated files. Only the source files need to + # be updated after which these files are regenerated. + autogenfiles="./etc/*.db ./etc/passwd ./var/db/services.db" + (cd $1 && printf '%s\n' $autogenfiles >> $metatmp && \ + rm -f $autogenfiles) || return 1 + + # Remove empty files. These just clutter the output of 'diff'. + (cd $1 && find . -type f -size 0 -delete -print >> $metatmp) || \ + return 1 + + # Trim empty directories. + (cd $1 && find . -depth -type d -empty -delete -print >> $metatmp) || \ + return 1 + + if [ -n "$noroot" ]; then + # Rewrite the METALOG to exclude the files (and directories) + # removed above. $metatmp contains the list of files to delete, + # and we append #METALOG# as a delimiter followed by the + # original METALOG. This lets us scan through $metatmp in awk + # building up a table of names to delete until we reach the + # delimiter, then emit all the entries of the original METALOG + # after it that aren't in that table. We also exclude ./usr/obj + # and its children explicitly for simplicity rather than + # building up that list (and in practice only ./usr/obj itself + # will be in the METALOG since nothing is installed there). + echo '#METALOG#' >> $metatmp || return 1 + cat $1/METALOG >> $metatmp || return 1 + awk '/^#METALOG#$/ { metalog = 1; next } + { f=$1; gsub(/\/\/+/, "/", f) } + !metalog { rm[f] = 1; next } + !rm[f] && f !~ /^\.\/usr\/obj(\/|$)/ { print }' \ + $metatmp > $1/METALOG || return 1 + fi + + return 0 +) + +# Generate a new tree. If tarball is set, then the tree is +# extracted from the tarball. Otherwise the tree is built from a +# source tree. +# +# $1 - directory to store new tree in +extract_tree() +{ + local files + + # If we have a tarball, extract that into the new directory. + if [ -n "$tarball" ]; then + files= + if [ -n "$preworld" ]; then + files="$PREWORLD_FILES" + fi + if ! (mkdir -p $1 && tar xf $tarball -C $1 $files) \ + >&3 2>&1; then + echo "Failed to extract new tree." + remove_tree $1 + exit 1 + fi + else + if ! build_tree $1; then + echo "Failed to build new tree." + remove_tree $1 + exit 1 + fi + fi +} + +# Forcefully remove a tree. Returns true (0) if the operation succeeds. +# +# $1 - path to tree +remove_tree() +{ + + rm -rf $1 >&3 2>&1 + if [ -e $1 ]; then + chflags -R noschg $1 >&3 2>&1 + rm -rf $1 >&3 2>&1 + fi + [ ! -e $1 ] +} + +# Return values for compare() +COMPARE_EQUAL=0 +COMPARE_ONLYFIRST=1 +COMPARE_ONLYSECOND=2 +COMPARE_DIFFTYPE=3 +COMPARE_DIFFLINKS=4 +COMPARE_DIFFFILES=5 + +# Compare two files/directories/symlinks. Note that this does not +# recurse into subdirectories. Instead, if two nodes are both +# directories, they are assumed to be equivalent. +# +# Returns true (0) if the nodes are identical. If only one of the two +# nodes are present, return one of the COMPARE_ONLY* constants. If +# the nodes are different, return one of the COMPARE_DIFF* constants +# to indicate the type of difference. +# +# $1 - first node +# $2 - second node +compare() +{ + local first second + + # If the first node doesn't exist, then check for the second + # node. Note that -e will fail for a symbolic link that + # points to a missing target. + if ! exists $1; then + if exists $2; then + return $COMPARE_ONLYSECOND + else + return $COMPARE_EQUAL + fi + elif ! exists $2; then + return $COMPARE_ONLYFIRST + fi + + # If the two nodes are different file types fail. + first=`stat -f "%Hp" $1` + second=`stat -f "%Hp" $2` + if [ "$first" != "$second" ]; then + return $COMPARE_DIFFTYPE + fi + + # If both are symlinks, compare the link values. + if [ -L $1 ]; then + first=`readlink $1` + second=`readlink $2` + if [ "$first" = "$second" ]; then + return $COMPARE_EQUAL + else + return $COMPARE_DIFFLINKS + fi + fi + + # If both are files, compare the file contents. + if [ -f $1 ]; then + if cmp -s $1 $2; then + return $COMPARE_EQUAL + else + return $COMPARE_DIFFFILES + fi + fi + + # As long as the two nodes are the same type of file, consider + # them equivalent. + return $COMPARE_EQUAL +} + +# Returns true (0) if the only difference between two regular files is a +# change in the FreeBSD ID string. +# +# $1 - path of first file +# $2 - path of second file +fbsdid_only() +{ + + diff -qI '\$FreeBSD.*\$' $1 $2 >/dev/null 2>&1 +} + +# This is a wrapper around compare that will return COMPARE_EQUAL if +# the only difference between two regular files is a change in the +# FreeBSD ID string. It only makes this adjustment if the -F flag has +# been specified. +# +# $1 - first node +# $2 - second node +compare_fbsdid() +{ + local cmp + + compare $1 $2 + cmp=$? + + if [ -n "$FREEBSD_ID" -a "$cmp" -eq $COMPARE_DIFFFILES ] && \ + fbsdid_only $1 $2; then + return $COMPARE_EQUAL + fi + + return $cmp +} + +# Returns true (0) if a directory is empty. +# +# $1 - pathname of the directory to check +empty_dir() +{ + local contents + + contents=`ls -A $1` + [ -z "$contents" ] +} + +# Returns true (0) if one directories contents are a subset of the +# other. This will recurse to handle subdirectories and compares +# individual files in the trees. Its purpose is to quiet spurious +# directory warnings for dryrun invocations. +# +# $1 - first directory (sub) +# $2 - second directory (super) +dir_subset() +{ + local contents file + + if ! [ -d $1 -a -d $2 ]; then + return 1 + fi + + # Ignore files that are present in the second directory but not + # in the first. + contents=`ls -A $1` + for file in $contents; do + if ! compare $1/$file $2/$file; then + return 1 + fi + + if [ -d $1/$file ]; then + if ! dir_subset $1/$file $2/$file; then + return 1 + fi + fi + done + return 0 +} + +# Returns true (0) if a directory in the destination tree is empty. +# If this is a dryrun, then this returns true as long as the contents +# of the directory are a subset of the contents in the old tree +# (meaning that the directory would be empty in a non-dryrun when this +# was invoked) to quiet spurious warnings. +# +# $1 - pathname of the directory to check relative to DESTDIR. +empty_destdir() +{ + + if [ -n "$dryrun" ]; then + dir_subset $DESTDIR/$1 $OLDTREE/$1 + return + fi + + empty_dir $DESTDIR/$1 +} + +# Output a diff of two directory entries with the same relative name +# in different trees. Note that as with compare(), this does not +# recurse into subdirectories. If the nodes are identical, nothing is +# output. +# +# $1 - first tree +# $2 - second tree +# $3 - node name +# $4 - label for first tree +# $5 - label for second tree +diffnode() +{ + local first second file old new diffargs + + if [ -n "$FREEBSD_ID" ]; then + diffargs="-I \\\$FreeBSD.*\\\$" + else + diffargs="" + fi + + compare_fbsdid $1/$3 $2/$3 + case $? in + $COMPARE_EQUAL) + ;; + $COMPARE_ONLYFIRST) + echo + echo "Removed: $3" + echo + ;; + $COMPARE_ONLYSECOND) + echo + echo "Added: $3" + echo + ;; + $COMPARE_DIFFTYPE) + first=`file_type $1/$3` + second=`file_type $2/$3` + echo + echo "Node changed from a $first to a $second: $3" + echo + ;; + $COMPARE_DIFFLINKS) + first=`readlink $1/$file` + second=`readlink $2/$file` + echo + echo "Link changed: $file" + rule "=" + echo "-$first" + echo "+$second" + echo + ;; + $COMPARE_DIFFFILES) + echo "Index: $3" + rule "=" + diff -u $diffargs -L "$3 ($4)" $1/$3 -L "$3 ($5)" $2/$3 + ;; + esac +} + +# Run one-off commands after an update has completed. These commands +# are not tied to a specific file, so they cannot be handled by +# post_install_file(). +post_update() +{ + local args + + # None of these commands should be run for a pre-world update. + if [ -n "$preworld" ]; then + return + fi + + # If /etc/localtime exists and is not a symlink and /var/db/zoneinfo + # exists, run tzsetup -r to refresh /etc/localtime. + if [ -f ${DESTDIR}/etc/localtime -a \ + ! -L ${DESTDIR}/etc/localtime ]; then + if [ -f ${DESTDIR}/var/db/zoneinfo ]; then + if [ -n "${DESTDIR}" ]; then + args="-C ${DESTDIR}" + else + args="" + fi + log "tzsetup -r ${args}" + if [ -z "$dryrun" ]; then + tzsetup -r ${args} >&3 2>&1 + fi + else + warn "Needs update: /etc/localtime (required" \ + "manual update via tzsetup(8))" + fi + fi +} + +# Create missing parent directories of a node in a target tree +# preserving the owner, group, and permissions from a specified +# template tree. +# +# $1 - template tree +# $2 - target tree +# $3 - pathname of the node (relative to both trees) +install_dirs() +{ + local args dir + + dir=`dirname $3` + + # Nothing to do if the parent directory exists. This also + # catches the degenerate cases when the path is just a simple + # filename. + if [ -d ${2}$dir ]; then + return 0 + fi + + # If non-directory file exists with the desired directory + # name, then fail. + if exists ${2}$dir; then + # If this is a dryrun and we are installing the + # directory in the DESTDIR and the file in the DESTDIR + # matches the file in the old tree, then fake success + # to quiet spurious warnings. + if [ -n "$dryrun" -a "$2" = "$DESTDIR" ]; then + if compare $OLDTREE/$dir $DESTDIR/$dir; then + return 0 + fi + fi + + args=`file_type ${2}$dir` + warn "Directory mismatch: ${2}$dir ($args)" + return 1 + fi + + # Ensure the parent directory of the directory is present + # first. + if ! install_dirs $1 "$2" $dir; then + return 1 + fi + + # Format attributes from template directory as install(1) + # arguments. + args=`stat -f "-o %Su -g %Sg -m %0Mp%0Lp" $1/$dir` + + log "install -d $args ${2}$dir" + if [ -z "$dryrun" ]; then + install -d $args ${2}$dir >&3 2>&1 + fi + return 0 +} + +# Perform post-install fixups for a file. This largely consists of +# regenerating any files that depend on the newly installed file. +# +# $1 - pathname of the updated file (relative to DESTDIR) +post_install_file() +{ + case $1 in + /etc/mail/aliases) + # Grr, newaliases only works for an empty DESTDIR. + if [ -z "$DESTDIR" ]; then + log "newaliases" + if [ -z "$dryrun" ]; then + newaliases >&3 2>&1 + fi + else + NEWALIAS_WARN=yes + fi + ;; + /usr/share/certs/trusted/* | /usr/share/certs/untrusted/*) + log "certctl rehash" + if [ -z "$dryrun" ]; then + env DESTDIR=${DESTDIR} certctl rehash >&3 2>&1 + fi + ;; + /etc/login.conf) + log "cap_mkdb ${DESTDIR}$1" + if [ -z "$dryrun" ]; then + cap_mkdb ${DESTDIR}$1 >&3 2>&1 + fi + ;; + /etc/master.passwd) + log "pwd_mkdb -p -d $DESTDIR/etc ${DESTDIR}$1" + if [ -z "$dryrun" ]; then + pwd_mkdb -p -d $DESTDIR/etc ${DESTDIR}$1 \ + >&3 2>&1 + fi + ;; + /etc/motd) + # /etc/rc.d/motd hardcodes the /etc/motd path. + # Don't warn about non-empty DESTDIR's since this + # change is only cosmetic anyway. + if [ -z "$DESTDIR" ]; then + log "sh /etc/rc.d/motd start" + if [ -z "$dryrun" ]; then + sh /etc/rc.d/motd start >&3 2>&1 + fi + fi + ;; + /etc/services) + log "services_mkdb -q -o $DESTDIR/var/db/services.db" \ + "${DESTDIR}$1" + if [ -z "$dryrun" ]; then + services_mkdb -q -o $DESTDIR/var/db/services.db \ + ${DESTDIR}$1 >&3 2>&1 + fi + ;; + esac +} + +# Install the "new" version of a file. Returns true if it succeeds +# and false otherwise. +# +# $1 - pathname of the file to install (relative to DESTDIR) +install_new() +{ + + if ! install_dirs $NEWTREE "$DESTDIR" $1; then + return 1 + fi + log "cp -Rp ${NEWTREE}$1 ${DESTDIR}$1" + if [ -z "$dryrun" ]; then + cp -Rp ${NEWTREE}$1 ${DESTDIR}$1 >&3 2>&1 + fi + post_install_file $1 + return 0 +} + +# Install the "resolved" version of a file. Returns true if it succeeds +# and false otherwise. +# +# $1 - pathname of the file to install (relative to DESTDIR) +install_resolved() +{ + + # This should always be present since the file is already + # there (it caused a conflict). However, it doesn't hurt to + # just be safe. + if ! install_dirs $NEWTREE "$DESTDIR" $1; then + return 1 + fi + + # Use cat rather than cp to preserve metadata + log "cat ${CONFLICTS}$1 > ${DESTDIR}$1" + cat ${CONFLICTS}$1 > ${DESTDIR}$1 2>&3 + post_install_file $1 + return 0 +} + +# Generate a conflict file when a "new" file conflicts with an +# existing file in DESTDIR. +# +# $1 - pathname of the file that conflicts (relative to DESTDIR) +new_conflict() +{ + + if [ -n "$dryrun" ]; then + return + fi + + install_dirs $NEWTREE $CONFLICTS $1 + diff --changed-group-format='<<<<<<< (local) +%<======= +%>>>>>>>> (stock) +' $DESTDIR/$1 $NEWTREE/$1 > $CONFLICTS/$1 +} + +# Remove the "old" version of a file. +# +# $1 - pathname of the old file to remove (relative to DESTDIR) +remove_old() +{ + log "rm -f ${DESTDIR}$1" + if [ -z "$dryrun" ]; then + rm -f ${DESTDIR}$1 >&3 2>&1 + fi + echo " D $1" +} + +# Update a file that has no local modifications. +# +# $1 - pathname of the file to update (relative to DESTDIR) +update_unmodified() +{ + local new old + + # If the old file is a directory, then remove it with rmdir + # (this should only happen if the file has changed its type + # from a directory to a non-directory). If the directory + # isn't empty, then fail. This will be reported as a warning + # later. + if [ -d $DESTDIR/$1 ]; then + if empty_destdir $1; then + log "rmdir ${DESTDIR}$1" + if [ -z "$dryrun" ]; then + rmdir ${DESTDIR}$1 >&3 2>&1 + fi + else + return 1 + fi + + # If both the old and new files are regular files, leave the + # existing file. This avoids breaking hard links for /.cshrc + # and /.profile. Otherwise, explicitly remove the old file. + elif ! [ -f ${DESTDIR}$1 -a -f ${NEWTREE}$1 ]; then + log "rm -f ${DESTDIR}$1" + if [ -z "$dryrun" ]; then + rm -f ${DESTDIR}$1 >&3 2>&1 + fi + fi + + # If the new file is a directory, note that the old file has + # been removed, but don't do anything else for now. The + # directory will be installed if needed when new files within + # that directory are installed. + if [ -d $NEWTREE/$1 ]; then + if empty_dir $NEWTREE/$1; then + echo " D $file" + else + echo " U $file" + fi + elif install_new $1; then + echo " U $file" + fi + return 0 +} + +# Update the FreeBSD ID string in a locally modified file to match the +# FreeBSD ID string from the "new" version of the file. +# +# $1 - pathname of the file to update (relative to DESTDIR) +update_freebsdid() +{ + local new dest file + + # If the FreeBSD ID string is removed from the local file, + # there is nothing to do. In this case, treat the file as + # updated. Otherwise, if either file has more than one + # FreeBSD ID string, just punt and let the user handle the + # conflict manually. + new=`grep -c '\$FreeBSD.*\$' ${NEWTREE}$1` + dest=`grep -c '\$FreeBSD.*\$' ${DESTDIR}$1` + if [ "$dest" -eq 0 ]; then + return 0 + fi + if [ "$dest" -ne 1 -o "$dest" -ne 1 ]; then + return 1 + fi + + # If the FreeBSD ID string in the new file matches the FreeBSD ID + # string in the local file, there is nothing to do. + new=`grep '\$FreeBSD.*\$' ${NEWTREE}$1` + dest=`grep '\$FreeBSD.*\$' ${DESTDIR}$1` + if [ "$new" = "$dest" ]; then + return 0 + fi + + # Build the new file in three passes. First, copy all the + # lines preceding the FreeBSD ID string from the local version + # of the file. Second, append the FreeBSD ID string line from + # the new version. Finally, append all the lines after the + # FreeBSD ID string from the local version of the file. + file=`mktemp $WORKDIR/etcupdate-XXXXXXX` + awk '/\$FreeBSD.*\$/ { exit } { print }' ${DESTDIR}$1 >> $file + awk '/\$FreeBSD.*\$/ { print }' ${NEWTREE}$1 >> $file + awk '/\$FreeBSD.*\$/ { ok = 1; next } { if (ok) print }' \ + ${DESTDIR}$1 >> $file + + # As an extra sanity check, fail the attempt if the updated + # version of the file has any differences aside from the + # FreeBSD ID string. + if ! fbsdid_only ${DESTDIR}$1 $file; then + rm -f $file + return 1 + fi + + log "cp $file ${DESTDIR}$1" + if [ -z "$dryrun" ]; then + cp $file ${DESTDIR}$1 >&3 2>&1 + fi + rm -f $file + post_install_file $1 + echo " M $1" + return 0 +} + +# Attempt to update a file that has local modifications. This routine +# only handles regular files. If the 3-way merge succeeds without +# conflicts, the updated file is installed. If the merge fails, the +# merged version with conflict markers is left in the CONFLICTS tree. +# +# $1 - pathname of the file to merge (relative to DESTDIR) +merge_file() +{ + local res + + # Try the merge to see if there is a conflict. + diff3 -E -m ${DESTDIR}$1 ${OLDTREE}$1 ${NEWTREE}$1 > /dev/null 2>&3 + res=$? + case $res in + 0) + # No conflicts, so just redo the merge to the + # real file. + log "diff3 -E -m ${DESTDIR}$1 ${OLDTREE}$1 ${NEWTREE}$1" + if [ -z "$dryrun" ]; then + temp=$(mktemp -t etcupdate) + diff3 -E -m ${DESTDIR}$1 ${OLDTREE}$1 ${NEWTREE}$1 > ${temp} + # Use "cat >" to preserve metadata. + cat ${temp} > ${DESTDIR}$1 + rm -f ${temp} + fi + post_install_file $1 + echo " M $1" + ;; + 1) + # Conflicts, save a version with conflict markers in + # the conflicts directory. + if [ -z "$dryrun" ]; then + install_dirs $NEWTREE $CONFLICTS $1 + log "diff3 -m ${DESTDIR}$1 ${CONFLICTS}$1" + diff3 -m -L "yours" -L "original" -L "new" \ + ${DESTDIR}$1 ${OLDTREE}$1 ${NEWTREE}$1 > \ + ${CONFLICTS}$1 + fi + echo " C $1" + ;; + *) + panic "merge failed with status $res" + ;; + esac +} + +# Returns true if a file contains conflict markers from a merge conflict. +# +# $1 - pathname of the file to resolve (relative to DESTDIR) +has_conflicts() +{ + + egrep -q '^(<{7}|\|{7}|={7}|>{7}) ' $CONFLICTS/$1 +} + +# Attempt to resolve a conflict. The user is prompted to choose an +# action for each conflict. If the user edits the file, they are +# prompted again for an action. The process is very similar to +# resolving conflicts after an update or merge with Perforce or +# Subversion. The prompts are modelled on a subset of the available +# commands for resolving conflicts with Subversion. +# +# $1 - pathname of the file to resolve (relative to DESTDIR) +resolve_conflict() +{ + local command junk + + echo "Resolving conflict in '$1':" + edit= + while true; do + # Only display the resolved command if the file + # doesn't contain any conflicts. + echo -n "Select: (p) postpone, (df) diff-full, (e) edit," + if ! has_conflicts $1; then + echo -n " (r) resolved," + fi + echo + echo -n " (h) help for more options: " + read command + case $command in + df) + diff -u ${DESTDIR}$1 ${CONFLICTS}$1 + ;; + e) + $EDITOR ${CONFLICTS}$1 + ;; + h) + cat </dev/null 2>&1 + fi + echo " D $dir" + else + warn "Non-empty directory remains: $dir" + fi + fi +} + +# Handle a file that exists in both the old and new trees. If the +# file has not changed in the old and new trees, there is nothing to +# do. If the file in the destination directory matches the new file, +# there is nothing to do. If the file in the destination directory +# matches the old file, then the new file should be installed. +# Everything else becomes some sort of conflict with more detailed +# handling. +# +# $1 - pathname of the file (relative to DESTDIR) +handle_modified_file() +{ + local cmp dest file new newdestcmp old + + file=$1 + if ignore $file; then + log "IGNORE: modified file $file" + return + fi + + compare $OLDTREE/$file $NEWTREE/$file + cmp=$? + if [ $cmp -eq $COMPARE_EQUAL ]; then + return + fi + + if [ $cmp -eq $COMPARE_ONLYFIRST -o $cmp -eq $COMPARE_ONLYSECOND ]; then + panic "Changed file now missing" + fi + + compare $NEWTREE/$file $DESTDIR/$file + newdestcmp=$? + if [ $newdestcmp -eq $COMPARE_EQUAL ]; then + return + fi + + # If the only change in the new file versus the destination + # file is a change in the FreeBSD ID string and -F is + # specified, just install the new file. + if [ -n "$FREEBSD_ID" -a $newdestcmp -eq $COMPARE_DIFFFILES ] && \ + fbsdid_only $NEWTREE/$file $DESTDIR/$file; then + if update_unmodified $file; then + return + else + panic "Updating FreeBSD ID string failed" + fi + fi + + # If the local file is the same as the old file, install the + # new file. If -F is specified and the only local change is + # in the FreeBSD ID string, then install the new file as well. + if compare_fbsdid $OLDTREE/$file $DESTDIR/$file; then + if update_unmodified $file; then + return + fi + fi + + # If the file was removed from the dest tree, just whine. + if [ $newdestcmp -eq $COMPARE_ONLYFIRST ]; then + # If the removed file matches an ALWAYS_INSTALL glob, + # then just install the new version of the file. + if always_install $file; then + log "ALWAYS: adding $file" + if ! [ -d $NEWTREE/$file ]; then + if install_new $file; then + echo " A $file" + fi + fi + return + fi + + # If the only change in the new file versus the old + # file is a change in the FreeBSD ID string and -F is + # specified, don't warn. + if [ -n "$FREEBSD_ID" -a $cmp -eq $COMPARE_DIFFFILES ] && \ + fbsdid_only $OLDTREE/$file $NEWTREE/$file; then + return + fi + + case $cmp in + $COMPARE_DIFFTYPE) + old=`file_type $OLDTREE/$file` + new=`file_type $NEWTREE/$file` + warn "Remove mismatch: $file ($old became $new)" + ;; + $COMPARE_DIFFLINKS) + old=`readlink $OLDTREE/$file` + new=`readlink $NEWTREE/$file` + warn \ + "Removed link changed: $file (\"$old\" became \"$new\")" + ;; + $COMPARE_DIFFFILES) + warn "Removed file changed: $file" + ;; + esac + return + fi + + # Treat the file as unmodified and force install of the new + # file if it matches an ALWAYS_INSTALL glob. If the update + # attempt fails, then fall through to the normal case so a + # warning is generated. + if always_install $file; then + log "ALWAYS: updating $file" + if update_unmodified $file; then + return + fi + fi + + # If the only change in the new file versus the old file is a + # change in the FreeBSD ID string and -F is specified, just + # update the FreeBSD ID string in the local file. + if [ -n "$FREEBSD_ID" -a $cmp -eq $COMPARE_DIFFFILES ] && \ + fbsdid_only $OLDTREE/$file $NEWTREE/$file; then + if update_freebsdid $file; then + continue + fi + fi + + # If the file changed types between the old and new trees but + # the files in the new and dest tree are both of the same + # type, treat it like an added file just comparing the new and + # dest files. + if [ $cmp -eq $COMPARE_DIFFTYPE ]; then + case $newdestcmp in + $COMPARE_DIFFLINKS) + new=`readlink $NEWTREE/$file` + dest=`readlink $DESTDIR/$file` + warn \ + "New link conflict: $file (\"$new\" vs \"$dest\")" + return + ;; + $COMPARE_DIFFFILES) + new_conflict $file + echo " C $file" + return + ;; + esac + else + # If the file has not changed types between the old + # and new trees, but it is a different type in + # DESTDIR, then just warn. + if [ $newdestcmp -eq $COMPARE_DIFFTYPE ]; then + new=`file_type $NEWTREE/$file` + dest=`file_type $DESTDIR/$file` + warn "Modified mismatch: $file ($new vs $dest)" + return + fi + fi + + case $cmp in + $COMPARE_DIFFTYPE) + old=`file_type $OLDTREE/$file` + new=`file_type $NEWTREE/$file` + dest=`file_type $DESTDIR/$file` + warn "Modified $dest changed: $file ($old became $new)" + ;; + $COMPARE_DIFFLINKS) + old=`readlink $OLDTREE/$file` + new=`readlink $NEWTREE/$file` + warn \ + "Modified link changed: $file (\"$old\" became \"$new\")" + ;; + $COMPARE_DIFFFILES) + merge_file $file + ;; + esac +} + +# Handle a file that has been added in the new tree. If the file does +# not exist in DESTDIR, simply copy the file into DESTDIR. If the +# file exists in the DESTDIR and is identical to the new version, do +# nothing. Otherwise, generate a diff of the two versions of the file +# and mark it as a conflict. +# +# $1 - pathname of the file (relative to DESTDIR) +handle_added_file() +{ + local cmp dest file new + + file=$1 + if ignore $file; then + log "IGNORE: added file $file" + return + fi + + compare $DESTDIR/$file $NEWTREE/$file + cmp=$? + case $cmp in + $COMPARE_EQUAL) + return + ;; + $COMPARE_ONLYFIRST) + panic "Added file now missing" + ;; + $COMPARE_ONLYSECOND) + # Ignore new directories. They will be + # created as needed when non-directory nodes + # are installed. + if ! [ -d $NEWTREE/$file ]; then + if install_new $file; then + echo " A $file" + fi + fi + return + ;; + esac + + + # Treat the file as unmodified and force install of the new + # file if it matches an ALWAYS_INSTALL glob. If the update + # attempt fails, then fall through to the normal case so a + # warning is generated. + if always_install $file; then + log "ALWAYS: updating $file" + if update_unmodified $file; then + return + fi + fi + + case $cmp in + $COMPARE_DIFFTYPE) + new=`file_type $NEWTREE/$file` + dest=`file_type $DESTDIR/$file` + warn "New file mismatch: $file ($new vs $dest)" + ;; + $COMPARE_DIFFLINKS) + new=`readlink $NEWTREE/$file` + dest=`readlink $DESTDIR/$file` + warn "New link conflict: $file (\"$new\" vs \"$dest\")" + ;; + $COMPARE_DIFFFILES) + # If the only change in the new file versus + # the destination file is a change in the + # FreeBSD ID string and -F is specified, just + # install the new file. + if [ -n "$FREEBSD_ID" ] && \ + fbsdid_only $NEWTREE/$file $DESTDIR/$file; then + if update_unmodified $file; then + return + else + panic \ + "Updating FreeBSD ID string failed" + fi + fi + + new_conflict $file + echo " C $file" + ;; + esac +} + +# Main routines for each command + +# Build a new tree and save it in a tarball. +build_cmd() +{ + local dir tartree + + if [ $# -ne 1 ]; then + echo "Missing required tarball." + echo + usage + fi + + log "build command: $1" + + # Create a temporary directory to hold the tree + dir=`mktemp -d $WORKDIR/etcupdate-XXXXXXX` + if [ $? -ne 0 ]; then + echo "Unable to create temporary directory." + exit 1 + fi + if ! build_tree $dir; then + echo "Failed to build tree." + remove_tree $dir + exit 1 + fi + if [ -n "$noroot" ]; then + tartree=@METALOG + else + tartree=. + fi + if ! tar cfj $1 -C $dir $tartree >&3 2>&1; then + echo "Failed to create tarball." + remove_tree $dir + exit 1 + fi + remove_tree $dir +} + +# Output a diff comparing the tree at DESTDIR to the current +# unmodified tree. Note that this diff does not include files that +# are present in DESTDIR but not in the unmodified tree. +diff_cmd() +{ + local file + + if [ $# -ne 0 ]; then + usage + fi + + # Requires an unmodified tree to diff against. + if ! [ -d $NEWTREE ]; then + echo "Reference tree to diff against unavailable." + exit 1 + fi + + # Unfortunately, diff alone does not quite provide the right + # level of options that we want, so improvise. + for file in `(cd $NEWTREE; find .) | sed -e 's/^\.//'`; do + if ignore $file; then + continue + fi + + diffnode $NEWTREE "$DESTDIR" $file "stock" "local" + done +} + +# Just extract a new tree into NEWTREE either by building a tree or +# extracting a tarball. This can be used to bootstrap updates by +# initializing the current "stock" tree to match the currently +# installed system. +# +# Unlike 'update', this command does not rotate or preserve an +# existing NEWTREE, it just replaces any existing tree. +extract_cmd() +{ + + if [ $# -ne 0 ]; then + usage + fi + + log "extract command: tarball=$tarball" + + # Create a temporary directory to hold the tree + dir=`mktemp -d $WORKDIR/etcupdate-XXXXXXX` + if [ $? -ne 0 ]; then + echo "Unable to create temporary directory." + exit 1 + fi + + extract_tree $dir + + if [ -d $NEWTREE ]; then + if ! remove_tree $NEWTREE; then + echo "Unable to remove current tree." + remove_tree $dir + exit 1 + fi + fi + + if ! mv $dir $NEWTREE >&3 2>&1; then + echo "Unable to rename temp tree to current tree." + remove_tree $dir + exit 1 + fi +} + +# Resolve conflicts left from an earlier merge. +resolve_cmd() +{ + local conflicts + + if [ $# -ne 0 ]; then + usage + fi + + if ! [ -d $CONFLICTS ]; then + return + fi + + if ! [ -d $NEWTREE ]; then + echo "The current tree is not present to resolve conflicts." + exit 1 + fi + + conflicts=`(cd $CONFLICTS; find . ! -type d) | sed -e 's/^\.//'` + for file in $conflicts; do + resolve_conflict $file + done + + if [ -n "$NEWALIAS_WARN" ]; then + warn "Needs update: /etc/mail/aliases.db" \ + "(requires manual update via newaliases(1))" + echo + echo "Warnings:" + echo " Needs update: /etc/mail/aliases.db" \ + "(requires manual update via newaliases(1))" + fi +} + +# Restore files to the stock version. Only files with a local change +# are restored from the stock version. +revert_cmd() +{ + local cmp file + + if [ $# -eq 0 ]; then + usage + fi + + for file; do + log "revert $file" + + if ! [ -e $NEWTREE/$file ]; then + echo "File $file does not exist in the current tree." + exit 1 + fi + if [ -d $NEWTREE/$file ]; then + echo "File $file is a directory." + exit 1 + fi + + compare $DESTDIR/$file $NEWTREE/$file + cmp=$? + if [ $cmp -eq $COMPARE_EQUAL ]; then + continue + fi + + if update_unmodified $file; then + # If this file had a conflict, clean up the + # conflict. + if [ -e $CONFLICTS/$file ]; then + if ! rm $CONFLICTS/$file >&3 2>&1; then + echo "Failed to remove conflict " \ + "for $file". + fi + fi + fi + done +} + +# Report a summary of the previous merge. Specifically, list any +# remaining conflicts followed by any warnings from the previous +# update. +status_cmd() +{ + + if [ $# -ne 0 ]; then + usage + fi + + if [ -d $CONFLICTS ]; then + (cd $CONFLICTS; find . ! -type d) | sed -e 's/^\./ C /' + fi + if [ -s $WARNINGS ]; then + echo "Warnings:" + cat $WARNINGS + fi +} + +# Perform an actual merge. The new tree can either already exist (if +# rerunning a merge), be extracted from a tarball, or generated from a +# source tree. +update_cmd() +{ + local dir new old + + if [ $# -ne 0 ]; then + usage + fi + + log "update command: rerun=$rerun tarball=$tarball preworld=$preworld" + + if [ `id -u` -ne 0 ]; then + echo "Must be root to update a tree." + exit 1 + fi + + # Enforce a sane umask + umask 022 + + # XXX: Should existing conflicts be ignored and removed during + # a rerun? + + # Trim the conflicts tree. Whine if there is anything left. + if [ -e $CONFLICTS ]; then + find -d $CONFLICTS -type d -empty -delete >&3 2>&1 + rmdir $CONFLICTS >&3 2>&1 + fi + if [ -d $CONFLICTS ]; then + echo "Conflicts remain from previous update, aborting." + exit 1 + fi + + # Save tree names to use for rotation later. + old=$OLDTREE + new=$NEWTREE + if [ -z "$rerun" ]; then + # Extract the new tree to a temporary directory. The + # trees are only rotated after a successful update to + # avoid races if an update command is interrupted + # before it completes. + dir=`mktemp -d $WORKDIR/etcupdate-XXXXXXX` + if [ $? -ne 0 ]; then + echo "Unable to create temporary directory." + exit 1 + fi + + # Populate the new tree. + extract_tree $dir + + # Compare the new tree against the previous tree. For + # the preworld case OLDTREE already points to the + # current stock tree. + if [ -z "$preworld" ]; then + OLDTREE=$NEWTREE + fi + NEWTREE=$dir + fi + + if ! [ -d $OLDTREE ]; then + cat < $WORKDIR/old.files + (cd $NEWTREE; find .) | sed -e 's/^\.//' | sort > $WORKDIR/new.files + + # Split the files up into three groups using comm. + comm -23 $WORKDIR/old.files $WORKDIR/new.files > $WORKDIR/removed.files + comm -13 $WORKDIR/old.files $WORKDIR/new.files > $WORKDIR/added.files + comm -12 $WORKDIR/old.files $WORKDIR/new.files > $WORKDIR/both.files + + # Initialize conflicts and warnings handling. + rm -f $WARNINGS + mkdir -p $CONFLICTS + if ! chmod 0700 ${CONFLICTS}; then + panic "Unable to set permissions on conflicts directory" + fi + + # Ignore removed files for the pre-world case. A pre-world + # update uses a stripped-down tree. + if [ -n "$preworld" ]; then + > $WORKDIR/removed.files + fi + + # The order for the following sections is important. In the + # odd case that a directory is converted into a file, the + # existing subfiles need to be removed if possible before the + # file is converted. Similarly, in the case that a file is + # converted into a directory, the file needs to be converted + # into a directory if possible before the new files are added. + + # First, handle removed files. + for file in `cat $WORKDIR/removed.files`; do + handle_removed_file $file + done + + # For the directory pass, reverse sort the list to effect a + # depth-first traversal. This is needed to ensure that if a + # directory with subdirectories is removed, the entire + # directory is removed if there are no local modifications. + for file in `sort -r $WORKDIR/removed.files`; do + handle_removed_directory $file + done + + # Second, handle files that exist in both the old and new + # trees. + for file in `cat $WORKDIR/both.files`; do + handle_modified_file $file + done + + # Finally, handle newly added files. + for file in `cat $WORKDIR/added.files`; do + handle_added_file $file + done + + if [ -n "$NEWALIAS_WARN" ]; then + warn "Needs update: /etc/mail/aliases.db" \ + "(requires manual update via newaliases(1))" + fi + + # Run any special one-off commands after an update has completed. + post_update + + if [ -s $WARNINGS ]; then + echo "Warnings:" + cat $WARNINGS + fi + + # If this was a dryrun, remove the temporary tree if we built + # a new one. + if [ -n "$dryrun" ]; then + if [ -n "$dir" ]; then + if [ -n "$rerun" ]; then + panic "Should not have a temporary directory" + fi + remove_tree $dir + fi + return + fi + + # Finally, rotate any needed trees. + if [ "$new" != "$NEWTREE" ]; then + if [ -n "$rerun" ]; then + panic "Should not have a temporary directory" + fi + if [ -z "$dir" ]; then + panic "Should have a temporary directory" + fi + + # Rotate the old tree if needed + if [ "$old" != "$OLDTREE" ]; then + if [ -n "$preworld" ]; then + panic "Old tree should be unchanged" + fi + + if ! remove_tree $old; then + echo "Unable to remove previous old tree." + exit 1 + fi + + if ! mv $OLDTREE $old >&3 2>&1; then + echo "Unable to rename old tree." + exit 1 + fi + fi + + # Rotate the new tree. Remove a previous pre-world + # tree if it exists. + if [ -d $new ]; then + if [ -z "$preworld" ]; then + panic "New tree should be rotated to old" + fi + if ! remove_tree $new; then + echo "Unable to remove previous pre-world tree." + exit 1 + fi + fi + + if ! mv $NEWTREE $new >&3 2>&1; then + echo "Unable to rename current tree." + exit 1 + fi + fi +} + +# Determine which command we are executing. A command may be +# specified as the first word. If one is not specified then 'update' +# is assumed as the default command. +command="update" +if [ $# -gt 0 ]; then + case "$1" in + build|diff|extract|status|resolve|revert) + command="$1" + shift + ;; + -*) + # If first arg is an option, assume the + # default command. + ;; + *) + usage + ;; + esac +fi + +# Set default variable values. + +# The path to the source tree used to build trees. +SRCDIR=/usr/src + +# The destination directory where the modified files live. +DESTDIR= + +# Ignore changes in the FreeBSD ID string. +FREEBSD_ID= + +# Files that should always have the new version of the file installed. +ALWAYS_INSTALL= + +# Files to ignore and never update during a merge. +IGNORE_FILES= + +# The path to the make binary +MAKE_CMD=make + +# Flags to pass to 'make' when building a tree. +MAKE_OPTIONS= + +# Include a config file if it exists. Note that command line options +# override any settings in the config file. More details are in the +# manual, but in general the following variables can be set: +# - ALWAYS_INSTALL +# - DESTDIR +# - EDITOR +# - FREEBSD_ID +# - IGNORE_FILES +# - LOGFILE +# - MAKE_CMD +# - MAKE_OPTIONS +# - SRCDIR +# - WORKDIR +if [ -r /etc/etcupdate.conf ]; then + . /etc/etcupdate.conf +fi + +# Parse command line options +tarball= +rerun= +always= +dryrun= +ignore= +nobuild= +preworld= +noroot= +while getopts "d:m:nprs:t:A:BD:FI:L:M:N" option; do + case "$option" in + d) + WORKDIR=$OPTARG + ;; + m) + MAKE_CMD=$OPTARG + ;; + n) + dryrun=YES + ;; + p) + preworld=YES + ;; + r) + rerun=YES + ;; + s) + SRCDIR=$OPTARG + ;; + t) + tarball=$OPTARG + ;; + A) + # To allow this option to be specified + # multiple times, accumulate command-line + # specified patterns in an 'always' variable + # and use that to overwrite ALWAYS_INSTALL + # after parsing all options. Need to be + # careful here with globbing expansion. + set -o noglob + always="$always $OPTARG" + set +o noglob + ;; + B) + nobuild=YES + ;; + D) + DESTDIR=$OPTARG + ;; + F) + FREEBSD_ID=YES + ;; + I) + # To allow this option to be specified + # multiple times, accumulate command-line + # specified patterns in an 'ignore' variable + # and use that to overwrite IGNORE_FILES after + # parsing all options. Need to be careful + # here with globbing expansion. + set -o noglob + ignore="$ignore $OPTARG" + set +o noglob + ;; + L) + LOGFILE=$OPTARG + ;; + M) + MAKE_OPTIONS="$OPTARG" + ;; + N) + noroot=YES + ;; + *) + echo + usage + ;; + esac +done +shift $((OPTIND - 1)) + +# Allow -A command line options to override ALWAYS_INSTALL set from +# the config file. +set -o noglob +if [ -n "$always" ]; then + ALWAYS_INSTALL="$always" +fi + +# Allow -I command line options to override IGNORE_FILES set from the +# config file. +if [ -n "$ignore" ]; then + IGNORE_FILES="$ignore" +fi +set +o noglob + +# Where the "old" and "new" trees are stored. +WORKDIR=${WORKDIR:-$DESTDIR/var/db/etcupdate} + +# Log file for verbose output from program that are run. The log file +# is opened on fd '3'. +LOGFILE=${LOGFILE:-$WORKDIR/log} + +# The path of the "old" tree +OLDTREE=$WORKDIR/old + +# The path of the "new" tree +NEWTREE=$WORKDIR/current + +# The path of the "conflicts" tree where files with merge conflicts are saved. +CONFLICTS=$WORKDIR/conflicts + +# The path of the "warnings" file that accumulates warning notes from an update. +WARNINGS=$WORKDIR/warnings + +# Use $EDITOR for resolving conflicts. If it is not set, default to vi. +EDITOR=${EDITOR:-/usr/bin/vi} + +# Files that need to be updated before installworld. +PREWORLD_FILES="etc/master.passwd etc/group" + +# Handle command-specific argument processing such as complaining +# about unsupported options. Since the configuration file is always +# included, do not complain about extra command line arguments that +# may have been set via the config file rather than the command line. +case $command in + update) + if [ -n "$rerun" -a -n "$tarball" ]; then + echo "Only one of -r or -t can be specified." + echo + usage + fi + if [ -n "$rerun" -a -n "$preworld" ]; then + echo "Only one of -p or -r can be specified." + echo + usage + fi + ;; + build|diff|status|revert) + if [ -n "$dryrun" -o -n "$rerun" -o -n "$tarball" -o \ + -n "$preworld" ]; then + usage + fi + ;; + resolve) + if [ -n "$dryrun" -o -n "$rerun" -o -n "$tarball" ]; then + usage + fi + ;; + extract) + if [ -n "$dryrun" -o -n "$rerun" -o -n "$preworld" ]; then + usage + fi + ;; +esac + +# Pre-world mode uses a different set of trees. It leaves the current +# tree as-is so it is still present for a full etcupdate run after the +# world install is complete. Instead, it installs a few critical files +# into a separate tree. +if [ -n "$preworld" ]; then + OLDTREE=$NEWTREE + NEWTREE=$WORKDIR/preworld +fi + +# Open the log file. Don't truncate it if doing a minor operation so +# that a minor operation doesn't lose log info from a major operation. +if ! mkdir -p $WORKDIR 2>/dev/null; then + echo "Failed to create work directory $WORKDIR" +fi + +case $command in + diff|resolve|revert|status) + exec 3>>$LOGFILE + ;; + *) + exec 3>$LOGFILE + ;; +esac + +${command}_cmd "$@" diff --git a/conf/system/include/14.3/jib b/conf/system/include/14.3/jib new file mode 100755 index 0000000..55d9084 --- /dev/null +++ b/conf/system/include/14.3/jib @@ -0,0 +1,417 @@ +#!/bin/sh +#- +# Copyright (c) 2016 Devin Teske +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +############################################################ IDENT(1) +# +# $Title: if_bridge(4) management script for vnet jails $ +# +############################################################ INFORMATION +# +# Use this tool with jail.conf(5) (or rc.conf(5) ``legacy'' configuration) to +# manage `vnet' interfaces for jails. Designed to automate the creation of vnet +# interface(s) during jail `prestart' and destroy said interface(s) during jail +# `poststop'. +# +# In jail.conf(5) format: +# +# ### BEGIN EXCERPT ### +# +# xxx { +# host.hostname = "xxx.yyy"; +# path = "/vm/xxx"; +# +# # +# # NB: Below 2-lines required +# # NB: The number of eNb_xxx interfaces should match the number of +# # arguments given to `jib addm xxx' in exec.prestart value. +# # +# vnet; +# vnet.interface = e0b_xxx, e1b_xxx, ...; +# +# exec.clean; +# exec.system_user = "root"; +# exec.jail_user = "root"; +# +# # +# # NB: Below 2-lines required +# # NB: The number of arguments after `jib addm xxx' should match +# # the number of eNb_xxx arguments in vnet.interface value. +# # +# exec.prestart += "jib addm xxx em0 em1 ..."; +# exec.poststop += "jib destroy xxx"; +# +# # Standard recipe +# exec.start += "/bin/sh /etc/rc"; +# exec.stop = "/bin/sh /etc/rc.shutdown jail"; +# exec.consolelog = "/var/log/jail_xxx_console.log"; +# mount.devfs; +# +# # Optional (default off) +# #allow.mount; +# #allow.set_hostname = 1; +# #allow.sysvipc = 1; +# #devfs_ruleset = "11"; # rule to unhide bpf for DHCP +# } +# +# ### END EXCERPT ### +# +# In rc.conf(5) ``legacy'' format (used when /etc/jail.conf does not exist): +# +# ### BEGIN EXCERPT ### +# +# jail_enable="YES" +# jail_list="xxx" +# +# # +# # Global presets for all jails +# # +# jail_devfs_enable="YES" # mount devfs +# +# # +# # Global options (default off) +# # +# #jail_mount_enable="YES" # mount /etc/fstab.{name} +# #jail_set_hostname_allow="YES" # Allow hostname to change +# #jail_sysvipc_allow="YES" # Allow SysV Interprocess Comm. +# +# # xxx +# jail_xxx_hostname="xxx.shxd.cx" # hostname +# jail_xxx_rootdir="/vm/xxx" # root directory +# jail_xxx_vnet_interfaces="e0b_xxx e1bxxx ..." # vnet interface(s) +# jail_xxx_exec_prestart0="jib addm xxx em0 em1 ..." # bridge interface(s) +# jail_xxx_exec_poststop0="jib destroy xxx" # destroy interface(s) +# #jail_xxx_mount_enable="YES" # mount /etc/fstab.xxx +# #jail_xxx_devfs_ruleset="11" # rule to unhide bpf for DHCP +# +# ### END EXCERPT ### +# +# Note that the legacy rc.conf(5) format is converted to +# /var/run/jail.{name}.conf by /etc/rc.d/jail if jail.conf(5) is missing. +# +# ASIDE: dhclient(8) inside a vnet jail... +# +# To allow dhclient(8) to work inside a vnet jail, make sure the following +# appears in /etc/devfs.rules (which should be created if it doesn't exist): +# +# [devfsrules_jail=11] +# add include $devfsrules_hide_all +# add include $devfsrules_unhide_basic +# add include $devfsrules_unhide_login +# add path 'bpf*' unhide +# +# And set ether devfs.ruleset="11" (jail.conf(5)) or +# jail_{name}_devfs_ruleset="11" (rc.conf(5)). +# +# NB: While this tool can't create every type of desirable topology, it should +# handle most setups, minus some which considered exotic or purpose-built. +# +############################################################ GLOBALS + +pgm="${0##*/}" # Program basename + +# +# Global exit status +# +SUCCESS=0 +FAILURE=1 + +############################################################ FUNCTIONS + +usage() +{ + local action usage descr + exec >&2 + echo "Usage: $pgm action [arguments]" + echo "Actions:" + for action in \ + addm \ + show \ + show1 \ + destroy \ + ; do + eval usage=\"\$jib_${action}_usage\" + [ "$usage" ] || continue + eval descr=\"\$jib_${action}_descr\" + printf "\t%s\n\t\t%s\n" "$usage" "$descr" + done + exit $FAILURE +} + +action_usage() +{ + local usage descr action="$1" + eval usage=\"\$jib_${action}_usage\" + echo "Usage: $pgm $usage" >&2 + eval descr=\"\$jib_${action}_descr\" + printf "\t%s\n" "$descr" + exit $FAILURE +} + +derive_mac() +{ + local OPTIND=1 OPTARG __flag + local __mac_num= __make_pair= + while getopts 2n: __flag; do + case "$__flag" in + 2) __make_pair=1 ;; + n) __mac_num=${OPTARG%%[^0-9]*} ;; + esac + done + shift $(( $OPTIND - 1 )) + + if [ ! "$__mac_num" ]; then + eval __mac_num=\${_${iface}_num:--1} + __mac_num=$(( $__mac_num + 1 )) + eval _${iface}_num=\$__mac_num + fi + + local __iface="$1" __name="$2" __var_to_set="$3" __var_to_set_b="$4" + local __iface_devid __new_devid __num __new_devid_b + # + # Calculate MAC address derived from given iface. + # + # The formula I'm using is ``NP:SS:SS:II:II:II'' where: + # + N denotes 4 bits used as a counter to support branching + # each parent interface up to 15 times under the same jail + # name (see S below). + # + P denotes the special nibble whose value, if one of + # 2, 6, A, or E (but usually 2) denotes a privately + # administered MAC address (while remaining routable). + # + S denotes 16 bits, the sum(1) value of the jail name. + # + I denotes bits that are inherited from parent interface. + # + # The S bits are a CRC-16 checksum of NAME, allowing the jail + # to change link numbers in ng_bridge(4) without affecting the + # MAC address. Meanwhile, if... + # + the jail NAME changes (e.g., it was duplicated and given + # a new name with no other changes) + # + the underlying network interface changes + # + the jail is moved to another host + # the MAC address will be recalculated to a new, similarly + # unique value preventing conflict. + # + __iface_devid=$( ifconfig $__iface ether | awk '/ether/,$0=$2' ) + # ??:??:??:II:II:II + __new_devid=${__iface_devid#??:??:??} # => :II:II:II + # => :SS:SS:II:II:II + __num=$( set -- `echo -n "$__name" | sum` && echo $1 ) + __new_devid=$( printf :%02x:%02x \ + $(( $__num >> 8 & 255 )) $(( $__num & 255 )) )$__new_devid + # => P:SS:SS:II:II:II + case "$__iface_devid" in + ?2:*) __new_devid=a$__new_devid __new_devid_b=e$__new_devid ;; + ?[Ee]:*) __new_devid=2$__new_devid __new_devid_b=6$__new_devid ;; + *) __new_devid=2$__new_devid __new_devid_b=e$__new_devid + esac + # => NP:SS:SS:II:II:II + __new_devid=$( printf %x $(( $__mac_num & 15 )) )$__new_devid + __new_devid_b=$( printf %x $(( $__mac_num & 15 )) )$__new_devid_b + + # + # Return derivative MAC address(es) + # + if [ "$__make_pair" ]; then + if [ "$__var_to_set" -a "$__var_to_set_b" ]; then + eval $__var_to_set=\$__new_devid + eval $__var_to_set_b=\$__new_devid_b + else + echo $__new_devid $__new_devid_b + fi + else + if [ "$__var_to_set" ]; then + eval $__var_to_set=\$__new_devid + else + echo $__new_devid + fi + fi +} + +mustberoot_to_continue() +{ + if [ "$( id -u )" -ne 0 ]; then + echo "Must run as root!" >&2 + exit $FAILURE + fi +} + +jib_addm_usage="addm [-b BRIDGE_NAME] NAME [!]iface0 [[!]iface1 ...]" +jib_addm_descr="Creates e0b_NAME [e1b_NAME ...]" +jib_addm() +{ + local OPTIND=1 OPTARG flag bridge=bridge + while getopts b: flag; do + case "$flag" in + b) bridge="${OPTARG:-bridge}" ;; + *) action_usage addm # NOTREACHED + esac + done + shift $(( $OPTIND - 1 )) + + local name="$1" + [ "${name:-x}" = "${name#*[!0-9a-zA-Z_]}" -a $# -gt 1 ] || + action_usage addm # NOTREACHED + shift 1 # name + + mustberoot_to_continue + + local iface eiface_devid_a eiface_devid_b + local new no_derive num quad i=0 + for iface in $*; do + + no_derive= + case "$iface" in + !*) iface=${iface#!} no_derive=1 ;; + esac + + # Make sure the interface doesn't exist already + if ifconfig "e${i}a_$name" > /dev/null 2>&1; then + i=$(( $i + 1 )) + continue + fi + + # Bring the interface up + ifconfig $iface up || return + + # Make sure the interface has been bridged + if ! ifconfig "$iface$bridge" > /dev/null 2>&1; then + new=$( ifconfig bridge create ) || return + ifconfig $new addm $iface || return + ifconfig $new name "$iface$bridge" || return + ifconfig "$iface$bridge" up || return + fi + + # Create a new interface to the bridge + new=$( ifconfig epair create ) || return + ifconfig "$iface$bridge" addm $new || return + + # Rename the new interface + ifconfig $new name "e${i}a_$name" || return + ifconfig ${new%a}b name "e${i}b_$name" || return + ifconfig "e${i}a_$name" up || return + ifconfig "e${i}b_$name" up || return + + # + # Set the MAC address of the new interface using a sensible + # algorithm to prevent conflicts on the network. + # + eiface_devid_a= eiface_devid_b= + [ "$no_derive" ] || derive_mac -2 $iface "$name" \ + eiface_devid_a eiface_devid_b + if [ "$eiface_devid_a" -a "$eiface_devid_b" ]; then + ifconfig "e${i}a_$name" ether $eiface_devid_a + ifconfig "e${i}b_$name" ether $eiface_devid_b + fi > /dev/null 2>&1 + + i=$(( $i + 1 )) + done # for iface +} + +jib_show_usage="show" +jib_show_descr="List possible NAME values for \`show NAME'" +jib_show1_usage="show NAME" +jib_show1_descr="Lists e0b_NAME [e1b_NAME ...]" +jib_show2_usage="show [NAME]" +jib_show() +{ + local OPTIND=1 OPTARG flag + while getopts "" flag; do + case "$flag" in + *) action_usage show2 # NOTREACHED + esac + done + shift $(( $OPTIND - 1 )) + if [ $# -eq 0 ]; then + ifconfig | awk ' + /^[^:[:space:]]+:/ { + iface = $1 + sub(/:.*/, "", iface) + next + } + $1 == "groups:" { + for (n = split($0, group); n > 1; n--) { + if (group[n] != "bridge") continue + print iface + next + } + }' | + xargs -rn1 ifconfig | + awk '$1 == "member:" && + sub(/^e[[:digit:]]+a_/, "", $2), $0 = $2' | + sort -u + return + fi + ifconfig | awk -v name="$1" ' + match($0, /^e[[:digit:]]+a_/) && sub(/:.*/, "") && + substr($1, RSTART + RLENGTH) == name + ' | sort +} + +jib_destroy_usage="destroy NAME" +jib_destroy_descr="Destroy e0b_NAME [e1b_NAME ...]" +jib_destroy() +{ + local OPTIND=1 OPTARG flag + while getopts "" flag; do + case "$flag" in + *) action_usage destroy # NOTREACHED + esac + done + shift $(( $OPTIND -1 )) + local name="$1" + [ "${name:-x}" = "${name#*[!0-9a-zA-Z_]}" -a $# -eq 1 ] || + action_usage destroy # NOTREACHED + mustberoot_to_continue + jib_show "$name" | xargs -rn1 -I eiface ifconfig eiface destroy +} + +############################################################ MAIN + +# +# Command-line arguments +# +action="$1" +[ "$action" ] || usage # NOTREACHED + +# +# Validate action argument +# +if [ "$BASH_VERSION" ]; then + type="$( type -t "jib_$action" )" || usage # NOTREACHED +else + type="$( type "jib_$action" 2> /dev/null )" || usage # NOTREACHED +fi +case "$type" in +*function) + shift 1 # action + eval "jib_$action" \"\$@\" + ;; +*) usage # NOTREACHED +esac + +################################################################################ +# END +################################################################################ diff --git a/conf/system/include/14.3/makewhatis b/conf/system/include/14.3/makewhatis new file mode 100644 index 0000000..10e74c4 Binary files /dev/null and b/conf/system/include/14.3/makewhatis differ diff --git a/conf/system/include/14.3/pf.os b/conf/system/include/14.3/pf.os new file mode 100644 index 0000000..e131d1b --- /dev/null +++ b/conf/system/include/14.3/pf.os @@ -0,0 +1,708 @@ +# $OpenBSD: pf.os,v 1.27 2016/09/03 17:08:57 sthen Exp $ +# passive OS fingerprinting +# ------------------------- +# +# SYN signatures. Those signatures work for SYN packets only (duh!). +# +# (C) Copyright 2000-2003 by Michal Zalewski +# (C) Copyright 2003 by Mike Frantzen +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# +# This fingerprint database is adapted from Michal Zalewski's p0f passive +# operating system package. The last database sync was from a Nov 3 2003 +# p0f.fp. +# +# +# Each line in this file specifies a single fingerprint. Please read the +# information below carefully before attempting to append any signatures +# reported as UNKNOWN to this file to avoid mistakes. +# +# We use the following set metrics for fingerprinting: +# +# - Window size (WSS) - a highly OS dependent setting used for TCP/IP +# performance control (max. amount of data to be sent without ACK). +# Some systems use a fixed value for initial packets. On other +# systems, it is a multiple of MSS or MTU (MSS+40). In some rare +# cases, the value is just arbitrary. +# +# NEW SIGNATURE: if p0f reported a special value of 'Snn', the number +# appears to be a multiple of MSS (MSS*nn); a special value of 'Tnn' +# means it is a multiple of MTU ((MSS+40)*nn). Unless you notice the +# value of nn is not fixed (unlikely), just copy the Snn or Tnn token +# literally. If you know this device has a simple stack and a fixed +# MTU, you can however multiply S value by MSS, or T value by MSS+40, +# and put it instead of Snn or Tnn. +# +# If WSS otherwise looks like a fixed value (for example a multiple +# of two), or if you can confirm the value is fixed, please quote +# it literally. If there's no apparent pattern in WSS chosen, you +# should consider wildcarding this value. +# +# - Overall packet size - a function of all IP and TCP options and bugs. +# +# NEW SIGNATURE: Copy this value literally. +# +# - Initial TTL - We check the actual TTL of a received packet. It can't +# be higher than the initial TTL, and also shouldn't be dramatically +# lower (maximum distance is defined as 40 hops). +# +# NEW SIGNATURE: *Never* copy TTL from a p0f-reported signature literally. +# You need to determine the initial TTL. The best way to do it is to +# check the documentation for a remote system, or check its settings. +# A fairly good method is to simply round the observed TTL up to +# 32, 64, 128, or 255, but it should be noted that some obscure devices +# might not use round TTLs (in particular, some shoddy appliances use +# "original" initial TTL settings). If not sure, you can see how many +# hops you're away from the remote party with traceroute or mtr. +# +# - Don't fragment flag (DF) - some modern OSes set this to implement PMTU +# discovery. Others do not bother. +# +# NEW SIGNATURE: Copy this value literally. +# +# - Maximum segment size (MSS) - this setting is usually link-dependent. P0f +# uses it to determine link type of the remote host. +# +# NEW SIGNATURE: Always wildcard this value, except for rare cases when +# you have an appliance with a fixed value, know the system supports only +# a very limited number of network interface types, or know the system +# is using a value it pulled out of nowhere. Specific unique MSS +# can be used to tell Google crawlbots from the rest of the population. +# +# - Window scaling (WSCALE) - this feature is used to scale WSS. +# It extends the size of a TCP/IP window to 32 bits. Some modern +# systems implement this feature. +# +# NEW SIGNATURE: Observe several signatures. Initial WSCALE is often set +# to zero or other low value. There's usually no need to wildcard this +# parameter. +# +# - Timestamp - some systems that implement timestamps set them to +# zero in the initial SYN. This case is detected and handled appropriately. +# +# - Selective ACK permitted - a flag set by systems that implement +# selective ACK functionality. +# +# - The sequence of TCP all options (MSS, window scaling, selective ACK +# permitted, timestamp, NOP). Other than the options previously +# discussed, p0f also checks for timestamp option (a silly +# extension to broadcast your uptime ;-), NOP options (used for +# header padding) and sackOK option (selective ACK feature). +# +# NEW SIGNATURE: Copy the sequence literally. +# +# To wildcard any value (except for initial TTL or TCP options), replace +# it with '*'. You can also use a modulo operator to match any values +# that divide by nnn - '%nnn'. +# +# Fingerprint entry format: +# +# wwww:ttt:D:ss:OOO...:OS:Version:Subtype:Details +# +# wwww - window size (can be *, %nnn, Snn or Tnn). The special values +# "S" and "T" which are a multiple of MSS or a multiple of MTU +# respectively. +# ttt - initial TTL +# D - don't fragment bit (0 - not set, 1 - set) +# ss - overall SYN packet size +# OOO - option value and order specification (see below) +# OS - OS genre (Linux, Solaris, Windows) +# Version - OS Version (2.0.27 on x86, etc) +# Subtype - OS subtype or patchlevel (SP3, lo0) +# details - Generic OS details +# +# If OS genre starts with '*', p0f will not show distance, link type +# and timestamp data. It is useful for userland TCP/IP stacks of +# network scanners and so on, where many settings are randomized or +# bogus. +# +# If OS genre starts with @, it denotes an approximate hit for a group +# of operating systems (signature reporting still enabled in this case). +# Use this feature at the end of this file to catch cases for which +# you don't have a precise match, but can tell it's Windows or FreeBSD +# or whatnot by looking at, say, flag layout alone. +# +# Option block description is a list of comma or space separated +# options in the order they appear in the packet: +# +# N - NOP option +# Wnnn - window scaling option, value nnn (or * or %nnn) +# Mnnn - maximum segment size option, value nnn (or * or %nnn) +# S - selective ACK OK +# T - timestamp +# T0 - timestamp with a zero value +# +# To denote no TCP options, use a single '.'. +# +# Please report any additions to this file, or any inaccuracies or +# problems spotted, to the maintainers: lcamtuf@coredump.cx, +# frantzen@openbsd.org and bugs@openbsd.org with a tcpdump packet +# capture of the relevant SYN packet(s) +# +# A test and submission page is available at +# http://lcamtuf.coredump.cx/p0f-help/ +# +# +# WARNING WARNING WARNING +# ----------------------- +# +# Do not add a system X as OS Y just because NMAP says so. It is often +# the case that X is a NAT firewall. While nmap is talking to the +# device itself, p0f is fingerprinting the guy behind the firewall +# instead. +# +# When in doubt, use common sense, don't add something that looks like +# a completely different system as Linux or FreeBSD or LinkSys router. +# Check DNS name, establish a connection to the remote host and look +# at SYN+ACK - does it look similar? +# +# Some users tweak their TCP/IP settings - enable or disable RFC1323 +# functionality, enable or disable timestamps or selective ACK, +# disable PMTU discovery, change MTU and so on. Always compare a new rule +# to other fingerprints for this system, and verify the system isn't +# "customized" before adding it. It is OK to add signature variants +# caused by a commonly used software (personal firewalls, security +# packages, etc), but it makes no sense to try to add every single +# possible /proc/sys/net/ipv4 tweak on Linux or so. +# +# KEEP IN MIND: Some packet firewalls configured to normalize outgoing +# traffic (OpenBSD pf with "scrub" enabled, for example) will, well, +# normalize packets. Signatures will not correspond to the originating +# system (and probably not quite to the firewall either). +# +# NOTE: Try to keep this file in some reasonable order, from most to +# least likely systems. This will speed up operation. Also keep most +# generic and broad rules near the end. +# + +########################## +# Standard OS signatures # +########################## + +# ----------------- AIX --------------------- + +# AIX is first because its signatures are close to NetBSD, MacOS X and +# Linux 2.0, but it uses a fairly rare MSSes, at least sometimes... +# This is a shoddy hack, though. + +45046:64:0:44:M*: AIX:4.3::AIX 4.3 +16384:64:0:44:M512: AIX:4.3:2-3:AIX 4.3.2 and earlier + +16384:64:0:60:M512,N,W%2,N,N,T: AIX:4.3:3:AIX 4.3.3-5.2 +16384:64:0:60:M512,N,W%2,N,N,T: AIX:5.1-5.2::AIX 4.3.3-5.2 +32768:64:0:60:M512,N,W%2,N,N,T: AIX:4.3:3:AIX 4.3.3-5.2 +32768:64:0:60:M512,N,W%2,N,N,T: AIX:5.1-5.2::AIX 4.3.3-5.2 +65535:64:0:60:M512,N,W%2,N,N,T: AIX:4.3:3:AIX 4.3.3-5.2 +65535:64:0:60:M512,N,W%2,N,N,T: AIX:5.1-5.2::AIX 4.3.3-5.2 +65535:64:0:64:M*,N,W1,N,N,T,N,N,S: AIX:5.3:ML1:AIX 5.3 ML1 + +# ----------------- Linux ------------------- + +# S1:64:0:44:M*:A: Linux:1.2::Linux 1.2.x (XXX quirks support) +512:64:0:44:M*: Linux:2.0:3x:Linux 2.0.3x +16384:64:0:44:M*: Linux:2.0:3x:Linux 2.0.3x + +# Endian snafu! Nelson says "ha-ha": +2:64:0:44:M*: Linux:2.0:3x:Linux 2.0.3x (MkLinux) on Mac +64:64:0:44:M*: Linux:2.0:3x:Linux 2.0.3x (MkLinux) on Mac + + +S4:64:1:60:M1360,S,T,N,W0: Linux:google::Linux (Google crawlbot) + +S2:64:1:60:M*,S,T,N,W0: Linux:2.4::Linux 2.4 (big boy) +S3:64:1:60:M*,S,T,N,W0: Linux:2.4:.18-21:Linux 2.4.18 and newer +S4:64:1:60:M*,S,T,N,W0: Linux:2.4::Linux 2.4/2.6 <= 2.6.7 +S4:64:1:60:M*,S,T,N,W0: Linux:2.6:.1-7:Linux 2.4/2.6 <= 2.6.7 + +S4:64:1:60:M*,S,T,N,W5: Linux:2.6::Linux 2.6 (newer, 1) +S4:64:1:60:M*,S,T,N,W6: Linux:2.6::Linux 2.6 (newer, 2) +S4:64:1:60:M*,S,T,N,W7: Linux:2.6::Linux 2.6 (newer, 3) +T4:64:1:60:M*,S,T,N,W7: Linux:2.6::Linux 2.6 (newer, 4) + +S10:64:1:60:M*,S,T,N,W4: Linux:3.0::Linux 3.0 + +S3:64:1:60:M*,S,T,N,W1: Linux:2.5::Linux 2.5 (sometimes 2.4) +S4:64:1:60:M*,S,T,N,W1: Linux:2.5-2.6::Linux 2.5/2.6 +S3:64:1:60:M*,S,T,N,W2: Linux:2.5::Linux 2.5 (sometimes 2.4) +S4:64:1:60:M*,S,T,N,W2: Linux:2.5::Linux 2.5 (sometimes 2.4) + +S20:64:1:60:M*,S,T,N,W0: Linux:2.2:20-25:Linux 2.2.20 and newer +S22:64:1:60:M*,S,T,N,W0: Linux:2.2::Linux 2.2 +S11:64:1:60:M*,S,T,N,W0: Linux:2.2::Linux 2.2 + +# Popular cluster config scripts disable timestamps and +# selective ACK: +S4:64:1:48:M1460,N,W0: Linux:2.4:cluster:Linux 2.4 in cluster + +# This needs to be investigated. On some systems, WSS +# is selected as a multiple of MTU instead of MSS. I got +# many submissions for this for many late versions of 2.4: +T4:64:1:60:M1412,S,T,N,W0: Linux:2.4::Linux 2.4 (late, uncommon) + +# This happens only over loopback, but let's make folks happy: +32767:64:1:60:M16396,S,T,N,W0: Linux:2.4:lo0:Linux 2.4 (local) +S8:64:1:60:M3884,S,T,N,W0: Linux:2.2:lo0:Linux 2.2 (local) + +# Opera visitors: +16384:64:1:60:M*,S,T,N,W0: Linux:2.2:Opera:Linux 2.2 (Opera?) +32767:64:1:60:M*,S,T,N,W0: Linux:2.4:Opera:Linux 2.4 (Opera?) + +# Some fairly common mods: +S4:64:1:52:M*,N,N,S,N,W0: Linux:2.4:ts:Linux 2.4 w/o timestamps +S22:64:1:52:M*,N,N,S,N,W0: Linux:2.2:ts:Linux 2.2 w/o timestamps + + +# ----------------- FreeBSD ----------------- + +16384:64:1:44:M*: FreeBSD:2.0-2.2::FreeBSD 2.0-4.2 +16384:64:1:44:M*: FreeBSD:3.0-3.5::FreeBSD 2.0-4.2 +16384:64:1:44:M*: FreeBSD:4.0-4.2::FreeBSD 2.0-4.2 +16384:64:1:60:M*,N,W0,N,N,T: FreeBSD:4.4::FreeBSD 4.4 + +1024:64:1:60:M*,N,W0,N,N,T: FreeBSD:4.4::FreeBSD 4.4 + +57344:64:1:44:M*: FreeBSD:4.6-4.8:noRFC1323:FreeBSD 4.6-4.8 (no RFC1323) +57344:64:1:60:M*,N,W0,N,N,T: FreeBSD:4.6-4.9::FreeBSD 4.6-4.9 + +32768:64:1:60:M*,N,W0,N,N,T: FreeBSD:4.8-4.11::FreeBSD 4.8-5.1 (or MacOS X) +32768:64:1:60:M*,N,W0,N,N,T: FreeBSD:5.0-5.1::FreeBSD 4.8-5.1 (or MacOS X) +65535:64:1:60:M*,N,W0,N,N,T: FreeBSD:4.8-4.11::FreeBSD 4.8-5.2 (or MacOS X) +65535:64:1:60:M*,N,W0,N,N,T: FreeBSD:5.0-5.2::FreeBSD 4.8-5.2 (or MacOS X) +65535:64:1:60:M*,N,W1,N,N,T: FreeBSD:4.7-4.11::FreeBSD 4.7-5.2 +65535:64:1:60:M*,N,W1,N,N,T: FreeBSD:5.0-5.2::FreeBSD 4.7-5.2 + +# XXX need quirks support +# 65535:64:1:60:M*,N,W0,N,N,T:Z:FreeBSD:5.1-5.4::5.1-current (1) +# 65535:64:1:60:M*,N,W1,N,N,T:Z:FreeBSD:5.1-5.4::5.1-current (2) +# 65535:64:1:60:M*,N,W2,N,N,T:Z:FreeBSD:5.1-5.4::5.1-current (3) +# 65535:64:1:44:M*:Z:FreeBSD:5.2::FreeBSD 5.2 (no RFC1323) + +# 16384:64:1:60:M*,N,N,N,N,N,N,T:FreeBSD:4.4:noTS:FreeBSD 4.4 (w/o timestamps) + +# ----------------- NetBSD ------------------ + +16384:64:0:60:M*,N,W0,N,N,T: NetBSD:1.3::NetBSD 1.3 +65535:64:0:60:M*,N,W0,N,N,T0: NetBSD:1.6:opera:NetBSD 1.6 (Opera) +16384:64:0:60:M*,N,W0,N,N,T0: NetBSD:1.6::NetBSD 1.6 +16384:64:1:60:M*,N,W0,N,N,T0: NetBSD:1.6:df:NetBSD 1.6 (DF) +65535:64:1:60:M*,N,W1,N,N,T0: NetBSD:1.6::NetBSD 1.6W-current (DF) +65535:64:1:60:M*,N,W0,N,N,T0: NetBSD:1.6::NetBSD 1.6X (DF) +32768:64:1:60:M*,N,W0,N,N,T0: NetBSD:1.6:randomization:NetBSD 1.6ZH-current (w/ ip_id randomization) + +# ----------------- OpenBSD ----------------- + +16384:64:0:60:M*,N,W0,N,N,T: OpenBSD:2.6::NetBSD 1.3 (or OpenBSD 2.6) +16384:64:1:64:M*,N,N,S,N,W0,N,N,T: OpenBSD:3.0-4.8::OpenBSD 3.0-4.8 +16384:64:0:64:M*,N,N,S,N,W0,N,N,T: OpenBSD:3.0-4.8:no-df:OpenBSD 3.0-4.8 (scrub no-df) +57344:64:1:64:M*,N,N,S,N,W0,N,N,T: OpenBSD:3.3-4.0::OpenBSD 3.3-4.0 +57344:64:0:64:M*,N,N,S,N,W0,N,N,T: OpenBSD:3.3-4.0:no-df:OpenBSD 3.3-4.0 (scrub no-df) + +65535:64:1:64:M*,N,N,S,N,W0,N,N,T: OpenBSD:3.0-4.0:opera:OpenBSD 3.0-4.0 (Opera) + +16384:64:1:64:M*,N,N,S,N,W3,N,N,T: OpenBSD:4.9::OpenBSD 4.9 +16384:64:0:64:M*,N,N,S,N,W3,N,N,T: OpenBSD:4.9:no-df:OpenBSD 4.9 (scrub no-df) + +16384:64:1:64:M*,N,N,S,N,W6,N,N,T: OpenBSD:6.1::OpenBSD 6.1 +16384:64:0:64:M*,N,N,S,N,W6,N,N,T: OpenBSD:6.1:no-df:OpenBSD 6.1 (scrub no-df) + +# ----------------- DragonFly BSD ----------------- + +57344:64:1:60:M*,N,W0,N,N,T: DragonFly:1.0:A:DragonFly 1.0A +57344:64:0:64:M*,N,W0,N,N,S,N,N,T: DragonFly:1.2-1.12::DragonFly 1.2-1.12 +5840:64:1:60:M*,S,T,N,W4: DragonFly:2.0-2.1::DragonFly 2.0-2.1 +57344:64:0:64:M*,N,W0,N,N,S,N,N,T: DragonFly:2.2-2.3::DragonFly 2.2-2.3 +57344:64:0:64:M*,N,W5,N,N,S,N,N,T: DragonFly:2.4-2.7::DragonFly 2.4-2.7 + +# ----------------- Solaris ----------------- + +S17:64:1:64:N,W3,N,N,T0,N,N,S,M*: Solaris:8:RFC1323:Solaris 8 RFC1323 +S17:64:1:48:N,N,S,M*: Solaris:8::Solaris 8 +S17:255:1:44:M*: Solaris:2.5-2.7::Solaris 2.5 to 7 + +S6:255:1:44:M*: Solaris:2.6-2.7::Solaris 2.6 to 7 +S23:255:1:44:M*: Solaris:2.5:1:Solaris 2.5.1 +S34:64:1:48:M*,N,N,S: Solaris:2.9::Solaris 9 +S44:255:1:44:M*: Solaris:2.7::Solaris 7 + +4096:64:0:44:M1460: SunOS:4.1::SunOS 4.1.x + +S34:64:1:52:M*,N,W0,N,N,S: Solaris:10:beta:Solaris 10 (beta) +32850:64:1:64:M*,N,N,T,N,W1,N,N,S: Solaris:10::Solaris 10 1203 + +# ----------------- IRIX -------------------- + +49152:64:0:44:M*: IRIX:6.4::IRIX 6.4 +61440:64:0:44:M*: IRIX:6.2-6.5::IRIX 6.2-6.5 +49152:64:0:52:M*,N,W2,N,N,S: IRIX:6.5:RFC1323:IRIX 6.5 (RFC1323) +49152:64:0:52:M*,N,W3,N,N,S: IRIX:6.5:RFC1323:IRIX 6.5 (RFC1323) + +61440:64:0:48:M*,N,N,S: IRIX:6.5:12-21:IRIX 6.5.12 - 6.5.21 +49152:64:0:48:M*,N,N,S: IRIX:6.5:15-21:IRIX 6.5.15 - 6.5.21 + +49152:60:0:64:M*,N,W2,N,N,T,N,N,S: IRIX:6.5:IP27:IRIX 6.5 IP27 + + +# ----------------- Tru64 ------------------- + +32768:64:1:48:M*,N,W0: Tru64:4.0::Tru64 4.0 (or OS/2 Warp 4) +32768:64:0:48:M*,N,W0: Tru64:5.0::Tru64 5.0 +8192:64:0:44:M1460: Tru64:5.1:noRFC1323:Tru64 6.1 (no RFC1323) (or QNX 6) +61440:64:0:48:M*,N,W0: Tru64:5.1a:JP4:Tru64 v5.1a JP4 (or OpenVMS 7.x on Compaq 5.x stack) + +# ----------------- OpenVMS ----------------- + +6144:64:1:60:M*,N,W0,N,N,T: OpenVMS:7.2::OpenVMS 7.2 (Multinet 4.4 stack) + +# ----------------- MacOS ------------------- + +# XXX Need EOL tcp opt support +# S2:255:1:48:M*,W0,E:.:MacOS:8.6 classic + +# XXX some of these use EOL too +16616:255:1:48:M*,W0: MacOS:7.3-7.6:OTTCP:MacOS 7.3-8.6 (OTTCP) +16616:255:1:48:M*,W0: MacOS:8.0-8.6:OTTCP:MacOS 7.3-8.6 (OTTCP) +16616:255:1:48:M*,N,N,N: MacOS:8.1-8.6:OTTCP:MacOS 8.1-8.6 (OTTCP) +32768:255:1:48:M*,W0,N: MacOS:9.0-9.2::MacOS 9.0-9.2 +65535:255:1:48:M*,N,N,N,N: MacOS:9.1::MacOS 9.1 (OT 2.7.4) + + +# ----------------- Windows ----------------- + +# Windows TCP/IP stack is a mess. For most recent XP, 2000 and +# even 98, the patchlevel, not the actual OS version, is more +# relevant to the signature. They share the same code, so it would +# seem. Luckily for us, almost all Windows 9x boxes have an +# awkward MSS of 536, which I use to tell one from another +# in most difficult cases. + +8192:32:1:44:M*: Windows:3.11::Windows 3.11 (Tucows) +S44:64:1:64:M*,N,W0,N,N,T0,N,N,S: Windows:95::Windows 95 +8192:128:1:64:M*,N,W0,N,N,T0,N,N,S: Windows:95:b:Windows 95b + +# There were so many tweaking tools and so many stack versions for +# Windows 98 it is no longer possible to tell them from each other +# without some very serious research. Until then, there's an insane +# number of signatures, for your amusement: + +S44:32:1:48:M*,N,N,S: Windows:98:lowTTL:Windows 98 (low TTL) +8192:32:1:48:M*,N,N,S: Windows:98:lowTTL:Windows 98 (low TTL) +%8192:64:1:48:M536,N,N,S: Windows:98::Windows 98 +%8192:128:1:48:M536,N,N,S: Windows:98::Windows 98 +S4:64:1:48:M*,N,N,S: Windows:98::Windows 98 +S6:64:1:48:M*,N,N,S: Windows:98::Windows 98 +S12:64:1:48:M*,N,N,S: Windows:98::Windows 98 +T30:64:1:64:M1460,N,W0,N,N,T0,N,N,S: Windows:98::Windows 98 +32767:64:1:48:M*,N,N,S: Windows:98::Windows 98 +37300:64:1:48:M*,N,N,S: Windows:98::Windows 98 +46080:64:1:52:M*,N,W3,N,N,S: Windows:98:RFC1323:Windows 98 (RFC1323) +65535:64:1:44:M*: Windows:98:noSack:Windows 98 (no sack) +S16:128:1:48:M*,N,N,S: Windows:98::Windows 98 +S16:128:1:64:M*,N,W0,N,N,T0,N,N,S: Windows:98::Windows 98 +S26:128:1:48:M*,N,N,S: Windows:98::Windows 98 +T30:128:1:48:M*,N,N,S: Windows:98::Windows 98 +32767:128:1:52:M*,N,W0,N,N,S: Windows:98::Windows 98 +60352:128:1:48:M*,N,N,S: Windows:98::Windows 98 +60352:128:1:64:M*,N,W2,N,N,T0,N,N,S: Windows:98::Windows 98 + +# What's with 1414 on NT? +T31:128:1:44:M1414: Windows:NT:4.0:Windows NT 4.0 SP6a +64512:128:1:44:M1414: Windows:NT:4.0:Windows NT 4.0 SP6a +8192:128:1:44:M*: Windows:NT:4.0:Windows NT 4.0 (older) + +# Windows XP and 2000. Most of the signatures that were +# either dubious or non-specific (no service pack data) +# were deleted and replaced with generics at the end. + +65535:128:1:48:M*,N,N,S: Windows:2000:SP4:Windows 2000 SP4, XP SP1 +65535:128:1:48:M*,N,N,S: Windows:XP:SP1:Windows 2000 SP4, XP SP1 +%8192:128:1:48:M*,N,N,S: Windows:2000:SP2+:Windows 2000 SP2, XP SP1 (seldom 98 4.10.2222) +%8192:128:1:48:M*,N,N,S: Windows:XP:SP1:Windows 2000 SP2, XP SP1 (seldom 98 4.10.2222) +S20:128:1:48:M*,N,N,S: Windows:2000::Windows 2000/XP SP3 +S20:128:1:48:M*,N,N,S: Windows:XP:SP3:Windows 2000/XP SP3 +S45:128:1:48:M*,N,N,S: Windows:2000:SP4:Windows 2000 SP4, XP SP 1 +S45:128:1:48:M*,N,N,S: Windows:XP:SP1:Windows 2000 SP4, XP SP 1 +40320:128:1:48:M*,N,N,S: Windows:2000:SP4:Windows 2000 SP4 + +S6:128:1:48:M*,N,N,S: Windows:2000:SP2:Windows XP, 2000 SP2+ +S6:128:1:48:M*,N,N,S: Windows:XP::Windows XP, 2000 SP2+ +S12:128:1:48:M*,N,N,S: Windows:XP:SP1:Windows XP SP1 +S44:128:1:48:M*,N,N,S: Windows:2000:SP3:Windows Pro SP1, 2000 SP3 +S44:128:1:48:M*,N,N,S: Windows:XP:SP1:Windows Pro SP1, 2000 SP3 +64512:128:1:48:M*,N,N,S: Windows:2000:SP3:Windows SP1, 2000 SP3 +64512:128:1:48:M*,N,N,S: Windows:XP:SP1:Windows SP1, 2000 SP3 +32767:128:1:48:M*,N,N,S: Windows:2000:SP4:Windows SP1, 2000 SP4 +32767:128:1:48:M*,N,N,S: Windows:XP:SP1:Windows SP1, 2000 SP4 + +8192:128:1:52:M*,N,W2,N,N,S: Windows:Vista::Windows Vista/7 + +# Odds, ends, mods: + +S52:128:1:48:M1260,N,N,S: Windows:2000:cisco:Windows XP/2000 via Cisco +S52:128:1:48:M1260,N,N,S: Windows:XP:cisco:Windows XP/2000 via Cisco +65520:128:1:48:M*,N,N,S: Windows:XP::Windows XP bare-bone +16384:128:1:52:M536,N,W0,N,N,S: Windows:2000:ZoneAlarm:Windows 2000 w/ZoneAlarm? +2048:255:0:40:.: Windows:.NET::Windows .NET Enterprise Server + +44620:64:0:48:M*,N,N,S: Windows:ME::Windows ME no SP (?) +S6:255:1:48:M536,N,N,S: Windows:95:winsock2:Windows 95 winsock 2 +32768:32:1:52:M1460,N,W0,N,N,S: Windows:2003:AS:Windows 2003 AS + + +# No need to be more specific, it passes: +# *:128:1:48:M*,N,N,S:U:-Windows:XP/2000 while downloading (leak!) XXX quirk +# there is an equiv similar generic sig w/o the quirk + +# ----------------- HP/UX ------------------- + +32768:64:1:44:M*: HP-UX:B.10.20::HP-UX B.10.20 +32768:64:0:48:M*,W0,N: HP-UX:11.0::HP-UX 11.0 +32768:64:1:48:M*,W0,N: HP-UX:11.10::HP-UX 11.0 or 11.11 +32768:64:1:48:M*,W0,N: HP-UX:11.11::HP-UX 11.0 or 11.11 + +# Whoa. Hardcore WSS. +0:64:0:48:M*,W0,N: HP-UX:B.11.00:A:HP-UX B.11.00 A (RFC1323) + +# ----------------- RiscOS ------------------ + +# We don't yet support the ?12 TCP option +#16384:64:1:68:M1460,N,W0,N,N,T,N,N,?12: RISCOS:3.70-4.36::RISC OS 3.70-4.36 +12288:32:0:44:M536: RISC OS:3.70:4.10:RISC OS 3.70 inet 4.10 + +# XXX quirk +# 4096:64:1:56:M1460,N,N,T:T: RISC OS:3.70:freenet:RISC OS 3.70 freenet 2.00 + + + +# ----------------- BSD/OS ------------------ + +# Once again, power of two WSS is also shared by MacOS X with DF set +8192:64:1:60:M1460,N,W0,N,N,T: BSD/OS:3.1::BSD/OS 3.1-4.3 (or MacOS X 10.2 w/DF) +8192:64:1:60:M1460,N,W0,N,N,T: BSD/OS:4.0-4.3::BSD/OS 3.1-4.3 (or MacOS X 10.2) + + +# ---------------- NewtonOS ----------------- + +4096:64:0:44:M1420: NewtonOS:2.1::NewtonOS 2.1 + +# ---------------- NeXTSTEP ----------------- + +S4:64:0:44:M1024: NeXTSTEP:3.3::NeXTSTEP 3.3 +S8:64:0:44:M512: NeXTSTEP:3.3::NeXTSTEP 3.3 + +# ------------------ BeOS ------------------- + +1024:255:0:48:M*,N,W0: BeOS:5.0-5.1::BeOS 5.0-5.1 +12288:255:0:44:M1402: BeOS:5.0::BeOS 5.0.x + +# ------------------ OS/400 ----------------- + +8192:64:1:60:M1440,N,W0,N,N,T: OS/400:VR4::OS/400 VR4/R5 +8192:64:1:60:M1440,N,W0,N,N,T: OS/400:VR5::OS/400 VR4/R5 +4096:64:1:60:M1440,N,W0,N,N,T: OS/400:V4R5:CF67032:OS/400 V4R5 + CF67032 + +# XXX quirk +# 28672:64:0:44:M1460:A:OS/390:? + +# ------------------ ULTRIX ----------------- + +16384:64:0:40:.: ULTRIX:4.5::ULTRIX 4.5 + +# ------------------- QNX ------------------- + +S16:64:0:44:M512: QNX:::QNX demodisk + +# ------------------ Novell ----------------- + +16384:128:1:44:M1460: Novell:NetWare:5.0:Novel Netware 5.0 +6144:128:1:44:M1460: Novell:IntranetWare:4.11:Novell IntranetWare 4.11 +6144:128:1:44:M1368: Novell:BorderManager::Novell BorderManager ? + +6144:128:1:52:M*,W0,N,S,N,N: Novell:Netware:6:Novell Netware 6 SP3 + + +# ----------------- SCO ------------------ +S3:64:1:60:M1460,N,W0,N,N,T: SCO:UnixWare:7.1:SCO UnixWare 7.1 +S17:64:1:60:M1380,N,W0,N,N,T: SCO:UnixWare:7.1:SCO UnixWare 7.1.3 MP3 +S23:64:1:44:M1380: SCO:OpenServer:5.0:SCO OpenServer 5.0 + +# ------------------- DOS ------------------- + +2048:255:0:44:M536: DOS:WATTCP:1.05:DOS Arachne via WATTCP/1.05 +T2:255:0:44:M984: DOS:WATTCP:1.05Arachne:Arachne via WATTCP/1.05 (eepro) + +# ------------------ OS/2 ------------------- + +S56:64:0:44:M512: OS/2:4::OS/2 4 +28672:64:0:44:M1460: OS/2:4::OS/2 Warp 4.0 + +# ----------------- TOPS-20 ----------------- + +# Another hardcore MSS, one of the ACK leakers hunted down. +# XXX QUIRK 0:64:0:44:M1460:A:TOPS-20:version 7 +0:64:0:44:M1460: TOPS-20:7::TOPS-20 version 7 + +# ----------------- FreeMiNT ---------------- + +S44:255:0:44:M536: FreeMiNT:1:16A:FreeMiNT 1 patch 16A (Atari) + +# ------------------ AMIGA ------------------ + +# XXX TCP option 12 +# S32:64:1:56:M*,N,N,S,N,N,?12:.:AMIGA:3.9 BB2 with Miami stack + +# ------------------ Plan9 ------------------ + +65535:255:0:48:M1460,W0,N: Plan9:4::Plan9 edition 4 + +# ----------------- AMIGAOS ----------------- + +16384:64:1:48:M1560,N,N,S: AMIGAOS:3.9::AMIGAOS 3.9 BB2 MiamiDX + +########################################### +# Appliance / embedded / other signatures # +########################################### + +# ---------- Firewalls / routers ------------ + +S12:64:1:44:M1460: @Checkpoint:::Checkpoint (unknown 1) +S12:64:1:48:N,N,S,M1460: @Checkpoint:::Checkpoint (unknown 2) +4096:32:0:44:M1460: ExtremeWare:4.x::ExtremeWare 4.x + +# XXX TCP option 12 +# S32:64:0:68:M512,N,W0,N,N,T,N,N,?12:.:Nokia:IPSO w/Checkpoint NG FP3 +# S16:64:0:68:M1024,N,W0,N,N,T,N,N,?12:.:Nokia:IPSO 3.7 build 026 + +S4:64:1:60:W0,N,S,T,M1460: FortiNet:FortiGate:50:FortiNet FortiGate 50 + +8192:64:1:44:M1460: Eagle:::Eagle Secure Gateway + +S52:128:1:48:M1260,N,N,N,N: LinkSys:WRV54G::LinkSys WRV54G VPN router + + + +# ------- Switches and other stuff ---------- + +4128:255:0:44:M*: Cisco:::Cisco Catalyst 3500, 7500 etc +S8:255:0:44:M*: Cisco:12008::Cisco 12008 +60352:128:1:64:M1460,N,W2,N,N,T,N,N,S: Alteon:ACEswitch::Alteon ACEswitch +64512:128:1:44:M1370: Nortel:Contivity Client::Nortel Conectivity Client + + +# ---------- Caches and whatnots ------------ + +S4:64:1:52:M1460,N,N,S,N,W0: AOL:web cache::AOL web cache + +32850:64:1:64:N,W1,N,N,T,N,N,S,M*: NetApp:5.x::NetApp Data OnTap 5.x +16384:64:1:64:M1460,N,N,S,N,W0,N: NetApp:5.3:1:NetApp 5.3.1 +65535:64:0:64:M1460,N,N,S,N,W*,N,N,T: NetApp:5.3-5.5::NetApp 5.3-5.5 +65535:64:0:60:M1460,N,W0,N,N,T: NetApp:CacheFlow::NetApp CacheFlow +8192:64:1:64:M1460,N,N,S,N,W0,N,N,T: NetApp:5.2:1:NetApp NetCache 5.2.1 +20480:64:1:64:M1460,N,N,S,N,W0,N,N,T: NetApp:4.1::NetApp NetCache4.1 + +65535:64:0:60:M1460,N,W0,N,N,T: CacheFlow:4.1::CacheFlow CacheOS 4.1 +8192:64:0:60:M1380,N,N,N,N,N,N,T: CacheFlow:1.1::CacheFlow CacheOS 1.1 + +S4:64:0:48:M1460,N,N,S: Cisco:Content Engine::Cisco Content Engine + +27085:128:0:40:.: Dell:PowerApp cache::Dell PowerApp (Linux-based) + +65535:255:1:48:N,W1,M1460: Inktomi:crawler::Inktomi crawler +S1:255:1:60:M1460,S,T,N,W0: LookSmart:ZyBorg::LookSmart ZyBorg + +16384:255:0:40:.: Proxyblocker:::Proxyblocker (what's this?) + +65535:255:0:48:M*,N,N,S: Redline:::Redline T|X 2200 + +32696:128:0:40:M1460: Spirent:Avalanche::Spirent Web Avalanche HTTP benchmarking engine + +# ----------- Embedded systems -------------- + +S9:255:0:44:M536: PalmOS:Tungsten:C:PalmOS Tungsten C +S5:255:0:44:M536: PalmOS:3::PalmOS 3/4 +S5:255:0:44:M536: PalmOS:4::PalmOS 3/4 +S4:255:0:44:M536: PalmOS:3:5:PalmOS 3.5 +2948:255:0:44:M536: PalmOS:3:5:PalmOS 3.5.3 (Handera) +S29:255:0:44:M536: PalmOS:5::PalmOS 5.0 +16384:255:0:44:M1398: PalmOS:5.2:Clie:PalmOS 5.2 (Clie) +S14:255:0:44:M1350: PalmOS:5.2:Treo:PalmOS 5.2.1 (Treo) + +S23:64:1:64:N,W1,N,N,T,N,N,S,M1460: SymbianOS:7::SymbianOS 7 + +8192:255:0:44:M1460: SymbianOS:6048::Symbian OS 6048 (Nokia 7650?) +8192:255:0:44:M536: SymbianOS:9210::Symbian OS (Nokia 9210?) +S22:64:1:56:M1460,T,S: SymbianOS:P800::Symbian OS ? (SE P800?) +S36:64:1:56:M1360,T,S: SymbianOS:6600::Symbian OS 60xx (Nokia 6600?) + + +# Perhaps S4? +5840:64:1:60:M1452,S,T,N,W1: Zaurus:3.10::Zaurus 3.10 + +32768:128:1:64:M1460,N,W0,N,N,T0,N,N,S: PocketPC:2002::PocketPC 2002 + +S1:255:0:44:M346: Contiki:1.1:rc0:Contiki 1.1-rc0 + +4096:128:0:44:M1460: Sega:Dreamcast:3.0:Sega Dreamcast Dreamkey 3.0 +T5:64:0:44:M536: Sega:Dreamcast:HKT-3020:Sega Dreamcast HKT-3020 (browser disc 51027) +S22:64:1:44:M1460: Sony:PS2::Sony Playstation 2 (SOCOM?) + +S12:64:0:44:M1452: AXIS:5600:v5.64:AXIS Printer Server 5600 v5.64 + +3100:32:1:44:M1460: Windows:CE:2.0:Windows CE 2.0 + +#################### +# Fancy signatures # +#################### + +1024:64:0:40:.: *NMAP:syn scan:1:NMAP syn scan (1) +2048:64:0:40:.: *NMAP:syn scan:2:NMAP syn scan (2) +3072:64:0:40:.: *NMAP:syn scan:3:NMAP syn scan (3) +4096:64:0:40:.: *NMAP:syn scan:4:NMAP syn scan (4) + +# Requires quirks support +# 1024:64:0:40:.:A:*NMAP:TCP sweep probe (1) +# 2048:64:0:40:.:A:*NMAP:TCP sweep probe (2) +# 3072:64:0:40:.:A:*NMAP:TCP sweep probe (3) +# 4096:64:0:40:.:A:*NMAP:TCP sweep probe (4) + +1024:64:0:60:W10,N,M265,T: *NMAP:OS:1:NMAP OS detection probe (1) +2048:64:0:60:W10,N,M265,T: *NMAP:OS:2:NMAP OS detection probe (2) +3072:64:0:60:W10,N,M265,T: *NMAP:OS:3:NMAP OS detection probe (3) +4096:64:0:60:W10,N,M265,T: *NMAP:OS:4:NMAP OS detection probe (4) + +32767:64:0:40:.: *NAST:::NASTsyn scan + +# Requires quirks support +# 12345:255:0:40:.:A:-p0f:sendsyn utility + + +##################################### +# Generic signatures - just in case # +##################################### + +#*:64:1:60:M*,N,W*,N,N,T: @FreeBSD:4.0-4.9::FreeBSD 4.x/5.x +#*:64:1:60:M*,N,W*,N,N,T: @FreeBSD:5.0-5.1::FreeBSD 4.x/5.x + +*:128:1:52:M*,N,W0,N,N,S: @Windows:XP:RFC1323:Windows XP/2000 (RFC1323 no tstamp) +*:128:1:52:M*,N,W0,N,N,S: @Windows:2000:RFC1323:Windows XP/2000 (RFC1323 no tstamp) +*:128:1:52:M*,N,W*,N,N,S: @Windows:XP:RFC1323:Windows XP/2000 (RFC1323 no tstamp) +*:128:1:52:M*,N,W*,N,N,S: @Windows:2000:RFC1323:Windows XP/2000 (RFC1323 no tstamp) +*:128:1:64:M*,N,W0,N,N,T0,N,N,S: @Windows:XP:RFC1323:Windows XP/2000 (RFC1323) +*:128:1:64:M*,N,W0,N,N,T0,N,N,S: @Windows:2000:RFC1323:Windows XP/2000 (RFC1323) +*:128:1:64:M*,N,W*,N,N,T0,N,N,S: @Windows:XP:RFC1323:Windows XP (RFC1323, w+) +*:128:1:48:M536,N,N,S: @Windows:98::Windows 98 +*:128:1:48:M*,N,N,S: @Windows:XP::Windows XP/2000 +*:128:1:48:M*,N,N,S: @Windows:2000::Windows XP/2000 + + diff --git a/conf/system/include/14.3/pfctl b/conf/system/include/14.3/pfctl new file mode 100644 index 0000000..226bc7f Binary files /dev/null and b/conf/system/include/14.3/pfctl differ diff --git a/conf/system/include/14.3/pfilctl b/conf/system/include/14.3/pfilctl new file mode 100644 index 0000000..264de1c Binary files /dev/null and b/conf/system/include/14.3/pfilctl differ diff --git a/conf/system/include/14.3/pflogd b/conf/system/include/14.3/pflogd new file mode 100644 index 0000000..d4927c1 Binary files /dev/null and b/conf/system/include/14.3/pflogd differ diff --git a/conf/system/include/14.3/setfib b/conf/system/include/14.3/setfib new file mode 100644 index 0000000..3265584 Binary files /dev/null and b/conf/system/include/14.3/setfib differ diff --git a/conf/system/include/14.3/sum b/conf/system/include/14.3/sum new file mode 100644 index 0000000..fcc62cd Binary files /dev/null and b/conf/system/include/14.3/sum differ diff --git a/conf/system/include/14.3/zstd b/conf/system/include/14.3/zstd new file mode 100644 index 0000000..b9deb33 Binary files /dev/null and b/conf/system/include/14.3/zstd differ diff --git a/gui/bastille_manager-lib.inc b/gui/bastille_manager-lib.inc old mode 100755 new mode 100644 index d6cf529..b15870d --- a/gui/bastille_manager-lib.inc +++ b/gui/bastille_manager-lib.inc @@ -2,7 +2,7 @@ /* bastille_manager-lib.inc - Copyright (c) 2019-2020 José Rivera (joserprg@gmail.com). + Copyright (c) 2019-2026 José Rivera (joserprg@gmail.com). All rights reserved. Redistribution and use in source and binary forms, with or without @@ -30,16 +30,18 @@ SUCH DAMAGE. */ + require_once 'super_fun.inc'; require_once 'globals.inc'; require_once 'array.inc'; require_once 'system.inc'; -// Initialize some variables. -// TODO: Some infos can be gathered with- -// internal PHP functions rather than external shell commands. +// ===== OPTIMIZATION: Cache Configuration ===== +define('JAIL_INFO_CACHE_TIME', 5); // seconds +define('JAIL_INFO_CACHE_FILE', '/tmp/bastille_jail_info_cache.json'); +// ============================================= -//$rootfolder = dirname($config['rc']['postinit']['cmd'][$i]); +// Initialize some variables. $prdname = "bastille"; $application = "Bastille Manager"; $restore_name = "restore"; @@ -67,42 +69,42 @@ $tarballversion = "/usr/local/bin/bastille"; $bastille_version_min = exec("grep 'BASTILLE_VERSION=' $tarballversion | cut -d '\"' -f2 | tr -d '.'"); $host_version = exec("/bin/cat /etc/prd.version | tr -d '.'"); $linux_compat_support = exec("/usr/bin/grep 'LINUX_COMPAT_SUPPORT=' $configfile | /usr/bin/cut -d'\"' -f2"); +$jail_settings = "settings.conf"; // Ensure the root directory is configured. -if ($rootfolder == "") +if ($rootfolder == ""): $input_errors[] = gtext("Extension installed with fault"); -else { +else: // Initialize locales. $textdomain = "/usr/local/share/locale"; $textdomain_bastille = "/usr/local/share/locale-bastille"; - if (!is_link($textdomain_bastille)) { mwexec("ln -s {$rootfolder}/locale-bastille {$textdomain_bastille}", true); } + if (!is_link($textdomain_bastille)): + mwexec("ln -s {$rootfolder}/locale-bastille {$textdomain_bastille}", true); + endif; bindtextdomain("xigmanas", $textdomain_bastille); -} +endif; if (is_file("{$rootfolder}/postinit")) unlink("{$rootfolder}/postinit"); // Check releases dir. function is_dir_empty($reldir) { - if (!is_readable($reldir)) return NULL; + if (!is_readable($reldir)) return NULL; return (count(scandir($reldir)) == 2); } // Get bastille version function get_version_bastille() { global $tarballversion, $prdname; - if (is_file("{$tarballversion}")) { - //exec("/bin/cat {$tarballversion}", $result); - exec("/usr/bin/grep 'BASTILLE_VERSION=' {$tarballversion} | cut -d'\"' -f2", $result); + if (is_file("{$tarballversion}")): + exec("/usr/bin/grep 'BASTILLE_VERSION=' {$tarballversion} | cut -d'=' -f2", $result); return ($result[0] ?? ''); - } - else { + else: exec("/usr/local/bin/{$prdname} version | awk 'NR==1'", $result); return ($result[0] ?? ''); - } + endif; } // Initial install banner function initial_install_banner() { - // Never display this if bastille is already bootstraped/activated. global $rootfolder; global $zfs_activated; $is_activated = ""; @@ -122,7 +124,7 @@ function initial_install_banner() { return $is_bootstrapped = "YES"; break; endif; - endforeach; + endforeach; endif; } @@ -144,7 +146,7 @@ function get_state_zfs() { function get_all_release_list() { global $rootfolder; global $g; - exec("/bin/echo; /bin/ls {$rootfolder}/releases 2>/dev/null | /usr/bin/tr -s ' ' '\n'",$relinfo); + exec("/bin/echo; /bin/ls {$rootfolder}/releases | grep RELEASE 2>/dev/null | /usr/bin/tr -s ' ' '\n'",$relinfo); array_shift($relinfo); $rellist = []; foreach($relinfo as $rel): @@ -189,102 +191,179 @@ foreach($a_interface as $k_interface => $ifinfo): $l_interfaces[$k_interface] = $k_interface; endforeach; -// Get jail infos. +// ===== CACHE FUNCTIONS ===== +function is_cache_valid() { + if (!file_exists(JAIL_INFO_CACHE_FILE)) { + return false; + } + $cache_age = time() - filemtime(JAIL_INFO_CACHE_FILE); + return $cache_age < JAIL_INFO_CACHE_TIME; +} + +function get_cached_jail_info() { + if (!is_cache_valid()) { + return null; + } + $cache_data = @file_get_contents(JAIL_INFO_CACHE_FILE); + if ($cache_data === false) { + return null; + } + return json_decode($cache_data, true); +} + +function save_jail_info_cache($data) { + @file_put_contents(JAIL_INFO_CACHE_FILE, json_encode($data)); +} + +function invalidate_jail_cache() { + @unlink(JAIL_INFO_CACHE_FILE); +} + +// ===== OPTIMIZED: Get jail infos ===== +// Get jail infos - OPTIMIZED VERSION function get_jail_infos() { global $img_path; global $image_dir; global $configfile; global $jail_dir; + + // Try cache first + $cached = get_cached_jail_info(); + if ($cached !== null) { + return $cached; + } + $result = []; - if(is_dir($jail_dir)): - $cmd = '/usr/local/bin/bastille list jail 2>&1'; - else: - $cmd = ":"; - endif; - mwexec2($cmd,$rawdata); - foreach($rawdata as $line): - $a = preg_split('/\t/',$line); + + if (!is_dir($jail_dir)) { + return $result; + } + + // OPTIMIZATION: Get bastille list ONCE and parse all jails + // Format: JID Name Boot Prio State Type IP_Address Published_Ports Release Tags + $cmd = '/usr/local/bin/bastille list 2>&1'; + mwexec2($cmd, $rawdata); + + // Build a lookup table from bastille list output + $jail_data_map = []; + $header_skipped = false; + + foreach ($rawdata as $line) { + // Skip header line + if (!$header_skipped) { + $header_skipped = true; + continue; + } + + // Parse fields: JID Name Boot Prio State Type IP Ports Release Tags + $fields = preg_split('/\s+/', trim($line), 10); + + if (count($fields) >= 6) { + $name = $fields[1]; + $jail_data_map[$name] = [ + 'jid' => $fields[0], + 'boot' => $fields[2], + 'prio' => $fields[3], + 'state' => $fields[4], + 'type' => $fields[5], + 'ip' => $fields[6] ?? '-', + 'ports' => $fields[7] ?? '-', + 'release' => $fields[8] ?? '-', + 'tags' => $fields[9] ?? '-' + ]; + } + } + + // Now process each jail from bastille list jail (for jail names) + $cmd = '/usr/local/bin/bastille list jail 2>&1'; + mwexec2($cmd, $jail_names); + + foreach ($jail_names as $line) { + $a = preg_split('/\t/', $line); $r = []; $name = $a[0]; - if(preg_match('/(.*)/', $name, $m)): - $r['name'] = $m[1]; - else: - $r['name'] = '-'; - endif; - $r['jailname'] = $r['name']; - // Set the JID on the running jails. - $item = $r['jailname']; - $r['id'] = exec("/usr/sbin/jls | /usr/bin/awk '/{$item}\ /{print $1}'"); - if (!$r['id']): - $r['id'] = "-"; - endif; - // Set the IPv4 on the running jails. - //$r['ip'] = exec("/usr/sbin/jls | /usr/bin/grep {$item} | /usr/bin/awk '{print $2}'"); - $r['ip'] = exec("/usr/bin/grep -w 'ip4.addr' {$jail_dir}/{$item}/jail.conf | /usr/bin/awk '{print $3}' | /usr/bin/tr -d ';'"); - if (!$r['ip']): - $r['ip'] = exec("/usr/bin/grep -w 'ip6.addr' {$jail_dir}/{$item}/jail.conf | /usr/bin/awk '{print $3}' | /usr/bin/tr -d ';'"); - endif; - // Try to get ip from vnet config. - if(!$r['ip']): - $r['ip'] = exec("/usr/local/bin/bastille cmd {$item} cat /etc/rc.conf | /usr/bin/grep 'ifconfig_vnet0=' | cut -d'\"' -f2 | sed 's/inet //'"); - endif; - if (!$r['ip']): - $r['ip'] = "-"; - endif; - // Display release. - $r['rel'] = exec("/usr/sbin/jexec {$item} freebsd-version 2>/dev/null"); - if (!$r['rel']): - $r['rel'] = exec("/usr/sbin/jexec {$item} uname -o 2>/dev/null"); - elseif (!$r['rel']): - $r['rel'] = "-"; - endif; - // Display interfaces. - $r['nic'] = exec("/usr/bin/grep -wE 'interface.*=.*;|vnet.interface.*=.*;' {$jail_dir}/{$item}/jail.conf | /usr/bin/awk '{print $3}' | /usr/bin/tr -d ';'"); - if (!$r['nic']): - $r['nic'] = "-"; - endif; - // Display path. - $r['path'] = exec("/usr/bin/grep -w 'path' {$jail_dir}/{$item}/jail.conf | /usr/bin/awk '{print $3}' | /usr/bin/tr -d ';'"); - if (!$r['path']): - $r['path'] = "-"; - endif; - // Display auto-start settings. - $jail_autostart = exec("/usr/bin/grep -w {$item}_AUTO_START $configfile | cut -d'=' -f2 | tr -d '\"'"); - if ($jail_autostart == 'YES') { - $r['boot'] = $img_path['ena']; - } elseif ($jail_autostart == 'NO') { - $r['boot'] = $img_path['dis']; + if (preg_match('/(.*)/', $name, $m)) { + $r['name'] = $m[1]; } else { - $r['boot'] = $img_path['dis']; + $r['name'] = '-'; } - // Display running status icons. - $jail_running = exec("/usr/sbin/jls name | /usr/bin/awk '/^{$item}\$/'"); - if ($jail_running): + + $r['jailname'] = $r['name']; + $item = $r['jailname']; + + // Get data from our lookup table instead of executing bastille list again + if (isset($jail_data_map[$item])) { + $jail_data = $jail_data_map[$item]; + + $r['id'] = $jail_data['jid']; + $r['boot'] = $jail_data['boot']; + $r['prio'] = $jail_data['prio']; + $r['state'] = $jail_data['state']; + $r['type'] = $jail_data['type']; + $r['ip'] = $jail_data['ip']; + $r['ports'] = $jail_data['ports']; + $r['rel'] = $jail_data['release']; + $r['tags'] = $jail_data['tags']; + } else { + // Fallback if jail not in bastille list output + $r['id'] = '-'; + $r['boot'] = '-'; + $r['prio'] = '-'; + $r['state'] = '-'; + $r['type'] = '-'; + $r['ip'] = '-'; + $r['ports'] = '-'; + $r['rel'] = '-'; + $r['tags'] = '-'; + } + + // Get description + // $r['description'] = exec("/usr/local/bin/bastille config {$item} get description"); + // if (!$r['description']) $r['description'] = "-"; + + // Set defaults for empty values + if (!$r['id']) $r['id'] = "-"; + if (!$r['boot']) $r['boot'] = "-"; + if (!$r['prio']) $r['prio'] = "-"; + if (!$r['state']) $r['state'] = "-"; + if (!$r['type']) $r['type'] = "-"; + if (!$r['ip']) $r['ip'] = "-"; + if (!$r['ports']) $r['ports'] = "-"; + if (!$r['rel']) $r['rel'] = "-"; + if (!$r['tags']) $r['tags'] = "-"; + + // Display running status icons + if ($r['state'] == "Up") { $r['stat'] = $img_path['ena']; - else: + } else { $r['stat'] = $img_path['dis']; - endif; - // Display custom template icons if available. + } + + // Display custom template icons if available $template_icon = "{$jail_dir}/{$item}/plugin_icon.png"; - if(file_exists($template_icon)): - if(!file_exists("{$image_dir}/{$item}_icon.png")): - copy("$template_icon", "{$image_dir}/{$item}_icon.png"); - endif; + if (file_exists($template_icon)) { + if (!file_exists("{$image_dir}/{$item}_icon.png")) { + @copy("$template_icon", "{$image_dir}/{$item}_icon.png"); + } $r['logo'] = "{$image_dir}/{$item}_icon.png"; - else: - $template_icon = exec("/usr/bin/grep linsysfs {$jail_dir}/{$item}/fstab"); - if($template_icon): - // Display standard Linux icon. + } else { + $template_icon = exec("/usr/bin/grep linsysfs {$jail_dir}/{$item}/fstab 2>/dev/null"); + if ($template_icon) { + // Display standard Linux icon $r['logo'] = "{$image_dir}/linux_icon.png"; - else: - // Display standard FreeBSD icon. + } else { + // Display standard FreeBSD icon $r['logo'] = "{$image_dir}/bsd_icon.png"; - endif; - endif; + } + } $result[] = $r; - endforeach; + } + + // Save to cache + save_jail_info_cache($result); + return $result; } -?> +?> \ No newline at end of file diff --git a/gui/bastille_manager_add.php b/gui/bastille_manager_add.php index 65cad35..cb11c48 100644 --- a/gui/bastille_manager_add.php +++ b/gui/bastille_manager_add.php @@ -2,7 +2,7 @@ /* bastille_manager_add.php - Copyright (c) 2019 José Rivera (joserprg@gmail.com). + Copyright (c) 2019-2026 José Rivera (joserprg@gmail.com). All rights reserved. Portions of XigmaNAS® (https://www.xigmanas.com). @@ -59,6 +59,12 @@ if(!get_all_release_list()): $prerequisites_ok = false; endif; +$zfs_status = get_state_zfs(); +if($zfs_status == "Invalid ZFS configuration"): + // Warning if invalid ZFS configuration. + $input_errors[] = gtext("WARNING: Invalid ZFS configuration detected."); +endif; + if($_POST): global $jail_dir; global $configfile; @@ -69,6 +75,12 @@ if($_POST): exit; endif; if(isset($_POST['Create']) && $_POST['Create']): + $zfs_status = get_state_zfs(); + if($zfs_status == "Invalid ZFS configuration"): + // Abort jail creation if invalid ZFS configuration. + $input_errors[] = gtext("Cannot create jail with an invalid ZFS configuration."); + else: + $jname = $pconfig['jailname']; $ipaddr = $pconfig['ipaddress']; $release = $pconfig['release']; @@ -113,10 +125,10 @@ if($_POST): // Just create an empty container with minimal jail.conf. $cmd = ("/usr/local/bin/bastille create -E {$jname}"); else: - if (isset($_POST['nowstart'])): - $cmd = ("/usr/local/bin/bastille create {$options} {$jname} {$release} {$ipaddr} {$interface} && /usr/local/bin/bastille start {$jname}"); - else: + if (isset($_POST['autostart'])): $cmd = ("/usr/local/bin/bastille create {$options} {$jname} {$release} {$ipaddr} {$interface}"); + else: + $cmd = ("/usr/local/bin/bastille create --no-boot {$options} {$jname} {$release} {$ipaddr} {$interface}"); endif; endif; @@ -124,16 +136,15 @@ if($_POST): if(get_all_release_list()): unset($output,$retval);mwexec2($cmd,$output,$retval); if($retval == 0): - if (isset($_POST['autostart'])): - exec("/usr/sbin/sysrc -f {$configfile} {$jname}_AUTO_START=\"YES\""); - endif; + //if (isset($_POST['autostart'])): + // exec("/usr/sbin/sysrc -f {$configfile} {$jname}_AUTO_START=\"YES\""); + //endif; if(is_link($resolv_conf)): if(unlink($resolv_conf)): //exec("/usr/local/bin/bastille cp $jname $resolv_host etc"); copy($resolv_host, $resolv_conf); endif; endif; - //$savemsg .= gtext("Boot Environment created and activated successfully."); header('Location: bastille_manager_gui.php'); exit; else: @@ -143,6 +154,8 @@ if($_POST): $errormsg .= gtext(" <<< Failed to create container."); endif; endif; + + endif; endif; endif; @@ -163,7 +176,7 @@ function emptyjail_change() { showElementById('thickjail_tr', 'show'); showElementById('vnetjail_tr', 'show'); showElementById('bridgejail_tr', 'show'); - showElementById('nowstart_tr', 'show'); + //showElementById('nowstart_tr', 'show'); showElementById('autostart_tr', 'show'); showElementById('linuxjail_tr', 'show'); break; @@ -174,7 +187,7 @@ function emptyjail_change() { showElementById('thickjail_tr', 'hide'); showElementById('vnetjail_tr', 'hide'); showElementById('bridgejail_tr', 'hide'); - showElementById('nowstart_tr', 'hide'); + //showElementById('nowstart_tr', 'hide'); showElementById('autostart_tr', 'hide'); showElementById('linuxjail_tr', 'hide'); break; @@ -190,7 +203,7 @@ function linuxjail_change() { showElementById('thickjail_tr', 'show'); showElementById('vnetjail_tr', 'show'); showElementById('bridgejail_tr', 'show'); - showElementById('nowstart_tr', 'show'); + //showElementById('nowstart_tr', 'show'); showElementById('autostart_tr', 'show'); showElementById('linuxjail_tr', 'show'); showElementById('emptyjail_tr', 'show'); @@ -202,7 +215,7 @@ function linuxjail_change() { showElementById('thickjail_tr', 'hide'); showElementById('vnetjail_tr', 'hide'); showElementById('bridgejail_tr', 'hide'); - showElementById('nowstart_tr', 'show'); + //showElementById('nowstart_tr', 'show'); showElementById('autostart_tr', 'show'); showElementById('emptyjail_tr', 'hide'); break; @@ -218,7 +231,7 @@ function vnetjail_change() { showElementById('thickjail_tr', 'show'); showElementById('vnetjail_tr', 'show'); showElementById('bridgejail_tr', 'show'); - showElementById('nowstart_tr', 'show'); + //showElementById('nowstart_tr', 'show'); showElementById('autostart_tr', 'show'); showElementById('linuxjail_tr', 'show'); break; @@ -229,7 +242,7 @@ function vnetjail_change() { showElementById('thickjail_tr', 'show'); showElementById('vnetjail_tr', 'show'); showElementById('bridgejail_tr', 'hide'); - showElementById('nowstart_tr', 'show'); + //showElementById('nowstart_tr', 'show'); showElementById('autostart_tr', 'show'); showElementById('linuxjail_tr', 'show'); break; @@ -245,7 +258,7 @@ function bridgejail_change() { showElementById('thickjail_tr', 'show'); showElementById('vnetjail_tr', 'show'); showElementById('bridgejail_tr', 'show'); - showElementById('nowstart_tr', 'show'); + //showElementById('nowstart_tr', 'show'); showElementById('autostart_tr', 'show'); showElementById('linuxjail_tr', 'show'); break; @@ -256,7 +269,7 @@ function bridgejail_change() { showElementById('thickjail_tr', 'show'); showElementById('vnetjail_tr', 'hide'); showElementById('bridgejail_tr', 'show'); - showElementById('nowstart_tr', 'show'); + //showElementById('nowstart_tr', 'show'); showElementById('autostart_tr', 'show'); showElementById('linuxjail_tr', 'show'); break; @@ -310,17 +323,17 @@ $document->render(); html_combobox2('interface',gettext('Network interface'),!empty($pconfig['interface']),$a_action,'',true,false); html_combobox2('release',gettext('Base release'),!empty($pconfig['release']),$b_action,'',true,false); if($bastille_version_min > "0700000000"): - html_checkbox2('thickjail',gettext('Create a thick container'),!empty($pconfig['thickjail']) ? true : false,gettext('These containers consume more space, but are self contained.'),'',false); + html_checkbox2('thickjail',gettext('Create a thick container'),!empty($pconfig['thickjail']) ? true : false,gettext('These containers consume more space, but are self contained and fully independent.'),'',false); if($host_version > "12100"): html_checkbox2('vnetjail',gettext('Enable VNET(VIMAGE)'),!empty($pconfig['vnetjail']) ? true : false,gettext('VNET-enabled containers are attached to a virtual bridge interface for connectivity(Only supported on 13.x and above).'),'',false,false,'vnetjail_change()'); html_checkbox2('bridgejail',gettext('Enable Bridge VNET(VIMAGE)'),!empty($pconfig['bridgejail']) ? true : false,gettext('Bridge VNET-enabled containers are attached to a specified, already existing external bridge(Only supported on 13.x and above).'),'',false,false,'bridgejail_change()'); endif; html_checkbox2('emptyjail',gettext('Create an empty container'),!empty($pconfig['emptyjail']) ? true : false,gettext('This are ideal for custom builds, experimenting with unsupported RELEASES or Linux jails.'),'',false,false,'emptyjail_change()'); if($linux_compat_support == "YES"): - html_checkbox2('linuxjail',gettext('Create a Linux container'),!empty($pconfig['linuxjail']) ? true : false,gettext('This will create a Linux container, this is highly experimental and for testing purposes.'),'',false,false,'linuxjail_change()'); + //html_checkbox2('linuxjail',gettext('Create a Linux container'),!empty($pconfig['linuxjail']) ? true : false,gettext('This will create a Linux container, this is highly experimental and for testing purposes.'),'',false,false,'linuxjail_change()'); endif; endif; - html_checkbox2('nowstart',gettext('Start after creation'),!empty($pconfig['nowstart']) ? true : false,gettext('Start the container after creation(May be overridden by later bastille releases).'),'',false); + //html_checkbox2('nowstart',gettext('Start after creation'),!empty($pconfig['nowstart']) ? true : false,gettext('Start the container after creation(May be overridden by later bastille releases).'),'',false); html_checkbox2('autostart',gettext('Auto start on boot'),!empty($pconfig['autostart']) ? true : false,gettext('Automatically start the container at boot time.'),'',false); ?> diff --git a/gui/bastille_manager_config.php b/gui/bastille_manager_config.php index 1f85530..8f3c422 100644 --- a/gui/bastille_manager_config.php +++ b/gui/bastille_manager_config.php @@ -2,7 +2,7 @@ /* bastille_manager_config.php - Copyright (c) 2019 José Rivera (joserprg@gmail.com). + Copyright (c) 2019-2026 José Rivera (joserprg@gmail.com). All rights reserved. Copyright (c) 2018 Andreas Schmidhuber @@ -64,6 +64,12 @@ if(!initial_install_banner()): $prerequisites_ok = false; endif; +$zfs_status = get_state_zfs(); +if($zfs_status == "Invalid ZFS configuration"): + // Warning if invalid ZFS configuration. + $input_errors[] = gtext("WARNING: Invalid ZFS configuration detected."); +endif; + function htmlInput($name, $title, $value="", $size=80) { $result = ""; return $result; @@ -135,7 +141,7 @@ if ($_POST) { if (isset($_POST['saveParam']) && $_POST['saveParam']) { // saveParam s/n/v $buttonTag = explode("#", $_POST['saveParam']); // buttonTag[0] = section, buttonTag[1] = paramName - $hashTag = str_replace(["[", "]", ".", "#"], "", $buttonTag[0]); // create destination to jump to after post + $hashTag = str_replace(["[", "]", ".", "#"], "", $buttonTag[0]); // create destination to jump to after post $nameTag = str_replace(["[", "]", ".", "#"], "", $_POST['saveParam']); // nameTag = $configArray[$buttonTag[0]][$buttonTag[1]] = $_POST[$nameTag]; // save param to section #$savemsg .= "saveParam s/n/v: ".$_POST['saveParam']." ".$nameTag." ".$_POST[$nameTag]; @@ -165,10 +171,10 @@ bindtextdomain("xigmanas", $textdomain_bastille); echo ""; if (!empty($input_errors)) print_input_errors($input_errors); if (!empty($savemsg)) print_info_box($savemsg); - echo ""; + echo ""; // loop through configuration $firstSection = true; // prevent first html_separator in loop - if (is_array($configArray) && !empty($configArray)) + if (is_array($configArray) && !empty($configArray)) foreach($configArray as $key => $line) { // traverse array, key = section $nameTag = str_replace(["[", "]", "."], "", $key); // create tag for post jump address and config changes if (is_array($line)) { diff --git a/gui/bastille_manager_editor.php b/gui/bastille_manager_editor.php index 616ebbd..0b20b38 100644 --- a/gui/bastille_manager_editor.php +++ b/gui/bastille_manager_editor.php @@ -2,7 +2,7 @@ /* bastille_manager_editor.php - Copyright (c) 2019 José Rivera (joserprg@gmail.com). + Copyright (c) 2019-2026 José Rivera (joserprg@gmail.com). All rights reserved. Portions of XigmaNAS® (https://www.xigmanas.com). @@ -60,7 +60,7 @@ if(isset($_POST['submit'])) { } else { $savemsg = sprintf('%s %s', gtext('File not found'), $savetopath); $content = ''; - $savetopath = ''; + $savetopath = ''; } } break; @@ -128,7 +128,7 @@ $(window).on("load", function() { -
+
'images/add.png', + 'mod' => 'images/edit.png', + 'del' => 'images/delete.png', + 'loc' => 'images/locked.png', + 'unl' => 'images/unlocked.png', + 'mai' => 'images/maintain.png', + 'inf' => 'images/info.png', + 'ena' => 'images/status_enabled.png', + 'dis' => 'images/status_disabled.png', + 'mup' => 'images/up.png', + 'mdn' => 'images/down.png' +]; + +// --- START AUTO-REFRESH LOGIC --- +if (isset($_GET['action']) && $_GET['action'] === 'refresh_table') { + error_reporting(0); + ini_set('display_errors', 0); + ob_start(); + + // Fetch fresh data + $jls_list = []; + if (function_exists('get_jail_infos')) { + $jls_list = get_jail_infos(); + } + + // Return JSON + ob_clean(); + header('Content-Type: application/json'); + header('Cache-Control: no-cache'); + echo json_encode(['success' => true, 'jails' => $jls_list ?: []]); + exit; +} +// --- END AUTO-REFRESH LOGIC --- + +function mwexec_parallel($commands) { + $processes = []; + $results = []; + + foreach ($commands as $key => $command) { + $descriptors = [ + 0 => ['pipe', 'r'], // stdin + 1 => ['pipe', 'w'], // stdout + 2 => ['pipe', 'w'] // stderr + ]; + + $process = proc_open($command, $descriptors, $pipes); + + if (is_resource($process)) { + stream_set_blocking($pipes[1], false); + stream_set_blocking($pipes[2], false); + + $processes[$key] = [ + 'process' => $process, + 'pipes' => $pipes, + 'command' => $command + ]; + } + } + + $timeout = 30; + $start_time = time(); + + foreach ($processes as $key => $proc) { + $elapsed = time() - $start_time; + if ($elapsed < $timeout) { + $stdout = stream_get_contents($proc['pipes'][1]); + $stderr = stream_get_contents($proc['pipes'][2]); + + fclose($proc['pipes'][0]); + fclose($proc['pipes'][1]); + fclose($proc['pipes'][2]); + + $return_code = proc_close($proc['process']); + + $results[$key] = [ + 'return_code' => $return_code, + 'stdout' => $stdout, + 'stderr' => $stderr + ]; + } else { + proc_terminate($proc['process']); + proc_close($proc['process']); + + $results[$key] = [ + 'return_code' => -1, + 'stdout' => '', + 'stderr' => 'Command timeout' + ]; + } + } + + return $results; +} + +function mwexec_background($command) { + $command = $command . ' > /dev/null 2>&1 &'; + exec($command); +} + $sphere_scriptname = basename(__FILE__); $sphere_scriptname_child = 'bastille_manager_util.php'; $sphere_header = 'Location: '.$sphere_scriptname; @@ -53,24 +153,13 @@ $gt_record_mod = gtext('Utilities'); $gt_selection_start = gtext('Start Selected'); $gt_selection_stop = gtext('Stop Selected'); $gt_selection_restart = gtext('Restart Selected'); +$gt_selection_autoboot = gtext('Auto-boot Selected'); $gt_record_conf = gtext('Jail Configuration'); $gt_record_inf = gtext('Information'); $gt_selection_start_confirm = gtext('Do you really want to start selected jail(s)?'); $gt_selection_stop_confirm = gtext('Do you want to stop the selected jail(s)?'); $gt_selection_restart_confirm = gtext('Do you want to restart the selected jail(s)?'); -$img_path = [ - 'add' => 'images/add.png', - 'mod' => 'images/edit.png', - 'del' => 'images/delete.png', - 'loc' => 'images/locked.png', - 'unl' => 'images/unlocked.png', - 'mai' => 'images/maintain.png', - 'inf' => 'images/info.png', - 'ena' => 'images/status_enabled.png', - 'dis' => 'images/status_disabled.png', - 'mup' => 'images/up.png', - 'mdn' => 'images/down.png' -]; +$gt_selection_autoboot_confirm = gtext('Do you want to set auto-boot on selected jail(s)?'); $jls_list = get_jail_infos(); $sphere_array = $jls_list; @@ -90,6 +179,12 @@ if(!initial_install_banner()): $prerequisites_ok = false; endif; +$zfs_status = get_state_zfs(); +if($zfs_status == "Invalid ZFS configuration"): + // Warning if invalid ZFS configuration. + $input_errors[] = gtext("WARNING: Invalid ZFS configuration detected."); +endif; + if($_POST): if(isset($_POST['apply']) && $_POST['apply']): $ret = array('output' => [], 'retval' => 0); @@ -108,106 +203,511 @@ if($_POST): if(isset($_POST['start_selected_jail']) && $_POST['start_selected_jail']): $checkbox_member_array = isset($_POST[$checkbox_member_name]) ? $_POST[$checkbox_member_name] : []; + $commands = []; + foreach($checkbox_member_array as $checkbox_member_record): if(false !== ($index = array_search_ex($checkbox_member_record, $sphere_array, 'jailname'))): if(!isset($sphere_array[$index]['protected'])): - $cmd = ("/usr/local/bin/bastille start {$checkbox_member_record}"); - $return_val = mwexec($cmd); - if($return_val == 0): - //$savemsg .= gtext("Jail(s) started successfully."); - header($sphere_header); - else: - $errormsg .= gtext("Failed to start jail(s)."); - endif; + $commands[] = "/usr/local/bin/bastille start {$checkbox_member_record}"; endif; endif; endforeach; + + if (!empty($commands)): + $results = mwexec_parallel($commands); + + $success_count = 0; + $fail_count = 0; + + foreach ($results as $result): + if ($result['return_code'] == 0): + $success_count++; + else: + $fail_count++; + endif; + endforeach; + + if (function_exists('invalidate_jail_cache')) { + invalidate_jail_cache(); + } + + if ($fail_count > 0): + $errormsg = sprintf(gtext("Started %d jail(s), failed %d jail(s)."), $success_count, $fail_count); + else: + $savemsg = sprintf(gtext("%d jail(s) started successfully."), $success_count); + endif; + + header($sphere_header); + endif; endif; if(isset($_POST['stop_selected_jail']) && $_POST['stop_selected_jail']): $checkbox_member_array = isset($_POST[$checkbox_member_name]) ? $_POST[$checkbox_member_name] : []; + $commands = []; + foreach($checkbox_member_array as $checkbox_member_record): if(false !== ($index = array_search_ex($checkbox_member_record, $sphere_array, 'jailname'))): if(!isset($sphere_array[$index]['protected'])): - $cmd = ("/usr/local/bin/bastille stop {$checkbox_member_record}"); - $return_val = mwexec($cmd); - if($return_val == 0): - //$savemsg .= gtext("Jail(s) stopped successfully."); - header($sphere_header); - else: - $errormsg .= gtext("Failed to stop jail(s)."); - endif; + $commands[] = "/usr/local/bin/bastille stop {$checkbox_member_record}"; endif; endif; endforeach; + + if (!empty($commands)): + $results = mwexec_parallel($commands); + + $success_count = 0; + $fail_count = 0; + + foreach ($results as $result): + if ($result['return_code'] == 0): + $success_count++; + else: + $fail_count++; + endif; + endforeach; + + if (function_exists('invalidate_jail_cache')) { + invalidate_jail_cache(); + } + + if ($fail_count > 0): + $errormsg = sprintf(gtext("Stopped %d jail(s), failed %d jail(s)."), $success_count, $fail_count); + else: + $savemsg = sprintf(gtext("%d jail(s) stopped successfully."), $success_count); + endif; + + header($sphere_header); + endif; endif; if(isset($_POST['restart_selected_jail']) && $_POST['restart_selected_jail']): $checkbox_member_array = isset($_POST[$checkbox_member_name]) ? $_POST[$checkbox_member_name] : []; + $commands = []; + foreach($checkbox_member_array as $checkbox_member_record): if(false !== ($index = array_search_ex($checkbox_member_record, $sphere_array, 'jailname'))): if(!isset($sphere_array[$index]['protected'])): - $cmd = ("/usr/local/bin/bastille restart {$checkbox_member_record}"); - $return_val = mwexec($cmd); - if($return_val == 0): - //$savemsg .= gtext("Jail(s) restarted successfully."); - header($sphere_header); - else: - $errormsg .= gtext("Failed to restart jail(s)."); - endif; + $commands[] = "/usr/local/bin/bastille restart {$checkbox_member_record}"; endif; endif; endforeach; + + if (!empty($commands)): + $results = mwexec_parallel($commands); + + $success_count = 0; + $fail_count = 0; + + foreach ($results as $result): + if ($result['return_code'] == 0): + $success_count++; + else: + $fail_count++; + endif; + endforeach; + + if (function_exists('invalidate_jail_cache')) { + invalidate_jail_cache(); + } + + if ($fail_count > 0): + $errormsg = sprintf(gtext("Restarted %d jail(s), failed %d jail(s)."), $success_count, $fail_count); + else: + $savemsg = sprintf(gtext("%d jail(s) restarted successfully."), $success_count); + endif; + + header($sphere_header); + endif; + endif; + + if(isset($_POST['autoboot_selected_jail']) && $_POST['autoboot_selected_jail']): + $checkbox_member_array = isset($_POST[$checkbox_member_name]) ? $_POST[$checkbox_member_name] : []; + $commands = []; + + foreach($checkbox_member_array as $checkbox_member_record): + if(false !== ($index = array_search_ex($checkbox_member_record, $sphere_array, 'jailname'))): + if(!isset($sphere_array[$index]['protected'])): + $commands[] = "/usr/local/bin/bastille config {$checkbox_member_record} set boot on"; + endif; + endif; + endforeach; + + if (!empty($commands)): + $results = mwexec_parallel($commands); + + $success_count = 0; + $fail_count = 0; + + foreach ($results as $result): + if ($result['return_code'] == 0): + $success_count++; + else: + $fail_count++; + endif; + endforeach; + + if (function_exists('invalidate_jail_cache')) { + invalidate_jail_cache(); + } + + if ($fail_count > 0): + $errormsg = sprintf(gtext("Set autoboot on %d jail(s), failed %d jail(s)."), $success_count, $fail_count); + else: + $savemsg = sprintf(gtext("Autoboot set on %d jail(s) successfully."), $success_count); + endif; + + header($sphere_header); + endif; endif; endif; -$pgtitle = [gtext("Extensions"), gtext('Bastille')]; +$pgtitle = [gtext("Extensions"), gtext('Bastille'), gtext('Manager')]; include 'fbegin.inc'; ?> + + @@ -250,36 +750,57 @@ $document->render(); - - - + +
+ + + + - - + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + @@ -308,12 +829,16 @@ $document->render(); ?> - + + + + + + + - - - + @@ -351,7 +877,7 @@ $document->render(); - + @@ -362,10 +888,12 @@ $document->render(); +
                @@ -336,6 +861,7 @@ $document->render(); endif; endif; ?> + <?=$gt_record_conf?>
<?=$gt_record_add;?>
\ No newline at end of file diff --git a/gui/bastille_manager_info.php b/gui/bastille_manager_info.php index 3512ae2..ef8e620 100644 --- a/gui/bastille_manager_info.php +++ b/gui/bastille_manager_info.php @@ -2,7 +2,7 @@ /* bastille_manager_info.php - Copyright (c) 2019 José Rivera (joserprg@gmail.com). + Copyright (c) 2019-2026 José Rivera (joserprg@gmail.com). All rights reserved. Portions of XigmaNAS® (https://www.xigmanas.com). @@ -39,6 +39,12 @@ require_once 'auth.inc'; require_once 'guiconfig.inc'; require_once("bastille_manager-lib.inc"); +$zfs_status = get_state_zfs(); +if($zfs_status == "Invalid ZFS configuration"): + // Warning if invalid ZFS configuration. + $input_errors[] = gtext("WARNING: Invalid ZFS configuration detected."); +endif; + function jls_get_jail_list(string $entity_name = NULL) { if(isset($entity_name)): $cmd = "/usr/sbin/jls -v -j $entity_name 2>&1"; @@ -141,7 +147,7 @@ $document->render(); - + @@ -442,6 +532,7 @@ endif; . gtext('For additional information about the jail configuration file, check the FreeBSD documentation') . '.'; html_remark("note", gtext('Note'), $helpinghand); + html_remark("note", gtext("Warning"), sprintf(gtext("Please be careful here as no input validation will be performed."))); ?> diff --git a/gui/bastille_manager_maintenance.php b/gui/bastille_manager_maintenance.php index c2a8c85..ebb4121 100644 --- a/gui/bastille_manager_maintenance.php +++ b/gui/bastille_manager_maintenance.php @@ -2,7 +2,7 @@ /* bastille_manager_maintenance.php - Copyright (c) 2019-2020 José Rivera (joserprg@gmail.com). + Copyright (c) 2019-2026 José Rivera (joserprg@gmail.com). All rights reserved. Copyright (c) 2016 Andreas Schmidhuber @@ -54,6 +54,12 @@ if(!initial_install_banner()): $prerequisites_ok = false; endif; +$zfs_status = get_state_zfs(); +if($zfs_status == "Invalid ZFS configuration"): + // Warning if invalid ZFS configuration. + $input_errors[] = gtext("WARNING: Invalid ZFS configuration detected."); +endif; + // For legacy product versions. $legacy_check = mwexec("/bin/cat /etc/prd.version | cut -d'.' -f1 | /usr/bin/grep '10'", true); if ($legacy_check == 0) { @@ -82,8 +88,11 @@ if ($_POST) { ob_start(); include("{$logevent}"); $ausgabe = ob_get_contents(); - ob_end_clean(); + ob_end_clean(); $savemsg .= str_replace("\n", "
", $ausgabe)."
"; + // Silently execute bastille-init post upgrade for pending changes. + // This is to make sure that minor changes are always applied. + exec('bastille-init'); else: $input_errors[] = gtext('An error has occurred during upgrade process.'); $cmd = sprintf('echo %s: %s An error has occurred during upgrade process. >> %s',$date,$application,$logfile); @@ -100,7 +109,7 @@ if ($_POST) { ob_start(); include("{$logevent}"); $ausgabe = ob_get_contents(); - ob_end_clean(); + ob_end_clean(); $savemsg .= str_replace("\n", "
", $ausgabe)."
"; else: $input_errors[] = gtext('An error has occurred during core update process.'); @@ -116,12 +125,12 @@ if ($_POST) { if (is_link($textdomain_bastille)) mwexec("rm -f {$textdomain_bastille}", true); if (is_dir($confdir)) mwexec("rm -Rf {$confdir}", true); mwexec("rm /usr/local/www/bastille_manager_gui.php && rm -R /usr/local/www/ext/bastille", true); - mwexec("{$rootfolder}/usr/local/sbin/bastille-init -t", true); + mwexec("{$rootfolder}/usr/local/sbin/bastille-init -t", true); $uninstall_cmd = "echo 'y' | /usr/local/sbin/bastille-init -U"; mwexec($uninstall_cmd, true); if (is_link("/usr/local/share/{$prdname}")) mwexec("rm /usr/local/share/{$prdname}", true); - if (is_link("/var/cache/pkg")) mwexec("rm /var/cache/pkg", true); - if (is_link("/var/db/pkg")) mwexec("rm /var/db/pkg && mkdir /var/db/pkg", true); + //if (is_link("/var/cache/pkg")) mwexec("rm /var/cache/pkg", true); + //if (is_link("/var/db/pkg")) mwexec("rm /var/db/pkg && mkdir /var/db/pkg", true); // Remove start postinit cmd in later product versions. if (is_array($config['rc']) && is_array($config['rc']['param'])) { @@ -211,7 +220,7 @@ if ($_POST) { ob_start(); include("{$logevent}"); $ausgabe = ob_get_contents(); - ob_end_clean(); + ob_end_clean(); $savemsg .= str_replace("\n", "
", $ausgabe)."
"; exec("/usr/sbin/sysrc -f {$configfile} ZFS_ACTIVATED=\"YES\""); else: @@ -237,8 +246,6 @@ if ($_POST) { $savemsg .= gtext("ZFS activation option has been skipped."); endif; endif; - # Run bastille-init to update config. - exec("bastille-init"); } if (isset($_POST['restore']) && $_POST['restore']) { @@ -299,6 +306,23 @@ $(document).ready(function(){ $('#getinfo_bastille').html(data.bastille); $('#getinfo_ext').html(data.ext); }); + + // --- LOGICA DEL CHECKBOX REFRESH (LocalStorage) --- + var $chk = $("#show_refresh_button"); + + // 1. Leer estado inicial desde LocalStorage + var savedState = localStorage.getItem('bastille_show_refresh_button'); + if (savedState === 'true') { + $chk.prop('checked', true); + } else { + $chk.prop('checked', false); // Por defecto deshabilitado + } + + // 2. Guardar cambios al hacer click + $chk.change(function() { + var isChecked = $(this).is(':checked'); + localStorage.setItem('bastille_show_refresh_button', isChecked); + }); }); //]]> @@ -306,19 +330,16 @@ $(document).ready(function(){
+
  • + +
    -
      -
    • +
        +
      • -
      • -
      -
    • @@ -352,14 +373,20 @@ $(document).ready(function(){ html_checkbox2('zfs_activate',gtext('ZFS support activation'),'' ? true : false,gtext('Check this to activate ZFS support or leave unchecked to dismiss (requires ZFS support to be available/enabled), this is a one time option and this row will disappear after clicking Save button or page refresh.'),'',false); endif; ?> - +
    " value=""/> " value="" /> - " value="" /> + " value="" /> " value="" />
    + + + + + +
    @@ -369,6 +396,7 @@ $(document).ready(function(){ +
    " value="" onclick="return confirm('')" /> @@ -378,8 +406,6 @@ $(document).ready(function(){ - + \ No newline at end of file diff --git a/gui/bastille_manager_tarballs.php b/gui/bastille_manager_tarballs.php index ba8d0bb..0041eee 100644 --- a/gui/bastille_manager_tarballs.php +++ b/gui/bastille_manager_tarballs.php @@ -2,7 +2,7 @@ /* bastille_manager_tarballs.php - Copyright (c) 2019 José Rivera (joserprg@gmail.com). + Copyright (c) 2019-2026 José Rivera (joserprg@gmail.com). All rights reserved. Portions of XigmaNAS® (https://www.xigmanas.com). @@ -53,7 +53,7 @@ function get_rel_list() { if (is_dir("{$rootfolder}/releases")): $entries = preg_grep('/^[0-9]+\.[0-9]+\-RELEASE|(Debian[0-9]{1,2}$)|(Ubuntu_[0-9]{4}$)/', scandir("{$rootfolder}/releases")); foreach($entries as $entry): - $a = preg_split('/\t/',$entry); + $a = preg_split('/\t/',$entry); $r = []; $name = $a[0]; if(preg_match('/^[0-9]+\.[0-9]+\-RELEASE|(Debian[0-9]{1,2}$)|(Ubuntu_[0-9]{4}$)/', $name, $m)): @@ -67,53 +67,42 @@ function get_rel_list() { endif; return $result; } + +$zfs_status = get_state_zfs(); +if($zfs_status == "Invalid ZFS configuration"): + // Warning if invalid ZFS configuration. + $input_errors[] = gtext("WARNING: Invalid ZFS configuration detected."); +endif; + $rel_list = get_rel_list(); $sphere_array = $rel_list; if ($linux_compat_support == "YES"): $a_action = [ - //'14.2-RELEASE' => gettext('14.2-RELEASE'), + '14.3-RELEASE' => gettext('14.3-RELEASE'), + '14.2-RELEASE' => gettext('14.2-RELEASE'), '14.1-RELEASE' => gettext('14.1-RELEASE'), '14.0-RELEASE' => gettext('14.0-RELEASE'), + '13.5-RELEASE' => gettext('13.5-RELEASE'), '13.4-RELEASE' => gettext('13.4-RELEASE'), - '13.3-RELEASE' => gettext('13.3-RELEASE'), - '13.2-RELEASE' => gettext('13.2-RELEASE'), - '13.1-RELEASE' => gettext('13.1-RELEASE'), - '13.0-RELEASE' => gettext('13.0-RELEASE'), - '12.4-RELEASE' => gettext('12.4-RELEASE'), - '12.3-RELEASE' => gettext('12.3-RELEASE'), - '12.2-RELEASE' => gettext('12.2-RELEASE'), - '12.1-RELEASE' => gettext('12.1-RELEASE'), - '12.0-RELEASE' => gettext('12.0-RELEASE'), - '11.4-RELEASE' => gettext('11.4-RELEASE'), - '11.3-RELEASE' => gettext('11.3-RELEASE'), - '11.2-RELEASE' => gettext('11.2-RELEASE'), - 'ubuntu-jammy' => gettext('Ubuntu-Jammy'), - 'ubuntu-focal' => gettext('Ubuntu-Focal'), - 'ubuntu-bionic' => gettext('Ubuntu-Bionic'), - 'debian-bookworm' => gettext('Debian-Bookworm'), - 'debian-bullseye' => gettext('Debian-Bullseye'), - 'debian-buster' => gettext('Debian-Buster'), - //'debian-stretch' => gettext('Debian-Stretch'), -> Obsolete, removed from bastille boostrap. + // Linux base release bootstrap is allowed from command-line. + //'ubuntu-noble' => gettext('Ubuntu-noble'), + //'ubuntu-jammy' => gettext('Ubuntu-Jammy'), + //'ubuntu-focal' => gettext('Ubuntu-Focal'), + //'ubuntu-bionic' => gettext('Ubuntu-Bionic'), + //'debian-bookworm' => gettext('Debian-Bookworm'), + //'debian-bullseye' => gettext('Debian-Bullseye'), + //'debian-buster' => gettext('Debian-Buster'), + //'debian-stretch' => gettext('Debian-Stretch'), ]; else: $a_action = [ - //'14.2-RELEASE' => gettext('14.2-RELEASE'), + '14.3-RELEASE' => gettext('14.3-RELEASE'), + '14.2-RELEASE' => gettext('14.2-RELEASE'), '14.1-RELEASE' => gettext('14.1-RELEASE'), '14.0-RELEASE' => gettext('14.0-RELEASE'), + '13.5-RELEASE' => gettext('13.5-RELEASE'), '13.4-RELEASE' => gettext('13.4-RELEASE'), - '13.3-RELEASE' => gettext('13.3-RELEASE'), - '13.2-RELEASE' => gettext('13.2-RELEASE'), - '13.1-RELEASE' => gettext('13.1-RELEASE'), - '13.0-RELEASE' => gettext('13.0-RELEASE'), - '12.4-RELEASE' => gettext('12.4-RELEASE'), - '12.3-RELEASE' => gettext('12.3-RELEASE'), - '12.2-RELEASE' => gettext('12.2-RELEASE'), - '12.1-RELEASE' => gettext('12.1-RELEASE'), - '12.0-RELEASE' => gettext('12.0-RELEASE'), - '11.4-RELEASE' => gettext('11.4-RELEASE'), - '11.3-RELEASE' => gettext('11.3-RELEASE'), - '11.2-RELEASE' => gettext('11.2-RELEASE'), ]; endif; @@ -135,6 +124,7 @@ if($_POST): $check_release = ("{$rootfolder}/releases/{$get_release}"); $cmd = sprintf('/bin/echo "Y" | /usr/local/bin/bastille bootstrap %1$s > %2$s',$get_release,$logevent); $base_mandatory = "base"; + $zfs_status = get_state_zfs(); //unset($lib32,$ports,$src); if (isset($_POST['lib32'])): @@ -148,12 +138,12 @@ if($_POST): endif; $opt_tarballs = "$lib32 $ports $src"; - // FreeBSD base release check. - //if(file_exists($check_release)): - // $savemsg .= sprintf(gtext('%s base appears to be already extracted.'),$get_release); - //else: - // Download a FreeBSD base release. - if ($_POST['Download']): + // Download a FreeBSD base release. + if ($_POST['Download']): + if($zfs_status == "Invalid ZFS configuration"): + // Abort bootstrap if invalid ZFS configuration. + $input_errors[] = gtext("Cannot bootstrap with an invalid ZFS configuration."); + else: $savemsg = ""; $errormsg = ""; if ($opt_tarballs): @@ -177,8 +167,9 @@ if($_POST): else: $errormsg .= sprintf(gtext('%s Failed to download and/or extract release base.'),$get_release); endif; + endif; - //endif; + endif; endif; if (isset($_POST['Destroy']) && $_POST['Destroy']): @@ -212,7 +203,7 @@ if($_POST): // Do not delete base releases with containers child. if ($check_used): $errormsg .= sprintf(gtext('%s base appears to have containers child.'),$get_release); - else: + else: // Delete the FreeBSD base release/directory. if ($_POST['Destroy']): unset($output,$retval);mwexec2($cmd,$output,$retval); @@ -222,7 +213,7 @@ if($_POST): else: $errormsg .= sprintf(gtext('%s failed to delete.'),$get_release); endif; - endif; + endif; endif; endif; endif; @@ -284,7 +275,7 @@ $document->render(); = $bastille_version_min): if ($zfs_activated == "YES"): if ($pconfig['format'] == "default"): $export_format = "--xz"; - $cmd = ("$bastille_bin_path/bastille export $export_option $export_format '{$item}'"); + $cmd = ("/usr/local/bin/bastille export $export_option $export_format '{$item}'"); else: - $cmd = ("$bastille_bin_path/bastille export $export_option $user_export_format '{$item}'"); + $cmd = ("/usr/local/bin/bastille export $export_option $user_export_format '{$item}'"); endif; else: if ($pconfig['format'] == "default"): $export_format = "--txz"; - $cmd = ("$bastille_bin_path/bastille export $export_format '{$item}'"); + $cmd = ("/usr/local/bin/bastille export $export_option $export_format '{$item}'"); else: - $cmd = ("$bastille_bin_path/bastille export $user_export_format '{$item}'"); + $cmd = ("/usr/local/bin/bastille export $export_option $user_export_format '{$item}'"); endif; endif; - else: - $cmd = ("$bastille_bin_path/bastille export '{$item}'"); - endif; unset($output,$retval);mwexec2($cmd,$output,$retval); if($retval == 0): @@ -225,9 +241,17 @@ if($_POST): $current_release = exec("/usr/bin/grep '\-RELEASE' {$jail_dir}/{$item}/fstab | awk '{print $1}' | grep -o '[^/]*$'"); if ($_POST['update_base']): - $cmd = ("/usr/local/sbin/bastille-init update '{$current_release}'"); + if ($_POST['update_base_force']): + $cmd = ("/usr/local/sbin/bastille-init update_force '{$current_release}'"); + else: + $cmd = ("/usr/local/sbin/bastille-init update '{$current_release}'"); + endif; elseif ($_POST['update_jail']): - $cmd = ("/usr/local/sbin/bastille-init update '{$item}'"); + if ($_POST['update_jail_force']): + $cmd = ("/usr/local/sbin/bastille-init update_force '{$item}'"); + else: + $cmd = ("/usr/local/sbin/bastille-init update '{$item}'"); + endif; else: $input_errors[] = sprintf(gtext("Failed to update container %s."),$item); break; @@ -236,7 +260,14 @@ if($_POST): unset($output,$retval);mwexec2($cmd,$output,$retval); if($retval == 0): $update_release = exec("/usr/sbin/jexec -l {$item} freebsd-version"); - $savemsg .= sprintf(gtext("Container release updated to %s successfully."),$update_release); + if (($_POST['update_jail_force']) || ($_POST['update_base_force'])): + $savemsg .= sprintf(gtext("Container release forcefully updated to %s successfully, a restart is required to apply pending changes."),$update_release); + else: + $savemsg .= sprintf(gtext("Container release updated to %s successfully, a restart is required to apply pending changes."),$update_release); + endif; + if ($_POST['update_base']): + exec("/usr/local/bin/bastille config {$item} set osrelease $update_release"); + endif; exec("echo '{$date}: {$application}: Container release updated to {$update_release} successfully for {$item}' >> {$logfile}"); //header('Location: bastille_manager_gui.php'); //exit; @@ -284,7 +315,8 @@ if($_POST): $container['jailname'] = $_POST['jailname']; $confirm_name = $pconfig['confirmname']; $item = $container['jailname']; - $cmd = ("/usr/sbin/sysrc -f {$configfile} {$item}_AUTO_START=\"YES\""); + //$cmd = ("/usr/sbin/sysrc -f {$configfile} {$item}_AUTO_START=\"YES\""); + $cmd = ("/usr/sbin/sysrc -f {$jail_dir}/{$item}/{$jail_settings} boot=\"on\""); unset($output,$retval);mwexec2($cmd,$output,$retval); if($retval == 0): header('Location: bastille_manager_gui.php'); @@ -303,8 +335,9 @@ if($_POST): $container['jailname'] = $_POST['jailname']; $confirm_name = $pconfig['confirmname']; $item = $container['jailname']; - if(exec("/usr/sbin/sysrc -f $configfile -qn {$item}_AUTO_START")): - $cmd = ("/usr/sbin/sysrc -f $configfile -x {$item}_AUTO_START"); + if(exec("/usr/sbin/sysrc -f {$jail_dir}/{$item}/{$jail_settings} -qn boot")): + //$cmd = ("/usr/sbin/sysrc -f $configfile -x {$item}_AUTO_START"); + $cmd = ("/usr/sbin/sysrc -f {$jail_dir}/{$item}/{$jail_settings} boot=\"off\""); unset($output,$retval);mwexec2($cmd,$output,$retval); if($retval == 0): header('Location: bastille_manager_gui.php'); @@ -316,6 +349,31 @@ if($_POST): endif; break; + case 'priority': + // Input validation required + if(empty($input_errors)): + $container = []; + $container['uuid'] = $_POST['uuid']; + $container['jailname'] = $_POST['jailname']; + $set_priority = $pconfig['prioritynumber']; + $item = $container['jailname']; + if(exec("/usr/sbin/sysrc -f {$jail_dir}/{$item}/{$jail_settings} -qn priority")): + if (is_numeric($set_priority)): + $cmd = ("/usr/local/bin/bastille config {$item} set priority {$set_priority}"); + unset($output,$retval);mwexec2($cmd,$output,$retval); + if($retval == 0): + header('Location: bastille_manager_gui.php'); + exit; + else: + $input_errors[] = gtext("Failed to set priority."); + endif; + else: + $input_errors[] = gtext("Priority value must be a number."); + endif; + endif; + endif; + break; + case 'fstab': // Input validation not required if(empty($input_errors)): @@ -376,7 +434,7 @@ if($_POST): break; case 'delete': - // Delete a contained + // Delete a container if(empty($input_errors)): $container = []; $container['uuid'] = $_POST['uuid']; @@ -390,9 +448,9 @@ if($_POST): break; else: if (isset($_POST['nowstop'])): - $cmd = ("/usr/local/bin/bastille destroy -f {$item}"); + $cmd = ("/usr/local/bin/bastille destroy -afy {$item}"); else: - $cmd = ("/usr/local/bin/bastille destroy {$item}"); + $cmd = ("/usr/local/bin/bastille destroy -fy {$item}"); endif; unset($output,$retval);mwexec2($cmd,$output,$retval); if($retval == 0): @@ -439,6 +497,8 @@ function action_change() { showElementById('release_tr','hide'); showElementById('update_base_tr','hide'); showElementById('update_jail_tr','hide'); + showElementById('update_base_force_tr', 'hide'); + showElementById('update_jail_force_tr', 'hide'); showElementById('newname_tr', 'hide'); showElementById('newipaddr_tr', 'hide'); showElementById('clonestop_tr', 'hide'); @@ -447,15 +507,15 @@ function action_change() { showElementById('backup_tr', 'hide'); showElementById('format_tr', 'hide'); showElementById('safemode_tr', 'hide'); - //showElementById('dateadd_tr','hide'); + showElementById('livemode_tr', 'hide'); + showElementById('prioritynumber_tr','hide'); var action = document.iform.action.value; switch (action) { case "backup": - showElementById('confirmname_tr','hide'); - showElementById('nowstop_tr','hide'); showElementById('backup_tr', 'show'); showElementById('format_tr', 'show'); showElementById('safemode_tr', 'show'); + showElementById('livemode_tr', 'show'); break; case "clone": showElementById('newname_tr','show'); @@ -463,30 +523,25 @@ function action_change() { showElementById('clonestop_tr','show'); break; case "update": - showElementById('confirmname_tr','hide'); - showElementById('nowstop_tr','hide'); showElementById('update_base_tr','show'); showElementById('update_jail_tr','show'); + showElementById('update_base_force_tr', 'show'); + showElementById('update_jail_force_tr', 'show'); break; case "base": - showElementById('confirmname_tr','hide'); - showElementById('nowstop_tr','hide'); showElementById('jail_release_tr', 'show'); showElementById('release_tr','show'); break; case "autoboot": - showElementById('confirmname_tr','hide'); - showElementById('nowstop_tr','hide'); showElementById('auto_boot_tr', 'show'); break; case "noauto": - showElementById('confirmname_tr','hide'); - showElementById('nowstop_tr','hide'); showElementById('no_autoboot_tr', 'show'); break; + case "priority": + showElementById('prioritynumber_tr','show'); + break; case "fstab": - showElementById('confirmname_tr','hide'); - showElementById('nowstop_tr','hide'); showElementById('source_path_tr','show'); showElementById('target_path_tr','show'); showElementById('path_check_tr','show'); @@ -499,8 +554,6 @@ function action_change() { showElementById('nowstop_tr','show'); break; case "advanced": - showElementById('confirmname_tr','hide'); - showElementById('nowstop_tr','hide'); showElementById('advanced_tr','show'); break; default: @@ -548,6 +601,7 @@ $document->render(); /dev/null"); $current_release = ""; @@ -575,6 +629,7 @@ $document->render(); 'base' => gettext('Release'), 'autoboot' => gettext('Autoboot'), 'noauto' => gettext('Noauto'), + 'priority' => gettext('Priority'), 'fstab' => gettext('Fstab'), 'delete' => gettext('Destroy'), 'advanced' => gettext('Advanced'), @@ -587,47 +642,56 @@ $document->render(); 'raw' => gettext('RAW'), 'tgz' => gettext('TGZ'), 'txz' => gettext('TXZ'), + 'tzst' => gettext('TZST'), 'xz' => gettext('XZ'), + 'zst' => gettext('ZST'), ]; else: $c_action = [ 'default' => gettext('Default'), 'tgz' => gettext('TGZ'), 'txz' => gettext('TXZ'), + 'tzst' => gettext('TZST'), ]; endif; html_combobox2('action',gettext('Action'),!empty($pconfig['action']),$a_action,'',true,false,'action_change()'); html_combobox2('format',gettext('Archive format'),!empty($pconfig['format']),$c_action,'',true,false); if ($zfs_activated == "YES"): - html_checkbox2('safemode',gettext('Safe ZFS export'),!empty($pconfig['safemode']) ? true : false,gettext('Safely stop and start a ZFS jail before the exporting process, this has no effect on .TGZ/TXZ since the jail should be stopped regardless.'),'',false); + html_checkbox2('safemode',gettext('Safe Jail export'),!empty($pconfig['safemode']) ? true : false,gettext('Safely stop and start the jail before the exporting process.'),'',false); + html_checkbox2('livemode',gettext('Live ZFS export'),!empty($pconfig['livemode']) ? true : false,gettext('Export a running ZFS jail, safe export overrides this option, this has no effect on .TGZ/TXZ/TZST since the jail should be stopped regardless.'),'',false); + else: + html_checkbox2('safemode',gettext('Safe Jail export'),!empty($pconfig['safemode']) ? true : false,gettext('Safely stop and start the jail before the exporting process.'),'',false); endif; html_inputbox2('confirmname',gettext('Enter name for confirmation'),!empty($pconfig['confirmname']),'',true,30); + html_inputbox2('prioritynumber',gettext('Enter priority value'),!empty($pconfig['prioritynumber']),'',true,30); html_checkbox2('nowstop',gettext('Stop container'),!empty($pconfig['nowstop']) ? true : false,gettext('Stop the container if running before deletion.'),'',false); html_inputbox2('newname',gettext('Enter a name for the new container'),!empty($pconfig['newname']),'',true,30); html_inputbox2('newipaddr',gettext('Enter a IP address for the new container'),!empty($pconfig['newipaddr']),'',true,30); html_checkbox2('clonestop',gettext('Stop container'),!empty($pconfig['clonestop']) ? true : false,gettext('Stop the container if running before cloning, mandatory on UFS filesystem.'),'',false); html_filechooser("source_path",gtext("Source Data Directory"),!empty($pconfig['source_path']), gtext("Source data directory to be shared, full path here, if the path contain spaces they will be automatically escaped with the ASCII \"\\040\" octal code."), !empty($source_path), false, 60); - html_filechooser("target_path",gtext("Target Data Directory"),!empty($pconfig['target_path']), gtext("Target data directory to be mapped, full path to jail here, if the path contain spaces they will be automatically escaped with the ASCII \"\\040\" octal code."), !empty($target_path), false, 60); - html_checkbox2("path_check", gettext("Source/Target path check"),!empty($pconfig['path_check']) ? true : false, gettext("If this option is selected no examination of the source/target directory paths will be performed."), "".gettext("Please use this option only if you know what you are doing here!")."", false); - html_checkbox2('advanced',gettext('Advanced jail configuration Files'),!empty($pconfig['advanced']) ? true : false,gettext('I want to edit the jail files manually, Warning: It is recommended to stop the jail before config edit to prevent issues.'),'',true); + html_filechooser("target_path",gtext("Target Data Directory"),!empty($pconfig['target_path']), gtext("Target data directory to be mapped, full path to jail here, if the path contain spaces they will be automatically escaped with the ASCII \"\\040\" octal code."), !empty($target_path), false, 60); + html_checkbox2("path_check", gettext("Source/Target path check"),!empty($pconfig['path_check']) ? true : false, gettext("If this option is selected no examination of the source/target directory paths will be performed."), "".gettext("Please use this option only if you know what you are doing here!")."", false); + html_checkbox2('advanced',gettext('Advanced jail configuration Files'),!empty($pconfig['advanced']) ? true : false,gettext('I want to edit the jail files manually, Warning: It is recommended to stop the jail before editing the config to prevent issues.'),'',true); html_checkbox2('readonly',gettext('Read-Only Mode'),!empty($pconfig['readonly']) ? true : false,gettext('Set target directory in Read-Only mode.'),'',true); html_checkbox2('automount',gettext('Auto-mount Nullfs'),!empty($pconfig['automount']) ? true : false,gettext('Auto-mount the nullfs mountpoint if the container is already running.'),'',true); html_checkbox2('createdir',gettext('Create Target Directory'),!empty($pconfig['createdir']) ? true : true,gettext('Create target directory if missing (recommended).'),'',true); if ($is_thinjail): - html_checkbox2('update_base',gettext('Base update confirm'),!empty($pconfig['update_base']) ? true : false,gettext('This is a thin container, therefore the base release will be updated, this affects child containers.'),'',true); + //html_checkbox2('update_base',gettext('Base update confirm'),!empty($pconfig['update_base']) ? true : false,gettext('This is a thin container, therefore the base release will be updated, this affects child containers.'),'',true); + //html_checkbox2('update_base_force',gettext('Base update force confirm:'),!empty($pconfig['update_base']) ? true : false,gettext('This will perform a forced base update, this affects child containers.'),'',true); + html_text2('update_base',gettext('Container Update'),htmlspecialchars("This is a thin container, the host is missing some core components to manage updates on this containers, therefore this containers has to be manually upgraded from the command-line.")); else: html_checkbox2('update_jail',gettext('Container update confirm:'),!empty($pconfig['update_jail']) ? true : false,gettext('This is a thick container, therefore the update will be performed within its root, current containers are not affected.'),'',true); + html_checkbox2('update_jail_force',gettext('Container update force confirm:'),!empty($pconfig['update_jail']) ? true : false,gettext('This will perform a forced jail update, current containers are not affected.'),'',true); endif; html_text2('jail_release',gettext('Current base release:'),htmlspecialchars($current_release)); html_text2('auto_boot',gettext('Enable container auto-startup'),htmlspecialchars("This will cause the container to automatically start each time the system restart.")); html_text2('no_autoboot',gettext('Disable container auto-startup'),htmlspecialchars("This will disable the container automatic startup.")); - html_text2('backup',gettext('Export container'),htmlspecialchars("This will export a container to a compressed file/image, please execute `bastille export` for more info in regards exporting formats, Default is .XZ on ZFS setups or .TXZ otherwise, For faster compressed backups consider .GZ/.TGZ.")); + html_text2('backup',gettext('Export container'),htmlspecialchars("This will export a container to a compressed file/image, please execute `bastille export` for more info in regards exporting formats, Default is .XZ on ZFS setups or .TXZ otherwise, For faster compressed backups consider .ZST/.TZST or .GZ/.TGZ")); if ($disable_base_change == "no"): html_combobox2('release',gettext('New base release'),!empty($pconfig['release']),$b_action,gettext("Warning: This will change current shared base to the selected base on the thin container only, the user is responsible for package updates and/or general incompatibilities issues, or use the command line for native upgrade."),true,false,); endif; - //html_checkbox2('dateadd',gettext('Date'),!empty($pconfig['dateadd']) ? true : false,gettext('Append the date in the following format: ITEM-XXXX-XX-XX-XXXXXX.'),'',false); ?> diff --git a/gui/css/bastille-header-refresh.css b/gui/css/bastille-header-refresh.css new file mode 100644 index 0000000..91a947f --- /dev/null +++ b/gui/css/bastille-header-refresh.css @@ -0,0 +1,58 @@ +/* bastille_manager.css + Estilo NATIVO (Minimalista) +*/ + +#refresh-controls { + /* Fondo transparente y sin bordes para integrarse con el tema */ + background: transparent; + border: none; + padding: 10px 0; + margin-bottom: 5px; + + /* Alineación a la derecha */ + display: flex; + justify-content: flex-end; + align-items: center; + gap: 15px; + + /* Fuente estándar del sistema */ + font-size: 13px; + color: inherit; +} + +#refresh-status { + /* Color de texto por defecto del tema (negro/gris) */ + color: inherit; + margin-right: 5px; + + /* Coloca el texto a la izquierda de los botones */ + order: -1; +} + +/* Pequeño spinner azul discreto solo cuando actualiza */ +#refresh-status.updating .refresh-spinner { + display: inline-block; + width: 10px; + height: 10px; + border: 2px solid #ccc; + border-top-color: #007bff; + border-radius: 50%; + animation: spin 1s linear infinite; + margin-right: 5px; +} + +/* Animación del spinner */ +@keyframes spin { + to { transform: rotate(360deg); } +} + +/* Asegurar que los iconos de la tabla estén centrados verticalmente */ +.area_data_selection tbody td img { + vertical-align: middle; +} + +/* Centrado perfecto para los checkboxes */ +.lcelc { + text-align: center; + vertical-align: middle; +} \ No newline at end of file diff --git a/unionfs.sh b/unionfs.sh old mode 100755 new mode 100644 index c719ce9..66d4234 --- a/unionfs.sh +++ b/unionfs.sh @@ -10,7 +10,7 @@ # Debug script #set -x -# Copyright (c) 2019-2024, José Rivera (joserprg@gmail.com). +# Copyright (c) 2019-2026, José Rivera (joserprg@gmail.com). # All rights reserved. # Redistribution and use in source and binary forms, with or without @@ -51,20 +51,9 @@ error_notify() { # Log/notify message on error and exit. MSG="${*}" logger -t "${SCRIPTNAME}" "${MSG}" - echo -e "${MSG}" >&2; exit 1 -} - -platform_check() -{ - # Check for working platform. - if [ "${PRDPLATFORM}" = "x64-embedded" ]; then - pkg_symlink - else - if [ -d "/var/cache/pkg" ]; then - echo "Cleaning the pkg cache." - pkg clean -y -a - fi - fi + echo -e "${MSG}" >&2 + posterror_exec + exit 1 } load_kmods() { @@ -79,7 +68,7 @@ load_kmods() { # Skip already loaded known modules. for _req_kmod in ${required_mods}; do - if ! sysrc -f /boot/loader.conf -qn ${_req_kmod}_load=YES | grep -q "YES"; then + if ! sysrc -f /boot/loader.conf -qc ${_req_kmod}_load=YES; then sysrc -f /boot/loader.conf ${_req_kmod}_load=YES fi if ! kldstat -m ${_req_kmod} >/dev/null 2>&1; then @@ -95,66 +84,95 @@ load_kmods() { kldload -v ${_lin_kmod} fi done - if ! sysrc -qn linux_enable=YES | grep -q "YES"; then + if ! sysrc -qc linux_enable=YES; then sysrc linux_enable=YES fi } -pkg_symlink() { - if ! sysrc -f ${CWDIR}${EXTCONF} -qn LINUX_COMPAT_SUPPORT | grep -q "YES"; then - echo "Creating pkg environment for embedded platforms." +unload_kmods() { + required_mods="fdescfs linprocfs linsysfs tmpfs" + linuxarc_mods="linux linux64" - if [ -d "/var/cache/pkg" ]; then - if [ ! -L "/var/cache/pkg" ]; then - rm -R /var/cache/pkg - mkdir -p ${CWDIR}/system/cache/pkg - ln -vFs ${CWDIR}/system/cache/pkg /var/cache/pkg - fi - else - mkdir -m 0755 -p /var/cache - mkdir -p ${CWDIR}/system/cache/pkg - ln -vFs ${CWDIR}/system/cache/pkg /var/cache/pkg + for _req_kmod in ${required_mods}; do + if sysrc -f /boot/loader.conf -qc ${_req_kmod}_load=YES; then + echo "Unset kernel module: ${_req_kmod}" + sysrc -f /boot/loader.conf -x ${_req_kmod}_load fi + done - if [ -d "/var/db/pkg" ]; then - if [ ! -L "/var/db/pkg" ]; then - rm -R /var/db/pkg - mkdir -p ${CWDIR}/system/pkg/db - ln -vFs ${CWDIR}/system/pkg/db /var/db/pkg - fi - else - mkdir -p ${CWDIR}/system/pkg/db - ln -vFs ${CWDIR}/system/pkg/db /var/db/pkg - fi + if sysrc -qc linux_enable=YES; then + echo "Unset linux_enable" + sysrc -x linux_enable fi } +posterror_exec() { + # Commands to be executed post errors. + unionfs_disable + + # Clean for stale pkg. + if [ -d "${CWDIR}/system/All" ]; then + rm -r ${CWDIR}/system/All + fi +} + +unionfs_disable() { + # Check and disable uniofs mounts on error. + unionfs_pkgoff + unionfs_off +} + +unionfs_pkgon() { + if ! df | grep -q "${CWDIR}/system/var/db/pkg"; then + echo "Enabling UnionFS for ${CWDIR}/system/var/db/pkg." + mount_unionfs -o avobe ${CWDIR}/system/var/db/pkg /var/db/pkg + fi +} + +unionfs_pkgoff() { + if df | grep -q "${CWDIR}/system/var/db/pkg"; then + echo "Disabling UnionFS for ${CWDIR}/system/var/db/pkg." + umount -f /var/db/pkg + fi +} + +fetch_cmd() { + PKG_LIST="debootstrap debian-keyring" + pkg fetch -y -d -o ${CWDIR}/system/ ${PKG_LIST} +} + fetch_pkg() { - if ! sysrc -f ${CWDIR}${EXTCONF} -qn LINUX_COMPAT_SUPPORT | grep -q "YES"; then - echo "Fetching required packages." + if [ ! -d "/var/db/pkg" ]; then + mkdir -p "/var/db/pkg" + fi + if [ ! -d "${CWDIR}/system/var/db/pkg" ]; then + mkdir -p ${CWDIR}/system/var/db/pkg + fi - # Skip existing packages/ports bundled with XigmaNAS. - #PKGLIST="#bash #ca_root_nss debootstrap #gettext-runtime glib gmp gnugrep gnugpg gnutls #indexinfo libassuan #libedit #libffi libgcrypt libgpg-error #libiconv libidn2 libksba libtasn1 libunistring libxml2 mpdecimal nettle npth p11-kit #pcre perl5 pinentry pinentry-curses #python38 #readline #sqlite3 tpm-emulator #trousers ubuntu-keyring wget" - PKGLIST="debootstrap glib gmp gnugrep gnupg gnutls libassuan libgcrypt libgpg-error libidn2 libksba libtasn1 libunistring libxml2 mpdecimal nettle npth p11-kit perl5 pinentry pinentry-curses tpm-emulator ubuntu-keyring wget" + trap "unionfs_pkgoff" 0 1 2 5 15 + unionfs_pkgon - for pkg in ${PKGLIST}; do - pkg fetch -y "${pkg}" || error_notify "Error while fetching required [${pkg}] package, exiting." - done + echo "Fetching required packages." + # Fetch deboostrap and dependency packages. + fetch_cmd || echo "Cleaning addon stale pkg db and retry..." + rm -rf ${CWDIR}/system/var/db/pkg/* + fetch_cmd || error_notify "Error while fetching packages, exiting." + echo "Done." - extract_pkg + unionfs_pkgoff + + extract_pkg +} + +fetch_debootstrap() { + if ! sysrc -f ${CWDIR}${EXTCONF} -qc LINUX_COMPAT_SUPPORT=YES; then + fetch_pkg fi } extract_pkg() { echo "Extracting required packages." - - if [ "${PRDPLATFORM}" = "x64-embedded" ]; then - FILELIST=$(find "${CWDIR}/system/cache/pkg" -type f) - LINKLIST=$(find "${CWDIR}/system/cache/pkg" -type l) - else - FILELIST=$(find "/var/cache/pkg" -type f) - LINKLIST=$(find "/var/cache/pkg" -type l) - fi + FILELIST=$(find "${CWDIR}/system/All" -type f) for item in ${FILELIST}; do if [ -f "${item}" ]; then @@ -163,59 +181,68 @@ extract_pkg() { fi done - # Clean leftovers pkg symlinks - if [ "${PRDPLATFORM}" = "x64-embedded" ]; then - for item in ${LINKLIST}; do - if [ -L "${item}" ]; then - rm -rf ${item} - fi - done - else - echo "Cleaning the pkg cache." - pkg clean -y -a + if [ -d "${CWDIR}/system/All" ]; then + rm -r ${CWDIR}/system/All fi if [ ! -d "${CWDIR}/templates" ]; then mkdir -p ${CWDIR}/templates fi + + if [ ! -d "${CWDIR}/system/var/run" ]; then + mkdir -p ${CWDIR}/system/var/run + fi + + echo "Done." } unionfs_on() { if ! df | grep -q "${CWDIR}/system/usr/local"; then - echo "Enabling UnionFS mount for ${CWDIR}/system/usr/local." - mount_unionfs -o below ${CWDIR}/system/usr/local /usr/local + echo "Enabling UnionFS for ${CWDIR}/system/usr/local." + mount_unionfs -o above ${CWDIR}/system/usr/local /usr/local fi - + if ! df | grep -q "${CWDIR}/system/var/run"; then - echo "Enabling UnionFS mount for ${CWDIR}/system/var/run." - mount_unionfs -o below ${CWDIR}/system/var/run /var/run + echo "Enabling UnionFS for ${CWDIR}/system/var/run." + mount_unionfs -o avobe ${CWDIR}/system/var/run /var/run fi } unionfs_off() { if df | grep -q "${CWDIR}/system/usr/local"; then - echo "Disabling UnionFS mounts for ${CWDIR}/system/usr/local." + echo "Disabling UnionFS for ${CWDIR}/system/usr/local." umount -f /usr/local fi if df | grep -q "${CWDIR}/system/var/run"; then - echo "Disabling UnionFS mounts for ${CWDIR}/system/var/run." + echo "Disabling UnionFS for ${CWDIR}/system/var/run." umount -f /var/run fi } +update_debootstrap() { + echo "Updating debootstrap..." + unionfs_off + fetch_pkg +} + case "${1}" in - fetch_pkg) - platform_check - fetch_pkg + fetch_debootstrap) + fetch_debootstrap ;; load_kmods) load_kmods ;; + unload_kmods) + unload_kmods + ;; unionfs_on) unionfs_on ;; unionfs_off) unionfs_off ;; + update_debootstrap) + update_debootstrap + ;; esac diff --git a/version b/version index 1b507d1..0661a4b 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.1.39 +1.4.04