# This file is part of the src2pkg program: # Copyright 2005-2009 Gilbert Ashley # src2pkg is released under the GNU General Public License Version 2 # a routine has been added at the end of make_description which handles # a couple of last minute items before the actual package is created. make_description() { if [[ $ALLOW_USER_EXTENSIONS = "YES" ]] ; then # check if the user has any pre-execution extensions to this file and run them, if so. [[ -f "$HOME"/.src2pkg/extensions/13.pre ]] && . "$HOME"/.src2pkg/extensions/13.pre fi if [[ "$FAILED" = "" ]] ; then cd "$CWD" ; mkdir -p "$PKG_DIR"/install chmod 755 "$PKG_DIR"/install # look for any of the FILENAMEs in SEARCH_PATHs for FILENAME in $PKG_DESC $PKG_DESC-$NAME $NAME-$PKG_DESC $NAME.$PKG_DESC $NAME-$VERSION-$ARCH.txt $NAME*.txt ; do for SEARCH_PATH in "$CWD" "$PATCHES_DIR"/$NAME-patches "$CWD"/patches "$CWD"/Resources ; do if [[ -f "$SEARCH_PATH"/$FILENAME ]] ; then DESC_FILEPATH="$SEARCH_PATH"/$FILENAME HAVE_DESC_FILEPATH=1 break ; fi done [[ $HAVE_DESC_FILEPATH ]] && break ; done if [[ $HAVE_DESC_FILEPATH ]] ; then nol=$( cat "$DESC_FILEPATH" | grep $NAME: | wc -l ) if [[ $nol -lt 9 ]] || [[ $nol -gt 13 ]] ; then [[ $FILENAME != $NAME*.txt ]] && reject_desc make_default_desc else cat "$DESC_FILEPATH" > "$PKG_DIR"/install/$PKG_DESC chmod 644 "$PKG_DIR"/install/$PKG_DESC if [[ $FILENAME = $NAME.txt ]] ; then echo $BLUE"Created $PKG_DESC from $NAME.txt - "$NORMAL"Inserting in package as PKG_DIR/install/$PKG_DESC " else echo $BLUE"Verified $FILENAME found - "$NORMAL"Inserting in package as PKG_DIR/install/$PKG_DESC" fi fi else make_default_desc fi fi # check if the user has any post-execution extensions to this file and run them, if so. [[ -f "$HOME"/.src2pkg/extensions/13.post ]] && . "$HOME"/.src2pkg/extensions/13.post } # end make_description # Internal function called by make_description make_default_desc() { if [[ "$FAILED" = "" ]] ; then echo -n $BLUE"Creating $PKG_DESC - "$NORMAL mkdir -p "$PKG_DIR"/install cat /dev/null > "$PKG_DIR"/install/$PKG_DESC # Align the text formatting guide starting at ':' (plus one space) namelen=${#NAME} offset=$(( $namelen + 1 )) spaces=0 echo -n '#' >> "$PKG_DIR"/install/$PKG_DESC while [[ $spaces -lt $offset ]] ; do echo -n ' ' >> "$PKG_DIR"/install/$PKG_DESC (( spaces++ )) done #echo "|-------------Use this guide to format your text with--------------|" >> "$PKG_DIR"/install/$PKG_DESC # Ha, watch this! We'll replace that simple line with a fancy bloated routine which lets you define # both the text to use and the line length to wrap to... I know, awk could probably do this with a one-liner :-) header_len=${#HANDY_RULER_TEXT} padding_len=$(( $DESC_WRAP_LENGTH - $header_len )) leading_pad=$(( $padding_len / 2 )) trailing_pad=$(( $padding_len - $leading_pad )) echo -n '|' >> "$PKG_DIR"/install/$PKG_DESC chars=1 while [[ $chars -lt $leading_pad ]] ; do echo -n '-' >> "$PKG_DIR"/install/$PKG_DESC chars=$(( $chars + 1 )) done echo -n $HANDY_RULER_TEXT >> "$PKG_DIR"/install/$PKG_DESC chars=1 while [[ $chars -lt $trailing_pad ]] ; do echo -n '-' >> "$PKG_DIR"/install/$PKG_DESC chars=$(( $chars + 1 )) done echo '|' >> "$PKG_DIR"/install/$PKG_DESC if [[ $AUTO_SCRIPT ]] ; then LICENSE=$(find_license_type) if [[ -n $LICENSE ]] ; then BLURB_9="LICENSE: $LICENSE" fi SPECFILE="" for FILENAME in $NAME.spec $ORIG_NAME.spec $NAME-$VERSION.spec $ORIG_NAME-$VERSION.spec $(basename $SOURCE_NAME .$EXT).spec \ $NAME.spec.in $ORIG_NAME.spec.in $NAME-$VERSION.spec.in $ORIG_NAME-$VERSION.spec.in $(basename $SOURCE_NAME .$EXT).spec.in \ $NAME.lsm $ORIG_NAME.lsm $NAME-$VERSION.lsm $ORIG_NAME-$VERSION.lsm $(basename $SOURCE_NAME .$EXT).lsm \ description-pak debian/control PKG-INFO ; do for SEARCH_PATH in "$PATCHES_DIR"/$NAME-patches "$CWD"/patches \ "$CWD"/Resources "$SRC_DIR" "$CWD" "$PATCHES_DIR" ; do if [[ -f $SEARCH_PATH/$FILENAME ]] ; then SPECFILE="$SEARCH_PATH"/$FILENAME case $SEARCH_PATH in "$PATCHES_DIR/$NAME-patches") SPEC_PATH=PATCHES_DIR/$NAME-patches ;; "$CWD/patches") SPEC_PATH=CWD/patches ;; "$CWD/Resources") SPEC_PATH=CWD/Resources ;; "$SRC_DIR") SPEC_PATH=SRC_DIR ;; "$CWD") SPEC_PATH=CWD ;; "$PATCHES_DIR") SPEC_PATH=PATCHES_DIR ;; esac break ; fi done [[ $SPECFILE != "" ]] && break ; done case $SPECFILE in *.spec|*.spec.in) echo "From text in $SPEC_PATH/$FILENAME" SUMMARY=$(grep -m1 'Summary:' $SPECFILE |cut -f2- -d: |white_out) HOMEPAGE=$(grep -m1 'URL:' $SPECFILE |cut -f2- -d: |white_out) if [[ "x$HOMEPAGE" = "x" ]] ; then HOMEPAGE=$(grep -m1 'Url:' $SPECFILE |cut -f2- -d: |white_out) fi echo "$NAME: $BLURB_1 $SUMMARY" >> "$PKG_DIR"/install/$PKG_DESC echo "$NAME: $BLURB_2" >> "$PKG_DIR"/install/$PKG_DESC cat "$SPECFILE" 2> /dev/null | read_rpm_desc | text_wrapper ;; *description-pak) echo "From text in $SPEC_PATH/$FILENAME" cat "$CWD"/description-pak |tail -n +3 > "$CWD"/$PKG_DESC.tmp echo "$NAME: $BLURB_1" >> "$PKG_DIR"/install/$PKG_DESC echo "$NAME: $BLURB_2" >> "$PKG_DIR"/install/$PKG_DESC read_description-pak ;; *.lsm) echo "From text in $SPEC_PATH/$FILENAME" BLURB_1=$(grep -m1 'Title:' "$SPECFILE" |cut -f2- -d: |white_out) HOMEPAGE=$(grep -m 1 'Primary-site:' $SPECFILE |cut -f2- -d: |white_out) if [[ "x$HOMEPAGE" = "x" ]] ; then HOMEPAGE=$(grep -m 1 'Original-site:' $SPECFILE |cut -f2- -d: |white_out) fi echo "$NAME: $BLURB_1" >> "$PKG_DIR"/install/$PKG_DESC echo "$NAME: $BLURB_2" >> "$PKG_DIR"/install/$PKG_DESC cat "$SPECFILE" 2> /dev/null | read_pkg-info_desc | text_wrapper ;; *PKG-INFO) echo "From text in $SPEC_PATH/$FILENAME" HOMEPAGE=$(grep -m 1 'Home-page:' $SPECFILE |cut -f2- -d: |white_out) BLURB_1=$(grep '-m 1 Summary:' "$SPECFILE" |cut -f2- -d: |white_out) echo "$NAME: $NAME $BLURB_1" >> "$PKG_DIR"/install/$PKG_DESC echo "$NAME: $BLURB_2" >> "$PKG_DIR"/install/$PKG_DESC cat "$SPECFILE" 2> /dev/null | read_pkg-info_desc | text_wrapper ;; *debian/control) echo "From text in $SPEC_PATH/$FILENAME" HOMEPAGE=$(grep -m 1 Homepage: "$SRC_DIR"/debian/control 2> /dev/null |cut -f2- -d: |white_out) if [[ "x$HOMEPAGE" = "x" ]] ; then DLSITE=$(grep -m 1 'It was downloaded from ' "$SRC_DIR"/debian/copyright |white_out) PROTOCOL=$(echo $DLSITE |rev |cut -f2 -d: |cut -f1 -d' ' |rev) DLSITE=$(grep -m 1 "$DLSITE" "$SRC_DIR"/debian/copyright |cut -f2- -d: |white_out) HOMEPAGE="$PROTOCOL:$DLSITE" fi echo "$NAME: $BLURB_1" >> "$PKG_DIR"/install/$PKG_DESC echo "$NAME: $BLURB_2" >> "$PKG_DIR"/install/$PKG_DESC cat "$SPECFILE" 2> /dev/null | read_deb_desc | text_wrapper ;; esac fi if [[ $(wc -l "$PKG_DIR"/install/$PKG_DESC |cut -f1 -d' ') = 1 ]] ; then if [[ "$QUERY_FOR_PKG_DESC" = "YES" ]] ; then echo "From interactive text input:" echo $BLUE"Interactive mode: "$NORMAL echo " Here you can give a description of this package for the $PKG_DESC file." echo " Type in the text as one long line and press ENTER when finished." echo " The text will automatically be formatted for you. Or just press ENTER " echo " to accept the default text: $BLURB_3" echo "" echo -n "> " read BLURB_3 echo "$NAME: $BLURB_1" >> "$PKG_DIR"/install/$PKG_DESC echo "$NAME: $BLURB_2" >> "$PKG_DIR"/install/$PKG_DESC if [[ "$BLURB_3" = "" ]] ; then BLURB_3="No description was given for this package." echo "$NAME: $BLURB_3" >> "$PKG_DIR"/install/$PKG_DESC cat /dev/null | text_wrapper else echo $BLURB_3 | text_wrapper fi else echo "From default text" cat >> "$PKG_DIR"/install/$PKG_DESC << END $NAME: $BLURB_1 $NAME: $BLURB_2 $NAME: $BLURB_3 $NAME: $BLURB_4 $NAME: $BLURB_5 $NAME: $BLURB_6 $NAME: $BLURB_7 $NAME: $BLURB_8 $NAME: $BLURB_9 $NAME: $BLURB_10 END fi fi echo "$NAME: $BLURB_11" >> "$PKG_DIR"/install/$PKG_DESC if [[ $BLURB_12 ]] ; then echo $NAME: ${BLURB_12} >> "$PKG_DIR"/install/$PKG_DESC fi if [[ $BLURB_13 ]] ; then echo $NAME: ${BLURB_13} >> "$PKG_DIR"/install/$PKG_DESC fi if [[ $AUTO_SCRIPT ]] ; then echo $BLUE"Copying $PKG_DESC to:"$NORMAL" CWD/new.$PKG_DESC" cat "$PKG_DIR"/install/$PKG_DESC > "$CWD"/new.$PKG_DESC echo " The file new.$PKG_DESC is a copy of the $PKG_DESC file" echo " inserted in the package. If you want to change the content," echo " edit and save the file as $PKG_DESC and rebuild" echo " Otherwise, it will be re-created when you repeat the build." fi # handle any slack-suggests or slack-conflicts here for FILENAME in $PKG_SUGGESTS $PKG_SUGGESTS-$NAME $NAME-$PKG_SUGGESTS $NAME.$PKG_SUGGESTS ; do for SEARCH_PATH in "$CWD" "$PATCHES_DIR"/$NAME-patches "$CWD"/patches "$CWD"/Resources ; do if [[ -f "$SEARCH_PATH"/$FILENAME ]] ; then echo $BLUE"Found $FILENAME - "$NORMAL"Copying to PKG_DIR/install/$PKG_SUGGESTS" cat "$SEARCH_PATH"/$PKG_SUGGESTS > "$PKG_DIR"/install/$PKG_SUGGESTS fi done done for FILENAME in $PKG_CONFLICTS $PKG_CONFLICTS-$NAME $NAME-$PKG_CONFLICTS $NAME.$PKG_CONFLICTS ; do for SEARCH_PATH in "$CWD" "$PATCHES_DIR"/$NAME-patches "$CWD"/patches "$CWD"/Resources ; do if [[ -f "$SEARCH_PATH"/$FILENAME ]] ; then echo $BLUE"Found $FILENAME - "$NORMAL"Copying to PKG_DIR/install/$PKG_CONFLICTS" cat "$SEARCH_PATH"/$FILENAME > "$PKG_DIR"/install/$PKG_CONFLICTS fi done done fi } reject_desc() { echo $YELLOW"WARNING! "$NORMAL"The supplied $FILENAME is not valid." echo "You need 9-13 lines that begin with '$NAME:' for this package." if ! [[ -e "$SEARCH_PATH"/rej.$PKG_DESC ]] ; then echo "It will be renamed to rej.$PKG_DESC and a new one created." mv "$SEARCH_PATH"/$FILENAME "$SEARCH_PATH"/rej.$PKG_DESC else rm -f "$SEARCH_PATH"/$FILENAME fi } # this function wraps text used in the PKG_DESC file and pads it # with extra lines when needed. text_wrapper() { # The first two lines of the PKG_DESC and the last one are reserved # so we only format 8 lines of text. Lines 12 and 13 can still be used # to add dependencies info.... # DESC_WRAP_LENGTH=70 # DESC_MAX_LINES=11 OUTPUT_LINE_COUNT=2 OUTPUT="" # collect all the input text into one long line while read LINE ; do STRING="$LINE" # replace newlines with a space STRING=${STRING/'\n'/ /} # add the new text to the OUTPUT with a space between # if there are double spaces they get removed below. OUTPUT="$OUTPUT $STRING" shift done PARSESTRING="$OUTPUT" while [[ $PARSESTRING != "" ]] ; do (( OUTPUT_LINE_COUNT++ )) # read the number of chars matching the wrap length CHUNK=${PARSESTRING:0:${DESC_WRAP_LENGTH}} # skip over everything but the last character of the CHUNK OFFSET_LENGTH=$(( $DESC_WRAP_LENGTH -1 )) # if the last character is a space or not null shorten the input line to the previous word if [[ "${CHUNK:$OFFSET_LENGTH:1}" = " " ]] || [[ "${CHUNK:$OFFSET_LENGTH:1}" != "" ]] ; then # keep everything before the last space CHUNK=${CHUNK%$" "*} fi # get the length of the finished chunk CHUNK_LENGTH=${#CHUNK} # advance the pointer the length of the chunk that we saved PARSESTRING=${PARSESTRING:$CHUNK_LENGTH} echo $NAME:"$CHUNK" >> "$PKG_DIR"/install/$PKG_DESC # exit if we have reached the maximum number of lines if [[ $OUTPUT_LINE_COUNT -gt $(( $DESC_MAX_LINES -4 )) ]] ; then break else CHUNK="" fi done # pad the PKG_DESC file to 11 lines if the above didn't reach that number while [[ $OUTPUT_LINE_COUNT -lt $(( $DESC_MAX_LINES -3 )) ]] ; do echo "$NAME:" >> "$PKG_DIR"/install/$PKG_DESC (( OUTPUT_LINE_COUNT++ )) done if [[ -n $LICENSE ]] && [[ $OUTPUT_LINE_COUNT -lt $(( $DESC_MAX_LINES -2 )) ]] ; then echo "$NAME: License: $LICENSE " >> "$PKG_DIR"/install/$PKG_DESC (( OUTPUT_LINE_COUNT++ )) else echo "$NAME: $BLURB_9" >> "$PKG_DIR"/install/$PKG_DESC fi if [[ -n $HOMEPAGE ]] && [[ $OUTPUT_LINE_COUNT -lt $(( $DESC_MAX_LINES -1 )) ]] ; then echo "$NAME: Homepage: $HOMEPAGE " >> "$PKG_DIR"/install/$PKG_DESC (( OUTPUT_LINE_COUNT++ )) else echo "$NAME: $BLURB_10" >> "$PKG_DIR"/install/$PKG_DESC fi } read_rpm_desc() { LINE_COUNT=0 FIRST_LINE=0 LAST_LINE=0 while read LINE ; do (( LINE_COUNT++ )) CHUNK=${LINE/\*/-} if [[ $FIRST_LINE -ne 0 ]] && [[ $LINE_COUNT -eq $FIRST_LINE ]] ; then echo $CHUNK elif [[ ${CHUNK:0:12} = "%description" ]] && [[ $FIRST_LINE -eq 0 ]] ; then FIRST_LINE=$(( $LINE_COUNT + 1 )) elif [[ ${CHUNK:0:1} = "%" ]] || [[ ${CHUNK:0:15} = "%description -l" ]] && [[ $FIRST_LINE -ne 0 ]] ; then LAST_LINE=$(( $LINE_COUNT -1 )) break elif [[ $FIRST_LINE -ne 0 ]] && [[ $LAST_LINE -eq 0 ]] ; then if [[ "$CHUNK" != "" ]] ; then echo $CHUNK fi fi done } read_deb_desc() { LINE_COUNT=0 FIRST_LINE=0 LAST_LINE=0 while read LINE ; do (( LINE_COUNT++ )) CHUNK=${LINE/\*/-} if [[ $FIRST_LINE -ne 0 ]] && [[ $LINE_COUNT -eq $FIRST_LINE ]] ; then echo $CHUNK elif [[ ${CHUNK:0:12} = "Description:" ]] && [[ $FIRST_LINE -eq 0 ]] ; then FIRST_LINE=$(( $LINE_COUNT + 1 )) elif [[ $CHUNK = "" ]] && [[ $FIRST_LINE -ne 0 ]] ; then LAST_LINE=$(( $LINE_COUNT -1 )) break elif [[ $FIRST_LINE -ne 0 ]] && [[ $LAST_LINE -eq 0 ]] ; then if [[ "$CHUNK" != "" ]] ; then echo $CHUNK fi fi done } read_pkg-info_desc() { LINE_COUNT=0 FIRST_LINE=0 LAST_LINE=0 while read LINE ; do (( LINE_COUNT++ )) CHUNK=${LINE/\*/-} if [[ ${CHUNK:0:12} = "Description:" ]] && [[ $FIRST_LINE -eq 0 ]] ; then echo ${CHUNK:12} FIRST_LINE=$(( $LINE_COUNT + 1 )) elif [[ $CHUNK = "" ]] || [[ "$(echo $CHUNK |grep ':')" != "" ]] && [[ $FIRST_LINE -ne 0 ]] ; then LAST_LINE=$(( $LINE_COUNT -1 )) break elif [[ $FIRST_LINE -ne 0 ]] && [[ $LAST_LINE -eq 0 ]] ; then if [[ "$CHUNK" != "" ]] ; then echo $CHUNK fi fi done } read_description-pak() { LINE_COUNT=1 while read LINE ; do if [[ $LINE_COUNT -gt 10 ]] ; then break elif [[ $LINE != "" ]] && [[ $HAVE_BREAK != 1 ]] ; then echo $NAME: $LINE >> "$PKG_DIR"/install/$PKG_DESC (( LINE_COUNT++ )) elif [[ $LINE = "" ]] && [[ $HAVE_BREAK != 1 ]] ; then HAVE_BREAK=1 (( LINE_COUNT++ )) else echo $NAME: $LINE >> "$PKG_DIR"/install/$PKG_DESC (( LINE_COUNT++ )) fi done <"$CWD"/$PKG_DESC.tmp rm -f "$CWD"/$PKG_DESC.tmp while [[ $LINE_COUNT -lt 10 ]] ; do echo "$NAME: " >> "$PKG_DIR"/install/$PKG_DESC (( LINE_COUNT++ )) done } find_license_type() { for FILE in $(find "$DOC_DIR" -name "COPYING*" -o -name "LICENSE*" -o -name "GPL*" -o -name "gpl*" -o -name "LGPL*" -o -name "Artistic*") ; do if [[ $(grep 'GNU GENERAL PUBLIC LICENSE' $FILE) ]] ; then if [[ $(grep 'Version 2, June 1991' $FILE) ]] ; then #[[ $DEBUG ]] && echo "Found LICENSE:$(basename $FILE) type: GPL-2" LICENSE=GPL-2 elif [[ $(grep 'Version 3, 29 June 2007' $FILE) ]] ; then #[[ $DEBUG ]] && echo "Found LICENSE:$(basename $FILE) type: GPL-3" LICENSE=GPL-3 elif [[ $(grep 'Version 1, February 1989' $FILE) ]] ; then #[[ $DEBUG ]] && echo "Found LICENSE:$(basename $FILE) type: GPL-1" LICENSE=GPL-1 fi elif [[ $(grep 'GNU LIBRARY GENERAL PUBLIC LICENSE' $FILE) ]] ; then if [[ $(grep 'Version 2, June 1991' $FILE) ]] ; then #[[ $DEBUG ]] && echo "Found LICENSE:$(basename $FILE) type: LGPL-2" LICENSE=LGPL-2 fi elif [[ $(grep 'GNU LESSER GENERAL PUBLIC LICENSE' $FILE) ]] ; then if [[ $(grep 'Version 2.1, February 1999' $FILE) ]] ; then #[[ $DEBUG ]] && echo "Found LICENSE:$(basename $FILE) type: LGPL-2.1" LICENSE=LGPL-2.1 elif [[ $(grep 'Version 3, 29 June 2007' $FILE) ]] ; then #[[ $DEBUG ]] && echo "Found LICENSE:$(basename $FILE) type: LGPL-3" LICENSE=LGPL-3 fi elif [[ $(grep 'The "Artistic License"' $FILE) ]] ; then #[[ $DEBUG ]] && echo "Found LICENSE:$(basename $FILE) type: Artistic" LICENSE=Artistic fi if [[ -n $LICENSE ]] ; then echo $LICENSE break ; fi done if [[ -z $LICENSE ]] ; then for FILENAME in $NAME.spec $ORIG_NAME.spec $NAME-$VERSION.spec $ORIG_NAME-$VERSION.spec $(basename $SOURCE_NAME .$EXT).spec \ $NAME.spec.in $ORIG_NAME.spec.in $NAME-$VERSION.spec.in $ORIG_NAME-$VERSION.spec.in $(basename $SOURCE_NAME .$EXT).spec.in \ $NAME.lsm $ORIG_NAME.lsm $NAME-$VERSION.lsm $ORIG_NAME-$VERSION.lsm $(basename $SOURCE_NAME .$EXT).lsm \ description-pak debian/control PKG-INFO ; do for SEARCH_PATH in "$PATCHES_DIR"/$NAME-patches "$CWD"/patches \ "$CWD"/Resources "$SRC_DIR" "$CWD" "$PATCHES_DIR" ; do if [[ -f $SEARCH_PATH/$FILENAME ]] ; then SPECFILE="$SEARCH_PATH"/$FILENAME ##### case $SPECFILE in *.spec|*.spec.in) if [[ $(grep 'Copyright:' $SPECFILE) ]] ; then LICENSE=$(grep -m1 'Copyright:' $SPECFILE |cut -f2- -d: |white_out) fi ;; *description-pak) true ;; *.lsm) true ;; *PKG-INFO) true ;; *debian/control) true ;; esac fi done if [[ -n $LICENSE ]] ; then echo $LICENSE break ; fi done fi }