Changeset View
Changeset View
Standalone View
Standalone View
boot_profile_manager
Property | Old Value | New Value |
---|---|---|
svn:executable | null | * \ No newline at end of property |
#!/bin/sh | |||||
# Copyright (c) 2019 Lorenzo Salvadore <phascolarctos@protonmail.ch> | |||||
# 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. | |||||
# PROVIDE: boot_profile_manager | |||||
# BEFORE: sysctl | |||||
. /etc/rc.subr | |||||
name="boot_profile_manager" | |||||
desc="Manages services for different boot profiles" | |||||
rcvar=boot_profile_manager_enable | |||||
start_cmd="${name}_start" | |||||
boot_profile_manager_profiles="$(echo ${boot_profile_manager_profiles} | cut -f -123 -w)" | |||||
test -n "${boot_profile_manager_profiles}" || boot_profile_manager_profiles="default" | |||||
(test -n "$(echo "${boot_profile_manager_timeout}" | tr -d "0123456789")" && test -n "${boot_profile_manager_timeout}") || boot_profile_manager_timeout=5 | |||||
boot_profile_manager_start() | |||||
{ | |||||
echo | |||||
echo "==================================================" | |||||
echo "============== Boot profile manager ==============" | |||||
echo "==================================================" | |||||
echo | |||||
echo "Please select a boot profile:" | |||||
echo | |||||
num=1 | |||||
for x in ${boot_profile_manager_profiles} | |||||
do | |||||
echo "${num}. $x" | |||||
num=$((${num} + 1)); | |||||
done | |||||
echo | |||||
timeout ${boot_profile_manager_timeout} sh -c " | |||||
profile_num=${num} | |||||
while test -z \"$(echo \"\${profile_num}\" | tr -d \"0123456789\")\" || test \${profile_num} -ge ${num} | |||||
do | |||||
read -p 'Insert a valid profile number: ' profile_num | |||||
done | |||||
exit \${profile_num}" | |||||
profile_num=$? | |||||
if test ${profile_num} -ge ${num} | |||||
then | |||||
echo | |||||
echo "Timeout. Defaults to profile 1." | |||||
profile_num=1 | |||||
fi | |||||
profile="$(echo ${boot_profile_manager_profiles} | cut -f ${profile_num} -d ' ')" | |||||
if test -e "/usr/local/etc/${name}/${profile}" | |||||
then | |||||
mount -u -w / | |||||
ln -Fs /usr/local/etc/${name}/${profile} /etc/rc.conf.d | |||||
mount -u -r / | |||||
else | |||||
echo "Error: selected profile does not exists." >&2 | |||||
echo "Using last set profile: this can fail if it has been removed since last successful boot." >&2 | |||||
exit 1 | |||||
fi | |||||
} | |||||
load_rc_config $name | |||||
run_rc_command "$1" |