[init] initial commit
This commit is contained in:
37
update/backups.sh
Normal file
37
update/backups.sh
Normal file
@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "========================================================================="
|
||||
echo Start Time: `date`
|
||||
set -x
|
||||
|
||||
cp -rf /var/spool/cron/crontabs/ /opt/configs/
|
||||
cp -rf /usr/local/nginx/conf/nginx.conf /opt/configs/nginx/nginx.conf
|
||||
cp -rf /usr/local/nginx/conf/domain_confs/ /opt/configs/nginx/
|
||||
cp -rf /etc/docker/daemon.json /opt/configs/conf/
|
||||
cp -rf /etc/sysctl.conf /opt/configs/conf/
|
||||
cp -rf /etc/pip.conf /opt/configs/conf/
|
||||
cp -rf /etc/apt/sources.list /opt/configs/conf/
|
||||
cp -rf /root/.acme.sh/*ecc /opt/configs/acme/
|
||||
|
||||
cd /opt && t=`date +%Y%m%dT%H%M%S`
|
||||
rsync -av apps configs logs scripts websites wd/72-Backups/CrossChain/VPS/ > /opt/logs/rsync/rsync_${t}.log
|
||||
cd /opt/logs/rsync/
|
||||
let count=`ls | wc -l`
|
||||
if [[ $count -gt 10 ]]; then
|
||||
rsync_logs=()
|
||||
for((i=1;i<=$count;i++)); do
|
||||
rsync_logs[$i]=`ls | sort -r | head -n $i | tail -1`
|
||||
done
|
||||
|
||||
for i in `seq 11 $count`; do
|
||||
rm -rf ${rsync_logs[$i]}
|
||||
done
|
||||
fi
|
||||
|
||||
# tar -I pixz -cf $backup_dir/vps-${t}.tar.xz -C /opt configs data logs scripts source-code websites > /dev/null 2>&1
|
||||
set +x
|
||||
echo End Time: `date`
|
||||
echo "========================================================================="
|
||||
echo
|
||||
echo
|
||||
|
17
update/calibre.sh
Normal file
17
update/calibre.sh
Normal file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
# get the pid of calibre, and write it into file /tmp/calibre_pids
|
||||
ps -ef | grep '/opt/apps/calibre/venv/bin/cps' | grep -v grep | awk '{print $2}' > /tmp/calibre_pids
|
||||
|
||||
# if not exist, signifying that there is no calibre process
|
||||
if [[ ! -s /tmp/calibre_pids ]]; then
|
||||
echo -e "\e[1;31mCannot terminate Calibre process cause there is no such things, will run calibre later automatically.\e[0m"
|
||||
else
|
||||
for calibre_pid in `cat /tmp/calibre_pids`; do
|
||||
kill -9 $calibre_pid > /dev/null 2>&1
|
||||
done
|
||||
fi
|
||||
|
||||
nohup /opt/apps/calibre/venv/bin/python /opt/apps/calibre/venv/bin/cps > /dev/null 2>&1 &
|
||||
echo -e "\e[1;32mCalibre process started successfully\e[0m"
|
||||
|
64
update/dash_rand_logo.sh
Normal file
64
update/dash_rand_logo.sh
Normal file
@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 设置图片数量和输出文件名
|
||||
IMAGE_NUM_ALL=`ls /opt/apps/localcr/A_dashboard/local/icons | wc -l`
|
||||
IMAGE_NUM_NEEDED=`cat /root/services.yaml | grep -E '[0-9]{1,3}.jpg' | wc -l`
|
||||
if [[ $IMAGE_NUM_NEEDED -gt $IMAGE_NUM_ALL ]]; then
|
||||
alarm='Dashboard:\nThere is NOT enough logos to use, please check ASAP.'
|
||||
bash /opt/scripts/alert/sendmsg.sh "$alarm"
|
||||
exit 233
|
||||
fi
|
||||
|
||||
# 初始化数组
|
||||
declare -a arr=()
|
||||
|
||||
# 随机选择图片名,不重复
|
||||
for ((i=0; i<$IMAGE_NUM_NEEDED; i++)); do
|
||||
while true; do
|
||||
# 随机生成图片名
|
||||
RAND=$((RANDOM%IMAGE_NUM_ALL))
|
||||
IMG_NAME=$RAND.jpg
|
||||
|
||||
# 判断图片名是否已经被选择过
|
||||
chosen=0
|
||||
for num in "${arr[@]}"; do
|
||||
if [ "$num" == "$IMG_NAME" ]; then
|
||||
chosen=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# 如果图片名未被选择过,则将其添加到数组中
|
||||
if [ "$chosen" -eq 0 ]; then
|
||||
arr=(${arr[@]} $IMG_NAME)
|
||||
break
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
# 需要修改的文件的路径和名称
|
||||
filename_origin="/opt/apps/localcr/A_dashboard/local/config/services.yaml"
|
||||
filename_copy="/opt/apps/localcr/A_dashboard/local/config/services_copy.yaml"
|
||||
# filename_origin="/root/services.yaml"
|
||||
# filename_copy="/root/services_copy.yaml"
|
||||
cp $filename_origin $filename_copy
|
||||
|
||||
# 循环处理所有符合指定模式的行
|
||||
let count=0
|
||||
lineno=1
|
||||
while read line; do
|
||||
# 获取文件名和路径
|
||||
oldname=$(echo $line | grep -Eo '[0-9]{1,3}.jpg')
|
||||
|
||||
if [[ $oldname != '' ]]; then
|
||||
newname=${arr[$count]}
|
||||
# 替换文件名
|
||||
sed -i "${lineno}s/\/$oldname/\/$newname/" $filename_origin
|
||||
let count=count+1
|
||||
fi
|
||||
let lineno=lineno+1
|
||||
done < $filename_copy
|
||||
|
||||
rm $filename_copy
|
||||
|
||||
|
38
update/jekyll_content_update.sh
Normal file
38
update/jekyll_content_update.sh
Normal file
@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
function bash_update() {
|
||||
echo $directory$filename $action
|
||||
rm -rf /opt/websites/just-the-docs/bash
|
||||
jekyll b -s /opt/apps/document/bash -d /opt/websites/just-the-docs/bash
|
||||
}
|
||||
|
||||
function python_update() {
|
||||
echo $directory$filename $action
|
||||
rm -rf /opt/websites/just-the-docs/python
|
||||
jekyll b -s /opt/apps/document/python -d /opt/websites/just-the-docs/python
|
||||
}
|
||||
|
||||
|
||||
function blog_update() {
|
||||
echo $directory$filename $action
|
||||
rm -rf /opt/websites/blog
|
||||
jekyll b -s /opt/apps/blog/ -d /opt/websites/blog/
|
||||
echo -e '\n'
|
||||
}
|
||||
|
||||
|
||||
echo -e '\n\n==================================================================' >> /opt/logs/jekyll_update.log
|
||||
date >> /opt/logs/jekyll_update.log
|
||||
if [[ $1 == 'blog' ]]; then
|
||||
blog_update >> /opt/logs/jekyll_update.log
|
||||
elif [[ $1 == 'python' ]]; then
|
||||
python_update >> /opt/logs/jekyll_update.log
|
||||
elif [[ $1 == 'bash' ]]; then
|
||||
bash_update >> /opt/logs/jekyll_update.log
|
||||
else
|
||||
echo Wrong >> /opt/logs/jekyll_update.log
|
||||
exit 2
|
||||
fi
|
||||
|
||||
|
||||
|
12
update/jekyll_update.sh
Normal file
12
update/jekyll_update.sh
Normal file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
inotify-hookable \
|
||||
--watch-directories /opt/apps/blog \
|
||||
--watch-directories /opt/apps/document/python \
|
||||
--watch-directories /opt/apps/document/bash \
|
||||
--ignore-paths /opt/apps/blog/.git/ \
|
||||
--ignore-paths /opt/apps/blog/img/avatar.jpg \
|
||||
--on-modify-path-command "(^/opt/apps/blog/.*)=(bash /opt/scripts/update/jekyll_content_update.sh blog)" \
|
||||
--on-modify-path-command "(^/opt/apps/document/python/.*)=(bash /opt/scripts/update/jekyll_content_update.sh python)" \
|
||||
--on-modify-path-command "(^/opt/apps/document/bash/.*)=(bash /opt/scripts/update/jekyll_content_update.sh 'bash')"
|
||||
|
62
update/nav_rand_logo.sh
Normal file
62
update/nav_rand_logo.sh
Normal file
@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 设置图片数量和输出文件名
|
||||
IMAGE_NUM_ALL=`ls /opt/websites/nav/assets/images/logos | wc -l`
|
||||
IMAGE_NUM_NEEDED=`cat /opt/websites/nav/index.html | grep -E '[0-9]{1,3}.jpg' | wc -l`
|
||||
if [[ $IMAGE_NUM_NEEDED -gt $IMAGE_NUM_ALL ]]; then
|
||||
alarm='Navigation:\nThere is NOT enough logos to use, please check ASAP.'
|
||||
bash /opt/scripts/alert/sendmsg.sh "$alarm"
|
||||
exit 233
|
||||
fi
|
||||
|
||||
# 初始化数组
|
||||
declare -a arr=()
|
||||
|
||||
# 随机选择图片名,不重复
|
||||
for ((i=0; i<$IMAGE_NUM_NEEDED; i++)); do
|
||||
while true; do
|
||||
# 随机生成图片名
|
||||
RAND=$((RANDOM%IMAGE_NUM_ALL))
|
||||
IMG_NAME=$RAND.jpg
|
||||
|
||||
# 判断图片名是否已经被选择过
|
||||
chosen=0
|
||||
for num in "${arr[@]}"; do
|
||||
if [ "$num" == "$IMG_NAME" ]; then
|
||||
chosen=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# 如果图片名未被选择过,则将其添加到数组中
|
||||
if [ "$chosen" -eq 0 ]; then
|
||||
arr=(${arr[@]} $IMG_NAME)
|
||||
break
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
# 需要修改的文件的路径和名称
|
||||
filename_origin="/opt/websites/nav/index.html"
|
||||
filename_copy="/opt/websites/nav/index_copy.html"
|
||||
cp $filename_origin $filename_copy
|
||||
|
||||
# 循环处理所有符合指定模式的行
|
||||
let count=0
|
||||
lineno=1
|
||||
while read line; do
|
||||
# 获取文件名和路径
|
||||
oldname=$(echo $line | grep -Eo '[0-9]{1,3}.jpg')
|
||||
|
||||
if [[ $oldname != '' ]]; then
|
||||
newname=${arr[$count]}
|
||||
# 替换文件名
|
||||
sed -i "${lineno}s/\/$oldname/\/$newname/" $filename_origin
|
||||
let count=count+1
|
||||
fi
|
||||
let lineno=lineno+1
|
||||
done < $filename_copy
|
||||
|
||||
rm $filename_copy
|
||||
|
||||
|
22
update/renew.sh
Normal file
22
update/renew.sh
Normal file
@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
# get latest hosts for accelerate github visiting
|
||||
curl https://raw.hellogithub.com/hosts >> /opt/logs/hosts
|
||||
|
||||
# renew images.json file for background picture of homepage
|
||||
cd /opt/websites/homepage/
|
||||
node assets/js/bing.js > /dev/null 2>&1
|
||||
|
||||
# random logo for navigation
|
||||
bash /opt/scripts/update/nav_rand_logo.sh
|
||||
|
||||
# random logo for dash
|
||||
bash /opt/scripts/update/dash_rand_logo.sh
|
||||
|
||||
# logo renew
|
||||
let numOfAvatar=`ls /opt/websites/nav/assets/images/logos/ | wc -l`
|
||||
let randNumber=$RANDOM%$numOfAvatar
|
||||
cp /opt/websites/nav/assets/images/logos/${randNumber}.jpg /opt/websites/homepage/assets/img/logo.jpg
|
||||
cp /opt/websites/nav/assets/images/logos/${randNumber}.jpg /opt/websites/nav/assets/images/logos/avatar.jpg
|
||||
cp /opt/websites/nav/assets/images/logos/${randNumber}.jpg /opt/apps/blog/img/avatar.jpg
|
||||
|
Reference in New Issue
Block a user