存档2021

jenkins_01_复制备份包脚本.sh

#!/bin/bash
# 运行命令 # nohup java -jar ruoyi-admin.jar > ./nohup.out &
# 打包命令 # mvn package -P druid      jia包会在 target/ruoyi-admin.jar
# jump_guest.pem 私钥 
WORKSPACE="$1"
DATE=`date "+%Y-%m-%d %H:%M:%S"`
Jar='ruoyi-admin.jar'
Dir=/opt/scripts/ssyy99_scripts

echo "当前执行时间为:$DATE"
case $status in
Deploy)
        echo "========= status:$status =========="
        echo "========= 自定义输入version:$version =========="
        echo $PATH
        echo "========= 进入jenkins工作目录前端源码所在文件夹 =========="
        source /etc/profile

        cd $WORKSPACE

########## 用scp命令发动到远程服务器的部署目录下 ##########
        echo "========== 开始上传jar包到测试服务器 =========="
        sudo scp -P 59157 -r -i $Dir/jump_guest.pem $WORKSPACE/ruoyi-admin/target/$Jar jump_guest@192.168.10.1:/home/jump_guest/
        echo "========= 将jar包备份到backup_jar文件夹 =========="

########## 备份在jenkins的工作目录下的backup_app文件夹下,方便之后回滚 ##########
########## $BUILD_NUMBER 为构建id,初始为1 每一次构建递增1 可用于回滚 ##########
########## $WORKSPACE 为项目工作目录 实际为jenkins安装目录+项目名字 ##########
########## $JENKINS_HOME 为jenkins安装目录 在此为 /var/lib/jenkins ##########
        \cp $WORKSPACE/ruoyi-admin/target/$Jar  $JENKINS_HOME/workspace/backup_jar/"$Jar".$BUILD_NUMBER
        sudo find $JENKINS_HOME/workspace/backup_jar/ -type f -mtime +30 -exec rm -f  {} \;

    echo "deploy done!"
    ;;

Rollback)
        backup_path="${JENKINS_HOME}/workspace/backup_jar/"
        echo "======status:$status========"
        echo "======build_id:$version======="
        cd $backup_path
        ls
        echo "==============正在回滚 $Jar.$version 包 发送到远程测试服务器==================="
        sudo scp -P 59157 -r -i $Dir/jump_guest.pem "$Jar".$version  jump_guest@192.168.10.1:/home/jump_guest/$Jar

    echo "roll_back done!"
    ;;
*)
esac

authentication_答题认证.sh

#!/bin/bash
# 主要功能加入 验证 答题环节 bb - ff 为答题环节
# 次要功能为 替换 替换模板 主要在 aa 里面实现
while :
do
        echo -ne "\e[1;34m请输入模板的网址: \e[0m"
        read TEMPLATE
        if [ -z $TEMPLATE &> /dev/null ];then
                sleep 0.5
                echo -e "\e[1;31m输入的模板为空... ...请重新输入\e[0m"
        else
                #true
                break
        fi
done
web_dir=/www/wwwroot
while :
do
        echo
        echo -e "\e[1;35m您的网页目录为 $web_dir \e[0m"
        echo
	sleep 1
        echo -e "\e[1;35m请核对路径信息 如果网址路径相符合则不用修改\e[0m"
        echo
	sleep 1
        echo -ne "\e[1;36m直接回车不修改,输入 yes 修改路径 请输出:  \e[0m"
        read message
        echo
        if [ -z $message &> /dev/null ];then
                break;
        else
                echo -ne "\e[1;36m请输入您的网页目录: \e[0m"
                read web_dir
                echo
                echo -e "\e[1;34m您更改的 网页目录为 $web_dir\e[0m"
                echo
                break;
        fi
done

ip=`curl -s ip.sb`
dir=$web_dir/$TEMPLATE
apache_conf=/www/server/panel/vhost/apache
DATE=$(date +"%Y%m%d%s")
dujitang=https://api.btstu.cn/yan/api.php?charset=utf-8
n=1
j=30

function aa {
	#read -p '请输入模板的网址: ' TEMPLATE
	if [ -d $dir &> /dev/null ];then
		echo -e "\e[1;35m模板检测通过... ...\e[0m"
	else
		echo -e "\e[1;31m模板不存在... 请您先创建模板\e[0m"
		exit 1
	fi

	if [ -f $apache_conf/$TEMPLATE.conf ];then
		echo -e "\e[1;35m配置文件检测通过... ...\e[0m"
	else
		echo -e "\e[1;31m模板配置文件出错... 请您检查配置... ...\e[0m"
		exit 1
	fi
		echo -e "\e[1;35m正在部署新的模板... ...\e[0m"
	chattr -i /data/$TEMPLATE/.user.ini &> /dev/null
	mkdir -p /data/bak
	mv /data/$TEMPLATE /data/bak/$TEMPLATE_$DATE &> /dev/null
	mv /data/$TEMPLATE.conf /data/bak/$TEMPLATE_$DATE &> /dev/null
	cp -a $dir /data/ 
	cp -a $apache_conf/$TEMPLATE.conf /data/
	chattr -i $TEMPLATE/.user.ini &> /dev/null
	sed -i "s@^TEMPLATE=.*@TEMPLATE=$TEMPLATE@" /data/create_apache.sh
	echo -e "\e[1;35m新的模板部署完成... ...\e[0m"
	exit 0
}

