6 Commits

Author SHA1 Message Date
2cc2ab48b8 [dev] enhance riot; ddns avoid burst (#38)
* riot: add . for .ibd and non for proxied

* riot: 'user@..' to overwrite username, '...:22' to overwrite port, treat the arg as server name if it doesn't match any preset, sshl can accept only a port number and default to use localhost

* update.sh: ddns sleep for random seconds to avoid burst

* riot: support zssh and sftp, and set ssh options according to trust settings

* riot: add scp

* riot: support jump servers, sep by commas

* common.sh: argparser supports -d/--dev and -D/--dry-run

* install.sh: remove -s/--secure because of no use

* riot: if remote ends with dot, treat it as a full-hostname; add tests

* sagent.sh: refuse to work on windows

---------

Co-authored-by: xiongdian.me <xiongdian.me@bytedance.com>
2023-05-30 13:43:25 +08:00
37bf1fa1f0 [keys] remove pc{0,1}/old,sk0/fido,ph0/sep, update pc1/windows (#37)
keys: remove pc{0,1}/old,sk0/fido,ph0/sep, update pc1/windows
2023-04-29 17:46:01 +08:00
8fdd3c477f [dev] ddns; better ssh agent; riot sshl; sys.online; zsh hist import; DFS_DEBUG; cbd/cbds (#36)
* riot: bj1 -> proxy

* ci: test ask_for_yn

* --wip-- [skip ci]

* install.sh: will prompt version

* zshrc: piv-agent now can re-use agents

* zshrc: in docker use theme robbyrussell

* update.sh: will send online beacon

* beacon: support meta with limited len 64

* bug fix (Sat Jan 21 16:45:35 CST 2023)

* well, finally add ssh key for ltp1-bd

* set DFS_INITED and do not send login beacon if it was set

* rewrite piv-agent to sagent; fmt_note and fmt_into will write to stderr

* bug fix (Mon Jan 30 19:41:00 CST 2023)

* bug fix (Mon Jan 30 19:46:27 CST 2023)

* login beacon add details

* $DFS_ORPHAN turns logger off

* disable more beacons in CI

* install.sh: prepare config earlier

* init pbin

* install.sh: -H|--hist|--history

* install.sh: -H hint

* install.sh: -H support multiple keys

* fix zsh hist with no new line at the end

* remove ^M in hist

* bug fix (Wed Feb  1 21:11:41 CST 2023)

* bug fix (Wed Feb  1 21:16:29 CST 2023)

* bug fix (Wed Feb  1 21:20:21 CST 2023)

* ci will send gh.ci.fail

* show install opts

* DFS_DEBUG to set -x

* bug fix: install.sh re-start itself with no args incorrectly

* bug fix (Thu Feb  2 18:43:16 CST 2023)

* riot: ob->ebd, swap option $1 and $2 and $2 is default to ssh

* riot: introduce sshl

* logger.sh: support ddns

* bug fix (Wed Mar  1 16:37:42 CST 2023)

* dfs.ddns.failed -> dfs.ddns.fail

* login beacon 2>/dev/null

* logger.sh -> frigg-client.sh; curl add time limit 10s

* to-install.sh: improve docker-ce

* use $DFS_CURL_OPTIONS

* ci: add ddns

* bug fix (Wed Mar 15 19:37:21 CST 2023)

* Revert "bug fix (Wed Mar 15 19:37:21 CST 2023)"

This reverts commit 2df87ce1a8.

* Revert "ci: add ddns"

This reverts commit 4fe8321504.

* alias cbd and cbds, riot nasp port to 12022

* .zshrc: sagent -> sagt

* fix ci

* riot: bug fix when 'tmp' has leading zeros

* add ci for cbds

---------

Co-authored-by: xiongdian.me <xiongdian.me@bytedance.com>
2023-04-21 12:37:05 +08:00
9a4c9556f6 [dev] common.sh parses args; riot; getdfs; install.sh -x KEY=VAL (#35)
* common.sh: export vars in env; zshrc: gdebug

* fix error when locale not exists

* DFS_COLOR

* common.sh: parse args automatically

* ci: test common.sh getopts

* common.sh: argparser supports spaces

* ciot: init

* ciot -> diot; remove sibd, sob and snasp

* rename diot -> riot

* update home0 ssh pubkey; fix ci temperarily

* gdebug will record time

* gdebug supports empty; --dry-run wip

* get.dotfiles.cn

* bug fix (Thu Jan  5 20:53:58 CST 2023)

* fix ci

* fix ci

* install.sh: -d will set -x

* ci: -asl

* getdfs: install for another user using -u <uname>

* try fix when su doesnot exist

* bug fix (Thu Jan  5 22:58:40 CST 2023)

* bug fix (Thu Jan  5 22:59:33 CST 2023)

* introduce SUDOE and so debug

* ask_for_yn now use stdout to return

* getdfs: support multiple users

* install.sh: -x to set dfs config; ci

* fix ci

* bug fix (Fri Jan  6 15:11:24 CST 2023)

* auto-detect DFS_NO_WALL

* bug fix (Fri Jan  6 15:43:25 CST 2023)

* getdfs: ${repo}

* bug fix (Fri Jan  6 16:08:41 CST 2023)

* getdfs: prompt user

Co-authored-by: xiongdian.me <xiongdian.me@bytedance.com>
2023-01-06 16:14:41 +08:00
952bfabea4 zshrc: fix locale (#34)
* common.sh: export vars in env; zshrc: gdebug

* fix error when locale not exists

* fix ci

Co-authored-by: xiongdian.me <xiongdian.me@bytedance.com>
2022-12-10 19:11:05 +08:00
c3e0c28b64 [install.sh] hotfix (#33)
hotfix

Co-authored-by: xiongdian.me <xiongdian.me@bytedance.com>
2022-12-03 21:27:22 +08:00
22 changed files with 903 additions and 246 deletions

View File

@@ -17,7 +17,7 @@ jobs:
rev=`git rev-parse HEAD` rev=`git rev-parse HEAD`
pwd pwd
set -x set -x
./install.sh -adl DFS_NO_WALL=0 ./install.sh -adl
test `git rev-parse HEAD` = "$rev" test `git rev-parse HEAD` = "$rev"
- name: antigen build - name: antigen build
@@ -31,13 +31,11 @@ jobs:
run: | run: |
source tools/test.zsh source tools/test.zsh
antigen reset antigen reset
rm -rf $ANTIGEN $HOME/.antigen rm -rf $ANTIGEN $HOME/.antigen $HOME/.config/dotfiles
./install.sh -dl ./install.sh -dl
- name: antigen build with DFS_NO_WALL - name: antigen build with DFS_NO_WALL
shell: /bin/zsh -ileo PIPE_FAIL {0} shell: /bin/zsh -ileo PIPE_FAIL {0}
env:
DFS_NO_WALL: 1
run: | run: |
echo $SHELL echo $SHELL
antigen list antigen list
@@ -60,7 +58,7 @@ jobs:
rev=`git rev-parse HEAD` rev=`git rev-parse HEAD`
pwd pwd
set -x set -x
./install.sh -adl DFS_NO_WALL=0 ./install.sh -adl
test `git rev-parse HEAD` = "$rev" test `git rev-parse HEAD` = "$rev"
- name: antigen build - name: antigen build
@@ -74,13 +72,11 @@ jobs:
run: | run: |
source tools/test.zsh source tools/test.zsh
antigen reset antigen reset
rm -rf $ANTIGEN $HOME/.antigen rm -rf $ANTIGEN $HOME/.antigen $HOME/.config/dotfiles
./install.sh -dl ./install.sh -dl
- name: antigen build with DFS_NO_WALL - name: antigen build with DFS_NO_WALL
shell: /bin/zsh -ileo PIPE_FAIL {0} shell: /bin/zsh -ileo PIPE_FAIL {0}
env:
DFS_NO_WALL: 1
run: | run: |
echo $SHELL echo $SHELL
antigen list antigen list
@@ -109,10 +105,27 @@ jobs:
./install.sh -dal ./install.sh -dal
test `git rev-parse HEAD` = "$rev" test `git rev-parse HEAD` = "$rev"
- name: antigen build with DFS_NO_WALL - name: antigen build
shell: /bin/zsh -ileo PIPE_FAIL {0} shell: /bin/zsh -ileo PIPE_FAIL {0}
env:
DFS_NO_WALL: 1
run: | run: |
echo $SHELL echo $SHELL
antigen list antigen list
test-get-dotfiles-cn:
name: test of get.dotfiles.cn script
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: run the script
run: |
repo=https://github.com/DictXiong/dotfiles bash tools/get.dotfiles.cn -asl
- name: run tests
shell: /bin/zsh -ileo PIPE_FAIL {0}
run: |
dfs cd
source tools/test.zsh

View File

@@ -1,15 +1,8 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQD5VPD5c/pBtQM5mcKMzJ6vC2jDdVJU6ifkP1EvAeV/dKEyy5hOc+EXC8Ws7bAp3a7twvsQGSqNbeXuAO4PzX2KHhI49KiFyRugo8LsUF3TVVluOXtGWKgw+36TBO3rNFgWOnhw5B4IlNtxo2nk4grCkgEsE6w+Ignd+FrEFec457oal2SPN02TjUfRULaEPSpZTl7cA/5Re9/QmlcYjuyA9zbkO98KYA0M71W/eUcjfjNEaWXjn2pcloakoWwEEdi4v/yJ1Fk+gQYcbpoftxpWmWLvFhDGP+qvTZY5QHxDxiPbc3HDdx0qBvMOQW9XSt0J/L/btnxcZvA1lDtkC2bm8zvHxtLBZ9JBRutMbRhdSgkd3+5DwHDIO0EIUqckgCfX3t7avj5RsPAl0j4V40yB637YQim7saN3FWq43SpR3i6buNbQLPdgy2SDN6fAZcAPWvifE1KG7I2BtmiFFYjAy3iU1KD2Hgn6mIpOOCZOJV30/cf3Oq8ZSDfD7PmDu72yOea3h9JlvkKjjqknnF4NdQ5cy1FuIfyebnF6+ugbdA9UqY9PZdnuwy5RkwkmJwC4AVO3GaOfuQDU61UMSoTfYH1yB8x8HHUQcJzLtfExrYpVPAo89tyN1lcIIBUBoHhNMCwVBZipfV/H41cIxs5wkHsolQ02zZaAX6Cgbii9FQ== home
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPmMImRSAhksHUfCwNpcj61izGn0Xkv1KRIuxb0OSdJl pc0/old
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO4K5S3zDYbxlw7B45zOdmKud95nXU1V6kSxEvbTOsy2 pc1/old
# keys below are the new security system starting from 2022-07 # keys below are the new security system starting from 2022-07
sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIGdLJYOrBhWERmkQ+sNM8tGzJ37UBEKkEuhbtE9B65mOAAAABHNzaDo= sk0/fido
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGakUcSuNhuH7tk+Nj9gDfRtxYfGPL9yb8toQ/EpSJAM openpgp:0xD9271B01 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGakUcSuNhuH7tk+Nj9gDfRtxYfGPL9yb8toQ/EpSJAM openpgp:0xD9271B01
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCUN7IXF4nlFcVfgHesgik3LIAiXlVMYJPm3yD13EVarQx5jqdBgk8Dwgkgf4rPO6MFpvIpinOyEO8zOS6HHQrCLZUv5yTFaDkUuB7eQ0EmpicGbmk9bHqj1HkOZxaobkpEfQUmFKYvkp4EexVw66sO0qfXvjHZ4H6yCAJLK5aUnKfgrE8tODzP82sU/mpJjW+Pq3uanNq754gaHwhxCIXG143/zp8qzBAeKe38xVqqDq9fTkG4hvzFvkRdS88i6l1z++0P3n0HGdOjtSg7P7fO7+7ZyPYr0gO5vB720Om/zxqPrGd9cicWi4P+aVKa+0ujWH/pqufWG6uCjKWHnBs7 sk0.ibd.ink/piv/9a ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCUN7IXF4nlFcVfgHesgik3LIAiXlVMYJPm3yD13EVarQx5jqdBgk8Dwgkgf4rPO6MFpvIpinOyEO8zOS6HHQrCLZUv5yTFaDkUuB7eQ0EmpicGbmk9bHqj1HkOZxaobkpEfQUmFKYvkp4EexVw66sO0qfXvjHZ4H6yCAJLK5aUnKfgrE8tODzP82sU/mpJjW+Pq3uanNq754gaHwhxCIXG143/zp8qzBAeKe38xVqqDq9fTkG4hvzFvkRdS88i6l1z++0P3n0HGdOjtSg7P7fO7+7ZyPYr0gO5vB720Om/zxqPrGd9cicWi4P+aVKa+0ujWH/pqufWG6uCjKWHnBs7 sk0/piv/9a
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGV/6cLUGA5YWVI6uPhIBOBZvlNBlZLkehHQN0Gxnc+B ltp0/ubuntu ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGV/6cLUGA5YWVI6uPhIBOBZvlNBlZLkehHQN0Gxnc+B ltp0/ubuntu
@@ -23,10 +16,13 @@ ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBN24pvN1RMN+iSZyHPdyExA1Rvt8pdr3e6ih6iX+KrQ
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGZFTyR+R86fUpZBDkDR9yYzJpmeNsIv2CMHTh6EuEeq pc0/windows ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGZFTyR+R86fUpZBDkDR9yYzJpmeNsIv2CMHTh6EuEeq pc0/windows
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID8WHIpwdZl7+HIZfQpwIAhpxT1huI9sd6Ydeokilg5l pc1/windows ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHLYgVj+NPino6sOmahULN7SbAMaVAgzqPfDjz2S8zDv pc1/windows
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJ/+BWSTv3w1Ru9ksfse3EUbu4ukJruUU94fCG7Sk+5g3+F80KqJGykP9tHueU07iZfAuaYj7Zcy+IWx9Ih+eYA= ph0/sep
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNvHya5i3GNniGww9Yx5ikos4Z5jevu8zz8hCQi05++SgejFPnbw9UjbHFjODK2M+ZHuhRF5mdf996r4/BxWyP8= pad0/sep ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNvHya5i3GNniGww9Yx5ikos4Z5jevu8zz8hCQi05++SgejFPnbw9UjbHFjODK2M+ZHuhRF5mdf996r4/BxWyP8= pad0/sep
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBC5gu+U4picxVvCNYjLlmxGLpJl7svj3LklO7jSpwqdrNxlE+/xkx07PJx76AbA77dDM1Dxmm/VOvVQCKTRLTgk= ip14/sep ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBC5gu+U4picxVvCNYjLlmxGLpJl7svj3LklO7jSpwqdrNxlE+/xkx07PJx76AbA77dDM1Dxmm/VOvVQCKTRLTgk= ip14/sep
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIF52mPmbLEriZ+DfmrMHFtvg2kiO2JpRpitvs7PbJowh home0
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKhS4voo3K/Dvzqckr0bouO1WkCI5XxswstHWnuuyKBz ltp1-bd

View File

@@ -7,6 +7,20 @@ source "$THIS_DIR/tools/common.sh"
DFS_UPDATED_RET=${DFS_UPDATED_RET:-0} DFS_UPDATED_RET=${DFS_UPDATED_RET:-0}
DFS_UPDATE_CHANNEL=${DFS_UPDATE_CHANNEL:-"main"} DFS_UPDATE_CHANNEL=${DFS_UPDATE_CHANNEL:-"main"}
# send beacon online
apost_beacon "sys.online"
# update dns
if [[ "$DFS_DDNS_ENABLE" == "1" ]]; then
fmt_info "updating dns ..."
if ! is_tty; then
time_to_sleep=$((RANDOM%600))
fmt_note "sleep for $time_to_sleep seconds"
sleep $time_to_sleep
fi
"$THIS_DIR/tools/frigg-client.sh" ddns || (fmt_error "failed to update dns" && apost_beacon "dfs.ddns.fail")
fi
# fetch origin # fetch origin
cd $DOTFILES cd $DOTFILES
git fetch --all --prune git fetch --all --prune
@@ -18,7 +32,7 @@ fi
# get the specified commit id # get the specified commit id
case $DFS_UPDATE_CHANNEL in case $DFS_UPDATE_CHANNEL in
"main" ) DFS_COMMIT=$(curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id) ;; "main" ) DFS_COMMIT=$(curl $DFS_CURL_OPTIONS -fsSL https://api.beardic.cn/get-var/dfs-commit-id) ;;
"dev" ) DFS_COMMIT=$(git rev-parse origin/dev 2> /dev/null) || DFS_COMMIT=$(git rev-parse origin/main) ;; "dev" ) DFS_COMMIT=$(git rev-parse origin/dev 2> /dev/null) || DFS_COMMIT=$(git rev-parse origin/main) ;;
"latest" ) DFS_COMMIT=$(git for-each-ref --sort=-committerdate refs/heads refs/remotes --format='%(objectname)' | head -n 1) ;; "latest" ) DFS_COMMIT=$(git for-each-ref --sort=-committerdate refs/heads refs/remotes --format='%(objectname)' | head -n 1) ;;
* ) fmt_fatal "invalid update channel: $DFS_UPDATE_CHANNEL" ;; * ) fmt_fatal "invalid update channel: $DFS_UPDATE_CHANNEL" ;;
@@ -35,7 +49,7 @@ if [[ "$(git rev-parse HEAD)" == "$DFS_COMMIT" ]]; then
fmt_info "nothing to do" fmt_info "nothing to do"
else else
fmt_info "checking out to commit $DFS_COMMIT ..." fmt_info "checking out to commit $DFS_COMMIT ..."
if [[ -z "$DFS_DEV" ]]; then if [[ -z "$DFS_DEV" || "$DFS_DEV" == "0" ]]; then
post_beacon "dfs.updated" post_beacon "dfs.updated"
git -c advice.detachedHead=false checkout $DFS_COMMIT git -c advice.detachedHead=false checkout $DFS_COMMIT
cp ./.update.sh ./update.sh && chmod +x ./update.sh && exit $DFS_UPDATED_RET cp ./.update.sh ./update.sh && chmod +x ./update.sh && exit $DFS_UPDATED_RET

