#!/bin/bash # # Written by Dagmar d'Surreal # declare progname="Dropline Slackware Package Description Editor" declare progver="v0.90.0" declare -a DESC declare -a NEWDESC declare flag declare status usage_help() { local status=$1 echo "" echo "$progname $progver" echo "(c)2004 Dropline Gnome" echo "" echo "Usage:" echo " cd \$DLG_ROOT" echo " ./editdesc name-of-package" echo "" exit $status } filetoarray() { local f2a_varname=${1:?'Internal error: filetoarray needs a varname.'} local f2a_filename=${2:?'Internal error: filetoarray needs a filename.'} local limit=${3:-11} local idx local tmp if [ ! -r $f2a_filename ]; then echo "Filename not readable!" exit 1 fi for (( idx = 1 ; idx <= limit ; idx++ )); do eval $f2a_varname[$idx]='`read -r ; echo $REPLY`' done < $f2a_filename } readdesc() { local rd_varname=${1:?'Internal error. readdesc() requires a varname.'} local rd_filename=${2:?'Internal error. readdesc() requires a filename.'} local rd_tmpfile=`mktemp` || exit 1 grep "^$NAME:" $rd_filename | cut -c $(( ${#NAME} + 3 ))- > $rd_tmpfile filetoarray $rd_varname $rd_tmpfile 11 rm $rd_tmpfile } getdescription() { local gd_varname=${1:?'Internal error. getdescription() requires a varname.'} local gd_filename=${2:?'Internal error. getdescription() requires a filename.'} local tmp readdesc $gd_varname $gd_filename # Yes, we are obliterating some information which doesn't comply with the # way Slackware package descriptions are formatted. tmp=`echo "${DESC[1]}" | sed 's/^[^(]*(\(.*\))$/\1/'` #eval $gd_varname[2]=\'`echo "\${DESC[1]}" | sed 's/^.*(\(.*\))$/\1/'`\' #Okay, so I suck at sedding. if [ "$tmp" != "${DESC[1]}" ]; then eval $gd_varname[2]=\'$tmp\' fi #eval $gd_varname[1]=\'`echo "\${DESC[1]}" | cut -d " " -f 1`\' eval $gd_varname[1]=\'`echo "\${DESC[1]}" | sed 's/^\([^(]*\)(.*/\1/'`\' } putdescription() { local pd_varname=${1:?'Internal error. putdescription() requires a varname.'} local pd_filename=${2:?'Internal error. putdescription() requires a filename.'} local whitespace=" " # kludge local ruler="|-----handy-ruler------------------------------------------------------|" local index local tmp cat << XputdescriptionX > $pd_filename # HOW TO EDIT THIS FILE: # The "handy ruler" below makes it easier to edit a package description. Line # up the first '|' above the ':' following the base package name, and the '|' on# the right side marks the last column you can put a character in. You must make # exactly 11 lines for the formatting to be correct. It's also customary to # leave one space after the ':'. XputdescriptionX #tmp=$((${#NAME} - 1)) echo "${whitespace:0:${#NAME}}$ruler" >> $pd_filename for (( index = 1 ; index < 12 ; index++ )); do eval tmp='\${$pd_varname[$index]}' eval echo "$NAME: $tmp" >> $pd_filename done } editdescription() { local status dialog --backtitle "$progname $progver" --no-shadow \ --help-button --extra-button --extra-label "Reset" \ --form "Current description:" 20 77 12 \ "Package Name:" 1 1 "${DESC[1]}" 1 15 57 57 \ "Short Desc:" 2 3 "${DESC[2]}" 2 15 57 57 \ "" 0 0 "${DESC[3]}" 4 1 71 71 \ "" 0 0 "${DESC[4]}" 5 1 71 71 \ "" 0 0 "${DESC[5]}" 6 1 71 71 \ "" 0 0 "${DESC[6]}" 7 1 71 71 \ "" 0 0 "${DESC[7]}" 8 1 71 71 \ "" 0 0 "${DESC[8]}" 9 1 71 71 \ "" 0 0 "${DESC[9]}" 10 1 71 71 \ "" 0 0 "${DESC[10]}" 11 1 71 71 \ "" 0 0 "${DESC[11]}" 12 1 71 71 2>$TMPFILE status=$? if [ $? = 1 ]; then rm $TMPFILE fi return $status } help_pkgdescription() { dialog --backtitle "$progname $progver" --no-shadow \ --msgbox \ "Package Name: This is the name of the binary package, which should be at least loosely related to the name of the source package, preferably matching the first part of the binary package filename. Short Desc: This is the short, one line description that will appear in parenthesis next to the package name itself on the first line of the description file. Although you may enter exceptionally long strings for the first two fields, they are still restricted by the usual line length of 71 characters. If your entries are too long. the editor will refuse to accept them. The remaining fields are for a long (verbose) description of the package with enough plain-English text so the user can understand what the package is supposed to do and/or provide." \ 19 77 } err_oversize() { dialog --backtitle "$progname $progver" --no-shadow \ --title "Error: Fields too long" \ --msgbox \ "The total length of the package name and the short description you entered is too long to fit the description file format." \ 6 70 } renderdescription() { local tmp tmp="${DESC[1]}${DESC[2]:+" ("}${DESC[2]}${DESC[2]:+")"}" if [ ${#tmp} -gt 71 ]; then err_oversize return 1 fi NEWDESC[1]=$tmp NEWDESC[2]="" for (( tmp = 3 ; tmp < 12 ; tmp++ )); do NEWDESC[$tmp]=${DESC[$tmp]} done } approvedescription() { local tmp local index for (( index = 1 ; index < 12 ; index++ )); do tmp="$tmp${tmp:+\n}${NEWDESC[$index]}" done dialog --backtitle "$progname $progver" --no-shadow \ --title "Is this what you want?" \ --yesno \ "$tmp" 15 77 status=$? if [ $status -eq 1 -o $status -eq 255 ]; then return 1 fi } DLG_ROOT=${DLG_ROOT:-`pwd`} if [ ! -r $DLG_ROOT/config ]; then echo "You need to either set DLG_ROOT or be *in* DLG_ROOT when you run this!" exit 1 fi if [ -z "$@" ]; then usage_help exit else NAME=$@ fi . $DLG_ROOT/config if [ ! -z "$DLG_ALPHATESTER" ]; then if [ -d $DLG_ROOT/SCRIPTS-ALPHA/$NAME/ ]; then descfile=$DLG_ROOT/SCRIPTS-ALPHA/$NAME/desc export DLG_ALPHAPACKAGE="yessiree" elif [ -d $DLG_ROOT/SCRIPTS/$NAME/ ]; then descfile=$DLG_ROOT/SCRIPTS/$NAME/desc else echo "" echo "Unable to locate definition of package $NAME." echo "" exit 1 fi elif [ -d $DLG_ROOT/SCRIPTS/$NAME/ ]; then descfile=$DLG_ROOT/SCRIPTS/$NAME/desc else echo "" echo "Unable to locate definition of package $NAME." echo "" exit 1 fi getdescription DESC $descfile declare TMPFILE=`mktemp` || exit 1 until [ "$flag" = "done" ]; do editdescription status=$? filetoarray DESC $TMPFILE if [ $status = 1 -o $status = 255 ]; then echo "Aborted." exit elif [ $status = 2 ]; then help_pkgdescription elif [ $status = 3 ]; then getdescription DESC $descfile elif [ $status = 0 ]; then renderdescription if [ $? = 0 ]; then approvedescription if [ $? = 0 ]; then flag='done' fi fi fi done rm $TMPFILE putdescription NEWDESC $descfile