From ca2253895f8dc823aac74aa915e6840ae25b506d Mon Sep 17 00:00:00 2001 From: Ulrich Dangel Date: Sat, 30 Jan 2010 14:51:46 +0100 Subject: [PATCH] Initial import --- TODO | 1 - debian/changelog | 5 + debian/compat | 1 + debian/control | 37 +++++++ debian/copyright | 42 ++++++++ debian/docs | 0 debian/grml-quickconfig-standard.install | 1 + debian/grml-quickconfig.install | 1 + debian/grml-quickconfig.manpages | 1 + debian/rules | 12 +++ grml-quickconfig | 157 ++++++++++++++++++++++++++++ grml-quickconfig.8 | 173 +++++++++++++++++++++++++++++++ quickconfig/001-heading.sh | 14 +++ quickconfig/005-language.sh | 28 +++++ quickconfig/010-network.sh | 11 ++ quickconfig/015-netcardconfig.sh | 11 ++ quickconfig/020-delim.sh | 10 ++ quickconfig/025-info.sh | 11 ++ quickconfig/030-wm.sh | 89 ++++++++++++++++ quickconfig/035-menu.sh | 15 +++ quickconfig/040-grml2hd.sh | 13 +++ 21 files changed, 632 insertions(+), 1 deletion(-) delete mode 100644 TODO create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/docs create mode 100644 debian/grml-quickconfig-standard.install create mode 100644 debian/grml-quickconfig.install create mode 100644 debian/grml-quickconfig.manpages create mode 100755 debian/rules create mode 100755 grml-quickconfig create mode 100644 grml-quickconfig.8 create mode 100644 quickconfig/001-heading.sh create mode 100644 quickconfig/005-language.sh create mode 100644 quickconfig/010-network.sh create mode 100644 quickconfig/015-netcardconfig.sh create mode 100644 quickconfig/020-delim.sh create mode 100644 quickconfig/025-info.sh create mode 100644 quickconfig/030-wm.sh create mode 100644 quickconfig/035-menu.sh create mode 100644 quickconfig/040-grml2hd.sh diff --git a/TODO b/TODO deleted file mode 100644 index 1333ed7..0000000 --- a/TODO +++ /dev/null @@ -1 +0,0 @@ -TODO diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..975ad71 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +grml-quickconfig (0.1) unstable; urgency=low + + * Initial release. + + -- Ulrich Dangel Sat, 30 Jan 2010 14:24:06 +0100 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +7 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..4f0fc0f --- /dev/null +++ b/debian/control @@ -0,0 +1,37 @@ +Source: grml-quickconfig +Section: utils +Priority: optional +Maintainer: Ulrich Dangel +Build-Depends: debhelper (>= 7) +Standards-Version: 3.8.3 +Homepage: http://git.grml.org/?p=grml-quickconfig.git +Vcs-git: git://git.grml.org/grml-quickconfig.git +Vcs-Browser: http://git.grml.org/?p=grml-quickconfig.git + + +Package: grml-quickconfig +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, zsh | zsh-beta +Suggests: grml-quickconfig-standard +Conflicts: grml-scripts (<= 1.2.1) +Description: Menu framework for quick access of grml menu entries + This is the core package containing only grml-quickconfig itself + without any menu entries. + . + grml-quickconfig is a modularised and flexible way of creating + dynamic menues. + +Package: grml-quickconfig-standard +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, grml-quickconfig +Description: Standard menu entries for grml-quickconfig + This packagae contains the standard grml-quickconfig menu entries. + . + This package contains menu entries for: + * grml-lang + * netcardconfig + * netconfig + * grml-x + * grml2hd + * pdmenu + diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..25d6745 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,42 @@ +This work was packaged for Debian by: + + Ulrich Dangel on Sat, 30 Jan 2010 14:24:06 +0100 + +It was downloaded from: + + http://git.grml.org/?p=grml-quickconfig.git + +Upstream Author: + + Grml Team + +Copyright: + + Copyright (c) 2010+ by the grml team + +License: + + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation. + + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this package; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +On Debian systems, the complete text of the GNU General +Public License version 2 can be found in `/usr/share/common-licenses/GPL-2'. + +The Debian packaging is: + + Copyright (C) 2010 Ulrich Dangel + +you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. diff --git a/debian/docs b/debian/docs new file mode 100644 index 0000000..e69de29 diff --git a/debian/grml-quickconfig-standard.install b/debian/grml-quickconfig-standard.install new file mode 100644 index 0000000..05e1ec9 --- /dev/null +++ b/debian/grml-quickconfig-standard.install @@ -0,0 +1 @@ +quickconfig/* usr/share/grml-quickconfig/ diff --git a/debian/grml-quickconfig.install b/debian/grml-quickconfig.install new file mode 100644 index 0000000..bf23ced --- /dev/null +++ b/debian/grml-quickconfig.install @@ -0,0 +1 @@ +grml-quickconfig usr/sbin diff --git a/debian/grml-quickconfig.manpages b/debian/grml-quickconfig.manpages new file mode 100644 index 0000000..4db791c --- /dev/null +++ b/debian/grml-quickconfig.manpages @@ -0,0 +1 @@ +grml-quickconfig.8 diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..5170237 --- /dev/null +++ b/debian/rules @@ -0,0 +1,12 @@ +#!/usr/bin/make -f +# -*- makefile -*- + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +# This has to be exported to make some magic below work. +export DH_OPTIONS + + +%: + dh $@ diff --git a/grml-quickconfig b/grml-quickconfig new file mode 100755 index 0000000..52a22ac --- /dev/null +++ b/grml-quickconfig @@ -0,0 +1,157 @@ +#!/bin/zsh +# Filename: grml-quickconfig +# Purpose: get fast access to some basic grml-scripts +# Authors: Grml Team +# Bug-Reports: see http://grml.org/bugs/ +# License: This file is licensed under the GPL v2. +################################################################################ + +. /etc/grml/sh-lib +if ! checkbootparam 'nocolor'; then + . /etc/grml_colors +fi + +# variable setup {{{ +# maximum line length +MAXLEN=60 + +# switch between character sets +B="\x0e" +N="\x0f" + +set -A info +set -A keys +typeset -A keymap + +HLINE="$B x $N" +VLINE=$(repeat $MAXLEN echo -n q) +HILIGHT="$GREEN" +HILIGHT_NAME="$MAGENTA" +SCRIPTDIR="/usr/share/grml-quickconfig/" + + +# enable alternate console fonts +echo -n "(B)0" +# }}} + + +# helper functions {{{ +print_line() { + esc=$(printf '\033') + ORIG_LEN=$(echo $(printf '%s' "$1" | sed "s#${esc}\[[0-9;]*m##g" | wc -c)) + echo -n "${BLUE}$HLINE${NORMAL}" + echo -n "$1" + printf "%$[${MAXLEN}-${ORIG_LEN}-2]s${BLUE}${HLINE}${NORMAL}\n" +} + +print_starting_line() { + echo $B ${BLUE}l"$VLINE"k${NORMAL} $N +} + +print_closing_line() { + echo $B ${BLUE}m"$VLINE"j${NORMAL} $N +} + +print_delim() { + echo $B ${BLUE}t"$VLINE"u${NORMAL} $N +} + +hilight_char() { + echo $1 | sed -e "s/$2/$HILIGHT$2$NORMAL/" +} + +print_menu() { + print_starting_line + for x in ${info} ; do + echo $x + done + print_closing_line +} + +run() { + echo Running Command $* + $* + +} + +get_key() { + stty -echo ; read -kq $1?"Press a key: " +} +# }}} + +# check boot parameter {{{ +get_menu_dir() { + local TARGET="$1" + if [ -d "$TARGET" ] ; then + MENUDIR="$TARGET" + elif [ -d "$SCRIPTDIR/$TARGET" ] ; then + MENUDIR="$SCRIPTDIR/$TARGET" + fi +} +BOOT_PARAM=$(getbootparam menu) +if [ -n "$TARGET" ] ; then + get_menu_dir "$BOOT_PARAM" +fi +if [ -n "$1" ] ; then + get_menu_dir "$1" +fi + +if [ -z "$MENUDIR" ] ; then + MENUDIR="$SCRIPTDIR" +fi + +# }}} + +# load modules {{{ +for file in "$MENUDIR"/*.sh ; do + LINE="" + KEY="" + FUNCTION="" + NAME="" + [ ! -e "$file" ] && break + . $file + if display_entry ; then + setopt noglob + if [ -n "$LINE" ] ; then + info+="$(eval $LINE)" + fi + + for k in ${KEY} ; do + keymap[$k]=$FUNCTION + done + keys+=$KEY + setopt glob + fi +done +# }}} + +if [ -z "$info" ] ; then + exit 1 +fi +# mainloop {{{ +while : ; do + echo + print_menu + echo + get_key INPUT + case $INPUT in + [q|Q|$'\n']) + echo + break + ;; + [${(k)keys}]) + eval ${keymap[$INPUT]} + ;; + *) + echo "Unknown key" + echo + ;; + + esac + +done +echo "Happy Hacking" +# }}} + +## END OF FILE ################################################################# +# vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=3 diff --git a/grml-quickconfig.8 b/grml-quickconfig.8 new file mode 100644 index 0000000..35e97b2 --- /dev/null +++ b/grml-quickconfig.8 @@ -0,0 +1,173 @@ +.TH grml-quickconfig 8 +.SH "NAME" +grml-quickconfig \- get fast access to some basic grml-scripts +.SH SYNOPSIS +.B grml-quickconfig [menudir] +.SH DESCRIPTION +This manual page documents briefly the +.B grml-quickconfig +command. +.SH OPTIONS +.TP +.B menudir +Directory to load the menu files from. Menu files have to end in *.sh. + +If menudir is a directory files will be directly loaded from specified directory. +If it is not a directory it will be loaded from +.B /usr/share/grml-quickconfig/MENUDIR/ +(if exists) + +If no option is provided the bootparameter +.B menu +is used as directory +.SH NOTES +grml-quickconfig provides a console based interface to get fast +access to some basic grml-scripts like for example grml-network, +netcardconfig, grml-lang, grml-x and grml2hd. +.SH USAGE EXAMPLES +.TP +.B grml-quickconfig +Invoke the interface. +.TP +.B grml-quickconfig /opt/my_menu/ +Invoke the interface and load all files ending in *.sh +.TP +.B grml-quickconfig network +Test if dir is a directory and load all files edning in *.sh from it. If dir is not a valid directory +.B /usr/share/grml-quickconfig/network/ +is used. +.SH Writing own menu entries +A menu script is a shell script with some necessary informations described in this section. + +.SS API +Following predefined functions are available to write a script displaying a menu entry: +.TP +.B print_line text +Print the text in one line inside the menu. Shell +.TP +.B print_starting_line +Print the first line for a menu +.TP +.B print_closing_line +Print the closing line for a menu +.TP +.B print_delim +Print a delimiter line for a menu +.TP +.B run COMMAND +Print command before executing it +.TP +.B get_key VARIABLE_NAME +Get one key from user +.TP +.B Example + + # get user input + get_key INPUT + [ "$INPUT" == "c" ] && echo "C pressed" + + # print && execute grml-lang de + run grml-lang de + +.SS Predefined Variables +Following variables are predefined and could be used in a menu script: +.TP +.B NORMAL +Switch back to normal color +.TP +.B HILIGHT +Shall be used to hilight the used key for a menu +.TP +.B Example + print_line "Configure ${HILIGHT}n${NORMAL}etwork" +.SS MUST Provide +.TP +.B display_entry +A function named display_entry to determine if this entry shall be displayed. +.LP +.RS +.B Example +.LP +# Always display menu item + display_entry() { return 0 } + +# Only display menu item if specified program is available + display_entry() { + . /etc/grml/script-functions + check4progs PROGRAM >/dev/null + return $? + } + +.RE 1 +.TP +.B LINE +A variable used to determine what shall be done to generate a menu entry. Typically +used in combination with print_line. Only used if display_entry returns 0. +.LP +.RS +.B \ Example + # print Configure network (grml-network) + LINE='print_line "Configure ${HILIGHT}n${NORMAL}etwork (${HILIGHT_NAME}grml-network${NORMAL})"' +.RE 1 +.SS Optional entries +Following variables are optional and can be defined in a script but must not. +.TP +.B FUNCTION +A variable specifing the code which shall be executed if user selects this menu entry. +The variable $INPUT can be used to get the user input. +.RS +.B \ Example + # Print the key from the user + FUNCTION='echo $INPUT' + + # create a submenu + submenu() { ... } + FUNCTION='submenu' +.RE 1 + +.TP +.B KEY, array +An array containig all possible keys for executing the code specified in the FUNCTION variable, e.g: +.RS + # execute code in FUNCTION if c, d or e is pressed. +KEY=(c d e) + +.SS Complete Example + # language module for grml-quickconfig + LINE='print_line "Set keyboard layout (${HILIGHT_NAME}grml-lang${NORMAL}): \\ + ${HILIGHT}d${NORMAL}e ${HILIGHT}a${NORMAL}t ${HILIGHT}c${NORMAL}h e${HILIGHT}s${NORMAL} ${HILIGHT}u${NORMAL}s"' + + typeset -A lang_mapping + + # map keys to language + lang_mapping=( + d de + a at + c ch + s es + u us + ) + + # get all keys from assoc array + KEY=(${(k)lang_mapping}) + + # $INPUT is the user input + FUNCTION='run grml-lang ${lang_mapping[$INPUT]}' + + # always display entry + display_entry() { + return 0 + } + + ## END OF FILE ################################################################# + # vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=3 + + +.SH AUTHOR +Current grml-quickconfig was written by the Grml Team and is based on the +idea of Michael Schierl. + +The originaly grml-quickconfig was written by Michael Schierl . +.PP +This manual page was written by Michael Prokop + for the grml project (but may be used by others). diff --git a/quickconfig/001-heading.sh b/quickconfig/001-heading.sh new file mode 100644 index 0000000..2b9fe82 --- /dev/null +++ b/quickconfig/001-heading.sh @@ -0,0 +1,14 @@ +# grml-quickonfig module +# print the heading +LINE='print_line "Welcome to grml-quickconfig"; +print_line "Press a highlighted key to perform an action, or press"; +print_line "${HILIGHT}Return${NORMAL} or ${HILIGHT}q${NORMAL} to go back to the shell."; +print_delim; +' + +display_entry() { + return 0 +} + +## END OF FILE ################################################################# +# vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=3 diff --git a/quickconfig/005-language.sh b/quickconfig/005-language.sh new file mode 100644 index 0000000..daf21be --- /dev/null +++ b/quickconfig/005-language.sh @@ -0,0 +1,28 @@ +# language module for grml-quickconfig +LINE='print_line "Set keyboard layout (${HILIGHT_NAME}grml-lang${NORMAL}): \ +${HILIGHT}d${NORMAL}e ${HILIGHT}a${NORMAL}t ${HILIGHT}c${NORMAL}h e${HILIGHT}s${NORMAL} ${HILIGHT}u${NORMAL}s"' + +typeset -A lang_mapping + +# map keys to language +lang_mapping=( + d de + a at + c ch + s es + u us +) + +# get all keys from assoc array +KEY=(${(k)lang_mapping}) + +# $INPUT is the user input +FUNCTION='run grml-lang ${lang_mapping[$INPUT]}' + +# always display entry +display_entry() { + return 0 +} + +## END OF FILE ################################################################# +# vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=3 diff --git a/quickconfig/010-network.sh b/quickconfig/010-network.sh new file mode 100644 index 0000000..e1efa25 --- /dev/null +++ b/quickconfig/010-network.sh @@ -0,0 +1,11 @@ +# grml-network module for grml-quickconfig +LINE='print_line "Configure ${HILIGHT}n${NORMAL}etwork (${HILIGHT_NAME}grml-network${NORMAL})"' +KEY=(n) +FUNCTION='run grml-network' + +display_entry() { + return 0 +} + +## END OF FILE ################################################################# +# vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=3 diff --git a/quickconfig/015-netcardconfig.sh b/quickconfig/015-netcardconfig.sh new file mode 100644 index 0000000..2da0ed3 --- /dev/null +++ b/quickconfig/015-netcardconfig.sh @@ -0,0 +1,11 @@ +# netcardconfig module for grml-quickconfig +LINE='print_line "-> Configure ${HILIGHT}e${NORMAL}thernet card directly (${HILIGHT_NAME}netcardconfig${NORMAL})"' +KEY=(n) +FUNCTION='run netcardconfig' + +display_entry() { + return 0 +} + +## END OF FILE ################################################################# +# vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=3 diff --git a/quickconfig/020-delim.sh b/quickconfig/020-delim.sh new file mode 100644 index 0000000..9282b5f --- /dev/null +++ b/quickconfig/020-delim.sh @@ -0,0 +1,10 @@ +LINE='print_delim' +KEY= +FUNCTION='' + +display_entry() { + return 0 +} + +## END OF FILE ################################################################# +# vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=3 diff --git a/quickconfig/025-info.sh b/quickconfig/025-info.sh new file mode 100644 index 0000000..b550bc6 --- /dev/null +++ b/quickconfig/025-info.sh @@ -0,0 +1,11 @@ +# grml-info module for grml-quickconfig +LINE='print_line "Show ${HILIGHT}i${NORMAL}nformation about grml (${HILIGHT_NAME}grml-info${NORMAL})"' +KEY=(i) +FUNCTION="run grml-info" + +display_entry() { + return 0 +} + +## END OF FILE ################################################################# +# vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=3 diff --git a/quickconfig/030-wm.sh b/quickconfig/030-wm.sh new file mode 100644 index 0000000..31bcbf4 --- /dev/null +++ b/quickconfig/030-wm.sh @@ -0,0 +1,89 @@ +# window manager module for grml-quickconfig +LINE='print_line "Start ${HILIGHT}x${NORMAL} (${HILIGHT_NAME}grml-x${NORMAL})"' +KEY=(x) +FUNCTION='wm_menu' + +display_entry() { + return 0 +} + +# variable definition {{{ +typeset -A wms +typeset -A available +set -a output +# }}} + +# window manager definition {{{ +wms[a]=awesome +wms[d]=dwm +wms[e]=evilwm +wms[f]=fluxbox +wms[v]=fvwm +wms[2]=fvwm2 +wms[c]=fvwm-crystal +wms[j]=jwm +wms[o]=openbox +wms[k]=pekwm +wms[r]=ratpoison +wms[t]=twm +wms[9]=w9wm +wms[w]=windowlab +wms[i]=wmii +wms[n]=wm-ng +# }}} + +# deteremine installed window managers {{{ +print_available_wm() { + . /etc/grml/script-functions + line="" + LEN=0 + + for key value in ${(kv)wms} ; do + if check4progs $value >/dev/null ; then + available[$key]=$value + # test if word could be added to current line + if [ $[${(c)#key} + $LEN] -lt $MAXLEN ] ; then + LEN+=${(c)#wm} + line+="$(hilight_char $value $key) " + else + LEN=0 + output+="$line" + fi + fi + done + output+="$line" +} +# }}} + +# heading for wm menu {{{ +wm_heading() { + print_starting_line + print_line "Select a window manager (unsorted list):" + print_line "Press any other key to return to the main menu." + print_delim +} +# }}} + +# print windowm manager loop {{{ +wm_menu() { + echo + wm_heading + for line in $output ; do + print_line $line + done + print_closing_line + + echo + get_key INPUT + case $INPUT in + [${(k)available}]) + run su - grml -c "grml-x ${available[$INPUT]}" + ;; + esac +} +# }}} + +print_available_wm + +## END OF FILE ################################################################# +# vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=3 diff --git a/quickconfig/035-menu.sh b/quickconfig/035-menu.sh new file mode 100644 index 0000000..6e48b23 --- /dev/null +++ b/quickconfig/035-menu.sh @@ -0,0 +1,15 @@ +# application menu module for grml-quickconfig + +LINE='print_line "Show an application ${HILIGHT}m${NORMAL}enu (${HILIGHT_NAME}pdmenu${NORMAL})"' +KEY=(m) +MENU_PROGNAME=pdmenu +FUNCTION="run $MENU_PROGNAME" + +display_entry() { + . /etc/grml/script-functions + check4progs $MENU_PROGNAME >/dev/null + return $? +} + +## END OF FILE ################################################################# +# vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=3 diff --git a/quickconfig/040-grml2hd.sh b/quickconfig/040-grml2hd.sh new file mode 100644 index 0000000..f30deaa --- /dev/null +++ b/quickconfig/040-grml2hd.sh @@ -0,0 +1,13 @@ +LINE='print_line "Install grml to ${HILIGHT}h${NORMAL}ard disk (${HILIGHT_NAME}grml2hd${NORMAL}"' +KEY=(m) +HD_APP=grml2hd +FUNCTION="run $HD_APP" + +display_entry() { + . /etc/grml/script-functions + check4progs $HD_APP >/dev/null + return $? +} + +## END OF FILE ################################################################# +# vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=3 -- 2.1.4