58
.zshrc2
View File

@@ -1,6 +1,6 @@
# env for shell # env for shell
export TERM="xterm-256color" export TERM="xterm-256color"
if ( locale -a | grep -qxE "C.UTF-8|C.utf8" ); then if (command -v locale >/dev/null) && ( locale -a | grep -qxE "C.UTF-8|C.utf8" ); then
export LC_ALL=C.UTF-8 export LC_ALL=C.UTF-8
export LANG=C.UTF-8 export LANG=C.UTF-8
else else
@@ -14,17 +14,11 @@ export EDITOR='vim'
export PYTHONIOENCODING='UTF-8' export PYTHONIOENCODING='UTF-8'
export GPG_TTY=$(tty) export GPG_TTY=$(tty)
export LESS_TERMCAP_md=$'\E[01;33m' export LESS_TERMCAP_md=$'\E[01;33m'
# env for dfs
if [[ -f ~/.config/dotfiles/env ]]; then set -a; source ~/.config/dotfiles/env; set +a; fi
# antigen # antigen
if [[ -z "$DFS_NO_WALL" ]]; then if [[ "$DFS_NO_WALL" == "1" ]]; then
ANTIGEN_URL="https://gitee.com/dictxiong/antigen/raw/develop/bin/antigen.zsh"
ANTIGEN_OMZ_REPO_URL="https://gitee.com/dictxiong/ohmyzsh.git"
ANTIGEN_PLUGINS=(
"https://gitee.com/dictxiong/zsh-syntax-highlighting"
"https://gitee.com/dictxiong/zsh-completions"
"https://gitee.com/dictxiong/zsh-autosuggestions"
)
else
ANTIGEN_URL="https://raw.githubusercontent.com/zsh-users/antigen/develop/bin/antigen.zsh" ANTIGEN_URL="https://raw.githubusercontent.com/zsh-users/antigen/develop/bin/antigen.zsh"
ANTIGEN_OMZ_REPO_URL="https://github.com/ohmyzsh/ohmyzsh.git" ANTIGEN_OMZ_REPO_URL="https://github.com/ohmyzsh/ohmyzsh.git"
ANTIGEN_PLUGINS=( ANTIGEN_PLUGINS=(
@@ -32,6 +26,14 @@ else
"https://github.com/zsh-users/zsh-completions" "https://github.com/zsh-users/zsh-completions"
"https://github.com/zsh-users/zsh-autosuggestions" "https://github.com/zsh-users/zsh-autosuggestions"
) )
else
ANTIGEN_URL="https://gitee.com/dictxiong/antigen/raw/develop/bin/antigen.zsh"
ANTIGEN_OMZ_REPO_URL="https://gitee.com/dictxiong/ohmyzsh.git"
ANTIGEN_PLUGINS=(
"https://gitee.com/dictxiong/zsh-syntax-highlighting"
"https://gitee.com/dictxiong/zsh-completions"
"https://gitee.com/dictxiong/zsh-autosuggestions"
)
fi fi
ANTIGEN="$HOME/antigen.zsh" ANTIGEN="$HOME/antigen.zsh"
# Install antigen.zsh if not exist # Install antigen.zsh if not exist
@@ -77,7 +79,7 @@ done
# select theme # select theme
TMP_THEME=ys TMP_THEME=ys
if [[ -e /.dockerenv ]]; then if [[ -e /.dockerenv ]]; then
TMP_THEME=blinks TMP_THEME=robbyrussell
echo "===========================" echo "==========================="
echo "This is in docker container" echo "This is in docker container"
echo "===========================" echo "==========================="
@@ -88,10 +90,12 @@ antigen apply
# end of antigen config # end of antigen config
# beacon # beacon
if [[ -z "$DFS_INITED" && -z "$CI" ]]; then
if [[ "$EUID" == "0" ]]; then if [[ "$EUID" == "0" ]]; then
"$DOTFILES/tools/common.sh" apost_beacon "sys.login.root" "$DOTFILES/tools/common.sh" apost_beacon "sys.login.root" "$(who am i | sed -E 's/ +/ /g' | awk '$1=$1')" 2>/dev/null
else else
"$DOTFILES/tools/common.sh" apost_beacon "sys.login.user" "$DOTFILES/tools/common.sh" apost_beacon "sys.login.user" "$(who am i | sed -E 's/ +/ /g' | awk '$1=$1')" 2>/dev/null
fi
fi fi
# alias # alias
@@ -100,6 +104,9 @@ alias "se"='sudo -sE'
alias "pbd"='ping baidu.com' alias "pbd"='ping baidu.com'
alias "p114"='ping 114.114.114.114' alias "p114"='ping 114.114.114.114'
alias "p666"='ping6 2001:da8::666' alias "p666"='ping6 2001:da8::666'
alias "cbd"='curl http://www.baidu.com'
alias "cbds"='curl https://www.baidu.com'
alias "gdebug"='git add -A; git commit --allow-empty -m "bug fix ($(date))"'
case $(bash "$DOTFILES/tools/common.sh" get_os_type) in case $(bash "$DOTFILES/tools/common.sh" get_os_type) in
macos ) alias l='ls -lAGh -D "%y-%m-%d %H:%M"' ;; macos ) alias l='ls -lAGh -D "%y-%m-%d %H:%M"' ;;
* ) alias l='ls -lAGh --time-style="+%y-%m-%d %H:%M"' ;; * ) alias l='ls -lAGh --time-style="+%y-%m-%d %H:%M"' ;;
@@ -107,28 +114,8 @@ esac
if [[ -x $(command -v trash) ]]; then if [[ -x $(command -v trash) ]]; then
alias "rm"="echo use the full path i.e. '/bin/rm'\; consider using trash" alias "rm"="echo use the full path i.e. '/bin/rm'\; consider using trash"
fi fi
sibd() { ssh -p 12022 root@$1${1:+.}ibd.ink }
sob() { ssh -p 24022 root@$1${1:+.}ob.ac.cn }
snasp() { ssh -o ProxyJump="ssh@nasp.ob.ac.cn:36022" dictxiong@$1 }
gbes() { git for-each-ref --sort=-committerdate refs/heads refs/remotes --format="%(authordate:format:%y-%m-%d.%a %H:%M %z)|%(color:red)%(objectname:short)|%(color:yellow)%(refname:short)%(color:reset)|%(color:reset)%(authorname): %(color:green)%(subject)" --color=always | column -ts"|" | less -FX } gbes() { git for-each-ref --sort=-committerdate refs/heads refs/remotes --format="%(authordate:format:%y-%m-%d.%a %H:%M %z)|%(color:red)%(objectname:short)|%(color:yellow)%(refname:short)%(color:reset)|%(color:reset)%(authorname): %(color:green)%(subject)" --color=always | column -ts"|" | less -FX }
piv-agent() sagt() { eval "$($DOTFILES/tools/sagent.sh $@)" }
{
eval $(ssh-agent -k)
# they are: ubuntu, macos, respectively
local SO_PATHS=( "/usr/lib64/opensc-pkcs11.so" "/usr/local/lib/opensc-pkcs11.so" )
for i in ${SO_PATHS[*]}; do
if [[ -f "$i" ]]; then
echo "using: $i"
eval $(ssh-agent -P "$i")
ssh-add -s "$i"
echo "now available keys:"
ssh-add -l
return 0
fi
done
echo "opensc-pkcs11.so not found"
return 1
}
# key bindings # key bindings
bindkey "^b" beginning-of-line # ctrl+b bindkey "^b" beginning-of-line # ctrl+b
@@ -182,10 +169,11 @@ dfs()
echo 'Done. Please open a new shell to see the changes.' echo 'Done. Please open a new shell to see the changes.'
;; ;;
log ) "$DOTFILES/tools/common.sh" "post_log" "INFO" "dfs" "$2" ;; log ) "$DOTFILES/tools/common.sh" "post_log" "INFO" "dfs" "$2" ;;
beacon ) "$DOTFILES/tools/common.sh" "post_beacon" "$2" ;; beacon ) "$DOTFILES/tools/common.sh" "post_beacon" "$2" "$3" ;;
* ) echo "unknown command \"$1\". available: update, force-update, version, reset, cd, log" ;; * ) echo "unknown command \"$1\". available: update, force-update, version, reset, cd, log" ;;
esac esac
} }
# clean # clean
unset i unset i
export DFS_INITED=1

