1#!/bin/sh 2#- 3# Copyright (c) 2011 Nathan Whitehorn 4# Copyright (c) 2013-2018 Devin Teske 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26# SUCH DAMAGE. 27# 28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_include $BSDCFG_SHARE/dialog.subr 34 35############################################################ GLOBALS 36 37# 38# Strings that should be moved to an i18n file and loaded with f_include_lang() 39# 40hline_arrows_tab_enter="Press arrows, TAB or ENTER" 41hline_arrows_tab_space_enter="Press arrows, TAB, SPACE or ENTER" 42msg_abort="Abort" 43msg_an_installation_step_has_been_aborted="An installation step has been aborted. Would you like\nto restart the installation or exit the installer?" 44msg_auto_ufs="Auto (UFS)" 45msg_auto_ufs_desc="Guided UFS Disk Setup" 46msg_auto_ufs_help="Menu options help choose which disk to setup using UFS and standard partitions" 47msg_auto_zfs="Auto (ZFS)" 48msg_auto_zfs_desc="Guided Root-on-ZFS" 49msg_auto_zfs_help="To use ZFS with less than 8GB RAM, see https://wiki.freebsd.org/ZFSTuningGuide" 50msg_exit="Exit" 51msg_freebsd_installer="$OSNAME Installer" 52msg_gpt_active_fix="Your hardware is known to have issues booting in CSM/Legacy/BIOS mode from GPT partitions that are not set active. Would you like the installer to apply this workaround for you?" 53msg_lenovo_fix="Your model of Lenovo is known to have a BIOS bug that prevents it booting from GPT partitions without UEFI. Would you like the installer to apply a workaround for you?" 54msg_manual="Manual" 55msg_manual_desc="Manual Disk Setup (experts)" 56msg_manual_help="Create customized partitions from menu options" 57msg_no="NO" 58msg_restart="Restart" 59msg_shell="Shell" 60msg_shell_desc="Open a shell and partition by hand" 61msg_shell_help="Create customized partitions using command-line utilities" 62msg_yes="YES" 63 64############################################################ FUNCTIONS 65 66# error [$msg] 67# 68# Display generic error message when a script fails. An optional message 69# argument can preceed the generic message. User is given the choice of 70# restarting the installer or exiting. 71# 72error() 73{ 74 local title="$msg_abort" 75 local btitle="$msg_freebsd_installer" 76 local prompt="${1:+$1\n\n}$msg_an_installation_step_has_been_aborted" 77 local hline="$hline_arrows_tab_space_enter" 78 79 [ -f "$PATH_FSTAB" ] && bsdinstall umount 80 81 local height width 82 f_dialog_buttonbox_size height width \ 83 "$title" "$btitle" "$prompt" "$hline" 84 85 if $DIALOG \ 86 --title "$title" \ 87 --backtitle "$btitle" \ 88 --hline "$hline" \ 89 --no-label "$msg_exit" \ 90 --yes-label "$msg_restart" \ 91 --yesno "$prompt" $height $width 92 then 93 exec $0 94 # NOTREACHED 95 fi 96 exit 1 97} 98 99# dialog_workaround 100# 101# Ask the user if they wish to apply a workaround 102# 103dialog_workaround() 104{ 105 local passed_msg="$1" 106 local title="$DIALOG_TITLE" 107 local btitle="$DIALOG_BACKTITLE" 108 local prompt # Calculated below 109 local hline="$hline_arrows_tab_enter" 110 111 local height=8 width=50 prefix=" " 112 local plen=${#prefix} list= line= 113 local max_width=$(( $width - 3 - $plen )) 114 115 local yes no defaultno extra_args format 116 if [ "$USE_XDIALOG" ]; then 117 yes=ok no=cancel defaultno=default-no 118 extra_args="--wrap --left" 119 format="$passed_msg" 120 else 121 yes=yes no=no defaultno=defaultno 122 extra_args="--cr-wrap" 123 format="$passed_msg" 124 fi 125 126 # Add height for Xdialog(1) 127 [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 )) 128 129 prompt=$( printf "$format" ) 130 f_dprintf "%s: Workaround prompt" "$0" 131 $DIALOG \ 132 --title "$title" \ 133 --backtitle "$btitle" \ 134 --hline "$hline" \ 135 --$yes-label "$msg_yes" \ 136 --$no-label "$msg_no" \ 137 $extra_args \ 138 --yesno "$prompt" $height $width 139} 140 141############################################################ MAIN 142 143f_dprintf "Began Installation at %s" "$( date )" 144 145rm -rf $BSDINSTALL_TMPETC 146mkdir $BSDINSTALL_TMPETC 147 148[ -f /usr/libexec/bsdinstall/local.pre-everything ] && f_dprintf "Running local.pre-everything" && sh /usr/libexec/bsdinstall/local.pre-everything "$BSDINSTALL_CHROOT" 149 150trap true SIGINT # This section is optional 151[ -z "$BSDINSTALL_SKIP_KEYMAP" ] && bsdinstall keymap 152 153trap error SIGINT # Catch cntrl-C here 154if [ -z "$BSDINSTALL_SKIP_HOSTNAME" ]; then bsdinstall hostname || error "Set hostname failed"; fi 155 156if [ -n "$BSDINSTALL_USE_DISTRIBUTIONS" ]; then 157 exec 5>&1 158 export DISTRIBUTIONS=$( `dirname $0`/selectdists 2>&1 1>&5 ) 159 exec 5>&- 160fi 161 162rm -f $PATH_FSTAB 163touch $PATH_FSTAB 164 165[ -f /usr/libexec/bsdinstall/local.pre-partition ] && f_dprintf "Running local.pre-partition" && sh /usr/libexec/bsdinstall/local.pre-partition "$BSDINSTALL_CHROOT" 166 167# 168# Try to detect known broken platforms and apply their workarounds 169# 170 171if f_interactive; then 172 sys_maker=$( kenv -q smbios.system.maker ) 173 f_dprintf "smbios.system.maker=[%s]" "$sys_maker" 174 sys_model=$( kenv -q smbios.system.product ) 175 f_dprintf "smbios.system.product=[%s]" "$sys_model" 176 sys_version=$( kenv -q smbios.system.version ) 177 f_dprintf "smbios.system.version=[%s]" "$sys_version" 178 sys_mb_maker=$( kenv -q smbios.planar.maker ) 179 f_dprintf "smbios.planar.maker=[%s]" "$sys_mb_maker" 180 sys_mb_product=$( kenv -q smbios.planar.product ) 181 f_dprintf "smbios.planar.product=[%s]" "$sys_mb_product" 182 183 # 184 # Laptop Models 185 # 186 case "$sys_maker" in 187 "LENOVO") 188 case "$sys_version" in 189 "ThinkPad X220"|"ThinkPad T420"|"ThinkPad T520"|"ThinkPad W520"|"ThinkPad X1") 190 dialog_workaround "$msg_lenovo_fix" 191 retval=$? 192 f_dprintf "lenovofix_prompt=[%s]" "$retval" 193 if [ $retval -eq $DIALOG_OK ]; then 194 export ZFSBOOT_PARTITION_SCHEME="GPT + Lenovo Fix" 195 export WORKAROUND_LENOVO=1 196 fi 197 ;; 198 esac 199 ;; 200 "Dell Inc.") 201 case "$sys_model" in 202 "Latitude E6330"|"Latitude E7440"|"Latitude E7240"|"Precision Tower 5810") 203 dialog_workaround "$msg_gpt_active_fix" 204 retval=$? 205 f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" 206 if [ $retval -eq $DIALOG_OK ]; then 207 export ZFSBOOT_PARTITION_SCHEME="GPT + Active" 208 export WORKAROUND_GPTACTIVE=1 209 fi 210 ;; 211 esac 212 ;; 213 "Hewlett-Packard") 214 case "$sys_model" in 215 "HP ProBook 4330s") 216 dialog_workaround "$msg_gpt_active_fix" 217 retval=$? 218 f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" 219 if [ $retval -eq $DIALOG_OK ]; then 220 export ZFSBOOT_PARTITION_SCHEME="GPT + Active" 221 export WORKAROUND_GPTACTIVE=1 222 fi 223 ;; 224 esac 225 ;; 226 esac 227 # 228 # Motherboard Models 229 # 230 case "$sys_mb_maker" in 231 "Intel Corporation") 232 case "$sys_mb_product" in 233 "DP965LT"|"D510MO") 234 dialog_workaround "$msg_gpt_active_fix" 235 retval=$? 236 f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" 237 if [ $retval -eq $DIALOG_OK ]; then 238 export ZFSBOOT_PARTITION_SCHEME="GPT + Active" 239 export WORKAROUND_GPTACTIVE=1 240 fi 241 ;; 242 esac 243 ;; 244 "Acer") 245 case "$sys_mb_product" in 246 "Veriton M6630G") 247 dialog_workaround "$msg_gpt_active_fix" 248 retval=$? 249 f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" 250 if [ $retval -eq $DIALOG_OK ]; then 251 export ZFSBOOT_PARTITION_SCHEME="GPT + Active" 252 export WORKAROUND_GPTACTIVE=1 253 fi 254 ;; 255 esac 256 ;; 257 esac 258fi 259 260PMODES=" 261 '$msg_auto_ufs' '$msg_auto_ufs_desc' '$msg_auto_ufs_help' 262 '$msg_manual' '$msg_manual_desc' '$msg_manual_help' 263 '$msg_shell' '$msg_shell_desc' '$msg_shell_help' 264" # END-QUOTE 265 266CURARCH=$( uname -m ) 267case $CURARCH in 268 amd64|arm64|i386|riscv) # Booting ZFS Supported 269 PMODES=" 270 '$msg_auto_zfs' '$msg_auto_zfs_desc' '$msg_auto_zfs_help' 271 $PMODES 272 " # END-QUOTE 273 ;; 274 *) # Booting ZFS Unsupported 275 ;; 276esac 277 278exec 5>&1 279PARTMODE=`echo $PMODES | xargs -o bsddialog --backtitle "$OSNAME Installer" \ 280 --title "Partitioning" \ 281 --item-help \ 282 --menu "How would you like to partition your disk?" \ 283 0 0 0 2>&1 1>&5` || exit 1 284exec 5>&- 285 286case "$PARTMODE" in 287"$msg_auto_zfs") # ZFS 288 bsdinstall zfsboot || error "ZFS setup failed" 289 bsdinstall mount || error "Failed to mount filesystem" 290 ;; 291"$msg_auto_ufs") # Guided UFS 292 bsdinstall autopart || error "Partitioning error" 293 bsdinstall mount || error "Failed to mount filesystem" 294 ;; 295"$msg_shell") # Shell 296 clear 297 echo "Use this shell to set up partitions for the new system. When finished, mount the system at $BSDINSTALL_CHROOT and place an fstab file for the new system at $PATH_FSTAB. Then type 'exit'. You can also enter the partition editor at any time by entering 'bsdinstall partedit'." 298 sh 2>&1 299 ;; 300"$msg_manual") # Manual 301 if f_isset debugFile; then 302 # Give partedit the path to our logfile so it can append 303 BSDINSTALL_LOG="${debugFile#+}" bsdinstall partedit || error "Partitioning error" 304 else 305 bsdinstall partedit || error "Partitioning error" 306 fi 307 bsdinstall mount || error "Failed to mount filesystem" 308 ;; 309*) 310 error "Unknown partitioning mode" 311 ;; 312esac 313 314[ -f /usr/libexec/bsdinstall/local.pre-fetch ] && f_dprintf "Running local.pre-fetch" && sh /usr/libexec/bsdinstall/local.pre-fetch "$BSDINSTALL_CHROOT" 315 316if [ -n "$FETCH_DISTRIBUTIONS" ]; then 317 exec 5>&1 318 export BSDINSTALL_DISTDIR=$(`dirname $0`/fetchmissingdists 2>&1 1>&5) 319 FETCH_RESULT=$? 320 exec 5>&- 321 322 [ $FETCH_RESULT -ne 0 ] && error "Could not fetch remote distributions" 323fi 324if [ -n "$BSDINSTALL_USE_DISTRIBUTIONS" ]; then 325 bsdinstall checksum || error "Distribution checksum failed" 326 bsdinstall distextract || error "Distribution extract failed" 327fi 328 329# Set up boot loader 330bsdinstall bootconfig || error "Failed to configure bootloader" 331 332[ -f /usr/libexec/bsdinstall/local.pre-configure ] && f_dprintf "Running local.pre-configure" && sh /usr/libexec/bsdinstall/local.pre-configure "$BSDINSTALL_CHROOT" 333 334bsdinstall rootpass || error "Could not set root password" 335 336trap true SIGINT # This section is optional 337if [ "$NETCONFIG_DONE" != yes ]; then 338 bsdinstall netconfig # Don't check for errors -- the user may cancel 339fi 340[ -z "$BSDINSTALL_SKIP_TIME" ] && bsdinstall time 341[ -z "$BSDINSTALL_SKIP_SERVICES" ] && bsdinstall services 342[ -z "$BSDINSTALL_SKIP_HARDENING" ] && bsdinstall hardening 343 344[ -z "$BSDINSTALL_SKIP_USERS" ] && bsddialog --backtitle "$OSNAME Installer" \ 345 --title "Add User Accounts" --yesno \ 346 "Would you like to add users to the installed system now?" 0 0 && \ 347 bsdinstall adduser 348 349# Allow user to change his mind 350[ -z "$BSDINSTALL_SKIP_FINALCONFIG" ] && bsdinstall finalconfig 351 352trap error SIGINT # SIGINT is bad again 353bsdinstall config || error "Failed to save config" 354 355if [ ! -z "$BSDINSTALL_FETCHDEST" ]; then 356 rm -rf "$BSDINSTALL_FETCHDEST" 357fi 358 359[ -f /usr/libexec/bsdinstall/local.post-configure ] && f_dprintf "Running local.post-configure" && sh /usr/libexec/bsdinstall/local.post-configure "$BSDINSTALL_CHROOT" 360 361if [ -z "$BSDINSTALL_SKIP_MANUAL" ]; then 362 bsddialog --backtitle "$OSNAME Installer" --title "Manual Configuration" \ 363 --default-no --yesno \ 364 "The installation is now finished. Before exiting the installer, would you like to open a shell in the new system to make any final manual modifications?" 0 0 365 if [ $? -eq 0 ]; then 366 clear 367 echo This shell is operating in a chroot in the new system. \ 368 When finished making configuration changes, type \"exit\". 369 chroot "$BSDINSTALL_CHROOT" /bin/sh 2>&1 370 fi 371fi 372 373bsdinstall entropy 374bsdinstall umount 375 376f_dprintf "Installation Completed at %s" "$( date )" 377 378################################################################################ 379# END 380################################################################################ 381