11.04.2013 Views

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Appen<strong>di</strong>ce A. Script aggiuntivi<br />

if [ -z "$1" ]; then # Make sure we get something for wget to eat.<br />

echo "You must at least enter a URL or option!"<br />

echo "-$help for usage."<br />

exit $E_NO_OPTS<br />

fi<br />

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br />

# added added added added added added added added added added added added<br />

if [ ! -e "$Config" ]; then # See if configuration file exists.<br />

echo "Creating configuration file, $Config"<br />

echo "# This is the configuration file for wgetter2" > "$Config"<br />

echo "# Your customised settings will be saved in this file" >> "$Config"<br />

else<br />

source $Config # Import variables we set outside the script.<br />

fi<br />

if [ ! -e "$Cookie_List" ]; then<br />

# Set up a list of cookie files, if there isn’t one.<br />

echo "Hunting for cookies . . ."<br />

find -name cookies.txt >> $Cookie_List # Create the list of cookie files.<br />

fi # Isolate this in its own ’if’ statement,<br />

#+ in case we got interrupted while searching.<br />

if [ -z "$cFlag" ]; then # If we haven’t already done this . . .<br />

echo # Make a nice space after the command prompt.<br />

echo "Looks like you haven’t set up your source of cookies yet."<br />

n=0 # Make sure the counter doesn’t contain random values.<br />

while read; do<br />

Cookies[$n]=$REPLY # Put the cookie files we found into an array.<br />

echo "$n) ${Cookies[$n]}" # Create a menu.<br />

n=$(( n + 1 )) # Increment the counter.<br />

done < $Cookie_List # Feed the read statement.<br />

echo "Enter the number of the cookie file you want to use."<br />

echo "If you won’t be using cookies, just press RETURN."<br />

echo<br />

echo "I won’t be asking this again. E<strong>di</strong>t $Config"<br />

echo "If you decide to change at a later date"<br />

echo "or use the -${cook} option for per session changes."<br />

read<br />

if [ ! -z $REPLY ]; then # User <strong>di</strong>dn’t just press return.<br />

Cookie=" --load-cookies ${Cookies[$REPLY]}"<br />

# Set the variable here as well as in the config file.<br />

echo "Cookie=\" --load-cookies ${Cookies[$REPLY]}\"" >> $Config<br />

fi<br />

echo "cFlag=1" >> $Config # So we know not to ask again.<br />

fi<br />

# end added section end added section end added section end added section end<br />

719

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!