View File

@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
set -e
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd ) THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/tools/common.sh" source "$THIS_DIR/tools/common.sh"
@@ -10,6 +10,7 @@ fi
DOTFILE_TILDE=${DOTFILES/"$HOME"/\~} DOTFILE_TILDE=${DOTFILES/"$HOME"/\~}
CRON_JOB="0 * * * * ${DOTFILES}/update.sh" CRON_JOB="0 * * * * ${DOTFILES}/update.sh"
declare -a DFS_CONFIGS
declare -a HOME_FILES_PATH declare -a HOME_FILES_PATH
declare -a HOME_FILES_CONTENT declare -a HOME_FILES_CONTENT
HOME_FILES_PATH[0]=".zshrc" HOME_FILES_PATH[0]=".zshrc"
@@ -28,22 +29,32 @@ HOME_SYMLINKS_DST[0]=".ssh/authorized_keys2"
install_dependencies() install_dependencies()
{ {
local ret=0
fmt_note "installing dependencies ..." fmt_note "installing dependencies ..."
set +e
case $(get_os_name) in case $(get_os_name) in
"ubuntu"|"debian" ) "ubuntu"|"debian" )
$SUDO DFS_LITE=$DFS_LITE "$DOTFILES/tools/ubuntu.sh" apt-install $SUDOE "$DOTFILES/tools/ubuntu.sh" apt-install
ret=$?
;; ;;
"alpine" ) "alpine" )
$SUDO DFS_LITE=$DFS_LITE "$DOTFILES/tools/alpine.sh" apk-add $SUDOE "$DOTFILES/tools/alpine.sh" apk-add
ret=$?
;; ;;
"macos" ) "macos" )
DFS_LITE=$DFS_LITE "$DOTFILES/tools/macos.sh" brew-install "$DOTFILES/tools/macos.sh" brew-install
ret=$?
;; ;;
"msys" ) "msys" )
DFS_LITE=$DFS_LITE "$DOTFILES/tools/msys2.sh" pacman-S "$DOTFILES/tools/msys2.sh" pacman-S
ret=$?
;; ;;
* ) fmt_error "dfs auto-install is not implemented on OS: $(get_os_name)" * ) fmt_error "dfs auto-install is not implemented on OS: $(get_os_name). skipping ..."
esac esac
set -e
if [[ "$ret" != "0" ]]; then
fmt_error "failed to install dependencies."
fi
} }
preinstall_check() preinstall_check()
@@ -61,8 +72,8 @@ preinstall_check()
for i in "${optional_commands[@]}"; do for i in "${optional_commands[@]}"; do
if ! command -v $i 1>/dev/null; then if ! command -v $i 1>/dev/null; then
fmt_warning "\"$i\" not found" fmt_warning "\"$i\" not found"
ask_for_Yn "continue anyway?" yn=$(ask_for_Yn "continue anyway?")
if [[ "$?" == "0" ]]; then if [[ "$yn" == "0" ]]; then
fmt_info "all this utils are suggested: ${optional_commands[@]}" fmt_info "all this utils are suggested: ${optional_commands[@]}"
fmt_info "install them manually or check scripts in tools/" fmt_info "install them manually or check scripts in tools/"
fmt_fatal "aborting ..." fmt_fatal "aborting ..."
@@ -71,12 +82,45 @@ preinstall_check()
done done
} }
prepare_config()
{
local remote=$(cd "$DOTFILES" && git remote get-url origin)
if [[ -z "$DFS_NO_WALL" && $remote == *github* ]]; then
DFS_CONFIGS+=("DFS_NO_WALL=1")
fi
if [[ ${#DFS_CONFIGS[@]} == 0 ]]; then
return
fi
fmt_note "preparing dotfiles configurations ..."
local key value
for i in "${DFS_CONFIGS[@]}"; do
if [[ "$i" == *"="* ]]; then
key=${i%%=*}
value=${i#*=}
else
key=$i
value=$(eval echo \$$key)
fi
HOME_FILES_PATH+=(".config/dotfiles/env")
HOME_FILES_CONTENT+=("$key=$value")
echo -n "$key=$value "
export $key=$value
done
echo
}
append_hist()
{
fmt_note "appending zsh history ..."
"$DOTFILES/tools/append_zsh_hist.sh" "$@"
}
install_file_content() install_file_content()
{ {
fmt_note "installing file content ..." fmt_note "installing file content ..."
for ((i=0; i<${#HOME_FILES_PATH[@]}; i++)); do for ((i=0; i<${#HOME_FILES_PATH[@]}; i++)); do
local filename="$HOME/${HOME_FILES_PATH[$i]}" local filename="$HOME/${HOME_FILES_PATH[$i]}"
local content=${HOME_FILES_CONTENT[$i]} local content="${HOME_FILES_CONTENT[$i]}"
fmt_info "installing \"$content\" into \"$filename\" ..." fmt_info "installing \"$content\" into \"$filename\" ..."
mkdir -p $(dirname "$filename") mkdir -p $(dirname "$filename")
if [ ! -f "$filename" ]; then if [ ! -f "$filename" ]; then
@@ -119,8 +163,8 @@ install_symlink()
echo ---------- echo ----------
stat $dst stat $dst
echo ---------- echo ----------
ask_for_yN "would you like to replace ${dst}?" yn=$(ask_for_yN "would you like to replace ${dst}?")
if [ $? -eq 1 ]; then if [[ "$yn" == "1" ]]; then
rm $dst rm $dst
else else
fmt_error "aborting this job ..." fmt_error "aborting this job ..."
@@ -206,11 +250,16 @@ install_update()
cp "${DOTFILES}/.update.sh" "${DOTFILES}/update.sh" cp "${DOTFILES}/.update.sh" "${DOTFILES}/update.sh"
chmod +x "${DOTFILES}/update.sh" chmod +x "${DOTFILES}/update.sh"
fmt_note "running update.sh ..." fmt_note "running update.sh ..."
set +e
DFS_UPDATED_RET=85 ${DOTFILES}/update.sh DFS_UPDATED_RET=85 ${DOTFILES}/update.sh
if [[ $? == 85 ]]; then RET=$?
if [[ $RET == 85 ]]; then
fmt_note "dfs updated. re-running install.sh ..." fmt_note "dfs updated. re-running install.sh ..."
"${DOTFILES}/install.sh" "$ORIGIN_ARGS" && exit "${DOTFILES}/install.sh" "${ORIGIN_ARGS[@]}" && exit
elif [[ $RET != 0 ]]; then
fmt_fatal "update.sh failed with exit code $RET"
fi fi
set -e
} }
uninstall_update() uninstall_update()
@@ -222,6 +271,7 @@ uninstall_update()
install() install()
{ {
if [[ "$INSTALL_DEP" == "1" ]]; then install_dependencies; fi if [[ "$INSTALL_DEP" == "1" ]]; then install_dependencies; fi
prepare_config
install_update install_update
preinstall_check preinstall_check
install_crontab install_crontab
@@ -231,15 +281,15 @@ install()
# those that won't be uninstalled in the future # those that won't be uninstalled in the future
install_tmux_tpm install_tmux_tpm
install_vim_vundle install_vim_vundle
if [[ -n "$DFS_HIST" ]]; then append_hist "$DFS_HIST"; fi
fmt_note "done installing!" fmt_note "done installing!"
} }
uninstall() uninstall()
{ {
ask_for_yN "do you really want to uninstall?" yn=$(ask_for_yN "do you really want to uninstall?")
if [[ $? != 1 ]]; then if [[ "$yn" != "1" ]]; then
fmt_error "aborting this job ..." fmt_fatal "aborting this job ..."
return
fi fi
uninstall_update uninstall_update
uninstall_crontab uninstall_crontab
@@ -249,19 +299,30 @@ uninstall()
fmt_note "done uninstalling!" fmt_note "done uninstalling!"
} }
ORIGIN_ARGS="$@" echo "this is the dotfiles installer, version $(cd "$DOTFILES" && git describe --tags --always --dirty)"
parse_arg "$@" echo "install options:" "${GOT_OPTS[@]}"
FUNC=install FUNC=install
INSTALL_DEP=0 INSTALL_DEP=0
for i in ${PARSE_ARG_RET[@]}; do store_config=0
store_hist=0
for i in ${GOT_OPTS[@]}; do
if [[ "$store_config" == "1" ]]; then
store_config=0
DFS_CONFIGS+=("$i")
continue
fi
if [[ "$store_hist" == "1" ]]; then
store_hist=0
DFS_HIST=$i
continue
fi
case $i in case $i in
-i ) FUNC=install ;; -i ) FUNC=install ;;
-r ) FUNC=uninstall ;; -r ) FUNC=uninstall ;;
-d|--dev ) export DFS_DEV=1 ;;
-l|--lite ) export DFS_LITE=1 ;;
-a|--auto ) INSTALL_DEP=1 ;; -a|--auto ) INSTALL_DEP=1 ;;
-s|--secure ) export DFS_DEV=0 ;; -H|--hist|--history ) store_hist=1 ;;
* ) fmt_fatal "unknown option \"$i\". available: -i, -r, -q, -d, -l, -a, -s" ;; -x ) store_config=1 ;;
* ) fmt_fatal "unknown option \"$i\"" ;;
esac esac
done done
$FUNC $FUNC

