[init] initial commit

This commit is contained in:
2023-06-05 23:04:30 +08:00
commit 66b1dd4d70
72 changed files with 10079 additions and 0 deletions

80
utool/date2n.sh Normal file
View File

@ -0,0 +1,80 @@
#!/bin/bash
# 自定义颜色显示
c_br='\e[1;31m' # bold red
c_bg='\e[1;32m' # bold green
c_by='\e[1;33m' # bold yellow
c_bb='\e[1;34m' # bold blue
c_bp='\e[1;35m' # bold purple
c_bc='\e[1;36m' # bold cyan
c_bir='\e[1;3;31m' # * bold italic red
c_big='\e[1;3;32m' # bold italic cyan
c_bib='\e[1;3;34m' # * bold italic cyan
c_bic='\e[1;3;36m' # bold italic cyan
c_e='\e[0m' # reset
function usage() {
echo -e "${c_bir}将日期转换成十进制和十六进制时间戳,输入日期格式可参考如下,中间空格可替换成[a-zA-Z@#%^*:]中的任意一个单字符:${c_e}"
echo -e " 2023/03/09 09:29:02"
echo -e " 2023-03-09 09:29:02"
echo -e " 09/03/2023 09:29:02"
echo -e " 09/Mar/2023 09:29:02"
exit 4
}
ts=$@
if [[ $ts =~ (([J|j]an)|([F|f]eb)|([M|m]ar)|([A|a]pr)|([M|m]ay)|([J|j]un)|([J|j]ul)|([A|a]ug)|([S|s]ep)|([O|o]ct)|([N|n]ov)|([D|d]ec)) ]]; then
[[ ${#ts} -ne 20 ]] && usage
else
[[ ${#ts} -ne 19 ]] && usage
fi
# 2023/03/09 09:29:02
# 2023-03-09 09:29:02
fmt1="^[0-9]{4}[-/][0-9]{2}[-/][0-9]{2}[a-zA-Z@#%^*:]{0,1}[[:space:]]{0,1}[0-9]{2}:[0-9]{2}:[0-9]{2}$"
# 09/03/2023:09:29:02
fmt2="^[0-9]{2}/[0-9]{2}/[0-9]{4}[a-zA-Z@#%^*:]{0,1}[[:space:]]{0,1}[0-9]{2}:[0-9]{2}:[0-9]{2}$"
# 09/Mar/2023:09:29:02
fmt3="^[0-9]{2}/(([J|j]an)|([F|f]eb)|([M|m]ar)|([A|a]pr)|([M|m]ay)|([J|j]un)|([J|j]ul)|([A|a]ug)|([S|s]ep)|([O|o]ct)|([N|n]ov)|([D|d]ec))/[0-9]{4}[a-zA-Z@#%^*:]{0,1}[[:space:]]{0,1}[0-9]{2}:[0-9]{2}:[0-9]{2}$"
if [[ $ts =~ $fmt1 || $ts =~ $fmt2 ]]; then
ts=${ts:0:10}' '${ts:11}
dec=`date -d "$ts" +%s`
hex=`echo "obase=16; $dec" | bc`
echo "十进制的时间戳 - $dec"
echo "十六进制时间戳 - 0x$hex - $hex"
echo "十六进制时间戳 - 0x${hex,,} - ${hex,,}"
elif [[ $ts =~ $fmt3 ]]; then
day=${ts:0:2}
month=${ts:3:3}
left=${ts:7}
[[ $month =~ ^[J|j]an$ ]] && month='01'
[[ $month =~ ^[F|f]eb$ ]] && month='02'
[[ $month =~ ^[M|m]ar$ ]] && month='03'
[[ $month =~ ^[A|a]pr$ ]] && month='04'
[[ $month =~ ^[M|m]ay$ ]] && month='05'
[[ $month =~ ^[J|j]un$ ]] && month='06'
[[ $month =~ ^[J|j]ul$ ]] && month='07'
[[ $month =~ ^[A|a]ug$ ]] && month='08'
[[ $month =~ ^[S|s]ep$ ]] && month='09'
[[ $month =~ ^[O|o]ct$ ]] && month='10'
[[ $month =~ ^[N|n]ov$ ]] && month='11'
[[ $month =~ ^[D|d]ec$ ]] && month='12'
ts=$month'/'$day'/'$left
ts=${ts:0:10}' '${ts:11}
dec=`date -d "$ts" +%s`
hex=`echo "obase=16; $dec" | bc`
echo "十进制的时间 - $dec"
echo "十六进制时间 - 0x${hex} - $hex"
echo "十六进制时间 - 0x${hex,,} - ${hex,,}"
else
echo -e "${c_br}请检查输入的时间符合正常规则,退出...${c_e}"
usage
exit 10
fi

28
utool/genpw.sh Normal file
View File

@ -0,0 +1,28 @@
#!/bin/bash
if [[ $# -ne 1 ]]; then
echo -e "\e[1;3;31mNeed ONE and only ONE digital parameter.\e[0m"
exit 1
fi
if ! [[ $1 -gt 0 && $1 -lt 80 ]] 2>/dev/null; then
echo -e "\e[1;3;31mNeed ONE DIGITAL parameter, which must be greater than 0 and lower than 80.\e[0m"
exit 2
fi
# total 80 bits password
pwgen_0=`pwgen -sync`
pwgen_1=`pwgen -sync`
pwgen_2=`pwgen -sync`
pwgen_3=`pwgen -sync`
pwgen_4=`pwgen -sync`
pwgen_5=`pwgen -sync`
pwgen_6=`pwgen -sync`
pwgen_7=`pwgen -sync`
pwgen_8=`pwgen -sync`
pwgen_9=`pwgen -sync`
pwgen_80=${pwgen_0}${pwgen_1}${pwgen_2}${pwgen_3}${pwgen_4}${pwgen_5}${pwgen_6}${pwgen_7}${pwgen_8}${pwgen_9}
echo ${pwgen_80:0:${1}}

13
utool/ipports.sh Normal file
View File

@ -0,0 +1,13 @@
#!/bin/bash
if [[ $1 == 'port' ]]; then
find /opt/apps/localcr/ -type f -name "*:*:*" | \
awk -F '/' '{print $NF}' | \
awk -F':' 'BEGIN{print "Local", "Container", "Application"} {print $1, $2, $3}' | \
column -t | \
sort -nk 1
elif [[ $1 == 'ip' ]]; then
find /opt/apps/localcr/ -type f -name "10.10.0.*" | awk -F '/' '{print $(NF-1), $NF}' | column -t | sort -k2
else
:
fi

35
utool/number2d.sh Normal file
View File

@ -0,0 +1,35 @@
#!/bin/bash
# 自定义颜色显示
c_br='\e[1;31m' # bold red
c_bg='\e[1;32m' # bold green
c_by='\e[1;33m' # bold yellow
c_bb='\e[1;34m' # bold blue
c_bp='\e[1;35m' # bold purple
c_bc='\e[1;36m' # bold cyan
c_bir='\e[1;3;31m' # * bold italic red
c_big='\e[1;3;32m' # bold italic cyan
c_bib='\e[1;3;34m' # * bold italic cyan
c_bic='\e[1;3;36m' # bold italic cyan
c_e='\e[0m' # reset
number=$1
if [[ $number =~ ^[0-9]{1,11}$ ]]; then
date -d@$number +'%Y-%m-%d %H:%M:%S'
elif [[ $number =~ ^0[x|X][0-9a-fA-F]{1,9}$ ]]; then
hex=`printf "%d" $number`
date -d@$hex +'%Y-%m-%d %H:%M:%S'
elif [[ $number =~ ^[0-9a-fA-F]{1,9}$ ]]; then
hex=`printf "%d" '0x'$number`
date -d@$hex +'%Y-%m-%d %H:%M:%S'
else
echo -e "${c_br}请输入正确的十进制--11位以内或者十六进制数字--9位以内${c_e}"
echo -e " 十进制的时间戳 - 1678523385"
echo -e " 十六进制时间戳 - 0x640c3bf9/0X640C3BF9/0x640C3bf9/640c3bf9"
echo -e "${c_bb}有歧义时,使用'0x'或者'0X'来区分十进制和十六进制${c_e}"
exit 233
fi

56
utool/toolbox.sh Normal file
View File

@ -0,0 +1,56 @@
# You may uncomment the following lines if you want `ls' to be colorized:
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -ahl'
alias l='ls $LS_OPTIONS -lA'
PS1='\e[1;32m[ $? \u@\h \W]\$ \e[0m'
alias cls='clear'
alias ll='ls -alh'
alias l='ll'
alias ..='cd ..; ls'
alias ...='cd ../..; ls'
alias cdblog='cd /opt/source-code/blog/_posts'
alias cdscripts='cd /opt/scripts'
alias cdconfigs='cd /opt/configs'
alias cdfrp='cd /opt/source-code/frpc/'
alias cdalist='cd /opt/webdav/alist/CTC-Client/Manford/ && ls'
alias cdone='cd /opt/webdav/onedrive/ && ls'
alias cdwd='cd /opt/webdav/wd/ && ls'
alias cdman='cd /opt/source-code/manford && ls'
alias conf='cd /usr/local/nginx/conf'
alias so='source ~/.bashrc'
alias python='python3'
alias py='python3'
alias vi='vim'
alias g='vim'
alias txl='tmux ls'
alias txn='tmux new -s'
alias txa='tmux at -t'
alias acme.sh=~/.acme.sh/acme.sh
alias tt='/opt/scripts/todo/todo.sh -d /opt/scripts/todo/todo.cfg'
alias tdate='date +%Y-%m-%d'
alias jtddate='date +"%Y-%m-%d %H:%M:%S"'
complete -F _todo tt
alias cdpython='cd /opt/source-code/document/python/ && ls'
export TIMETAGGER_CREDENTIALS='timetagger:$2a$08$s6ZkrdZGmwNADKY3K9X0jOgGWu4XMSVCGs4qbqMTupYRaUM2n4RKq'
export Ali_Key='LTAI5tMoM6J3Nzoi6JbT9waY'
export Ali_Secret='N89cC4JpxdBL1Hqr8WhefIPRVcKEAs'
export CF_Key="f0971f82ebc8d6dfffc1a4871759f6b17fd1a"
export CF_Email="xgdfmf@gmail.com"
export EDITOR='/usr/bin/vim'
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
# [[ ! -d /tmp/rclone ]] && mkdir -p /tmp/rclone
#. /opt/scripts/rclone/rclone_bash_completion.sh
. /opt/scripts/todo/todo_completion
source /opt/source-code/v2ray-4.34.0/envfile

29
utool/usage.sh Normal file
View File

@ -0,0 +1,29 @@
#!/bin/bash
let col=`tput cols`
if [[ $col -lt 120 ]]; then
echo -e "\e[1;3;31mYour screen width is too small to show the usage info neatly. So make the display window maximized.\e[0m"
read -p "Press any key to continue..."
echo ''
fi
echo -e "\e[1;32mDESCRIPTION:\e[0m"
echo -e "\e[3;32mutool -- a self-defined command line interface, which is used to facilitate operating the system, supports the following options. In the description part, where there is a leading asterisk signifies that this option must take an argument.\e[0m"
echo -e "\e[1;4m \e[0m"
echo -e "\e[37;40m|\e[0m\e[1;4;37;40mOption| Description |Option| Description \e[0m\e[37;40m|\e[0m"
echo -e "\e[37;40m| -a | print all local ports of using for now | -n | |\e[0m"
echo -e "\e[37;40m| -b | generate two-factor key of GITHUB | -o | |\e[0m"
echo -e "\e[37;40m| -c | print all intranet IP using in docker | -p |*generate password of length 1~79 |\e[0m"
echo -e "\e[37;40m| -d | show external IP of this machine | -q | |\e[0m"
echo -e "\e[37;40m| -e |*show IP location | -r | |\e[0m"
echo -e "\e[37;40m| -f |*ganerate md5 value of the input string | -s | |\e[0m"
echo -e "\e[37;40m| -g | | -t | |\e[0m"
echo -e "\e[37;40m| -h | show this help information | -u | |\e[0m"
echo -e "\e[37;40m| -i |*get domain's registration info | -v | |\e[0m"
echo -e "\e[37;40m| -j |*convert a (hexa)decimal to specific time format | -w | |\e[0m"
echo -e "\e[37;40m| -k |*convert multi-formats time to a decimal | -x | |\e[0m"
echo -e "\e[37;40m| -l | | -y | |\e[0m"
echo -e "\e[37;40m|\e[0m\e[4;37;40m -m | | -z | \e[0m\e[37;40m|\e[0m\n"

178
utool/utool.py Executable file
View File

@ -0,0 +1,178 @@
#!/usr/bin/python3
# coding: utf-8
import os
import sys
import time
c_title = '\033[1;4;31;42m' # title color
c_br = '\033[1;31m' # bold red
c_bg = '\033[1;32m' # bold green
c_by = '\033[1;33m' # bold yellow
c_bb = '\033[1;34m' # bold blue
c_bp = '\033[1;35m' # bold purple
c_bc = '\033[1;36m' # bold cyan
c_bir= '\033[1;3;31m' # * bold italic red
c_bib = '\033[1;3;34m' # * bold italic cyan
c_bic = '\033[1;3;36m' # bold italic cyan
c_e = '\033[0m' # reset
if len(sys.argv) == 2:
opt_1 = sys.argv[1]
opt_rest = None
elif len(sys.argv) > 2:
opt_1 = sys.argv[1]
opt_rest = sys.argv[2:]
else:
opt_1 = None
opt_rest = None
opt_index = ['-do_not_use_this', '-a', '-b', '-c', '-d', '-e', '-f', '-g', '-h', '-i', '-j', '-k', '-l', '-m',
'-n', '-o', '-p', '-q', '-r', '-s', '-t', '-u', '-v', '-w', '-x', '-y', '-z']
if opt_1 not in opt_index:
os.system('/usr/bin/bash /opt/scripts/utool/usage.sh')
exit(100)
if opt_1 == '-a':
if opt_rest != None:
print(f"This option({opt_1}) will print all ports of now using for local, and accept NO parameter.")
exit(opt_index.index(opt_1))
os.system('/usr/bin/bash /opt/scripts/utool/ipports.sh port')
elif opt_1 == '-b':
if opt_rest != None:
print(f"This option({opt_1}) will generate a two-factor auth-key for github login, and accept NO parameter.")
exit(opt_index.index(opt_1))
os.system("/usr/bin/oathtool -b --totp 'G3NHHFO2L2LZ5W2R'")
elif opt_1 == '-c':
if opt_rest != None:
print(f"This option({opt_1}) will print all intranet IP using in docker, and accept NO parameter.")
exit(opt_index.index(opt_1))
os.system('/usr/bin/bash /opt/scripts/utool/ipports.sh ip')
elif opt_1 == '-d':
if opt_rest != None:
print(f"This option({opt_1}) will return the current IP of local machine, and accept NO parameter.")
exit(opt_index.index(opt_1))
os.system("/usr/bin/python3 /opt/scripts/roll_api/get_self_ip.py")
elif opt_1 == '-e':
if opt_rest == None:
print(f"This option({opt_1}) will return the IP info, and accept at least one IP parameter.")
exit(opt_index.index(opt_1))
for opt_2 in opt_rest:
os.environ['opt_2'] = opt_2
os.system('/usr/bin/python3 /opt/scripts/roll_api/get_ip.py $opt_2')
elif opt_1 == '-f':
if len(sys.argv) < 3:
print(f"{c_br}需要至少一个字符串作为输入,退出...{c_e}\n")
exit(opt_index.index(opt_1))
param=''
for item in sys.argv[2:]:
param += item
os.environ['param'] = param
print(f"{c_by}Warning: 输入字符串中间的任何空白符将会被删除,要保留的话,需手动将字符串用单引号括起来{c_e}")
print(f"本次计算MD5值的字符串为 - {param}\n本次计算得到的MD5的值为 - ", end='')
# print(f"本次计算得到的MD5的值为 - ", end='')
os.system('echo -n $param | md5sum | cut -d " " -f 1')
elif opt_1 == '-g':
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
exit(opt_index.index(opt_1))
elif opt_1 == '-h':
os.system('/usr/bin/bash /opt/scripts/utool/usage.sh')
exit(opt_index.index(opt_1))
elif opt_1 == '-i':
if opt_rest == None:
print(f"This option({opt_1}) will return the domain registration info, and accept at least one domain parameter.")
exit(opt_index.index(opt_1))
for opt_2 in opt_rest:
os.environ['opt_2'] = opt_2
os.system('/usr/bin/python3 /opt/scripts/roll_api/domain_reg_check.py $opt_2')
elif opt_1 == '-j':
if len(sys.argv) == 2:
print(f"{c_br}-j选项将十进制或者十六进制数字作为入参转换成标准时间格式只接收第一个参数其他参数将被丢弃有歧义时使用'0x'或者'0X'来区分十进制和十六进制,退出...{c_e}\n")
exit(opt_index.index(opt_1))
os.environ['param'] = sys.argv[2]
os.system('/usr/bin/bash /opt/scripts/utool/number2d.sh $param')
elif opt_1 == '-k':
if len(sys.argv) < 3:
print(f"{c_br}-k选项将输入的时间转换成十进制和十六进制需要一个字符串格式的时间作为输入退出...{c_e}\n")
exit(opt_index.index(opt_1))
param=''
for item in sys.argv[2:]:
param += item + ' '
os.environ['param'] = param
os.system('/usr/bin/bash /opt/scripts/utool/date2n.sh $param')
elif opt_1 == '-l':
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
exit(opt_index.index(opt_1))
elif opt_1 == '-m':
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
exit(opt_index.index(opt_1))
elif opt_1 == '-n':
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
exit(opt_index.index(opt_1))
elif opt_1 == '-o':
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
exit(opt_index.index(opt_1))
elif opt_1 == '-p':
if opt_rest == None:
opt_rest = ['',]
opt_2 = opt_rest[0]
os.environ['opt_2'] = opt_2
os.system('/usr/bin/bash /opt/scripts/utool/genpw.sh $opt_2')
elif opt_1 == '-q':
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
exit(opt_index.index(opt_1))
elif opt_1 == '-r':
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
exit(opt_index.index(opt_1))
elif opt_1 == '-s':
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
exit(opt_index.index(opt_1))
elif opt_1 == '-t':
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
exit(opt_index.index(opt_1))
elif opt_1 == '-u':
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
exit(opt_index.index(opt_1))
elif opt_1 == '-v':
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
exit(opt_index.index(opt_1))
elif opt_1 == '-w':
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
exit(opt_index.index(opt_1))
elif opt_1 == '-x':
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
exit(opt_index.index(opt_1))
elif opt_1 == '-y':
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
exit(opt_index.index(opt_1))
elif opt_1 == '-z':
print(f"This option({opt_1}) is reserved now, nothing is bound on it.")
exit(opt_index.index(opt_1))
else:
print("This line SHOULD NOT be executed, please check carefully.")
exit(255)