Crea file slack-desc: differenze tra le versioni
Da Slacky.eu.
(Nuova pagina: =Descrizione= Questo script si occupa di creare i file slack-desc (utilizzati nei pacchetti .tgz) =Script= <pre>#!/bin/bash # COUNT=0 CWD=$(pwd) # Set file name FILE=slack-desc clear...) |
(→Output) |
(7 versioni intermedie di uno stesso utente non sono mostrate) | |
(Nessuna differenza)
|
Versione attuale delle 21:34, 10 nov 2009
Descrizione
Questo script si occupa di creare i file slack-desc (utilizzati nei pacchetti .tgz)
Script
#!/bin/bash # COUNT=0 CWD=$(pwd) # Set file name FILE=slack-desc clear # Check wrong arguments if [ $# != 0 ]; then clear echo "" echo "This script builds for you, a slack-desc file." echo "Run the script without arguments, and answer to the simple questions." echo "Warning, the package's description must be written or pasted in only one row." echo "" exit 1 fi # Check if slack-desc alredy exist in current working directory CWD if [ -e $FILE ]; then while [ $COUNT == 0 ]; do clear echo "slack-desc on $CWD alredy exist! Overwrite?" echo "Type Y/N or Q to quit" read R0 case "$R0" in n | N ) echo "This slack-desc become slack-desc.new" FILE=$FILE.new COUNT=1 ;; y | Y ) rm $CWD/$FILE || exit 2 COUNT=1 ;; q | Q ) echo "Quit" exit 0 ;; * ) clear echo "Please enter only Y, N or Q to quit" sleep 2 esac done fi # Begin questions # First question echo "" echo "Write Package name, and press ENTER" echo "" read R1 # Use only ascii characters: a-z e - o _ # the SPACE will be replaced by -, and TAB removed NAME=$(echo "$R1" | sed -e "s/ /-/g" | sed -e "s/[ \t]//g") # Second question echo "" echo "Write a very short package's description and press ENTER" echo "(ex: Free FTP client)" echo "" read R2 # Third question echo "" echo "Write a package description and press ENTER" echo "(ascii only no fancy character: a-z and - or _)" echo "" read R3 # Fourth question echo "" echo "Write package's homepage and press ENTER" echo "(ex:http://www.example.org)" echo "" read R4 #build slack-desc NUM=0 SPACE=$(echo "$NAME" | sed -e "s/./ /g") RULER="|----handy-ruler----" N_RULER=$(echo -n "$RULER" | wc -m) CHA=$(echo -n "$NAME" | wc -m) # Set the max row for description MAX_ROW=7 # limit the columns COL=$[77-$CHA] if [ $CHA -gt "40" ]; then echo "Name too long, please change it" exit 1 fi while [ $N_RULER -lt $[$COL+1] ]; do LINE=$LINE$(echo -n "-") N_RULER=$[N_RULER+1] done # slack-desk header cat > $FILE <<END # 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 ':'. $SPACE$RULER$LINE| END # limit description for slack-desc ROW=$(echo $R3 | fmt -w $COL | sed -e "s/^/$NAME: &/ " | wc -l) if [ $ROW -ge "$MAX_ROW" ]; then ROW=$MAX_ROW fi MAX=$[$MAX_ROW-$ROW] # Adding package-name and short description to file, (all in one line) echo "$NAME ($R2)" | fmt -w $COL | sed -n -e "1,1s/^/$NAME: &/p " >> $CWD/$FILE # Adding a empty row echo $NAME: >> $CWD/$FILE # Adding the description in max 7 rows echo $R3 | fmt -w $COL | sed -n -e "1,7s/^/$NAME: &/p " >> $CWD/$FILE # Adding a empty row before homepage echo $NAME: >> $CWD/$FILE # Adding homepage echo "$NAME: ($R4)" >> $CWD/$FILE # If the rows are minus than 11, add the remaining (empty) while [ $NUM -lt $MAX ]; do echo "$NAME:" >> $CWD/$FILE NUM=$[NUM+1] done #end exit exit 0
Output
L'output dello script sarà un file slack-desc come da esempio seguente:
# 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 ':'. |----handy-ruler-------------------------------------------------------| esempio: esempio (Breve descrizione) esempio: esempio: Gallia est omnis divisa in partes tres, quarum unam incolunt esempio: Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra esempio: Galli appellantur. Hi omnes lingua, institutis, legibus inter se esempio: differunt. Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et esempio: Sequana dividit. Horum omnium fortissimi sunt Belgae, propterea quod esempio: a cultu atque humanitate provinciae longissime absunt, minimeque esempio: ad eos mercatores saepe commeant atque ea quae ad effeminandos esempio: esempio: (http://www.esempio.org)
- Data 16/03/2009
- Autore Naitso
- Thanks to Marco Pessotto a.k.a. melmothX
- 20091110 little update, thanks to ulisse89