View File

@@ -25,6 +25,6 @@ fi
if [[ -z "$CONTAINER" ]]; then if [[ -z "$CONTAINER" ]]; then
fmt_fatal "container not found" fmt_fatal "container not found"
else else
echo "--> ${CONTAINER_META[@]}" fmt_note "--> ${CONTAINER_META[@]}"
$SUDO docker exec -it $CONTAINER sh -c 'export DFS="bash <(curl dfs.beardic.cn) -a"; if [ -x "$(command -v zsh)" ]; then echo "--> zsh"; unset DFS; zsh; elif [ -x "$(command -v bash)" ]; then echo "--> bash"; bash; else echo "--> sh"; sh; fi' $SUDO docker exec -it $CONTAINER sh -c 'export DFS="bash <(curl dfs.beardic.cn) -a"; if [ -x "$(command -v zsh)" ]; then echo "--> zsh"; unset DFS; zsh; elif [ -x "$(command -v bash)" ]; then echo "--> bash"; bash; else echo "--> sh"; sh; fi'
fi fi

View File

@@ -20,6 +20,6 @@ fi
if [[ -z "$IMAGE" ]]; then if [[ -z "$IMAGE" ]]; then
fmt_fatal "image not found" fmt_fatal "image not found"
else else
echo "--> ${IMAGE_META[@]}" fmt_note "--> ${IMAGE_META[@]}"
$SUDO docker run ${2:+"--name"} $2 -itd $IMAGE sh $SUDO docker run ${2:+"--name"} $2 -itd $IMAGE sh
fi fi