function bb {

	while :
	do
		echo -e "\e[1;33m已经检测到此服务器不是我对象的服务器 现开启验证模式... ...\e[0m"
		sleep 1
		echo -e "\e[1;33m已经检测到此服务器不是我对象的服务器 现开启验证模式... ...\e[0m"
		sleep 1
		echo -e "\e[1;33m已经检测到此服务器不是我对象的服务器 现开启验证模式... ...\e[0m"
		echo
		sleep 5
		echo -en "\e[1;32m您是我的对象吗? 是/不是   \e[0m"
		read ans_1
		if [ -z $ans_1 &> /dev/null ];then
       			echo -e "\e[1;31m瞎啊...'是' 或 '不是' 看不到吗\e[0m"
			sleep 1
			echo
		fi

		if [ "$ans_1" == "是" -o "$ans_1" == "是的" -o "$ans_1" == "yes" -o "$ans_1" == "YES"&> /dev/null ];then
       			echo -e "\e[1;31m真的吗?... \e[0m"
			sleep 2
			echo
			cc	
		elif [ "$ans_1" == "不是" -o "$ans_1" == "no" -o "$ans_1" == "不是的" -o "$ans_1" == "NO"&> /dev/null ];then
       			echo -e "\e[1;31m有缘再见... \e[0m"
			echo
			exit 3
		else
       			echo -e "\e[1;31m瞎啊...'是' 或 '不是' 看不到吗\e[0m"
			sleep 1
			echo
		fi

	done
	

}

function cc {

	while :
	do
		echo -en "\e[1;32m我对象叫什么名字?   \e[0m"
		read ans_2
		if [ -z $ans_2 &> /dev/null ];then
       			echo -e "\e[1;31m什么都没输入呀... ... \e[0m"
			sleep 1
			echo
			continue
		fi

		if [ "$ans_2" == "hazel" -o "$ans_2" == "HAZEL" -o "$ans_2" == "黑柔" -o "$ans_2" == "小鱼" &> /dev/null ];then
       			echo -e "\e[1;31m嗯... 您有可能是我对象... \e[0m"
			echo
			sleep 1
			dd
		else
       			echo -e "\e[1;31m回答错误... 在给您一次机会\e[0m"
			sleep 1
			let cc1++
			echo
		fi

		if [ $cc1 -eq 5 ];then
       			echo -en "\e[1;36m看样您是真不知道了... 是否直接进入答题模式 是/否  \e[0m"
			sleep 1
			read ans_cc1
			if [ "$ans_cc1" == "是" -o "$ans_cc1" == "是的" -o "$ans_cc1" == "yes" -o "$ans_cc1" == "YES"&> /dev/null ];then
				sleep 1
				gg
			elif [ "$ans_cc1" == "不是" -o "$ans_cc1" == "no" -o "$ans_cc1" == "不是的" -o "$ans_cc1" == "NO"&> /dev/null ];then
				continue
			fi
		fi
	done
}	

function dd {

	while :
	do
		echo -en "\e[1;32m我对象漂亮吗?   \e[0m"
		read ans_3
		if [ -z $ans_3 &> /dev/null ];then
       			echo -e "\e[1;31m什么都没输入呀... ... \e[0m"
			sleep 1
			echo
			continue
		fi

		if [ "$ans_3" == "漂亮" -o "$ans_3" == "好看" -o "$ans_3" == "美丽" -o "$ans_3" == "beautiful" &> /dev/null ];then
       			echo -e "\e[1;31m嗯... 您眼光很好... \e[0m"
			echo
			sleep 1
			ee
		else
       			echo -e "\e[1;31m在说一次... ...\e[0m"
			sleep 1
			echo
		fi

	done
}	

