1#!/bin/sh 2#- 3# Copyright (c) 2012 Devin Teske 4# All Rights Reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, THE 17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# 27# $FreeBSD$ 28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_include $BSDCFG_SHARE/dialog.subr 34f_include $BSDCFG_SHARE/mustberoot.subr 35f_include $BSDCFG_SHARE/sysrc.subr 36 37BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="140.startup" 38f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr 39 40ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" ) 41[ $? -eq $SUCCESS -a "$ipgm" ] && pgm="$ipgm" 42 43############################################################ GLOBALS 44 45# 46# Operating environment 47# 48UNAME_P=$( uname -p ) # Processor Architecture (i.e. i386) 49 50############################################################ FUNCTIONS 51 52# dialog_menu_main 53# 54# Display the dialog(1)-based application main menu. 55# 56dialog_menu_main() 57{ 58 local menu_list var_list size 59 local hline="$hline_arrows_tab_enter" 60 local prompt="$msg_miscellaneous_menu_text" 61 62 menu_list=" 63 'X <<< $msg_exit' '$msg_exit_this_menu' 64 " # END-QUOTE 65 66 var_list=" 67 accounting_enable 68 local_startup 69 lpd_enable 70 named_enable 71 named_flags 72 nis_client_enable 73 nis_server_enable 74 nisdomainname 75 startup_dirs 76 " # END-QUOTE 77 78 if [ "$UNAME_P" = "i386" ]; then 79 var_list="$var_list 80 apm_enable 81 ibcs2_enable 82 svr4_enable 83 " # END-QUOTE 84 fi 85 86 menu_list="$menu_list $( 87 . "$RC_DEFAULTS" 88 source_rc_confs 89 export $var_list 90 export msg_apm msg_apm_desc 91 export msg_startup_dirs msg_startup_dirs_desc 92 export msg_named msg_named_desc 93 export msg_named_flags msg_named_flags_desc 94 export msg_nis_client msg_nis_client_desc 95 export msg_nis_domainname msg_nis_domainname_desc 96 export msg_nis_server msg_nis_server_desc 97 export msg_accounting msg_accounting_desc 98 export msg_lpd msg_lpd_desc 99 export msg_sco msg_sco_desc 100 export msg_svr4 msg_svr4_desc 101 :| awk \ 102 -v uname_p="$UNAME_P" \ 103 -v menu_tags="$DIALOG_MENU_TAGS" \ 104 -v menu_fmt="'%c [%c] %s' '%s'\n" \ 105 -v sep_fmt="' ' ' -- '\n" \ 106 'END { 107 i = 1 108 if ( uname_p == "i386" ) 109 { 110 # 111 # APM: Auto-power management services 112 # (typically laptops) 113 # 114 printf menu_fmt, substr(menu_tags, i++, 1), 115 ( ENVIRON["apm_enable"] ~ \ 116 /^[Yy][Ee][Ss]$/ ? "X" : " " ), 117 ENVIRON["msg_apm"], 118 ENVIRON["msg_apm_desc"] 119 } 120 121 # Separator 122 printf sep_fmt 123 124 # 125 # Startup dirs: Set the list of dirs to look for 126 # startup scripts 127 # 128 printf menu_fmt, substr(menu_tags, i++, 1), 129 ( length(ENVIRON["local_startup"]) > 0 \ 130 ? "X" : " " ), 131 ENVIRON["msg_startup_dirs"], 132 ENVIRON["msg_startup_dirs_desc"] 133 134 # 135 # named: Run a local name server on this host 136 # 137 printf menu_fmt, substr(menu_tags, i++, 1), 138 ( ENVIRON["named_enable"] ~ \ 139 /^[Yy][Ee][Ss]$/ ? "X" : " " ), 140 ENVIRON["msg_named"], 141 ENVIRON["msg_named_desc"] 142 143 # 144 # named flags: Set default flags to named (if enabled) 145 # 146 printf menu_fmt, substr(menu_tags, i++, 1), 147 ( length(ENVIRON["named_flags"]) > 0 \ 148 ? "X" : " " ), 149 ENVIRON["msg_named_flags"], 150 ENVIRON["msg_named_flags_desc"] 151 152 # 153 # NIS client: This host wishes to be an NIS client. 154 # 155 printf menu_fmt, substr(menu_tags, i++, 1), 156 ( ENVIRON["nis_client_enable"] ~ \ 157 /^[Yy][Ee][Ss]$/ ? "X" : " " ), 158 ENVIRON["msg_nis_client"], 159 ENVIRON["msg_nis_client_desc"] 160 161 # 162 # NIS domainname: Set NIS domainname (if enabled) 163 # 164 printf menu_fmt, substr(menu_tags, i++, 1), 165 ( length(ENVIRON["nisdomainname"]) > 0 \ 166 ? "X" : " " ), 167 ENVIRON["msg_nis_domainname"], 168 ENVIRON["msg_nis_domainname_desc"] 169 170 # 171 # NIS server: This host wishes to be an NIS server. 172 # 173 printf menu_fmt, substr(menu_tags, i++, 1), 174 ( ENVIRON["nis_server_enable"] ~ \ 175 /^[Yy][Ee][Ss]$/ ? "X" : " " ), 176 ENVIRON["msg_nis_server"], 177 ENVIRON["msg_nis_server_desc"] 178 179 # Separator 180 printf sep_fmt 181 182 # 183 # Accounting: This host wishes to run process 184 # accounting. 185 # 186 printf menu_fmt, substr(menu_tags, i++, 1), 187 ( ENVIRON["accounting_enable"] ~ \ 188 /^[Yy][Ee][Ss]$/ ? "X" : " " ), 189 ENVIRON["msg_accounting"], 190 ENVIRON["msg_accounting_desc"] 191 192 # 193 # lpd: This host has a printer and wants to run lpd. 194 # 195 printf menu_fmt, substr(menu_tags, i++, 1), 196 ( ENVIRON["lpd_enable"] ~ \ 197 /^[Yy][Ee][Ss]$/ ? "X" : " " ), 198 ENVIRON["msg_lpd"], 199 ENVIRON["msg_lpd_desc"] 200 201 if ( uname_p == "i386" ) 202 { 203 # 204 # SCO: This host wants to be able to run IBCS2 205 # binaries. 206 # 207 printf menu_fmt, substr(menu_tags, i++, 1), 208 ( ENVIRON["ibcs2_enable"] ~ \ 209 /^[Yy][Ee][Ss]$/ ? "X" : " " ), 210 ENVIRON["msg_sco"], 211 ENVIRON["msg_sco_desc"] 212 213 # 214 # SVR4: This host wants to be able to run SVR4 215 # binaries. 216 # 217 printf menu_fmt, substr(menu_tags, i++, 1), 218 ( ENVIRON["svr4_enable"] ~ \ 219 /^[Yy][Ee][Ss]$/ ? "X" : " " ), 220 ENVIRON["msg_svr4"], 221 ENVIRON["msg_svr4_desc"] 222 } 223 }' 224 )" 225 226 size=$( eval f_dialog_menu_size \ 227 \"\$DIALOG_TITLE\" \ 228 \"\$DIALOG_BACKTITLE\" \ 229 \"\$prompt\" \ 230 \"\$hline\" \ 231 $menu_list ) 232 233 local dialog_menu 234 dialog_menu=$( eval $DIALOG \ 235 --clear --title \"\$DIALOG_TITLE\" \ 236 --backtitle \"\$DIALOG_BACKTITLE\" \ 237 --hline \"\$hline\" \ 238 --ok-label \"\$msg_ok\" \ 239 --cancel-label \"\$msg_cancel\" \ 240 --menu \"\$prompt\" $size \ 241 $menu_list \ 242 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 243 ) 244 local retval=$? 245 setvar DIALOG_MENU_$$ "$dialog_menu" 246 return $retval 247} 248 249# dialog_input_value [ $prompt [ $init ] ] 250# 251# Prompt the user to input a value. If the user does not cancel or press ESC, 252# the return value is zero ($SUCCESS) and $value holds the user's input. 253# 254dialog_input_value() 255{ 256 local prompt="$1" _input="$2" 257 258 f_dialog_title "$msg_value_required" 259 _input=$( f_dialog_input "$prompt" "$_input" "$hline_alnum_tab_enter" ) 260 local retval=$? 261 f_dialog_title_restore 262 263 # Return if user has either pressed ESC or chosen Cancel/No 264 [ $retval -eq $SUCCESS ] || return $retval 265 266 value="$_input" 267 return $SUCCESS 268} 269 270############################################################ MAIN 271 272# Incorporate rc-file if it exists 273[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 274 275# 276# Process command-line arguments 277# 278while getopts hSX flag; do 279 case "$flag" in 280 h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; 281 esac 282done 283shift $(( $OPTIND - 1 )) 284 285# 286# Initialize 287# 288f_dialog_init 289f_dialog_title "$msg_miscellaneous_startup_services" 290f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 291f_mustberoot_init 292 293# 294# Launch application main menu 295# 296while :; do 297 dialog_menu_main 298 retval=$? 299 mtag=$( f_dialog_menutag ) 300 301 [ $retval -eq 0 ] || f_die 302 303 case "$mtag" in 304 "X <<< $msg_exit") break ;; 305 ?" ["?"] $msg_apm") 306 case "$mtag" in 307 ?" [X] "*) err=$( f_sysrc_set apm_enable NO 2>&1 ) ;; 308 ?" [ ] "*) err=$( f_sysrc_set apm_enable YES 2>&1 ) ;; 309 esac 310 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 311 ?" ["?"] $msg_startup_dirs") 312 dialog_input_value \ 313 "$msg_startup_dirs_desc" \ 314 "$( f_sysrc_get local_startup )" 315 if [ $? -eq $SUCCESS ]; then 316 err=$( f_sysrc_set local_startup "$value" ) || 317 f_show_msg "%s\n" "$err" 318 fi 319 ;; 320 ?" ["?"] $msg_named") 321 case "$mtag" in 322 ?" [X] "*) err=$( f_sysrc_set named_enable NO 2>&1 ) ;; 323 ?" [ ] "*) err=$( f_sysrc_set named_enable YES 2>&1 ) ;; 324 esac 325 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 326 ?" ["?"] $msg_named_flags") 327 dialog_input_value \ 328 "$msg_named_flags_desc" \ 329 "$( f_sysrc_get named_flags )" 330 if [ $? -eq $SUCCESS ]; then 331 err=$( f_sysrc_set named_flags "$value" ) || 332 f_show_msg "%s\n" "$err" 333 fi 334 ;; 335 ?" ["?"] $msg_nis_client") 336 case "$mtag" in 337 ?" [X] "*) err=$( f_sysrc_set nis_client_enable NO 2>&1 ) ;; 338 ?" [ ] "*) 339 err=$( f_sysrc_set nis_client_enable YES 2>&1 ) \ 340 && err=$( f_sysrc_set rpcbind_enable YES 2>&1 ) ;; 341 esac 342 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 343 ?" ["?"] $msg_nis_domainname") 344 dialog_input_value \ 345 "$msg_nis_domainname_desc" \ 346 "$( f_sysrc_get nisdomainname )" 347 if [ $? -eq $SUCCESS ]; then 348 err=$( f_sysrc_set nisdomainname "$value" ) || 349 f_show_msg "%s\n" "$err" 350 fi 351 ;; 352 ?" ["?"] $msg_nis_server") 353 case "$mtag" in 354 ?" [X] "*) err=$( f_sysrc_set nis_server_enable NO 2>&1 ) ;; 355 ?" [ ] "*) 356 err=$( f_sysrc_set nis_server_enable YES 2>&1 ) \ 357 && err=$( f_sysrc_set rpcbind_enable YES 2>&1 ) ;; 358 esac 359 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 360 ?" ["?"] $msg_accounting") 361 case "$mtag" in 362 ?" [X] "*) err=$( f_sysrc_set accounting_enable NO 2>&1 ) ;; 363 ?" [ ] "*) err=$( f_sysrc_set accounting_enable YES 2>&1 ) ;; 364 esac 365 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 366 ?" ["?"] $msg_lpd") 367 case "$mtag" in 368 ?" [X] "*) err=$( f_sysrc_set lpd_enable NO 2>&1 ) ;; 369 ?" [ ] "*) err=$( f_sysrc_set lpd_enable YES 2>&1 ) ;; 370 esac 371 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 372 ?" ["?"] $msg_sco") 373 case "$mtag" in 374 ?" [X] "*) err=$( f_sysrc_set ibcs2_enable NO 2>&1 ) ;; 375 ?" [ ] "*) err=$( f_sysrc_set ibcs2_enable YES 2>&1 ) ;; 376 esac 377 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 378 ?" ["?"] $msg_svr4") 379 case "$mtag" in 380 ?" [X] "*) err=$( f_sysrc_set svr4_enable NO 2>&1 ) ;; 381 ?" [ ] "*) err=$( f_sysrc_set svr4_enable YES 2>&1 ) ;; 382 esac 383 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 384 esac 385done 386 387exit $SUCCESS 388 389################################################################################ 390# END 391################################################################################ 392