44
scripts/pbin Executable file
View File

@@ -0,0 +1,44 @@
#!/bin/bash
set -e
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/../tools/common.sh"
get()
{
local key=$1
if [[ -z "$key" ]]; then
fmt_fatal "missing key"
fi
local output=${2:-/dev/stdout}
local url="https://pastebin.com/raw/$key"
curl -fsSL "$url" > "$output"
}
put()
{
local input=${1:-/dev/stdin}
(echo -n api_paste_code=; cat "$input") | curl -fsSL -X POST -d 'api_dev_key=SKZLfq9y_zW2hkgQOKZz1b5rw8hGiqxZ' -d 'api_option=paste' --data-binary @- "https://pastebin.com/api/api_post.php"
}
route()
{
local cmd=$1
if [[ -z "$cmd" ]]; then
put
exit
else
shift
fi
case $cmd in
get )
get "$@"
;;
put )
put "$@"
;;
* )
fmt_fatal "unknown command: $cmd"
esac
}
route "${GOT_OPTS[@]}"

221
scripts/riot Executable file
View File

@@ -0,0 +1,221 @@
#!/bin/bash
# connect to iot services
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}
# get single server setting
# may be called more than once
get_server_meta() {
# returns:
RET_HOSTNAME=""
RET_TRUST_SERVER=0
RET_PORT="" # optional
RET_USERNAME="" # optional
RET_JUMP_SERVER="" # optional
# body
local remote="$1"
# if in the form user@...
if [[ "$remote" == *@* ]]; then
RET_USERNAME=${remote%%@*}
remote=${remote#*@}
fi
# if in the form ...:22
if [[ "$remote" == *:* ]]; then
RET_PORT=${remote##*:}
remote=${remote%:*}
fi
# presets -- match domain
local domain=${remote##*.}
local host=${remote%.*}
# if there's no dot
if [[ "$host" == "$domain" ]]; then
domain="ibd"
fi
case $domain in
ibd|ebd )
RET_HOSTNAME=$host.$domain.ink
RET_PORT=${RET_PORT:-12022}
RET_USERNAME=${RET_USERNAME:-root}
RET_TRUST_SERVER=1
;;
nasp )
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
;;
x|proxied )
RET_HOSTNAME=proxy.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
;;
* )
test -z "$domain" || fmt_warning "unknown domain: \"$domain\". will try as host name"
RET_HOSTNAME="$remote"
esac
}
# remote setting, including jump servers
# will be called only once
# provides:
SERVER=""
TRUST_SERVER=1
PORT="" # optional
USERNAME="" # optional
SSH_OPTIONS="" # optional
if [[ "$RIOT_TRUST_CLIENT" == "1" ]]; then
SSH_OPTIONS='-o ControlMaster=auto -o ControlPath=/tmp/sshcm-%C -o PermitLocalCommand=yes'
fi
parse_remote() {
local remote="$1"
local jump_servers=""
# loop for jump servers
while [[ -n $remote ]]; do
local server=${remote%%,*}
remote=${remote#*,}
get_server_meta "$server"
if [[ -n "$RET_JUMP_SERVER" ]]; then
jump_servers="$jump_servers${jump_servers:+,}$RET_JUMP_SERVER"
fi
# only if all servers are trusted
TRUST_SERVER=$((TRUST_SERVER*RET_TRUST_SERVER))
if [[ "$server" == "$remote" || -z "$remote" ]]; then
SERVER="$RET_HOSTNAME"
PORT="$RET_PORT"
USERNAME="$RET_USERNAME"
remote=""
else
jump_servers="$jump_servers${jump_servers:+,}$RET_USERNAME${RET_USERNAME:+@}$RET_HOSTNAME${RET_PORT:+:}$RET_PORT"
fi
done
# construct cmd
if [[ "$RIOT_TRUST_SERVER" == "1" || "$TRUST_SERVER" == "1" ]]; then
SSH_OPTIONS="$SSH_OPTIONS -o ForwardX11=yes -o ForwardAgent=yes"
fi
if [[ -n "$jump_servers" ]]; then
SSH_OPTIONS="$SSH_OPTIONS -o ProxyJump=$jump_servers"
fi
}
eval_or_echo() {
if [[ "$DFS_DRY_RUN" == "1" ]]; then
echo $@
else
eval $@
fi
}
# ssh series
prepare_ssh_cmd() {
local ssh_bin="${1:-ssh}"
if [[ "$ssh_bin" == "scp" || "$ssh_bin" == "sftp" ]]; then
local port_param='-P'
else
local port_param='-p'
fi
echo "$ssh_bin ${PORT:+$port_param} $PORT $SSH_OPTIONS $SCP_SRC $USERNAME${USERNAME:+@}$SERVER $SCP_DST"
}
# ssh
run_ssh()
{
local cmd="$(prepare_ssh_cmd $1)"
fmt_note "-->" $cmd
eval_or_echo $cmd
}
# sshl
run_sshl()
{
local arg="$1"
if [[ "$arg" != *":"* ]]; then
# treat as a port number
arg=localhost:$arg
fi
while
local port=$(shuf -n 1 -i 49152-65535)
netstat -atun | grep -q "$port"
do
continue
done
SSH_OPTIONS="$SSH_OPTIONS -NC -L $port:$arg"
local cmd="$(prepare_ssh_cmd ssh)"
fmt_note "-->" $cmd
fmt_note " > please access localhost:$port"
eval_or_echo $cmd
}
# scp
run_scp() {
local src="$1"
local dst="$2"
local dst_is_remote=1
# whoever is ./*, it can't be the remote; whoever not exists on local, it's possible the remote.
# it is suggested to use ./* for local files.
if [[ "$src" != "./"* && ( "$dst" == "./"* || ( ! -e "$src" && -e "$dst" ) ) ]]; then
dst_is_remote=0
fi
if [[ "$dst_is_remote" == "1" ]]; then
SCP_SRC=\""$src"\"
SERVER="$SERVER":\""$dst"\"
else
SERVER="$SERVER":\""$src"\"
SCP_DST=\""$dst"\"
fi
SSH_OPTIONS="$SSH_OPTIONS -r"
local cmd="$(prepare_ssh_cmd scp)"
fmt_note "-->" $cmd
eval_or_echo $cmd
}
# main
print_help()
{
fmt_info "usage: $0 <service> [command] [options]"
echo "available commands: ssh (default), sshl (ssh -L), zssh, sftp"
}
router() {
if [[ -z "$1" || "$1" == "-h" || "$1" == "--help" ]]; then
print_help
exit
fi
parse_remote "$1"
case $2 in
-h|--help)
print_help
exit
;;
ssh|"" )
run_ssh
;;
zssh )
run_ssh zssh
;;
sftp )
run_ssh sftp
;;
sshl )
test -n "$3" || fmt_fatal "no target address provided"
run_sshl "$3"
;;
scp )
test -n "$3" || fmt_fatal "no source path specified"
test -n "$4" || fmt_fatal "no destination path specified"
run_scp "$3" "$4"
;;
* )
print_help
fmt_fatal "unknown command: $2"
;;
esac
}
router "${GOT_OPTS[@]}"

View File

@@ -15,7 +15,7 @@ apk_add()
# lite # lite
apk add zsh bash git tmux vim curl fzf iputils coreutils util-linux apk add zsh bash git tmux vim curl fzf iputils coreutils util-linux
# full # full
if [[ -z "$DFS_LITE" ]]; then if [[ -z "$DFS_LITE" || "$DFS_LITE" == "0" ]]; then
apk add wget python3 py3-pip htop gcc g++ cmake make perl linux-headers bind-tools man-db apk add wget python3 py3-pip htop gcc g++ cmake make perl linux-headers bind-tools man-db
fi fi
} }
@@ -34,8 +34,8 @@ router()
apk-add ) apk_add ;; apk-add ) apk_add ;;
set-timezone | set-tz ) set_timezone ;; set-timezone | set-tz ) set_timezone ;;
set-mirror ) set_mirror $2 ;; set-mirror ) set_mirror $2 ;;
* ) echo unknown command "$1". available: apk-add, set-timezone;; * ) echo unknown command \"$1\". available: apk-add, set-timezone;;
esac esac
} }
router $@ router "${GOT_OPTS[@]}"

