mirror of
https://github.com/LamGC/quickly-conf-sshd.git
synced 2025-04-30 06:37:35 +00:00
进行了一些bug修复。
This commit is contained in:
parent
2ddcf7c6ba
commit
732d37035e
18
conf-sshd.sh
18
conf-sshd.sh
@ -1,14 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
########## 一些配置 ##########
|
||||||
|
|
||||||
# 默认获取 SSH key 的地方,一般是 Github.
|
# 默认获取 SSH key 的地方,一般是 Github.
|
||||||
sshkey_url="https://github.com/LamGC.keys"
|
sshkey_url="https://quickly-conf-ssh-worker.lamgc.workers.dev/ssh.keys"
|
||||||
# 默认的 Cron 执行计划, 每天凌晨 0 点执行
|
# 默认的 Cron 执行计划, 每天凌晨 0 点执行
|
||||||
default_cron="0 0 * * *"
|
default_cron="0 0 * * *"
|
||||||
# 脚本 Url
|
# 脚本 Url
|
||||||
script_url="{{ script_url }}"
|
script_url="{{ script_url }}"
|
||||||
|
|
||||||
|
########### 脚本区 ###########
|
||||||
|
|
||||||
script_params=$@
|
script_params=$@
|
||||||
has_param() {
|
has_param() {
|
||||||
for param in $script_params; do
|
for param in $script_params; do
|
||||||
for tParam in $script_params; do
|
for tParam in $@; do
|
||||||
if [ "$tParam" == "$param" ]; then
|
if [ "$tParam" == "$param" ]; then
|
||||||
echo "true"
|
echo "true"
|
||||||
return
|
return
|
||||||
@ -19,7 +25,7 @@ has_param() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_param_value() {
|
get_param_value() {
|
||||||
$find=false
|
local find=false
|
||||||
for param in $script_params; do
|
for param in $script_params; do
|
||||||
if [ "$find" == "true" ]; then
|
if [ "$find" == "true" ]; then
|
||||||
echo $param
|
echo $param
|
||||||
@ -36,12 +42,13 @@ get_param_value() {
|
|||||||
|
|
||||||
# 检查并更新 SSH key 地址.
|
# 检查并更新 SSH key 地址.
|
||||||
if [ $(has_param "-k" "--sshkey-url") == "true" ]; then
|
if [ $(has_param "-k" "--sshkey-url") == "true" ]; then
|
||||||
new_sshkey_url=$(get_param_value "-k" "--sshkey-url")
|
local new_sshkey_url=$(get_param_value "-k" "--sshkey-url")
|
||||||
if [ "$new_sshkey_url" == "" ]; then
|
if [ "$new_sshkey_url" == "" ]; then
|
||||||
echo "Please specify the URL of the SSH public key."
|
echo "Please specify the URL of the SSH public key."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
sshkey_url=$new_sshkey_url
|
sshkey_url=$new_sshkey_url
|
||||||
|
echo "A new SSH keys URL has been specified: $sshkey_url"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 帮助信息.
|
# 帮助信息.
|
||||||
@ -72,7 +79,7 @@ update_sshkeys() {
|
|||||||
fi
|
fi
|
||||||
echo "Downloading SSH public key from `$sshkey_url`"
|
echo "Downloading SSH public key from `$sshkey_url`"
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
ssh_keys=$(curl -s $sshkey_url)
|
local ssh_keys=$(curl -s $sshkey_url)
|
||||||
if [ $? -ne 0 ] || [ "$ssh_keys" == "" ]; then
|
if [ $? -ne 0 ] || [ "$ssh_keys" == "" ]; then
|
||||||
echo "Failed to download SSH public key at $(date '+%Y-%m-%d %H:%M:%S')"
|
echo "Failed to download SSH public key at $(date '+%Y-%m-%d %H:%M:%S')"
|
||||||
exit 1
|
exit 1
|
||||||
@ -91,6 +98,7 @@ fi
|
|||||||
|
|
||||||
# 检查是否指定了 --update-self
|
# 检查是否指定了 --update-self
|
||||||
if [ $(has_param "-u" "--update-self") == "true" ]; then
|
if [ $(has_param "-u" "--update-self") == "true" ]; then
|
||||||
|
echo "Updating conf-sshd script..."
|
||||||
cp $0 ~/.conf-sshd/conf-sshd.sh.bak
|
cp $0 ~/.conf-sshd/conf-sshd.sh.bak
|
||||||
curl -s $script_url > $0 || cp ~/.conf-sshd/conf-sshd.sh.bak $0 && echo "Script update failed at $(date '+%Y-%m-%d %H:%M:%S')" && exit 1
|
curl -s $script_url > $0 || cp ~/.conf-sshd/conf-sshd.sh.bak $0 && echo "Script update failed at $(date '+%Y-%m-%d %H:%M:%S')" && exit 1
|
||||||
chmod +x ~/.conf-sshd/conf-sshd.sh
|
chmod +x ~/.conf-sshd/conf-sshd.sh
|
||||||
|
Loading…
Reference in New Issue
Block a user