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_menu_selection $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 hline="$hline_alnum_tab_enter" 257 local size prompt="$1" _input="$2" 258 259 f_dialog_title "$msg_value_required" 260 261 size=$( f_dialog_inputbox_size \ 262 "$DIALOG_TITLE" \ 263 "$DIALOG_BACKTITLE" \ 264 "$prompt" \ 265 "$_input" \ 266 "$hline" ) 267 268 local dialog_inputbox 269 dialog_inputbox=$( eval $DIALOG \ 270 --title \"\$DIALOG_TITLE\" \ 271 --backtitle \"\$DIALOG_BACKTITLE\" \ 272 --hline \"\$hline\" \ 273 --ok-label \"\$msg_ok\" \ 274 --cancel-label \"\$msg_cancel\" \ 275 --inputbox \"\$prompt\" $size \ 276 \"\$_input\" \ 277 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 278 ) 279 280 retval=$? 281 setvar DIALOG_INPUTBOX_$$ "$dialog_inputbox" 282 _input=$( f_dialog_inputstr ) 283 284 f_dialog_title_restore 285 286 # Return if user has either pressed ESC or chosen Cancel/No 287 [ $retval -eq $SUCCESS ] || return $retval 288 289 value="$_input" 290 return $SUCCESS 291} 292 293############################################################ MAIN 294 295# Incorporate rc-file if it exists 296[ -f "$HOME/.bsdconfigrc" ] && f_include "$HOME/.bsdconfigrc" 297 298# 299# Process command-line arguments 300# 301while getopts hSX flag; do 302 case "$flag" in 303 h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";; 304 esac 305done 306shift $(( $OPTIND - 1 )) 307 308# 309# Initialize 310# 311f_dialog_init 312f_dialog_title "$msg_miscellaneous_startup_services" 313f_dialog_backtitle "${ipgm:+bsdconfig }$pgm" 314f_mustberoot_init 315 316# 317# Launch application main menu 318# 319while :; do 320 dialog_menu_main 321 retval=$? 322 mtag=$( f_dialog_menutag ) 323 324 [ $retval -eq 0 ] || f_die 325 326 case "$mtag" in 327 "X <<< $msg_exit") break ;; 328 ?" ["?"] $msg_apm") 329 case "$mtag" in 330 ?" [X] "*) err=$( f_sysrc_set apm_enable NO 2>&1 ) ;; 331 ?" [ ] "*) err=$( f_sysrc_set apm_enable YES 2>&1 ) ;; 332 esac 333 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 334 ?" ["?"] $msg_startup_dirs") 335 dialog_input_value \ 336 "$msg_startup_dirs_desc" \ 337 "$( f_sysrc_get local_startup )" 338 if [ $? -eq $SUCCESS ]; then 339 err=$( f_sysrc_set local_startup "$value" ) || 340 f_show_msg "%s\n" "$err" 341 fi 342 ;; 343 ?" ["?"] $msg_named") 344 case "$mtag" in 345 ?" [X] "*) err=$( f_sysrc_set named_enable NO 2>&1 ) ;; 346 ?" [ ] "*) err=$( f_sysrc_set named_enable YES 2>&1 ) ;; 347 esac 348 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 349 ?" ["?"] $msg_named_flags") 350 dialog_input_value \ 351 "$msg_named_flags_desc" \ 352 "$( f_sysrc_get named_flags )" 353 if [ $? -eq $SUCCESS ]; then 354 err=$( f_sysrc_set named_flags "$value" ) || 355 f_show_msg "%s\n" "$err" 356 fi 357 ;; 358 ?" ["?"] $msg_nis_client") 359 case "$mtag" in 360 ?" [X] "*) err=$( f_sysrc_set nis_client_enable NO 2>&1 ) ;; 361 ?" [ ] "*) 362 err=$( f_sysrc_set nis_client_enable YES 2>&1 ) \ 363 && err=$( f_sysrc_set rpcbind_enable YES 2>&1 ) ;; 364 esac 365 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 366 ?" ["?"] $msg_nis_domainname") 367 dialog_input_value \ 368 "$msg_nis_domainname_desc" \ 369 "$( f_sysrc_get nisdomainname )" 370 if [ $? -eq $SUCCESS ]; then 371 err=$( f_sysrc_set nisdomainname "$value" ) || 372 f_show_msg "%s\n" "$err" 373 fi 374 ;; 375 ?" ["?"] $msg_nis_server") 376 case "$mtag" in 377 ?" [X] "*) err=$( f_sysrc_set nis_server_enable NO 2>&1 ) ;; 378 ?" [ ] "*) 379 err=$( f_sysrc_set nis_server_enable YES 2>&1 ) \ 380 && err=$( f_sysrc_set rpcbind_enable YES 2>&1 ) ;; 381 esac 382 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 383 ?" ["?"] $msg_accounting") 384 case "$mtag" in 385 ?" [X] "*) err=$( f_sysrc_set accounting_enable NO 2>&1 ) ;; 386 ?" [ ] "*) err=$( f_sysrc_set accounting_enable YES 2>&1 ) ;; 387 esac 388 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 389 ?" ["?"] $msg_lpd") 390 case "$mtag" in 391 ?" [X] "*) err=$( f_sysrc_set lpd_enable NO 2>&1 ) ;; 392 ?" [ ] "*) err=$( f_sysrc_set lpd_enable YES 2>&1 ) ;; 393 esac 394 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 395 ?" ["?"] $msg_sco") 396 case "$mtag" in 397 ?" [X] "*) err=$( f_sysrc_set ibcs2_enable NO 2>&1 ) ;; 398 ?" [ ] "*) err=$( f_sysrc_set ibcs2_enable YES 2>&1 ) ;; 399 esac 400 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 401 ?" ["?"] $msg_svr4") 402 case "$mtag" in 403 ?" [X] "*) err=$( f_sysrc_set svr4_enable NO 2>&1 ) ;; 404 ?" [ ] "*) err=$( f_sysrc_set svr4_enable YES 2>&1 ) ;; 405 esac 406 [ $? -eq $SUCCESS ] || f_show_msg "%s\n" "$err" ;; 407 esac 408done 409 410exit $SUCCESS 411 412################################################################################ 413# END 414################################################################################ 415