function ee {

	while :
	do
		echo -en "\e[1;32m我对象小名是什么?   \e[0m"
		read ans_4
		if [ -z $ans_4 &> /dev/null ];then
       			echo -e "\e[1;31m什么都没输入呀... ... \e[0m"
			echo
			sleep 1
			continue
		fi

		if [ "$ans_4" == "小鱼" &> /dev/null ];then
       			echo -e "\e[1;31m哇... 小名您都知道... \e[0m"
			echo
			sleep 1
			ff
		else
       			echo -e "\e[1;31m回答错误... 在给您一次机会\e[0m"
			echo
			sleep 1
			let ee1++
		fi

		if [ $ee1 -eq 5 ];then
       			echo -en "\e[1;36m看样您是真不知道了... 是否直接进入答题模式 是/否  \e[0m"
			sleep 1
			read ans_ee1
			if [ "$ans_ee1" == "是" -o "$ans_ee1" == "是的" -o "$ans_ee1" == "yes" -o "$ans_ee1" == "YES"&> /dev/null ];then
				sleep 1
				gg
			elif [ "$ans_ee1" == "不是" -o "$ans_ee1" == "no" -o "$ans_ee1" == "不是的" -o "$ans_ee1" == "NO"&> /dev/null ];then
				continue
			fi
		fi

	done
}	

function ff {

	while :
	do
		echo -en "\e[1;32m愿意当我女朋友吗?   \e[0m"
		read ans_5
		if [ -z $ans_5 &> /dev/null ];then
       			echo -e "\e[1;31m什么都没输入呀... ... \e[0m"
			echo
			sleep 1
			continue
		fi

		if [ "$ans_5" == "愿意" -o "$ans_5" == "我愿意" -o "$ans_5" == "yes" -o "$ans_5" == "YES" &> /dev/null ];then
       			echo -e "\e[1;31m真的吗?... 考验您一下吧... \e[0m"
			echo
			sleep 1
			gg
		elif [ "$ans_5" == "不" -o "$ans_5" == "no" -o "$ans_5" == "不愿意" -o "$ans_5" == "NO"&> /dev/null ];then
       			echo -e "\e[1;31m伤心了... .... 在给您一次机会好好说话\e[0m"
			echo
			sleep 1
		else
       			echo -e "\e[1;31m在给您一次机会... \e[0m"
			echo
			sleep 1
		fi

	done
}	

function gg {
	while [ $n -le 101 ]
	do
		sum1=`echo $RANDOM|cksum |cut -c 1-2`
		sum2=`echo $RANDOM|cksum |cut -c 1-2`
       		echo -ne "\e[1;32m $sum1 + $sum2 =  \e[0m"
		read ans_6
		sum=`echo $(($sum1+$sum2))`
		if echo $ans_6 | grep -q '[^0-9]' &> /dev/null ;then
       			echo -e "\e[1;31m能不能好好玩耍了... ...从新回答第 $n 题 \e[0m"
			continue
		fi

		if [ -z $ans_6 &> /dev/null ];then
       			echo -e "\e[1;31m什么都没输入呀...重新回答第 $n 题 \e[0m"
			sleep 1
			continue
		fi


		if [ $ans_6 == $sum ];then
       			echo -e "\e[1;31m您太聪明了... 这么难的都能答对... 完成 第 $n 题\e[0m"
			duji=$(curl -s $dujitang)
			echo -e "\e[1;36m$duji\e[0m"
			let n++
		else
       			echo -e "\e[1;31m回答错误 好好算算 第 $n 题\e[0m"
		fi

		if [ $n -eq 11 ];then
       			echo -e "\e[1;35m您是个能成就大事的人... ... 居然对了这么多道题目\e[0m"
			sleep 1
		fi

		if [ $n -eq 21 ];then
       			echo -e "\e[1;35m服务器已不能为您这高等智商的生物服务... 已开启 自毁模式 倒计时30秒 删除所有数据库...\e[0m"
			sleep 5
			while [ $j -gt 0 ]
			do
				echo -e "\e[1;36m$j\e[0m"
				let j--
				sleep 1
			done
       			echo -e "\e[1;35m一看您就是经历过风浪的人...遇事不慌...处事不惊...终究会成为人上之人...继续答题吧!!!\e[0m"
			
		fi
		
		if [ $n -ge 31 ];then
       			echo -e "\e[1;35m这样吧... 20210408 ...牢记这串数字对您会有帮助 \e[0m"
			sleep 1
		fi

		if [ $n -ge 41 ];then
       			echo -e "\e[1;35m因为这串数字是我对象第一次跟我说话的日子... \e[0m"
			sleep 1
		fi

		if [ $n -ge 41 ];then
       			echo -e "\e[1;35m人才 ... 祝您生活愉快...\e[0m"
			sleep 1
		fi

		if [ $n -ge 51 ];then
       			echo -e "\e[1;35m您有一颗成佛之心...上天也不会亏待您的... ...\e[0m"
			echo
			sleep 5
       			echo -e "\e[1;35m下次在使用直接执行命令 sh change.sh 20210408 或 sh change.sh hazel 即可跳过所有游戏项目... ...\e[0m"
			sleep 5
			aa
		fi

	done

}

if [ -z $1 ];then
	
	true	
else
	if [ "$1" == "20210408" -o "$1" == "hazel" -o "$1" == "HAZEL" ];then
		aa
	fi
	
fi

if [ "$ip" == "45.199.93.38" ];then
	aa
else
	bb
fi