10696600cSBjoern A. Zeeb#!/bin/sh 20696600cSBjoern A. Zeeb# 30696600cSBjoern A. Zeeb# Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org> 40696600cSBjoern A. Zeeb# All rights reserved. 50696600cSBjoern A. Zeeb# 60696600cSBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without 70696600cSBjoern A. Zeeb# modification, are permitted provided that the following conditions 80696600cSBjoern A. Zeeb# are met: 90696600cSBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright 100696600cSBjoern A. Zeeb# notice, this list of conditions and the following disclaimer. 110696600cSBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright 120696600cSBjoern A. Zeeb# notice, this list of conditions and the following disclaimer in the 130696600cSBjoern A. Zeeb# documentation and/or other materials provided with the distribution. 140696600cSBjoern A. Zeeb# 150696600cSBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 160696600cSBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 170696600cSBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 180696600cSBjoern A. Zeeb# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 190696600cSBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 200696600cSBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 210696600cSBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 220696600cSBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 230696600cSBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 240696600cSBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 250696600cSBjoern A. Zeeb# SUCH DAMAGE. 260696600cSBjoern A. Zeeb# 270696600cSBjoern A. Zeeb# 280696600cSBjoern A. Zeeb 290696600cSBjoern A. Zeeb# PROVIDE: gptboot 300696600cSBjoern A. Zeeb# REQUIRE: mountcritremote 310696600cSBjoern A. Zeeb# KEYWORD: nojail 320696600cSBjoern A. Zeeb 330696600cSBjoern A. Zeeb. /etc/rc.subr 340696600cSBjoern A. Zeeb 350696600cSBjoern A. Zeebname="gptboot" 360696600cSBjoern A. Zeebrcvar="gptboot_enable" 370696600cSBjoern A. Zeebstart_cmd="gptboot_report" 380696600cSBjoern A. Zeeb 390696600cSBjoern A. Zeebgptboot_report() 400696600cSBjoern A. Zeeb{ 410696600cSBjoern A. Zeeb gpart show | \ 420696600cSBjoern A. Zeeb egrep '(^=>| freebsd-ufs .*(\[|,)(bootfailed|bootonce)(,|\]))' | \ 430696600cSBjoern A. Zeeb sed 's/^=>//' | \ 440696600cSBjoern A. Zeeb egrep -v '(\[|,)bootme(,|\])' | \ 450696600cSBjoern A. Zeeb while read start size pos type attrs rest; do 460696600cSBjoern A. Zeeb case "${pos}" in 470696600cSBjoern A. Zeeb [0-9]*) 480696600cSBjoern A. Zeeb if [ -n "${disk}" ]; then 490696600cSBjoern A. Zeeb part="${disk}p${pos}" 500696600cSBjoern A. Zeeb echo "${attrs}" | egrep -q '(\[|,)bootfailed(,|\])' 510696600cSBjoern A. Zeeb bootfailed=$? 520696600cSBjoern A. Zeeb echo "${attrs}" | egrep -q '(\[|,)bootonce(,|\])' 530696600cSBjoern A. Zeeb bootonce=$? 540696600cSBjoern A. Zeeb if [ ${bootfailed} -eq 0 ]; then 550696600cSBjoern A. Zeeb logger -t gptboot -p local0.notice "Boot from ${part} failed." 560696600cSBjoern A. Zeeb gpart unset -a bootfailed -i ${pos} ${disk} >/dev/null 570696600cSBjoern A. Zeeb elif [ ${bootonce} -eq 0 ]; then 580696600cSBjoern A. Zeeb # We want to log success after all failures. 590696600cSBjoern A. Zeeb echo -n "Boot from ${part} succeeded." 600696600cSBjoern A. Zeeb gpart unset -a bootonce -i ${pos} ${disk} >/dev/null 610696600cSBjoern A. Zeeb fi 620696600cSBjoern A. Zeeb fi 630696600cSBjoern A. Zeeb ;; 640696600cSBjoern A. Zeeb *) 650696600cSBjoern A. Zeeb if [ "${type}" = "GPT" ]; then 660696600cSBjoern A. Zeeb disk="${pos}" 670696600cSBjoern A. Zeeb else 680696600cSBjoern A. Zeeb disk="" 690696600cSBjoern A. Zeeb fi 700696600cSBjoern A. Zeeb ;; 710696600cSBjoern A. Zeeb esac 720696600cSBjoern A. Zeeb done | logger -t gptboot -p local0.notice 730696600cSBjoern A. Zeeb} 740696600cSBjoern A. Zeeb 750696600cSBjoern A. Zeebload_rc_config $name 76*f99f0ee1SAlexander Leidinger 77*f99f0ee1SAlexander Leidinger# doesn't make sense to run in a svcj: config setting 78*f99f0ee1SAlexander Leidingergptboot_svcj="NO" 79*f99f0ee1SAlexander Leidinger 800696600cSBjoern A. Zeebrun_rc_command "$1" 81