33
tools/append_zsh_hist.sh Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/bash
set -e
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/common.sh"
zsh_hist_file="$HOME/.zsh_history"
do_append()
{
timestamp=$(date +%s)
while read -r line; do
if [[ -n "$line" ]]; then
echo ": $timestamp:0;$line" >> "$zsh_hist_file"
fi
done
}
main()
{
key=$1
if [[ -z "$key" ]]; then
fmt_fatal "missing key"
fi
IFS=',' read -r -a keys<<<"$key"
for k in "${keys[@]}";do
if [[ -z "$k" ]]; then
continue
fi
(curl -fsSL "https://pastebin.com/raw/$k" && echo) | sed 's/\r//' | do_append
done
}
main "${GOT_OPTS[@]}"

View File

@@ -1,12 +1,44 @@
#!/bin/bash #!/bin/bash
set -e
THIS_DIR_COMMON_SH=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd ) THIS_DIR_COMMON_SH=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
export DOTFILES=$( cd "$THIS_DIR_COMMON_SH/.." && pwd ) export DOTFILES=$( cd "$THIS_DIR_COMMON_SH/.." && pwd )
if [[ -f ~/.config/dotfiles/env ]]; then source ~/.config/dotfiles/env; fi if [[ -f ~/.config/dotfiles/env ]]; then set -a; source ~/.config/dotfiles/env; set +a; fi
if [[ "$DFS_DEV" == "1" ]]; then set -x; fi
DFS_CURL_OPTIONS="--retry 2 --max-time 20"
# parse args and set env, when it is sourced
# todo: make this skipable
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
ORIGIN_ARGS=("$@")
ARG=""
GOT_OPTS=()
while [[ $# > 0 || -n "$ARG" ]]; do
if [[ -z "$ARG" ]]; then ARG=$1; shift; fi
case $ARG in
-q*|--quite ) export DFS_QUIET=1 ;;
-l*|--lite ) export DFS_LITE=1 ;;
-d*|--dev ) export DFS_DEV=1; set -x ;;
-D*|--dry-run ) export DFS_DRY_RUN=1 ;;
--color ) export DFS_COLOR=1 ;;
--*=* ) GOT_OPTS+=("${ARG%%=*}" "${ARG#*=}") ;;
--* ) GOT_OPTS+=("$ARG") ;;
-* ) GOT_OPTS+=("${ARG:0:2}") ;;
* ) GOT_OPTS+=("$ARG") ;;
esac
if [[ "$ARG" == "--"* || ! "$ARG" == "-"* || ${#ARG} -le 2 ]]; then
ARG=""
else
ARG=-${ARG:2}
fi
done
set -- "${ORIGIN_ARGS[@]}"
unset ARG
# outputs: GOT_OPTS and ORIGIN_ARGS
fi
# Color settings # Color settings
# Source: https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh # Source: https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
if [ -t 1 ]; then if [[ -t 1 || "$DFS_COLOR" == "1" ]]; then
is_tty() { is_tty() {
true true
} }
@@ -46,11 +78,11 @@ fmt_warning() {
} }
fmt_info() { fmt_info() {
printf '%sinfo: %s\n' "${FMT_RESET}" "$*" >&1 printf '%sinfo: %s\n' "${FMT_RESET}" "$*" >&2
} }
fmt_note() { fmt_note() {
printf '%s%s%s\n' "${FMT_GREEN}" "$*" "${FMT_RESET}" >&1 printf '%s%s%s\n' "${FMT_GREEN}" "$*" "${FMT_RESET}" >&2
} }
setup_color() { setup_color() {
@@ -98,52 +130,36 @@ setup_color() {
# END of color settings # END of color settings
SUDO='' SUDO=''
SUDOE=''
if [[ "$EUID" != "0" && -x $(command -v sudo) ]]; then if [[ "$EUID" != "0" && -x $(command -v sudo) ]]; then
SUDO='sudo' SUDO='sudo'
SUDOE='sudo -E'
fi fi
parse_arg()
{
local ARG=""
PARSE_ARG_RET=()
while [[ $# > 0 || -n "$ARG" ]]; do
if [[ -z "$ARG" ]]; then ARG=$1; shift; fi
case $ARG in
-q*|--quite ) export DFS_QUIET=1 ;;
--* ) PARSE_ARG_RET+=("$ARG") ;;
-* ) PARSE_ARG_RET+=("${ARG:0:2}") ;;
* ) PARSE_ARG_RET+=("$ARG") ;;
esac
if [[ "$ARG" == "--"* || ! "$ARG" == "-"* || ${#ARG} -le 2 ]]; then
ARG=""
else
ARG=-${ARG:2}
fi
done
}
ask_for_yN() ask_for_yN()
{ {
while [[ -z "$DFS_QUIET" || "$DFS_QUIET" == "0" ]]; do if [[ "$DFS_QUIET" == "1" ]]; then
echo 0
else
read -p "${FMT_YELLOW}$1${FMT_RESET} [yN]: " yn read -p "${FMT_YELLOW}$1${FMT_RESET} [yN]: " yn
case $yn in case $yn in
[Yy]* ) return 1;; [Yy]* ) echo 1;;
* ) return 0;; * ) echo 0;;
esac esac
done fi
return 0
} }
ask_for_Yn() ask_for_Yn()
{ {
while [[ -z "$DFS_QUIET" || "$DFS_QUIET" == "0" ]]; do if [[ "$DFS_QUIET" == "1" ]]; then
echo 1
else
read -p "${FMT_YELLOW}$1${FMT_RESET} [Yn]: " yn read -p "${FMT_YELLOW}$1${FMT_RESET} [Yn]: " yn
case $yn in case $yn in
[Nn]* ) return 0;; [Nn]* ) echo 0;;
* ) return 1;; * ) echo 1;;
esac esac
done fi
return 1
} }
post_log() post_log()
@@ -151,7 +167,7 @@ post_log()
if [[ $# != 3 || -z "$1" || -z "$2" || -z "$3" ]]; then if [[ $# != 3 || -z "$1" || -z "$2" || -z "$3" ]]; then
fmt_fatal "usage: post_log <level> <section> <content>" fmt_fatal "usage: post_log <level> <section> <content>"
fi fi
"${DOTFILES}/tools/logger.sh" "log" "[$1][$2] $3" "${DOTFILES}/tools/frigg-client.sh" "log" "[$1][$2] $3"
} }
apost_log() apost_log()
@@ -161,10 +177,10 @@ apost_log()
post_beacon() post_beacon()
{ {
if [[ $# != 1 || -z "$1" ]]; then if [[ $# < 1 || -z "$1" ]]; then
fmt_fatal "usage: post_beacon <beacon>" fmt_fatal "usage: post_beacon <beacon>"
fi fi
"${DOTFILES}/tools/logger.sh" "beacon" "$1" "${DOTFILES}/tools/frigg-client.sh" "beacon" "$1" "$2"
} }
apost_beacon() apost_beacon()

165
tools/frigg-client.sh Executable file
View File

@@ -0,0 +1,165 @@
#!/bin/bash
set -e
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/common.sh"
if [[ "$DFS_ORPHAN" == "1" ]]; then
exit 0
fi
if [[ -n "$DFS_HOSTNAME" ]]; then
hostname=$DFS_HOSTNAME
elif [[ -x $(command -v hostname) ]]; then
hostname=$(hostname)
elif [[ -x $(command -v uname) ]]; then
hostname=$(uname -n)
elif [[ -x $(command -v hostnamectl) ]]; then
hostname=$(hostnamectl --static)
elif [[ -n "$HOSTNAME" ]]; then
hostname=$HOSTNAME
elif [[ -f /proc/sys/kernel/hostname ]]; then
hostname=$(cat /proc/sys/kernel/hostname)
elif [[ -f /etc/hostname ]]; then
hostname=$(cat /etc/hostname)
else
fmt_fatal "unable to get hostname"
fi
init_uuid()
{
if [[ -f ~/.config/dotfiles/uuid ]]; then
uuid=$(cat ~/.config/dotfiles/uuid)
else
if [[ -x $(command -v uuidgen) ]]; then
uuid=$(uuidgen)
elif [[ -f /proc/sys/kernel/random/uuid ]]; then
uuid=$(cat /proc/sys/kernel/random/uuid)
else
fmt_fatal "unable to generate uuid"
fi
mkdir -p ~/.config/dotfiles
echo "$uuid" > ~/.config/dotfiles/uuid
fi
}
handle_resp()
{
local resp="$1"
if grep -q "200" <<< "$resp"; then
echo $resp
elif grep -q "403" <<< "$resp"; then
echo $resp >&2
fmt_error "error accessing api: authentification failed"
fmt_info "try to register you hostname and uuid"
fmt_info "hostname: $hostname"
fmt_info "uuid: $uuid"
else
echo $resp >&2
fmt_fatal "server returned an error"
# here return 1 because this is not expected
fi
}
post_beacon()
{
local beacon_type=$1
local meta=$2
if [[ -n "$CI" && "$beacon_type" != "gh.ci" && "$beacon_type" != "dfs.invalid-commit" && "$beacon_type" != "dfs.dirty" ]]; then
return
fi
if [[ -z "$beacon_type" ]]; then
fmt_fatal "beacon type is required"
fi
resp=$(curl $DFS_CURL_OPTIONS -sSL -X POST -H "Content-Type: text/plain" -d "$meta" "https://api.beardic.cn/post-beacon?hostname=$hostname&beacon=$beacon_type")
handle_resp "$resp"
}
post_log()
{
local log_content=$1
if [[ -z "$log_content" ]]; then
fmt_fatal "log content is required"
fi
init_uuid
resp=$(curl $DFS_CURL_OPTIONS -sSL -X POST -H "Content-Type: text/plain" -d "$log_content" "https://api.beardic.cn/post-log?hostname=$hostname&uuid=$uuid")
handle_resp "$resp"
}
update_dns()
{
if [[ -z "$DFS_DDNS_IP4$DFS_DDNS_IP6" ]]; then
fmt_fatal "neither DFS_DDNS_IP4 nor DFS_DDNS_IP6 is configured"
fi
if [[ "$DFS_DDNS_IP4$DFS_DDNS_IP6" == "autoauto" ]]; then
fmt_fatal "DFS_DDNS_IP4 and DFS_DDNS_IP6 cannot both be auto"
fi
init_uuid
local ip4
local ip6
local api_url="https://api.beardic.cn"
# get ip4
if [[ -z "$DFS_DDNS_IP4" ]]; then
ip4=""
elif [[ "$DFS_DDNS_IP4" == "auto" ]]; then
ip4="auto"
elif [[ "$DFS_DDNS_IP4" == "api" ]]; then
ip4=$(curl $DFS_CURL_OPTIONS -sSL "https://api.ipify.org")
elif [[ "$DFS_DDNS_IP4" == "http"* ]]; then
ip4=$(curl $DFS_CURL_OPTIONS -sSL "$DFS_DDNS_IP4")
else
ip4=$(ip a show $DFS_DDNS_IP4 | grep inet | grep global | awk '/inet / {print $2}' | awk -F'[/]' '{print $1}')
fi
if [[ -n "$DFS_DDNS_IP4" && -z "$ip4" ]]; then
fmt_fatal "failed getting ip4 address"
fi
# get ip6
if [[ -z "$DFS_DDNS_IP6" ]]; then
ip6=""
elif [[ "$DFS_DDNS_IP6" == "auto" ]]; then
ip6="auto"
api_url="https://api6.beardic.cn"
elif [[ "$DFS_DDNS_IP6" == "api" ]]; then
ip6=$(curl $DFS_CURL_OPTIONS -sSL "https://api6.ipify.org")
elif [[ "$DFS_DDNS_IP6" == "http"* ]]; then
ip6=$(curl $DFS_CURL_OPTIONS -sSL "$DFS_DDNS_IP6")
else
ip6=$(ip a show $DFS_DDNS_IP6 | grep inet6 | grep global | awk '/inet6 / {print $2}' | awk -F'[/]' '{print $1}')
fi
if [[ -n "$DFS_DDNS_IP6" && -z "$ip6" ]]; then
fmt_fatal "failed getting ip6 address"
fi
# update dns
fmt_note "updating dns record for $hostname with ip4=$ip4 ip6=$ip6"
resp=$(curl $DFS_CURL_OPTIONS -sSL "$api_url/update-dns?hostname=$hostname&uuid=$uuid&ip4=$ip4&ip6=$ip6")
handle_resp "$resp"
}
print_help()
{
fmt_info "usage: $0 <beacon|log|ddns> [beacon_type|log_content]"
}
router()
{
case "$1" in
-h|--help)
print_help
;;
beacon)
post_beacon "$2" "$3"
;;
log)
post_log "$2"
;;
ddns)
update_dns
;;
*)
print_help
fmt_fatal "invalid argument"
;;
esac
}
router "${GOT_OPTS[@]}"

