#!/usr/local/ukmclient/bashukm -p UKMTESTMODEFILE="__UKMTESTMODE__" UPDATE_READY_FILE="__UPDATE_READY__" UKMUPDATEMANAGER="ukmupman" UKMUP_SH="ukmup.sh" RC_UKM="rc.ukm" PRE_UPDATE_FILE="preupdate" UPDATE_FILE="update.sh" UPDATE_IN_PROGRESS_FILE="UPDATE_IN_PROGRESS" CONTINUE_UPDATE_FILE="CONTINUE_UPDATE" DBHOST="127.0.0.1" UKM_DIR="/usr/local/ukmclient" # Disable console blank off echo -e "\033[9;0]" . /home/ukmclient/.bash_profile export TERM=linux reset_term() { chvt 2 chvt 1 clear # Restoring system font /sbin/setsysfont } update_ukmcli() { skip_backup_option=$1 LOG_STRING="${LOG_TIME}: Info: ukmstart.sh: starting update" echo "$LOG_STRING" >> $LOG_FILE if [ -f "$UKM_DIR/update/$PRE_UPDATE_FILE" ]; then cd $UKM_DIR/update LOG_STRING="${LOG_TIME}: Info: ukmstart.sh: starting preupdate" echo "$LOG_STRING" >> $LOG_FILE ./$PRE_UPDATE_FILE preupdate_exit_code=$? rm -f "$UKM_DIR/update/$PRE_UPDATE_FILE" cd $UKM_DIR if [ $preupdate_exit_code -eq 0 ]; then LOG_STRING="${LOG_TIME}: Info: ukmstart.sh: preupdate complete" echo "$LOG_STRING" >> $LOG_FILE else LOG_STRING="${LOG_TIME}: Error: ukmstart.sh: preupdate failed" echo "$LOG_STRING" >> $LOG_FILE touch $UPDATE_IN_PROGRESS_FILE continue fi fi if [ ! -f $UKMUPDATEMANAGER ]; then echo "ERROR: $UKMUPDATEMANAGER not found" touch $UPDATE_IN_PROGRESS_FILE LOG_STRING="${LOG_TIME}: Error: ukmstart.sh: $UKMUPDATEMANAGER not found" echo "$LOG_STRING" >> $LOG_FILE continue fi if [ ! -f $UKMUP_SH ]; then echo "ERROR: $UKMUP_SH not found" touch $UPDATE_IN_PROGRESS_FILE LOG_STRING="${LOG_TIME}: Error: ukmstart.sh: $UKMUP_SH not found" echo "$LOG_STRING" >> $LOG_FILE continue fi LOG_STRING="${LOG_TIME}: Info: ukmstart.sh: starting $UKMUP_SH" echo "$LOG_STRING" >> $LOG_FILE ./$UKMUP_SH $skip_backup_option if [ $? -eq 0 ]; then LOG_STRING="${LOG_TIME}: Info: ukmstart.sh: update complete" echo "$LOG_STRING" >> $LOG_FILE else LOG_STRING="${LOG_TIME}: Error: ukmstart.sh: update failed" echo "$LOG_STRING" >> $LOG_FILE fi } while : do reset_term cd $UKM_DIR if [ -f $UKM_DIR/update/$UPDATE_IN_PROGRESS_FILE ]; then if [ -f $UKM_DIR/update/$CONTINUE_UPDATE_FILE ]; then echo "Sleeping for 10 sec to be shure" echo "that MySQL started" sleep 10 LOG_CATEGORY="Info" LOG_FILE_BASE=`date +"%G%m%d"` LOG_FILE="${LOG_FILE_BASE}.log" LOG_TIME=`date +"%H:%M:%S"` LOG_STRING="${LOG_TIME}: ${LOG_CATEGORY}: ukmstart.sh: $CONTINUE_UPDATE_FILE found" echo "$LOG_STRING" >> $LOG_FILE rm -fv $UKM_DIR/update/$UPDATE_IN_PROGRESS_FILE rm -fv $UKM_DIR/update/$CONTINUE_UPDATE_FILE #calling update_ukmcli with the -x option to skip secondary backup update_ukmcli -x else echo echo "$UPDATE_IN_PROGRESS_FILE found" echo "Previous update failed or" echo "still in progress" echo "Press any key" echo read -t 60 continue fi fi # performing autoupdate if [ -f $UKM_DIR/update/$UPDATE_FILE ]; then chmod +x $UKM_DIR/update/$UPDATE_FILE cd $UKM_DIR/update ./$UPDATE_FILE rm -f $UKM_DIR/update/$UPDATE_FILE cd $UKM_DIR fi # Sleep a little to be shure that # MySQL server has been started sleep 1 if [ -f $RC_UKM ]; then . $RC_UKM fi if [ -f $UKMTESTMODEFILE ]; then ./cashmain -l --addr=$DBHOST else if [ -z "$UKMSERVER_PORT" ]; then ./cashmain --addr=$DBHOST else ./cashmain --addr=$DBHOST -p${UKMSERVER_PORT} --log-add=ckeyboardportstandard [C fi fi cashmain_exitcode=$? case "$cashmain_exitcode" in 1|2|3) LOG_CATEGORY="Info" ;; 4|5|8) LOG_CATEGORY="Warning" ;; *) LOG_CATEGORY="Error" ;; esac if [ $cashmain_exitcode -ne 6 ]; then reset_term echo echo "cashmain exit code = $cashmain_exitcode" echo fi LOG_FILE_BASE=`date +"%G%m%d"` LOG_FILE="${LOG_FILE_BASE}.log" LOG_TIME=`date +"%H:%M:%S"` LOG_STRING="${LOG_TIME}: ${LOG_CATEGORY}: ukmstart.sh: cashmain exit code = $cashmain_exitcode" echo "$LOG_STRING" >> $LOG_FILE case "$cashmain_exitcode" in 1) msg="Performing poweroff" echo $msg LOG_STRING="${LOG_TIME}: Info: $msg" echo "$LOG_STRING" >> $LOG_FILE sudo poweroff ;; 2) msg="Reloading cashmain" echo $msg LOG_STRING="${LOG_TIME}: Info: $msg" echo "$LOG_STRING" >> $LOG_FILE continue ;; 3) msg="Rebooting system" LOG_STRING="${LOG_TIME}: Info: $msg" echo "$LOG_STRING" >> $LOG_FILE sudo shutdown -r now ;; 4) msg="Activating test mode" LOG_STRING="${LOG_TIME}: Info: $msg" echo "$LOG_STRING" >> $LOG_FILE ./testmode.sh ;; 5) msg="Activating work mode" LOG_STRING="${LOG_TIME}: Info: $msg" echo "$LOG_STRING" >> $LOG_FILE ./workmode.sh ;; 6) msg="Standard error" LOG_STRING="${LOG_TIME}: Error: $msg" echo "$LOG_STRING" >> $LOG_FILE read -t 60 continue ;; # exit code 7 is reserved 8) # Update is ready update_ukmcli continue ;; *) msg="Unknown error - rebooting system" LOG_STRING="${LOG_TIME}: Warning: $msg" echo "$LOG_STRING" >> $LOG_FILE sudo shutdown -r now esac done