fixed long broken update, now using test for end of file marker in data before writing to actual file

This commit is contained in:
inxi-svn 2011-04-26 19:16:44 +00:00
parent be88d73701
commit 80ff3de839

22
inxi
View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
######################################################################## ########################################################################
#### Script Name: inxi #### Script Name: inxi
#### version: 1.4.83 #### version: 1.4.84
#### Date: April 26 2011 #### Date: April 26 2011
######################################################################## ########################################################################
#### SPECIAL THANKS #### SPECIAL THANKS
@ -1005,6 +1005,12 @@ error_handler()
13) 13)
error_message="The -t option requires the following extra arguments (no spaces between letters/numbers):\nc m cm [required], for example: -t cm8 OR -t cm OR -t c9\n(numbers: 1-20, > 5 throttled to 5 in irc clients) You entered: $2" error_message="The -t option requires the following extra arguments (no spaces between letters/numbers):\nc m cm [required], for example: -t cm8 OR -t cm OR -t c9\n(numbers: 1-20, > 5 throttled to 5 in irc clients) You entered: $2"
;; ;;
14)
error_message="failed to write correctly downloaded $SCRIPT_NAME to location $SCRIPT_HOME.\nThis usually means you don't have permission to write to that location, maybe you need to be root?\nThe operation failed with error: $2"
;;
15)
error_message="failed set execute permissions on $SCRIPT_NAME at location $SCRIPT_HOME.\nThis usually means you don't have permission to set permissions on files there, maybe you need to be root?\nThe operation failed with error: $2"
;;
*) error_message="error unknown: $@" *) error_message="error unknown: $@"
set -- 99 set -- 99
;; ;;
@ -1129,20 +1135,24 @@ create_rotate_logfiles()
script_self_updater() script_self_updater()
{ {
eval $LOGFS eval $LOGFS
local wget_error=0 local wget_error=0 file_contents=''
print_screen_output "Starting $SCRIPT_NAME self updater." print_screen_output "Starting $SCRIPT_NAME self updater."
print_screen_output "Currently running $SCRIPT_NAME version number: $SCRIPT_VERSION_NUMBER" print_screen_output "Currently running $SCRIPT_NAME version number: $SCRIPT_VERSION_NUMBER"
print_screen_output "Updating $SCRIPT_NAME in $SCRIPT_PATH using $2 as download source..." print_screen_output "Updating $SCRIPT_NAME in $SCRIPT_PATH using $2 as download source..."
# first test if path is good, need to make sure it's good because we're -O overwriting file
wget -q --spider $1$SCRIPT_NAME || wget_error=$? file_contents="$( wget -q -O - $1$SCRIPT_NAME )" || wget_error=$?
# then do the actual download # then do the actual download
if [[ $wget_error -eq 0 ]];then if [[ $wget_error -eq 0 ]];then
wget -q -O $SCRIPT_PATH/$SCRIPT_NAME $1$SCRIPT_NAME || wget_error=$? # make sure the whole file got downloaded and is in the variable
if [[ $wget_error -eq 0 ]];then if [[ -n $( grep '###**EOF**###' <<< "$file_contents" ) ]];then
echo "$file_contents" > $SCRIPT_PATH/$SCRIPT_NAME || error_handler 14 "$?"
chmod +x $SCRIPT_PATH/$SCRIPT_NAME || error_handler 15 "$?"
SCRIPT_VERSION_NUMBER=$( grep -im 1 'version:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3}' ) SCRIPT_VERSION_NUMBER=$( grep -im 1 'version:' $SCRIPT_PATH/$SCRIPT_NAME | gawk '{print $3}' )
print_screen_output "Successfully updated to $2 version: $SCRIPT_VERSION_NUMBER" print_screen_output "Successfully updated to $2 version: $SCRIPT_VERSION_NUMBER"
print_screen_output "To run the new version, just start $SCRIPT_NAME again." print_screen_output "To run the new version, just start $SCRIPT_NAME again."
exit 0 exit 0
else
error_handler
fi fi
fi fi
# now run the error handlers on any wget failure # now run the error handlers on any wget failure