63
tools/get.dotfiles.cn Normal file
View File

@@ -0,0 +1,63 @@
#!/bin/bash
set -e
ARG=""
GOT_OPTS=()
DFS_USER="$(whoami)"
while [[ $# > 0||-n "$ARG" ]];do
if [[ -z "$ARG" ]];then ARG=$1;shift;fi
case $ARG in
-s*|--secure)DFS_SECURE=1;;
-u*|--user)if [[ "$ARG" == --*=* ]];then
DFS_USER="${ARG#*=}"
else
DFS_USER=$1
shift
fi
if [[ -z "$DFS_USER" ]];then
echo "install user is required"
exit 1
fi;;
--*=*)GOT_OPTS+=("${ARG%%=*}" "${ARG#*=}");;
--*)GOT_OPTS+=("$ARG");;
-*)GOT_OPTS+=("${ARG:0:2}");;
*)GOT_OPTS+=("$ARG");;
esac
if [[ "$ARG" == "--"*||! "$ARG" == "-"*||${#ARG} -le 2 ]];then
ARG=""
else
ARG=-${ARG:2}
fi
done
IFS=',' read -r -a DFS_USERS<<<"$DFS_USER"
for u in "${DFS_USERS[@]}";do
if [[ -z "$u" ]];then
continue
fi
if ! id -u "$u" >/dev/null 2>&1;then
echo "user $u not exists"
exit 1
fi
if [[ "$u" == "$(whoami)" ]];then
SUCMD="bash"
else
SUCMD="su $u"
fi
echo "install for user $u in 3 seconds ..."
sleep 3
$SUCMD<<EOF
set -e
cd
if [[ ! -f ~/dotfiles/install.sh ]];then
git clone ${repo}
fi
if [[ "$DFS_SECURE" == "1" ]];then
echo "enter secure mode"
cd dotfiles
git fetch --all
git -c advice.detachedHead=false checkout $(curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id)
cd
fi
./dotfiles/install.sh ${GOT_OPTS[@]}
zsh -c "source ~/.zshrc"
EOF
done

View File

@@ -1,100 +0,0 @@
#!/bin/bash
set -e
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/common.sh"
if [[ -x $(command -v hostname) ]]; then
hostname=$(hostname)
elif [[ -x $(command -v uname) ]]; then
hostname=$(uname -n)
elif [[ -x $(command -v hostnamectl) ]]; then
hostname=$(hostnamectl --static)
elif [[ -n "$HOSTNAME" ]]; then
hostname=$HOSTNAME
elif [[ -f /proc/sys/kernel/hostname ]]; then
hostname=$(cat /proc/sys/kernel/hostname)
elif [[ -f /etc/hostname ]]; then
hostname=$(cat /etc/hostname)
else
fmt_fatal "unable to get hostname"
fi
init_uuid()
{
if [[ -f ~/.config/dotfiles/uuid ]]; then
uuid=$(cat ~/.config/dotfiles/uuid)
else
if [[ -x $(command -v uuidgen) ]]; then
uuid=$(uuidgen)
elif [[ -f /proc/sys/kernel/random/uuid ]]; then
uuid=$(cat /proc/sys/kernel/random/uuid)
else
fmt_fatal "unable to generate uuid"
fi
mkdir -p ~/.config/dotfiles
echo "$uuid" > ~/.config/dotfiles/uuid
fi
}
post_beacon()
{
local beacon_type=$1
if [[ -z "$beacon_type" ]]; then
fmt_fatal "beacon type is required"
fi
resp=$(curl -sSL -X POST "https://api.beardic.cn/post-beacon?hostname=$hostname&beacon=$beacon_type")
if grep -q "200" <<< "$resp"; then
echo $resp
else
echo $resp >&2
fmt_fatal "error posting beacon"
fi
}
post_log()
{
local log_content=$1
if [[ -z "$log_content" ]]; then
fmt_fatal "log content is required"
fi
init_uuid
resp=$(curl -sSL -X POST -H "Content-Type: text/plain" -d "$1" "https://api.beardic.cn/post-log?hostname=$hostname&uuid=$uuid")
if grep -q "200" <<< "$resp"; then
echo $resp
elif grep -q "403" <<< "$resp"; then
echo $resp >&2
fmt_error "error posting log: authentification failed"
fmt_info "try to register you hostname and uuid"
fmt_info "hostname: $hostname"
fmt_info "uuid: $uuid"
else
echo $resp >&2
fmt_fatal "error posting log"
fi
}
print_help()
{
fmt_info "usage: $0 <beacon|log> <beacon_type|log_content>"
}
if [[ $# != 2 ]]; then
print_help >&2
exit 1
fi
case "$1" in
-h|--help)
fmt_info "usage: $0 <beacon|log> <beacon_type|log_content>"
;;
beacon)
post_beacon "$2"
;;
log)
post_log "$2"
;;
*)
fmt_fatal "invalid argument"
;;
esac

View File

@@ -5,7 +5,7 @@ source "$THIS_DIR/common.sh"
brew_install() brew_install()
{ {
brew update # brew update
brew install git zsh curl tmux vim util-linux brew install git zsh curl tmux vim util-linux
} }
@@ -13,8 +13,8 @@ router()
{ {
case $1 in case $1 in
brew-install ) brew_install ;; brew-install ) brew_install ;;
* ) echo unknown command "$1". available: brew-install;; * ) echo unknown command \"$1\". available: brew-install;;
esac esac
} }
router $@ router "${GOT_OPTS[@]}"

