1*37e4aefeSkn# $OpenBSD: dot.profile,v 1.51 2023/02/20 01:55:41 kn Exp $ 2b4c8daf5Sderaadt# $NetBSD: dot.profile,v 1.1 1995/12/18 22:54:43 pk Exp $ 3a1f9bee1Sderaadt# 46b448d68Skrw# Copyright (c) 2009 Kenneth R. Westerback 5a1f9bee1Sderaadt# Copyright (c) 1995 Jason R. Thorpe 6a1f9bee1Sderaadt# Copyright (c) 1994 Christopher G. Demetriou 7a1f9bee1Sderaadt# All rights reserved. 8a1f9bee1Sderaadt# 9a1f9bee1Sderaadt# Redistribution and use in source and binary forms, with or without 10a1f9bee1Sderaadt# modification, are permitted provided that the following conditions 11a1f9bee1Sderaadt# are met: 12a1f9bee1Sderaadt# 1. Redistributions of source code must retain the above copyright 13a1f9bee1Sderaadt# notice, this list of conditions and the following disclaimer. 14a1f9bee1Sderaadt# 2. Redistributions in binary form must reproduce the above copyright 15a1f9bee1Sderaadt# notice, this list of conditions and the following disclaimer in the 16a1f9bee1Sderaadt# documentation and/or other materials provided with the distribution. 17a1f9bee1Sderaadt# 3. All advertising materials mentioning features or use of this software 18a1f9bee1Sderaadt# must display the following acknowledgement: 19a1f9bee1Sderaadt# This product includes software developed by Christopher G. Demetriou. 20a1f9bee1Sderaadt# 4. The name of the author may not be used to endorse or promote products 21a1f9bee1Sderaadt# derived from this software without specific prior written permission 22a1f9bee1Sderaadt# 23a1f9bee1Sderaadt# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24a1f9bee1Sderaadt# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25a1f9bee1Sderaadt# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26a1f9bee1Sderaadt# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27a1f9bee1Sderaadt# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28a1f9bee1Sderaadt# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29a1f9bee1Sderaadt# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30a1f9bee1Sderaadt# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31a1f9bee1Sderaadt# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32a1f9bee1Sderaadt# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33a1f9bee1Sderaadt# 34a1f9bee1Sderaadt 35*37e4aefeSkn# Turn off Strict Bourne shell. 36*37e4aefeSknset +o sh 37*37e4aefeSkn 386b448d68Skrwexport VNAME=$(sysctl -n kern.osrelease) 396b448d68Skrwexport VERSION="${VNAME%.*}${VNAME#*.}" 406b448d68Skrwexport ARCH=$(sysctl -n hw.machine) 416b448d68Skrwexport OBSD="OpenBSD/$ARCH $VNAME" 42a1f9bee1Sderaadtexport PATH=/sbin:/bin:/usr/bin:/usr/sbin:/ 43ca8824ddSrpe 44a1f9bee1Sderaadtumask 022 45ca8824ddSrpe 46214ca015Srpe# emacs-style command line editing. 47bf189321Skrwset -o emacs 48a1f9bee1Sderaadt 49e4c0bb8dSknTIMEOUT_PERIOD_SEC=5 50e4c0bb8dSkn 518f4f17b3Skn# Stop the background timer. 528f4f17b3Sknstop_timeout() { 538067c40cSderaadt local _pid; 548067c40cSderaadt if [ -f /tmp/dotpid ]; then 558067c40cSderaadt _pid=$(cat /tmp/dotpid) 568067c40cSderaadt kill -KILL -$_pid 2>/dev/null 578067c40cSderaadt wait $_pid 2>/dev/null 588067c40cSderaadt rm /tmp/dotpid 598067c40cSderaadt fi 608f4f17b3Skn} 618f4f17b3Skn 628067c40cSderaadt# Start a timeout process, in case install gets hung somehow 63e4c0bb8dSknstart_timeout() { 648067c40cSderaadt set -m 65e4c0bb8dSkn ( 668f4f17b3Skn sleep $TIMEOUT_PERIOD_SEC && kill $$ 678067c40cSderaadt ) & 688067c40cSderaadt echo $! > /tmp/dotpid 698067c40cSderaadt set +m 70e4c0bb8dSkn} 71a1f9bee1Sderaadt 72c900f233Srpeif [[ -z $DONEPROFILE ]]; then 73149e7ae8Sderaadt DONEPROFILE=YES 74149e7ae8Sderaadt 75c8b3c08fSrpe # Extract rootdisk from last 'root on ...' dmesg line. 76c8b3c08fSrpe rootdisk=$(dmesg | sed -E '/^root on ([^ ]+) .*$/h;$!d;g;s//\1/') 778f84877fSkrw mount -u /dev/${rootdisk:-rd0a} / 78a1f9bee1Sderaadt 79214ca015Srpe # Create a fake rc that just returns 1 and throws us back. 804bea26e7Shalex echo ! : >/etc/rc 814bea26e7Shalex 82c1680e7dSflorian # Create working directories with proper permissions in /tmp. 83c1680e7dSflorian mkdir -m u=rwx,go=rx -p /tmp/{ai,i} 84c1680e7dSflorian 85c1680e7dSflorian # Start autoconfiguration daemons. 86bc9eb55cSkn # Hide legit "already running" errors when reentering the installer. 87bc9eb55cSkn [[ -x /sbin/resolvd ]] && /sbin/resolvd 2>/dev/null 88bc9eb55cSkn [[ -x /sbin/dhcpleased ]] && /sbin/dhcpleased 2>/dev/null 89bc9eb55cSkn [[ -x /sbin/slaacd ]] && /sbin/slaacd 2>/dev/null 90569c7b0bSflorian 919d5693f4Srpe # Set up some sane tty defaults. 92a1f9bee1Sderaadt echo 'erase ^?, werase ^W, kill ^U, intr ^C, status ^T' 93bd9b0e00Sderaadt stty newcrt werase ^W intr ^C kill ^U erase ^? status ^T 94a1f9bee1Sderaadt 956b448d68Skrw cat <<__EOT 966b448d68Skrw 976b448d68SkrwWelcome to the $OBSD installation program. 986b448d68Skrw__EOT 99a817527fSflorian # try unattended install 100a817527fSflorian /autoinstall -x 101a817527fSflorian 1029d5693f4Srpe # Set timer to automatically start unattended installation or upgrade 1039d5693f4Srpe # if netbooted or if a response file is found in / after a timeout, 1049d5693f4Srpe # but only the very first time around. 105b4e5f129Suwe timeout=false 10620b90770Srpe if [[ ! -f /tmp/ai/noai ]] && { ifconfig netboot >/dev/null 2>&1 || 107c900f233Srpe [[ -f /auto_install.conf ]] || 108c900f233Srpe [[ -f /auto_upgrade.conf ]]; }; then 109ca8824ddSrpe 110e4c0bb8dSkn echo "Starting non-interactive mode in ${TIMEOUT_PERIOD_SEC} seconds..." 11120b90770Srpe >/tmp/ai/noai 112b4e5f129Suwe 1131d8578a6Srpe # Set trap handlers to remove timer if the shell is interrupted, 1141d8578a6Srpe # killed or about to exit. 1158428b335Shalex trap 'exit 1' INT 116b4e5f129Suwe trap 'timeout=true' TERM 117e4c0bb8dSkn trap 'stop_timeout' EXIT 118b4e5f129Suwe 1199d5693f4Srpe # Stop monitoring background processes to avoid printing job 120e4c0bb8dSkn # completion notices in interactive shell mode. 121e4c0bb8dSkn # Silence "[1] <pid>" on stderr when starting the timer. 122b4e5f129Suwe set +m 123e4c0bb8dSkn start_timeout 2>/dev/null 124b4e5f129Suwe fi 125b4e5f129Suwe 1264c60f505Shalex while :; do 127d5b65e3eSrpe read REPLY?'(I)nstall, (U)pgrade, (A)utoinstall or (S)hell? ' 128b4e5f129Suwe 129ca8824ddSrpe # Begin the automatic installation if the timeout has expired. 130b4e5f129Suwe if $timeout; then 131b4e5f129Suwe timeout=false 132b4e5f129Suwe echo 133b4e5f129Suwe REPLY=a 134b4e5f129Suwe else 135b4e5f129Suwe # User has made a choice; stop the read timeout. 136e4c0bb8dSkn stop_timeout 137b4e5f129Suwe fi 138b4e5f129Suwe 1396b448d68Skrw case $REPLY in 140f54c2229Srpe [aA]*) /autoinstall && break;; 141f54c2229Srpe [iI]*) /install && break;; 142f54c2229Srpe [uU]*) /upgrade && break;; 143f54c2229Srpe [sS]*) break;; 144a1f9bee1Sderaadt esac 145a1f9bee1Sderaadt done 146149e7ae8Sderaadtfi 147