SMIT 示例程序
以下示例程序意在帮助您编写您自己的节。
如果将这些节 添加到带有操作系统的 SMIT 目录,通过在 SMIT 主菜单中选择应用程序项将可通过 SMIT 访问它们。 除了未安装任何语言的演示 3 之外的所有演示均正常工作。
#----------------------------------------------------------------
# Intro:
# Unless you are creating a new SMIT database, first you need
# to decide where to insert the menu for your application.
# Your new menu will point to other menus, name headers, and
# dialogs. For this example, we are inserting a pointer to the
# demo menu under the "Applications" menu option. The next_id for
# the Applications menu item is "apps", so we begin by creating a
# menu_opt with "apps" as its id.
#----------------------------------------------------------------
sm_menu_opt:
id = "apps"
id_seq_num = "010"
next_id = "demo"
text = "SMIT Demos"
next_type = "m"
sm_menu_opt:
id = "demo"
id_seq_num = "010"
next_id = "demo_queue"
text = "Demo 1: Add a Print Queue"
next_type = "n"
sm_menu_opt:
id = "demo"
id_seq_num = "020"
next_id = "demo_mle_inst_lang_hdr"
text = "Demo 2: Add Language for Application Already Installed"
next_type = "n"
#----
# Since demo_mle_inst_lang_hdr is a descriptive, but not very
# memorable name, an alias with a simpler name can be made to
# point to the same place.
#----
sm_menu_opt:
id = "demo_lang"
next_id = "demo_mle_inst_lang_hdr"
next_type = "n"
alias = "y"
sm_menu_opt:
id_seq_num = "030"
id = "demo"
next_id = "demo_lspv"
text = "Demo 3: List Contents of a Physical Volume"
text_msg_file = "smit.cat"
next_type = "n"
sm_menu_opt:
id_seq_num = "040"
id = "demo"
next_id = "demo_date"
text = "Demo 4: Change / Show Date, Time"
text_msg_file = "smit.cat"
next_type = "n"
#----------------------------------------------------------------
# Demo 1
# ------
# Goal: Add a Print Queue. If the printers.rte package is not
# installed, install it automatically. If the user is
# running MSMIT (SMIT in a windows interface), launch a
# graphical program for this task. Otherwise, branch to
# the SMIT print queue task.
#
# Topics: 1. cooked output & cmd_to_classify
# 2. SMIT environment variable (msmit vs. ascii)
# 3. ghost name_hdr
# 4. super-ghost name_hdr
# 5. creating an "OK / cancel" option
# 6. dspmsg for translations
# 7. exit/exec mode
# 8. id_seq_num for a name_hdr option
#----------------------------------------------------------------
#----
# Topics: 1,4
# Note that the next_id is the same as the id. Remember that the
# output of the cmd_to_classify is appended to the next_id,
# since the type is "c", for cooked. So, the next_id will be
# either demo_queue1 or demo_queue2. None of the output of the
# name_hdr is displayed, and there is no cmd_to_list in the
# demo_queue_dummy_opt, making this name_hdr a super-ghost.
#----
sm_name_hdr:
id = "demo_queue"
next_id = "demo_queue"
option_id = "demo_queue_dummy_opt"
name = "Add a Print Queue"
name_msg_file = "smit.cat"
name_msg_set = 52
name_msg_id = 41
type = "c"
ghost = "y"
cmd_to_classify = "\
x()
{
# Check to see if the printer file is installed.
lslpp -l printers.rte 2>/dev/null 1>/dev/null
if [[ $? != 0 ]]
then
echo 2
else
echo 1
fi
}
x"
next_type = "n"
#----
# Topics: 2,4
# Having determined the printer software is installed, we want
# to know if the gui program should be run or if we should
# branch to the ascii SMIT screen for this task. To do this, we
# check the value of the environment variable SMIT, which is "m"
# for windows (Motif) or "a" for ascii. Here again we tack the
# output of the cmd_to_classify onto the next_id.
#----
sm_name_hdr:
id = "demo_queue1"
next_id = "mkpq"
option_id = "demo_queue_dummy_opt"
has_name_select = ""
ghost = "y"
next_type = "n"
type = "c"
cmd_to_classify = "\
gui_check()
{
if [ $SMIT = \"m\" ]; then
echo gui
fi
}
gui_check"
sm_name_hdr:
id = "mkpqgui"
next_id = "invoke_gui"
next_type = "d"
option_id = "demo_queue_dummy_opt"
ghost = "y"
#----
# Topics: 7
# Note: the exec_mode of this command is "e", which
# exits SMIT before running the cmd_to_exec.
#----
sm_cmd_hdr:
id = "invoke_gui"
cmd_to_exec = "/usr/bin/X11/xprintm"
exec_mode = "e"
ghost = "y"
sm_cmd_opt:
id = "demo_queue_dummy_opt"
id_seq_num = 0
#----
# Topics: 3,5
# The printer software is not installed. Install the software
# and loop back to demo_queue1 to check the SMIT environment
# variable. This is a ghost name_hdr. The cmd_to_list of the
# sm_cmd_opt is displayed immediately as a pop-up option
# instead of waiting for the user to input a response. In this
# ghost, the cmd_opt is a simple OK/cancel box that prompts the
# user to press return.
#----
sm_name_hdr:
id = "demo_queue2"
next_id = "demo_queue1"
option_id = "demo_queue_opt"
name = "Add a Print Queue"
name_msg_file = "smit.cat"
name_msg_set = 52
name_msg_id = 41
ghost = "y"
cmd_to_classify = "\
install_printers ()
{
# Install the printer package.
/usr/lib/assist/install_pkg \"printers.rte\" 2>&1 >/dev/null
if [[ $? != 0 ]]
then
echo "Error installing printers.rte"
exit 1
else
exit 0
fi
}
install_printers "
next_type = "n"
#----
# Topics: 5,6,8
# Here a cmd_opt is used as an OK/cancel box. Note also that the
# command dspmsg is used to display the text for the option. This
# allows for translation of the messages.
# Note: the id_seq_num for the option is 0. Only one option is
# allowed per name_hdr, and its id_seq_num must be 0.
#----
sm_cmd_opt:
id = "demo_queue_opt"
id_seq_num = "0"
disc_field_name = ""
name = "Add a Print Queue"
name_msg_file = "smit.cat"
name_msg_set = 52
name_msg_id = 41
op_type = "l"
cmd_to_list = "x()\
{
if [ $SMIT = \"a\" ] \n\
then \n\
dspmsg -s 52 smit.cat 56 \
'Press Enter to automatically install the printer software.\n\
Press F3 to cancel.\n\
'\n\
else \n\
dspmsg -s 52 smit.cat 57 'Click on this item to automatically install
the printer software.\n' \n\
fi\n\
} \n\
x"
entry_type = "t"
multi_select = "n"
#----------------------------------------------------------------
#
# Demo 2
# ------
# Goal: Add a Language for an Application Already Installed. It
# is often clearer to the user to get some information
# before displaying the dialog screen. Name Headers
# (sm_name_hdr) can be used for this purpose. In this
# example, two name headers are used to determine the
# language to install and the installation device. The
# dialog has entries for the rest of the information needed
# to perform the task.
#
# Topics:
# 1. Saving output from successive name_hdrs with
# cooked_field_name
# 2. Using getopts inside cmd_to_exec to process cmd_opt
# info
# 3. Ring list vs. cmd_to_list for displaying values
# cmd_opts
#----------------------------------------------------------------
#----
# Topic: 1
# This is the first name_hdr. It is called by the menu_opt for
# this function. We want to save the user's input for later use
# in the dialog. The parameter passed into the cmd_to_classify
# comes from the user's selection/entry. Cmd_to_classify cleans
# up the output and stores it in the variable specified by
# cooked_field_name. This overrides the default value for the
# cmd_to_classify output, which is _cookedname. The default must
# be overridden because we also need to save the output of the
# next name_hdr.
#----
sm_name_hdr:
id = "demo_mle_inst_lang_hdr"
next_id = "demo_mle_inst_lang"
option_id = "demo_mle_inst_lang_select"
name = "Add Language for Application Already Installed"
name_msg_file = "smit.cat"
name_msg_set = 53
name_msg_id = 35
type = "j"
ghost = "n"
cmd_to_classify = "\
foo() {
echo $1 | sed -n \"s/[^[]*\\[\\([^]]*\\).*/\\1/p\"
}
foo"
cooked_field_name = "add_lang_language"
next_type = "n"
help_msg_id = "2850325"
sm_cmd_opt:
id = "demo_mle_inst_lang_select"
id_seq_num = "0"
disc_field_name = "add_lang_language"
name = "LANGUAGE translation to install"
name_msg_file = "smit.cat"
name_msg_set = 53
name_msg_id = 20
op_type = "l"
entry_type = "n"
entry_size = 0
required = ""
prefix = "-l "
cmd_to_list_mode = "a"
cmd_to_list = "/usr/lib/nls/lsmle -l"
help_msg_id = "2850328"
#----
# Topic:1
# This is the second name_hdr. Here the user's input is passed
# directly through the cmd_to_classify and stored in the
# variable add_lang_input.
#----
sm_name_hdr:
id = "demo_mle_inst_lang"
next_id = "demo_dialog_add_lang"
option_id = "demo_add_input_select"
has_name_select = "y"
name = "Add Language for Application Already Installed"
name_msg_file = "smit.cat"
name_msg_set = 53
name_msg_id = 35
type = "j"
ghost = "n"
cmd_to_classify = "\
foo() {
echo $1
}
foo"
cooked_field_name = "add_lang_input"
next_type = "d"
help_msg_id = "2850328"
sm_cmd_opt:
id = "demo_add_input_select"
id_seq_num = "0"
disc_field_name = "add_lang_input"
name = "INPUT device/directory for software"
name_msg_file = "smit.cat"
name_msg_set = 53
name_msg_id = 11
op_type = "l"
entry_type = "t"
entry_size = 0
required = "y"
prefix = "-d "
cmd_to_list_mode = "1"
cmd_to_list = "/usr/lib/instl/sm_inst list_devices"
help_msg_id = "2850313"
#----
# Topic: 2
# Each of the cmd_opts formats its information for processing
# by the getopts command (a dash and a single character, followed
# by an optional parameter). The colon following the letter in
# the getopts command means that a parameter is expected after
# the dash option. This is a nice way to process the cmd_opt
# information if there are several options, especially if one of
# the options could be left out, causing the sequence of $1, $2,
# etc. to get out of order.
#----
sm_cmd_hdr:
id = "demo_dialog_add_lang"
option_id = "demo_mle_add_app_lang"
has_name_select = ""
name = "Add Language for Application Already Installed"
name_msg_file = "smit.cat"
name_msg_set = 53
name_msg_id = 35
cmd_to_exec = "\
foo()
{
while getopts d:l:S:X Option \"$@\"
do
case $Option in
d) device=$OPTARG;;
l) language=$OPTARG;;
S) software=$OPTARG;;
X) extend_fs="-X";;
esac
done
if [[ `/usr/lib/assist/check_cd -d $device` = '1' ]]
then
/usr/lib/assist/mount_cd $device
CD_MOUNTED=true
fi
if [[ $software = \"ALL\" ]]
then
echo "Installing all software for $language..."
else
echo "Installing $software for $language..."
fi
exit $RC
}
foo"
ask = "y"
ghost = "n"
help_msg_id = "2850325"
sm_cmd_opt:
id = "demo_mle_add_app_lang"
id_seq_num = "0"
disc_field_name = "add_lang_language"
name = "LANGUAGE translation to install"
name_msg_file = "smit.cat"
name_msg_set = 53
name_msg_id = 20
entry_type = "n"
entry_size = 0
required = "y"
prefix = "-l "
cmd_to_list_mode = "a"
help_msg_id = "2850328"
#----
# Topic: 2
# The prefix field precedes the value selected by the user, and
# both the prefix and the user-selected value are passed into
# the cmd_to_exec for getopts processing.
#----
sm_cmd_opt:
id = "demo_mle_add_app_lang"
id_seq_num = "020"
disc_field_name = "add_lang_input"
name = "INPUT device/directory for software"
name_msg_file = "smit.cat"
name_msg_set = 53
name_msg_id = 11
entry_type = "n"
entry_size = 0
required = "y"
prefix = "-d "
cmd_to_list_mode = "1"
cmd_to_list = "/usr/lib/instl/sm_inst list_devices"
help_msg_id = "2850313"
sm_cmd_opt:
id = "demo_mle_add_app_lang"
id_seq_num = "030"
name = "Installed APPLICATION"
name_msg_file = "smit.cat"
name_msg_set = 53
name_msg_id = 43
op_type = "l"
entry_type = "n"
entry_size = 0
required = "y"
prefix = "-S "
cmd_to_list_mode = ""
cmd_to_list = "\
list_messages ()
{
language=$1
device=$2
lslpp -Lqc | cut -f2,3 -d':'
}
list_messages"
cmd_to_list_postfix = "add_lang_language add_lang_input"
multi_select = ","
value_index = 0
disp_values = "ALL"
help_msg_id = "2850329"
#----
# Topic: 3
# Here, instead of a cmd_to_list, there is a comma-delimited set
# of Ring values in the disp_values field. This list is displayed
# one item at a time as the user presses tab in the cmd_opt entry
# field. However, instead of passing a yes or no to the cmd_hdr,
# it is more useful to use the aix_values field to pass either
# a -X or nothing. The list in the aix_values field must match
# one-to-one with the list in the disp_values field.
#----
sm_cmd_opt:
id_seq_num = "40"
id = "demo_mle_add_app_lang"
disc_field_name = ""
name = "EXTEND file systems if space needed?"
name_msg_file = "smit.cat"
name_msg_set = 53
name_msg_id = 12
op_type = "r"
entry_type = "n"
entry_size = 0
required = "y"
multi_select = "n"
value_index = 0
disp_values = "yes,no"
values_msg_file = "sm_inst.cat"
values_msg_set = 1
values_msg_id = 51
aix_values = "-X,"
help_msg_id = "0503005"
#----------------------------------------------------------------
#
# Demo 3
# ------
# Goal: Show Characteristics of a Logical Volume. The name of the
# logical volume is entered by the user and passed to the
# cmd_hdr as _rawname.
#
# Topics: 1. _rawname
# 2. Ringlist & aix_values
#----------------------------------------------------------------
#----
# Topic: 1
# No rawname is needed because we have only one name_hdr and
# we can use the default variable name _rawname.
#----
sm_name_hdr:
id = "demo_lspv"
next_id = "demo_lspvd"
option_id = "demo_cmdlvmpvns"
has_name_select = ""
name = "List Contents of a Physical Volume"
name_msg_file = "smit.cat"
name_msg_set = 15
name_msg_id = 100
type = "j"
ghost = ""
cmd_to_classify = ""
raw_field_name = ""
cooked_field_name = ""
next_type = "d"
help_msg_id = "0516100"
sm_cmd_opt:
id_seq_num = "0"
id = "demo_cmdlvmpvns"
disc_field_name = "PVName"
name = "PHYSICAL VOLUME name"
name_msg_file = "smit.cat"
name_msg_set = 15
name_msg_id = 101
op_type = "l"
entry_type = "t"
entry_size = 0
required = "+"
cmd_to_list_mode = "1"
cmd_to_list = "lsvg -o|lsvg -i -p|grep -v '[:P]'| \
cut -f1 -d' '"
cmd_to_list_postfix = ""
multi_select = "n"
help_msg_id = "0516021"
#----
# Topic: 1
# The cmd_to_discover_postfix passes in the name of the physical
# volume, which is the raw data selected by the user in the
# name_hdr - _rawname.
#----
sm_cmd_hdr:
id = "demo_lspvd"
option_id = "demo_cmdlvmlspv"
has_name_select = "y"
name = "List Contents of a Physical Volume"
name_msg_file = "smit.cat"
name_msg_set = 15
name_msg_id = 100
cmd_to_exec = "lspv"
ask = "n"
cmd_to_discover_postfix = "_rawname"
help_msg_id = "0516100"
sm_cmd_opt:
id_seq_num = "01"
id = "demo_cmdlvmlspv"
disc_field_name = "_rawname"
name = "PHYSICAL VOLUME name"
name_msg_file = "smit.cat"
name_msg_set = 15
name_msg_id = 101
op_type = "l"
entry_type = "t"
entry_size = 0
required = "+"
cmd_to_list_mode = "1"
cmd_to_list = "lsvg -o|lsvg -i -p|grep -v '[:P]'| \
cut -f1 -d' '"
help_msg_id = "0516021"
#----
# Topic: 2
# Here a ringlist of 3 values matches with the aix_values we
# want to pass to the sm_cmd_hdr's cmd_to_exec.
#----
sm_cmd_opt:
id_seq_num = "02"
id = "demo_cmdlvmlspv"
disc_field_name = "Option"
name = "List OPTION"
name_msg_file = "smit.cat"
name_msg_set = 15
name_msg_id = 92
op_type = "r"
entry_type = "n"
entry_size = 0
required = "n"
value_index = 0
disp_values = "status,logical volumes,physical \
partitions"
values_msg_file = "smit.cat"
values_msg_set = 15
values_msg_id = 103
aix_values = " ,-l,-p"
help_msg_id = "0516102"
#----------------------------------------------------------------
#
# Demo 4
# ------
# Goal: Change / Show Date & Time
#
# Topics: 1. Using a ghost name header to get variable
# values for the next dialog screen.
# 2. Using a cmd_to_discover to fill more than one
# cmd_opt with initial values.
# 3. Re-ordering parameters in a cmd_to_exec.
#----------------------------------------------------------------
#----
# Topic: 1
# This ghost name_hdr gets two values and stores them in the
# variables daylight_y_n and time_zone for use in the cmd_opts
# for the next dialog. The output of cmd_to_classify is colon-
# delimited, as is the list of field names in cooked_field_name.
#----
sm_name_hdr:
id = "demo_date"
next_id = "demo_date_dial"
option_id = "date_sel_opt"
name_msg_set = 0
name_msg_id = 0
ghost = "y"
cmd_to_classify = " \
if [ $(echo $TZ | awk '{ \
if (length($1) <=6 ) {printf(\"2\")} \
else {printf(\"1\")} }') = 1 ] \n\
then\n\
echo $(dspmsg smit.cat -s 30 18 'yes')\":$TZ\"\n\
else\n\
echo $(dspmsg smit.cat -s 30 19 'no')\":$TZ\"\n\
fi #"
cooked_field_name = "daylight_y_n:time_zone"
sm_cmd_opt:
id_seq_num = "0"
id = "date_sel_opt"
#----
# Topic: 2,3
# Here the cmd_to_discover gets six values, one for each of the
# editable sm_cmd_opts for this screen. The cmd_to_discover
# output is two lines, the first with a # followed by a list of
# variable names, and the second line the list of values. Both
# lists are colon-delimited. We also see here the cmd_to_exec
# takeing the parameters from the cmd_opts and reordering them
# when calling the command.
#----
sm_cmd_hdr:
id = "demo_date_dial"
option_id = "demo_chtz_opts"
has_name_select = "y"
name = "Change / Show Date & Time"
name_msg_file = "smit.cat"
name_msg_set = 30
name_msg_id = 21
cmd_to_exec = "date_proc () \
# MM dd hh mm ss yy\n\
# dialogue param order # 3 4 5 6 7 2\n\
{\n\
date \"$3$4$5$6.$7$2\"\n\
}\n\
date_proc "
exec_mode = "P"
cmd_to_discover = "disc_proc() \n\
{\n\
TZ=\"$1\"\n\
echo '#cur_month:cur_day:cur_hour:cur_min:cur_sec:cur_year'\n\
date +%m:%d:%H:%M:%S:%y\n\
}\n\
disc_proc"
cmd_to_discover_postfix = ""
help_msg_id = "055101"
#----
# The first two cmd_opts get their initial values
# (disc_field_name) from the name_hdr.
#----
sm_cmd_opt:
id_seq_num = "04"
id = "demo_chtz_opts"
disc_field_name = "time_zone"
name = "Time zone"
name_msg_file = "smit.cat"
name_msg_set = 30
name_msg_id = 16
required = "y"
sm_cmd_opt:
id_seq_num = "08"
id = "demo_chtz_opts"
disc_field_name = "daylight_y_n"
name = "Does this time zone go on Daylight Saving Time?\n"
name_msg_file = "smit.cat"
name_msg_set = 30
name_msg_id = 17
entry_size = 0
#----
# The last six cmd_opts get their values from the
# cmd_to_discover.
#----
sm_cmd_opt:
id_seq_num = "10"
id = "demo_chtz_opts"
disc_field_name = "cur_year"
name = "YEAR (00-99)"
name_msg_file = "smit.cat"
name_msg_set = 30
name_msg_id = 10
entry_type = "#"
entry_size = 2
required = "+"
help_msg_id = "055102"
sm_cmd_opt:
id_seq_num = "20"
id = "demo_chtz_opts"
disc_field_name = "cur_month"
name = "MONTH (01-12)"
name_msg_file = "smit.cat"
name_msg_set = 30
name_msg_id = 11
entry_type = "#"
entry_size = 2
required = "+"
help_msg_id = "055132"
sm_cmd_opt:
id_seq_num = "30"
id = "demo_chtz_opts"
disc_field_name = "cur_day"
name = "DAY (01-31)\n"
name_msg_file = "smit.cat"
name_msg_set = 30
name_msg_id = 12
entry_type = "#"
entry_size = 2
required = "+"
help_msg_id = "055133"
sm_cmd_opt:
id_seq_num = "40"
id = "demo_chtz_opts"
disc_field_name = "cur_hour"
name = "HOUR (00-23)"
name_msg_file = "smit.cat"
name_msg_set = 30
name_msg_id = 13
entry_type = "#"
entry_size = 2
required = "+"
help_msg_id = "055134"
sm_cmd_opt:
id_seq_num = "50"
id = "demo_chtz_opts"
disc_field_name = "cur_min"
name = "MINUTES (00-59)"
name_msg_file = "smit.cat"
name_msg_set = 30
name_msg_id = 14
entry_type = "#"
entry_size = 2
required = "+"
help_msg_id = "055135"
sm_cmd_opt:
id_seq_num = "60"
id = "demo_chtz_opts"
disc_field_name = "cur_sec"
name = "SECONDS (00-59)"
name_msg_file = "smit.cat"
name_msg_set = 30
name_msg_id = 15
entry_type = "#"
entry_size = 2
required = "+"
help_msg_id = "055136"