View File

@@ -17,7 +17,7 @@ pacman_S()
# lite # lite
pacman -S tmux git zsh bash curl vim pacman -S tmux git zsh bash curl vim
# full # full
if [[ -z "$DFS_LITE" ]]; then if [[ -z "$DFS_LITE" || "$DFS_LITE" == "0" ]]; then
pacman -S wget base-devel mingw-w64-x86_64-toolchain make cmake gcc zip unzip python3 python3-pip man-pages-posix pacman -S wget base-devel mingw-w64-x86_64-toolchain make cmake gcc zip unzip python3 python3-pip man-pages-posix
fi fi
} }
@@ -27,8 +27,8 @@ router()
case $1 in case $1 in
pacman-S ) pacman_S ;; pacman-S ) pacman_S ;;
set-mirror ) set_mirror $2 ;; set-mirror ) set_mirror $2 ;;
* ) echo unknown command "$1". available: pacman-S, set-mirror ;; * ) echo unknown command \"$1\". available: pacman-S, set-mirror ;;
esac esac
} }
router $@ router "${GOT_OPTS[@]}"

109
tools/sagent.sh Executable file
View File

@@ -0,0 +1,109 @@
#!/bin/bash
set -e
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
export DFS_COLOR=1
source "$THIS_DIR/common.sh"
find_so_file()
{
local SO_PATHS=( "/usr/lib64/opensc-pkcs11.so" "/usr/local/lib/opensc-pkcs11.so" )
local SO_FILE
for SO_FILE in ${SO_PATHS[*]}; do
if [[ -f "$SO_FILE" ]]; then
echo "$SO_FILE"
return
fi
done
}
create_agent()
{
local SO_FILE=$(find_so_file)
if [[ -n "$SO_FILE" ]]; then
fmt_note "opensc-pkcs11.so found"
SO_FILE="-P $SO_FILE"
fi
ssh-agent $SO_FILE
}
kill_agent()
{
if pgrep -x ssh-agent > /dev/null; then
fmt_note "killing existing agent"
pkill -9 -x ssh-agent
fi
}
add_piv()
{
local SO_FILE=$(find_so_file)
if [[ -n "$SO_FILE" ]]; then
echo ssh-add -s \"$SO_FILE\"
else
fmt_error "opensc-pkcs11.so not found"
fi
list
}
list()
{
echo echo "available keys:"
echo ssh-add -l
}
reset()
{
kill_agent
all
}
all()
{
local agent_file="/tmp/piv-agent-$(whoami)"
if [[ -f $agent_file ]]; then
source $agent_file > /dev/null
else
touch $agent_file
chmod 600 $agent_file
fi
if ! ps -p "$SSH_AGENT_PID" 1>/dev/null 2>&1; then
kill_agent
fmt_note "launching a new agent"
create_agent | tee $agent_file
else
fmt_note "using existing agent: $SSH_AGENT_PID"
cat $agent_file
fi
}
route()
{
os_type="$(get_os_type)"
if [[ "$os_type" == "msys" || "$os_type" == "cygwin" ]]; then
fmt_fatal "unsupported platform: $os_type. you may use WinCryptSSHAgent."
fi
if [[ $# -eq 0 ]]; then
all
return
fi
case $1 in
kill)
kill_agent
;;
piv)
add_piv
;;
reset)
reset
;;
list|ls)
list
;;
*)
fmt_error "unknown command: $1"
;;
esac
}
route "$@"

21
tools/test-getopts.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
set -ex
OPTS='-a -bcl --color --arg1=1 --arg2 2 " 1 2" yes'
TARGET_OPTS='-a -b -c --arg1 1 --arg2 2 1 2 yes'
eval set -- $OPTS
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/common.sh"
test "${GOT_OPTS[*]}" = "$TARGET_OPTS"
test $# -eq 8
test "$*" = "${OPTS//\"/}"
test "$DFS_LITE" = "1"
is_tty
test -z "$DFS_QUIET"
set +x
echo "test passed, args:"
for i in "${GOT_OPTS[@]}"; do
echo "$i"
done

View File

@@ -1,6 +1,7 @@
#!/bin/false "This script should be sourced in zsh, not executed directly" #!/bin/false "This script should be sourced in zsh, not executed directly"
set -ex set -ex
trap "dfs beacon gh.ci.fail" ERR
# check files # check files
cd / cd /
@@ -17,19 +18,27 @@ grep -q ".zshrc2" ~/.zshrc
# check scripts and functions # check scripts and functions
dfs version dfs version
dfs log 1 dfs log 1
dfs beacon gh.ci dfs beacon gh.ci $GITHUB_SHA
z ~ z ~
test ~ -ef "$(pwd)" test ~ -ef "$(pwd)"
dogo dogo
doll doll
dfs cd dfs cd
tools/common.sh get_os_type tools/test-getopts.sh
tools/common.sh get_linux_dist tools/common.sh get_os_name
test $(echo y | tools/common.sh ask_for_yN "test") = "1"
test $(echo n | tools/common.sh ask_for_yN "test") = "0"
test $(echo | tools/common.sh ask_for_yN "test") = "0"
test $(echo | tools/common.sh ask_for_Yn "test") = "1"
test $(DFS_QUIET=1 tools/common.sh ask_for_Yn "test") = "1"
test "$(DFS_TRUST=1 riot time@is.impt:2222,yes@you-r.right,you@are.really.recht.,ibd.,try@it scp /tmp/ ./tmp -D 2>/dev/null)" = 'scp -P 12022 -o ControlMaster=auto -o ControlPath=/tmp/sshcm-%C -o PermitLocalCommand=yes -o ProxyJump=time@is.impt:2222,yes@you-r.right,you@are.really.recht.,ibd. -r try@it.ibd.ink:"/tmp/" "./tmp"'
# check alias # check alias
alias p114 alias p114
which sibd alias cbds
piv-agent || which piv-agent which riot
sagt
test -f "/tmp/piv-agent-$(whoami)"
gbes || which gbes gbes || which gbes
# check update # check update
@@ -42,6 +51,10 @@ test `git rev-parse HEAD` = `curl -fsSL https://api.beardic.cn/get-var/dfs-commi
git reset --hard $DFS_VERSION git reset --hard $DFS_VERSION
# then check install.sh # then check install.sh
./install.sh -dx DFS_CI=1 -H e153a2eL,f8At3iFw
grep -qE "testhist 1$" ~/.zsh_history
grep -qE "testhist 4$" ~/.zsh_history
grep -qx "DFS_CI=1" ~/.config/dotfiles/env
./install.sh -l ./install.sh -l
dfs version dfs version
test `git rev-parse HEAD` = `curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id` test `git rev-parse HEAD` = `curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id`

View File

@@ -9,7 +9,7 @@ INSTALL_COMMANDS=(\
[oh-my-tuna]='wget https://tuna.moe/oh-my-tuna/oh-my-tuna.py && sudo python oh-my-tuna.py --global' \ [oh-my-tuna]='wget https://tuna.moe/oh-my-tuna/oh-my-tuna.py && sudo python oh-my-tuna.py --global' \
[v2fly]="bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) #--remove" \ [v2fly]="bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) #--remove" \
[zerotier-one]='curl -s https://install.zerotier.com | sudo bash' \ [zerotier-one]='curl -s https://install.zerotier.com | sudo bash' \
[docker-ce]='curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh #--mirror Aliyun #--dry-run' \ [docker-ce]='curl -fsSL https://get.docker.com | sudo bash -s - --mirror Aliyun #--dry-run' \
[lemonbench]='curl -fsSL https://ilemonra.in/LemonBenchIntl | bash -s fast # or full' \ [lemonbench]='curl -fsSL https://ilemonra.in/LemonBenchIntl | bash -s fast # or full' \
) )

View File

@@ -16,8 +16,8 @@ apt_install()
# lite # lite
apt-get install -y git zsh bash tmux vim curl inetutils-ping less bsdmainutils apt-get install -y git zsh bash tmux vim curl inetutils-ping less bsdmainutils
# full # full
if [[ -z "$DFS_LITE" ]]; then if [[ -z "$DFS_LITE" || "$DFS_LITE" == "0" ]]; then
apt-get install wget dialog net-tools dnsutils netcat traceroute sudo python3 python3-pip cron openssh-client openssh-server htop gcc g++ cmake make zip apt-get install -y wget dialog net-tools dnsutils netcat traceroute sudo python3 python3-pip cron openssh-client openssh-server htop gcc g++ cmake make zip
for i in {fzf,ripgrep,man-db}; do apt-get install -y $i; done for i in {fzf,ripgrep,man-db}; do apt-get install -y $i; done
fi fi
} }
@@ -35,8 +35,8 @@ router()
set-mirror ) set_mirror $2 ;; set-mirror ) set_mirror $2 ;;
set-timezone\ set-timezone\
| set-tz ) set_timezone $2 ;; | set-tz ) set_timezone $2 ;;
* ) echo unknown command "$1". available: apt-install, set-mirror, set-timezone;; * ) echo unknown command \"$1\". available: apt-install, set-mirror, set-timezone;;
esac esac
} }
router $@ router "${GOT_OPTS[@]}"