Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Tux Hat Linux Main Menu Setup Script
- name=$(basename "$0")
- longname='Tux Hat Linux'
- ver='3.3 - Main Menu Setup'
- trap '' SIGINT SIGTSTP
- # Helper functions.
- warn() { (printf ' \033[01;33m*\033[00m '; echo "$name: $*") > /dev/stderr; }
- error() { (printf ' \033[01;31m*\033[00m '; echo "$name: $*") > /dev/stderr; }
- exitnormal() { exit 0; }
- exiterror() { sleep 1; exit 1; }
- exitcancel() { exit 2; }
- yesno()
- {
- [ -z "$1" ] && return 1
- eval value=\$${1}
- case "$value" in
- [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;;
- [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;;
- *) warn "invalid value for \`$1'; falling back to \`no' for now.";;
- esac
- }
- # Source setup-tuxhat configurations.
- if [[ -n "$1" ]]; then
- if [[ -f "$1" ]]
- then
- source "$1"
- else
- error "config file \`$1' does not exist."
- exiterror
- fi
- elif [[ -f "$HOME/.sthrc" ]]; then
- source "$HOME/.sthrc"
- elif [[ -f /etc/sthrc ]]; then
- source /etc/sthrc
- fi
- # Default options.
- dialogrc=${dialogrc:-}
- display=${display:-0}
- [[ -z "${binlist[*]}" ]] && binlist=()
- [[ -z "${namelist[*]}" ]] && namelist=()
- [[ -z "${flaglist[*]}" ]] && flaglist=()
- # If $binlist is not set in cdmrc or by files in /etc/X11/Sessions,
- # try .desktop files in /usr/share/xsessions/ .
- if [[ "${#binlist[@]}" == 0 && -d /usr/share/xsessions ]]; then
- desktopsessions=($(find /usr/share/xsessions/ -regex .\*.desktop))
- #TODO: allow full quoting and expansion according to desktop entry spec:
- # http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables
- for ((count=0; count < ${#desktopsessions[@]}; count++)); do
- # TryExec key is there to determine if executable is present,
- # but as we are going to test the Exec key anyway, we ignore it.
- execkey=$(sed -n -e 's/^Exec=//p' <${desktopsessions[${count}]})
- namekey=$(sed -n -e 's/^Name=//p' <${desktopsessions[${count}]})
- if [[ -n ${execkey} && -n ${namekey} ]]; then
- # The .desktop files allow there Exec keys to use $PATH lookup.
- binitem="$(which $(cut -f 1 -d ' ' <<< ${execkey}))"
- # If which fails to return valid path, skip to next .desktop file.
- if [[ $? != 0 ]]; then continue; fi
- binlist+=("${binitem} $(cut -s -f 2- -d ' ' <<< ${execkey})")
- flaglist+=('X')
- namelist+=("${namekey}")
- fi
- done
- fi
- case "${#binlist[@]}" in
- 0)
- error "No programs found in cdm config file, /etc/X11/Sessions or /usr/share/xsessions."
- exiterror
- ;;
- 1)
- # No need to call dialog AND clear, only one possible program
- binindex=0
- ;;
- *)
- menu=()
- for ((count = 0; count < ${#namelist[@]}; count++)); do
- menu=("${menu[@]}" "$((count+countfrom))" "${namelist[${count}]}")
- done
- binindex=$(
- DIALOGRC="$dialogrc" dialog --colors --stdout \
- --backtitle "$longname v$ver" --ok-label ' Select ' \
- --cancel-label ' Exit ' --menu 'Select Setup Script' 0 0 0 "${menu[@]}"
- )
- if [[ $? != 0 ]]; then
- clear; exitcancel
- fi
- clear
- let binindex-=countfrom
- ;;
- esac
- # Run $bin according to its flag.
- bin=($(eval echo "${binlist[${binindex}]}"))
- case ${flaglist[$binindex]} in
- # *C*onsole programs.
- [Cc])
- # If $bin is a login shell, it might `exec' cdm again, causing an endless
- # loop. To solve this problem, export $CDM_SPAWN when `exec'ing $bin and
- # only let the shell automatically `exec' cdm when $CDM_SPAWN is not set.
- # See also the example shell profile file shipped with the cdm package.
- # Also untrap SIGINT and SIGTSTP before spawning process: If this is not
- # done, any child process of any child (bash) shell will completely
- # ignore SIGINT, which is rather confusing, and cannot be undone.
- trap - SIGINT SIGTSTP
- CDM_SPAWN=$$ exec "${bin[@]}"
- ;;
- esac
- # vim:ts=4:sw=4:et
Advertisement
Add Comment
Please, Sign In to add comment