Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
128 lines (114 sloc) 4.79 KB
#!/bin/bash
# #
# This code is written for Lunar Linux, see #
# http://lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/recovery #
# includes rebuild_status_files, replace_status_file, #
# check_status_files #
# 20020528 #
# #
############################################################
# #
# Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
# function : rebuild_status_files
# usage : rebuild_status_files
# purpose : rebuild the accidentally deleted status files
rebuild_status_files() {
debug_msg "rebuild_status_files ($@)"
if ! query \
"Do you want to re-construct the status files from install logs?" y; then
message "${PROBLEM_COLOR}Unable to continue without status files" \
"${DEFAULT_COLOR}"
exit 1
fi
if ! [ -d "$INSTALL_LOGS" ]; then
message "${PROBLEM_COLOR}Unable to continue without install logs " \
"${DEFAULT_COLOR}"
exit 1
fi
message "${MESSAGE_COLOR}Re-creating status files." \
"${DEFAULT_COLOR}"
LOG_FILES=$(ls -rt $INSTALL_LOGS)
for MODULE_NAME in $LOG_FILES; do
COUNTS=3
REAL_NAME=$MODULE_NAME
unset SECTION
while [ "$COUNTS" -gt "0" ]; do
REAL_NAME=$(echo $REAL_NAME | cut -d "-" -f -"$COUNTS")
SECTION=$(find_section $REAL_NAME)
if [ -n "$SECTION" ]; then
((COUNTS++))
VERSION=$(echo $MODULE_NAME | cut -d "-" -f "$COUNTS"-)
SIZE=$(find_module_size $REAL_NAME $VERSION)
DATE=$(ls -l $INSTALL_LOGS/$REAL_NAME-$VERSION --time-style=+%Y%m%d | awk '{print $6}')
remove_module "$REAL_NAME" &&
# adjusted add_module code that echos the DATE field ;^)
lock_file $MODULE_STATUS &&
lock_file $MODULE_STATUS_BACKUP &&
echo "$REAL_NAME:$DATE:installed:$VERSION:$SIZE" >>$MODULE_STATUS &&
cat "$MODULE_STATUS" >$MODULE_STATUS_BACKUP &&
unlock_file $MODULE_STATUS_BACKUP &&
unlock_file $MODULE_STATUS &&
message "Added: $REAL_NAME-$VERSION ($SIZE) ($DATE)"
break
fi
((COUNTS--))
done
done
message "${MESSAGE_COLOR}Success!!${DEFAULT_COLOR}\n"
}
# function : replace_status_file
# usage : replace_status_file
# purpose : cp $MODULE_STATUS_BACKUP $MODULE_STATUS via query
replace_status_file() {
debug_msg "replace_status_file ($@)"
if ! [ -f "$MODULE_STATUS_BACKUP" ]; then rebuild_status_files; return; fi
message "${PROBLEM_COLOR}Unable to find MODULE_STATUS file" \
"${MODULE_COLOR}$MODULE_STATUS" \
"${DEFAULT_COLOR}"
if query "Do you want to use the backup?" y; then
if ! [ -f "$MODULE_STATUS_BACKUP" ]; then rebuild_status_files; fi
if `cp $MODULE_STATUS_BACKUP $MODULE_STATUS`; then
message "${MESSAGE_COLOR}Success!!" \
"${DEFAULT_COLOR}"
else
message "${PROBLEM_COLOR}Unsuccessful :=( No more operation!!" \
"${DEFAULT_COLOR}"
exit 1
fi
else
message "${PROBLEM_COLOR}Unable to continue without that :=("\
"No more operation!!" \
"${DEFAULT_COLOR}"
exit 1
fi
}
# function : check_status_files
# usage : check_status_files
# purpose : checks the avail of MODULE_STATUS and MODULE_STATUS_BACKUP files
check_status_files() {
debug_msg "check_status_files ($@)"
if ! [ -f "$MODULE_STATUS" ]; then replace_status_file; fi
if ! [ -f "$MODULE_STATUS" ]; then echo "Unknown error!!!"; exit; fi
if ! [ -f "$MODULE_STATUS_BACKUP" ]; then
message "${PROBLEM_COLOR}Unable to find MODULE_STATUS_BACKUP file" \
"${MODULE_COLOR}$MODULE_STATUS_BACKUP" \
"${DEFAULT_COLOR}"
if `cp $MODULE_STATUS $MODULE_STATUS_BACKUP`; then
message "${MESSAGE_COLOR}MODULE_STATUS is successfully copied" \
"to MODULE_STATUS_BACKUP" \
"${DEFAULT_COLOR}"
else
message "${PROBLEM_COLOR}Unsuccessful while copying" \
"MODULE_STATUS to MODULE_STATUS_BACKUP :=( " \
"No more operation!!" \
"${DEFAULT_COLOR}"
exit 1
fi
fi
}
Something went wrong with that request. Please try again.