#! /bin/bash . /usr/lib/network/network # Scan all profiles i=0 # JP: change for prof to while read prof to avoid assumption that profile names are always single tokens (no spaces etc.) while read prof; do # if there is a profile called "main", Use as default [ "$prof" = "main" ] && DEFAULT=$prof unset DESCRIPTION # JP: we can''t sandbox the sourced profiles, because we need to expose profiles[] . $PROFILE_DIR/$prof profiles[$i]=$prof i=$((i+1)) profiles[$i]="$DESCRIPTION" # JP: this will usually have spaces and must be quoted i=$((i+1)) done < <(list_profiles | sort) # JP: re-use list_profiles instead of duplicating it; avoid subshell we'd get by piping it to the while read... if [ ${#profiles} -eq 0 ]; then exit_err "No profiles were found in $PROFILE_DIR" fi # if no default yet, use the first entry [ "$NETWORKS_MENU_DEFAULT" ] && DEFAULT="$NETWORKS_MENU_DEFAULT" [ "$DEFAULT" = "" ] && DEFAULT=${profiles[0]} ANSWER=$(mktemp) || exit 1 # Set timeout if [ "$1" = "" ]; then TIMEOUT="0" else TIMEOUT="$1" fi # Display Dialog dialog --timeout $TIMEOUT --default-item $DEFAULT \ --menu "Select the network profile you wish to use" \ 13 50 6 "${profiles[@]}" 2>$ANSWER ret=$? case $ret in 1) ;; # Cancel - do nothing 255) # timeout - use default netcfg2 $DEFAULT ;; 0) # User selection netcfg2 $(cat $ANSWER) ;; *) # Shouldnt happen exit_err "Abnormal ret code from dialog: $ret" ;; esac rm $ANSWER # vim: set ts=4 et sw=4: