#! /bin/bash . /usr/src/m2/framework/bash_functions.sh SOURCE_FILES_DIR=$1 my_exit() { rm -fr "$SOURCE_FILES_DIR/core.tar.gz" &> /dev/null exit "$1" } restart_radius() { report "Restarting Radius" 3 k_centos_version if [ "$centos_version" == "7" ];then systemctl daemon-reload fi /sbin/service radiusd stop > /dev/null 2>&1 /sbin/service safe_radiusd stop > /dev/null 2>&1 sleep 1 killall -9 radiusd &> /dev/null killall -9 safe_radiusd &> /dev/null sleep 1 /sbin/service radiusd start > /dev/null 2>&1 sleep 1 # Giving highest priority to the mysql, because radius is dependant on mysql renice -20 -p "$(pgrep mysqld)" > /dev/null 2>&1 renice -10 -p "$(pgrep radiusd)" > /dev/null 2>&1 if pgrep -x radiusd >/dev/null; then report "Radius is running" 0 else report "Radius is not running, can't continue" 6 my_exit 1 fi } remove_old_module() { if [ -f /usr/local/lib/rlm_m2.so ]; then rm -fr /usr/local/lib/rlm_m2.so fi if [ -f /usr/local/lib/rlm_m2.a ]; then rm -fr /usr/local/lib/rlm_m2.a fi if [ -f /usr/local/lib/rlm_m2.la ]; then rm -fr /usr/local/lib/rlm_m2.la fi } revert_core() { if [ -f /usr/local/lib/rlm_m2.so.backup ]; then report "Reverting Core" 0 remove_old_module cp -f /usr/local/lib/rlm_m2.so.backup /usr/local/lib/rlm_m2.so restart_radius # TODO not nice code-duplication, rework later delay=30 # 15s not enough in some cases k_delay $delay "Checking if Core revert is ok (Waiting for Radius to wake up)" # check if we can determine status CAN_DETECT=$(m2 show status | grep -Po "Core version" | wc -l) if [ "$CAN_DETECT" == "1" ]; then report "Core reverted" 0 chmod 0644 /var/log/radius/radius.log else report "Failed to revert core. Report to Robert/MK" 6 fi else report "Core backup is not present. Can't revert." 1 fi } check_if_core_installed() { delay=30 # 15s not enough in some cases k_delay $delay "Checking if Core is installed (Waiting for Radius to wake up)" # check if we can determine status CAN_DETECT=$(m2 show status | grep -Po "Core version" | wc -l) if [ "$CAN_DETECT" == "1" ]; then report "Core is installed" 0 chmod 0644 /var/log/radius/radius.log local m2corever="" m2corever=$(m2 show status | grep version) report "$m2corever" 0 else report "Can't determine if Core is installed" 1 revert_core fi } continue_without_backup() { report "Backup was not created." 1 read -p "Do you want to proceed? (y/N) " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then report "Installation without backup" 2 else rm -fr "$SOURCE_FILES_PATH" my_exit 1 fi } check_backup() { if [ -f "$1" ]; then report "Backup was created" 3 else continue_without_backup fi } # ---------- MAIN -------------------------------------- k_centos_version if [ "$centos_version" != "6" ]; then # hiredis library for Core to support Redis /usr/src/k_framework/helpers/redis/hiredis_install.sh # Redis for Core /usr/src/k_framework/helpers/redis/redis_install.sh fi if [ ! -f "$SOURCE_FILES_DIR/core.tar.gz" ]; then report "No core files" 1 my_exit 1 fi cd "$SOURCE_FILES_DIR" || report "Failed to enter $SOURCE_FILES_DIR" 1 if ! tar -xzf "$SOURCE_FILES_DIR/core.tar.gz"; then report "Cannot extract core files" 1 my_exit 1 fi cd "$SOURCE_FILES_DIR" || report "Failed to enter $SOURCE_FILES_DIR" 1 rm -f "$SOURCE_FILES_DIR/core.tar.gz" &> /dev/null cd ./* || report "Failed to enter $SOURCE_FILES_DIR" 1 SOURCE_FILES_PATH=$(pwd) report "Making Core backup" 3 if [ -f /usr/local/lib/rlm_m2.so ]; then cp -f /usr/local/lib/rlm_m2.so /usr/local/lib/rlm_m2.so.backup fi check_backup /usr/local/lib/rlm_m2.so.backup remove_old_module install rlm_m2.so /usr/local/lib report "Cleaning..." 3 rm -fr "$SOURCE_FILES_PATH" cd || report "Failed to change dir" 1 restart_radius check_if_core_installed my_exit 0