(experimental) riot config in a single file

This commit is contained in:
Dict Xiong 2023-12-06 21:52:54 +08:00
parent 2fa248fdb0
commit 79d376265e
8 changed files with 62 additions and 30 deletions

38
riot-config.sh Normal file
View File

@ -0,0 +1,38 @@
#!/bin/false
# remotes
j.remote() {
remote=sir0.ibd.ink
RET_PORT=${RET_PORT:-36122}
RET_USERNAME=${RET_USERNAME:-root}
RET_TRUST_SERVER=1
}
# domains
i.domain() {
RET_HOSTNAME=$host.ibd.ink
RET_PORT=${RET_PORT:-12022}
RET_USERNAME=${RET_USERNAME:-root}
RET_TRUST_SERVER=1
}
x.domain() {
RET_HOSTNAME=ssh.beardic.cn
local tmp=$(sha256sum <<< "$host" | tr -cd "[:digit:]")
tmp=${tmp:0:4}
RET_PORT=$((10#$tmp+36000))
RET_USERNAME=root
RET_TRUST_SERVER=1
}
nasp.domain() {
RET_HOSTNAME=$host
RET_PORT=${RET_PORT:-12022}
RET_USERNAME=${RET_USERNAME:-dictxiong}
RET_JUMP_SERVER="ssh@nasp.ob.ac.cn:36022"
RET_TRUST_SERVER=1
}
default.domain() {
i.domain
}

View File

@ -4,9 +4,20 @@ THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/../tools/common.sh"
RIOT_TRUST_CLIENT=${RIOT_TRUST_CLIENT:-${DFS_TRUST:-0}}
RIOT_TRUST_SERVER=${RIOT_TRUST_SERVER:-0}
RIOT_CONFIG_DIR="$THIS_DIR/riot.d"
RIOT_EXTRA_OPTIONS=""
# config
RIOT_CONFIG_FILES=(
"$DOTFILES/riot-config.sh"
"$HOME/.config/riot-config.sh"
"riot-config.sh"
)
for file in "${RIOT_CONFIG_FILES[@]}"; do
if [[ -f "$file" ]]; then
source "$file"
fi
done
# check if port number valid
check_port() {
( echo $1 | grep -qxE "[1-9][0-9]{0,4}" ) || return 1
@ -44,9 +55,9 @@ get_server_meta() {
check_port $RET_PORT || fmt_fatal invalid port number \"$RET_PORT\"
fi
# presets -- match remote
local remote_config="$RIOT_CONFIG_DIR/$remote.remote"
if [[ -f "$remote_config" ]]; then
source "$remote_config"
local remote_func="$remote.remote"
if is_function "$remote_func"; then
"$remote_func"
fi
# presets -- match domain
RET_HOSTNAME=${remote}
@ -56,13 +67,12 @@ get_server_meta() {
if [[ "$host" == "$domain" && "$host" != "["*"]" ]]; then
domain="default"
fi
local root_domain_config="$RIOT_CONFIG_DIR/.domain"
if [[ -f "$root_domain_config" ]]; then
source "$root_domain_config"
if is_function ".domain"; then
".domain"
fi
local domain_config="$RIOT_CONFIG_DIR/$domain.domain"
if [[ -n "$$domain" && -f "$domain_config" ]]; then
source "$domain_config"
local domain_func="$domain.domain"
if [[ -n "$domain" ]] && is_function "$domain_func"; then
"$domain_func"
fi
}

View File

@ -1 +0,0 @@
./i.domain

View File

@ -1,4 +0,0 @@
RET_HOSTNAME=$host.ibd.ink
RET_PORT=${RET_PORT:-12022}
RET_USERNAME=${RET_USERNAME:-root}
RET_TRUST_SERVER=1

View File

@ -1,4 +0,0 @@
remote=sir0.ibd.ink
RET_PORT=${RET_PORT:-36122}
RET_USERNAME=${RET_USERNAME:-root}
RET_TRUST_SERVER=1

View File

@ -1,5 +0,0 @@
RET_HOSTNAME=$host
RET_PORT=${RET_PORT:-12022}
RET_USERNAME=${RET_USERNAME:-dictxiong}
RET_JUMP_SERVER="ssh@nasp.ob.ac.cn:36022"
RET_TRUST_SERVER=1

View File

@ -1,6 +0,0 @@
RET_HOSTNAME=ssh.beardic.cn
local tmp=$(sha256sum <<< "$host" | tr -cd "[:digit:]")
tmp=${tmp:0:4}
RET_PORT=$((10#$tmp+36000))
RET_USERNAME=root
RET_TRUST_SERVER=1

View File

@ -258,6 +258,10 @@ get_free_port() {
echo $port
}
is_function() {
test "$(type -t "$1")" = "function"
}
# if bash-ed, else source-d
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
$1 "${@:2}"