mirror of
https://github.com/DictXiong/dotfiles.git
synced 2025-03-14 10:44:00 +08:00
Compare commits
36 Commits
Author | SHA1 | Date | |
---|---|---|---|
055d44886b | |||
92aa5fa920 | |||
483f7fd7f3 | |||
5fb7ff0833 | |||
39b8dfce82 | |||
1a62ffe74b | |||
2cc2ab48b8 | |||
37bf1fa1f0 | |||
8fdd3c477f | |||
9a4c9556f6 | |||
952bfabea4 | |||
c3e0c28b64 | |||
ff8ac21424 | |||
56e2b217eb | |||
f39193f28f | |||
c354f980bb | |||
3ce5a7ade8 | |||
6e33fc0875 | |||
995899f3a3 | |||
9a7f0b1b06 | |||
300b3a29b7 | |||
6dce3cfa18 | |||
5b00add073 | |||
b191403798 | |||
b6ff4116c8 | |||
0739410aef | |||
9778c69d78 | |||
83695d48fb | |||
5bd6d9f822 | |||
3421d27be9 | |||
18dfca5f39 | |||
fa737d482f | |||
8782121dcc | |||
f313a6887e | |||
7804f196b4 | |||
c834980b29 |
30
.eid/authorized_certificates
Normal file
30
.eid/authorized_certificates
Normal file
|
@ -0,0 +1,30 @@
|
|||
-----BEGIN CERTIFICATE-----
|
||||
MIIFIDCCAwigAwIBAgIUK1zXH5UosBim7i+kIZyPGpowU9cwDQYJKoZIhvcNAQEL
|
||||
BQAwgZUxCzAJBgNVBAYTAkNOMRAwDgYDVQQIDAdCRUlKSU5HMRAwDgYDVQQHDAdC
|
||||
RUlKSU5HMRIwEAYDVQQKDAlEaWN0IFRlY2gxEDAOBgNVBAsMB1Jvb3QgQ0ExHjAc
|
||||
BgNVBAMMFURpY3QgVGVjaCBSb290IENBIC0gMDEcMBoGCSqGSIb3DQEJARYNbWVA
|
||||
YmVhcmRpYy5jbjAeFw0yMjA3MjIxNzU5MjNaFw0yNTA3MjExNzU5MjNaMEkxEjAQ
|
||||
BgNVBAoMCURpY3QgVGVjaDEQMA4GA1UECAwHQkVJSklORzELMAkGA1UEBhMCQ04x
|
||||
FDASBgNVBAMMC3NrMC5pYmQuaW5rMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
|
||||
CgKCAQEAlDeyFxeJ5RXFX4B3rIIpNyyAIl5VTGCT5t8g9dxFWq0MeY6nQYJPA8IJ
|
||||
IH+KzzujBabyKYpzshDvMzkuhx0Kwi2VL+ckxWg5FLge3kNBJqYnBm5pPWx6o9R5
|
||||
DmcWqG5KRH0FJhSmL5KeBHsVcOurDtKn174x2eB+sggCSyuWlJyn4KxPLTg8z/Nr
|
||||
FP5qSY1vj6t7mpzau+eIGh8IcQiFxteN/86fKswQHint/MVaqg6vX05BuIb8xb5E
|
||||
XUvPIupdc/vtD959BxnTo7UoOz+3zu/u2cj2K9IDubwe9tDpv88aj6xnfXInFouD
|
||||
/mlSmvtLo1h/6arn1hurgoylh5wbOwIDAQABo4GyMIGvMAkGA1UdEwQCMAAwCwYD
|
||||
VR0PBAQDAgTwMB0GA1UdDgQWBBR9DxLqtR0+zUWoPyFoDRrnyJyDBTAfBgNVHSME
|
||||
GDAWgBRsprmVI/Tjey+sw4qoZpLd7PT0gTBVBgNVHSUETjBMBggrBgEFBQcDAgYI
|
||||
KwYBBQUHAwMGCCsGAQUFBwMEBggrBgEFBQcDCAYKKwYBBAGCN0MBAQYKKwYBBAGC
|
||||
N0MBAgYKKwYBBAGCNxQCAjANBgkqhkiG9w0BAQsFAAOCAgEA7BJXiRg32shmZWyY
|
||||
gPjq52ffN9RDNe58KadajJ1PnVP1yNJySgsOG3eSxONQX3ITr36Ihsfb3fZneBfX
|
||||
/IcXgjyvy1CDcvBBAyee91hdR8orMCePqMpeOSNP9CUp9Ctd4V+an0DE8Z1yrezA
|
||||
ieaYgBZCDxuZdloYSmj9Z/Rqn2dy4dcUAxKrEwW/6VPqQNrJETTtadS1SF0EsDxV
|
||||
XZpDqNYaS/N7/ciSm7TaQJud62A4m+FWWHNnttTp9IjLESr3U80+qtRY8yDNpulb
|
||||
/eNL8KK9aORiFUz9789l6M62HPi6vCsMflI0iHUeoi69GKX8mKf0WFR1KxoDsJiN
|
||||
DG9/1gCfj6whFCrT6fJTKAGl8Hp5toWMOeDprbsE5gf4Ik3p+sKMV9t43zNm3gvA
|
||||
1zNPtgQUffPU0kONlavIxUNfCmD8qVwK5ECT7wh0hrB8fRYfxTZHgN6Yvu7M9HNz
|
||||
SNt5JZCLBT4nLt0uQp9O/xctdHElZw+/W8OfnP5vxnPdccIeVOxpGIyzErwjD0+E
|
||||
9mNiqOa5JV9OMAJ+0I9cbOnuMaXm4mvHZadnetUzq2ZUw1Jba7z62zIJTciNRq9i
|
||||
ZJc6v5e+iqbE1ECZLco5LjWqqfvFfYCrkqeOhCRsRkVPsXnGPo2QDDYdTm4EGCmg
|
||||
dVZ6R452SZsrE4V+3LR011BxzEg=
|
||||
-----END CERTIFICATE-----
|
21
.gitconfig2
21
.gitconfig2
|
@ -1,5 +1,22 @@
|
|||
[user]
|
||||
email = me@beardic.cn
|
||||
name = Dict Xiong
|
||||
email = me@beardic.cn
|
||||
name = Dict Xiong
|
||||
[core]
|
||||
editor = vim
|
||||
# test this by `git update-index --test-untracked-cache`
|
||||
# disable this by setting `GIT_DISABLE_UNTRACKED_CACHE`
|
||||
untrackedCache = true
|
||||
quotepath = false # chinese chars
|
||||
[push]
|
||||
autoSetupRemote = true
|
||||
[pull]
|
||||
ff = only
|
||||
[branch]
|
||||
# Show most recently changed branches first.
|
||||
sort = -committerdate
|
||||
[help]
|
||||
autocorrect = 1
|
||||
[init]
|
||||
defaultBranch = main
|
||||
[log]
|
||||
date = iso
|
||||
|
|
31
.github/workflows/gitee_sync.yml
vendored
31
.github/workflows/gitee_sync.yml
vendored
|
@ -1,27 +1,22 @@
|
|||
name: sync repos to gitee
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- dev
|
||||
schedule:
|
||||
- cron: 10 4 * * *
|
||||
push: ~
|
||||
workflow_dispatch: ~
|
||||
jobs:
|
||||
dotfiles:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: DictXiong/dotfiles # 名字随便起
|
||||
uses: Yikun/hub-mirror-action@v1.2 # 使用Yikun/hub-mirror-action
|
||||
- name: DictXiong/dotfiles
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
with:
|
||||
src: github/DictXiong # 源端账户名(github)
|
||||
dst: gitee/dictxiong # 目的端账户名(gitee)
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} # SSH密钥对中的私钥
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }} # Gitee账户的私人令牌
|
||||
src: github/DictXiong
|
||||
dst: gitee/dictxiong
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }}
|
||||
src_account_type: user
|
||||
dst_account_type: user # 账户类型
|
||||
clone_style: "https" # 使用https方式进行clone,也可以使用ssh
|
||||
debug: true # 启用后会显示所有执行命令
|
||||
force_update: true # 启用后,强制同步,即强制覆盖目的端仓库
|
||||
static_list: "dotfiles" # 静态同步列表,在此填写需要同步的仓库名称,可填写多个
|
||||
timeout: '600s' # git超时设置,超时后会自动重试git操作
|
||||
dst_account_type: user
|
||||
clone_style: "https"
|
||||
debug: true
|
||||
force_update: true
|
||||
static_list: "dotfiles"
|
||||
timeout: '600s'
|
||||
|
|
250
.github/workflows/gitee_sync_dependencies.yml
vendored
250
.github/workflows/gitee_sync_dependencies.yml
vendored
|
@ -1,108 +1,142 @@
|
|||
name: sync dependencies to gitee
|
||||
on:
|
||||
schedule:
|
||||
- cron: 0 4 * * *
|
||||
workflow_dispatch: ~
|
||||
jobs:
|
||||
ohmyzsh:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: ohmyzsh repo # 名字随便起
|
||||
uses: Yikun/hub-mirror-action@v1.2 # 使用Yikun/hub-mirror-action
|
||||
with:
|
||||
src: github/ohmyzsh # 源端账户名(github)
|
||||
dst: gitee/dictxiong # 目的端账户名(gitee)
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} # SSH密钥对中的私钥
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }} # Gitee账户的私人令牌
|
||||
src_account_type: org
|
||||
dst_account_type: user # 账户类型
|
||||
clone_style: "https" # 使用https方式进行clone,也可以使用ssh
|
||||
debug: true # 启用后会显示所有执行命令
|
||||
force_update: true # 启用后,强制同步,即强制覆盖目的端仓库
|
||||
static_list: "ohmyzsh" # 静态同步列表,在此填写需要同步的仓库名称,可填写多个
|
||||
timeout: '600s' # git超时设置,超时后会自动重试git操作
|
||||
zsh-users:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: zsh-users repos # 名字随便起
|
||||
uses: Yikun/hub-mirror-action@v1.2 # 使用Yikun/hub-mirror-action
|
||||
with:
|
||||
src: github/zsh-users # 源端账户名(github)
|
||||
dst: gitee/dictxiong # 目的端账户名(gitee)
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} # SSH密钥对中的私钥
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }} # Gitee账户的私人令牌
|
||||
src_account_type: org
|
||||
dst_account_type: user # 账户类型
|
||||
clone_style: "https" # 使用https方式进行clone,也可以使用ssh
|
||||
debug: true # 启用后会显示所有执行命令
|
||||
force_update: true # 启用后,强制同步,即强制覆盖目的端仓库
|
||||
static_list: "antigen,zsh-syntax-highlighting,zsh-autosuggestions,zsh-completions" # 静态同步列表,在此填写需要同步的仓库名称,可填写多个
|
||||
timeout: '600s' # git超时设置,超时后会自动重试git操作
|
||||
tmux-mem-cpu-load:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: thewtex/tmux-mem-cpu-load # 名字随便起
|
||||
uses: Yikun/hub-mirror-action@v1.2 # 使用Yikun/hub-mirror-action
|
||||
with:
|
||||
src: github/thewtex # 源端账户名(github)
|
||||
dst: gitee/dictxiong # 目的端账户名(gitee)
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} # SSH密钥对中的私钥
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }} # Gitee账户的私人令牌
|
||||
src_account_type: user
|
||||
dst_account_type: user # 账户类型
|
||||
clone_style: "https" # 使用https方式进行clone,也可以使用ssh
|
||||
debug: true # 启用后会显示所有执行命令
|
||||
force_update: true # 启用后,强制同步,即强制覆盖目的端仓库
|
||||
static_list: "tmux-mem-cpu-load" # 静态同步列表,在此填写需要同步的仓库名称,可填写多个
|
||||
timeout: '600s' # git超时设置,超时后会自动重试git操作
|
||||
tmux-plugins:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: tmux-plugins # 名字随便起
|
||||
uses: Yikun/hub-mirror-action@v1.2 # 使用Yikun/hub-mirror-action
|
||||
with:
|
||||
src: github/tmux-plugins # 源端账户名(github)
|
||||
dst: gitee/dictxiong # 目的端账户名(gitee)
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} # SSH密钥对中的私钥
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }} # Gitee账户的私人令牌
|
||||
src_account_type: org
|
||||
dst_account_type: user # 账户类型
|
||||
clone_style: "https" # 使用https方式进行clone,也可以使用ssh
|
||||
debug: true # 启用后会显示所有执行命令
|
||||
force_update: true # 启用后,强制同步,即强制覆盖目的端仓库
|
||||
static_list: "tpm,tmux-resurrect" # 静态同步列表,在此填写需要同步的仓库名称,可填写多个
|
||||
timeout: '600s' # git超时设置,超时后会自动重试git操作
|
||||
vundle-vim:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: VundleVim/Vundle-vim # 名字随便起
|
||||
uses: Yikun/hub-mirror-action@v1.2 # 使用Yikun/hub-mirror-action
|
||||
with:
|
||||
src: github/VundleVim # 源端账户名(github)
|
||||
dst: gitee/dictxiong # 目的端账户名(gitee)
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} # SSH密钥对中的私钥
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }} # Gitee账户的私人令牌
|
||||
src_account_type: org
|
||||
dst_account_type: user # 账户类型
|
||||
clone_style: "https" # 使用https方式进行clone,也可以使用ssh
|
||||
debug: true # 启用后会显示所有执行命令
|
||||
force_update: true # 启用后,强制同步,即强制覆盖目的端仓库
|
||||
static_list: "Vundle.vim" # 静态同步列表,在此填写需要同步的仓库名称,可填写多个
|
||||
timeout: '600s' # git超时设置,超时后会自动重试git操作
|
||||
onedark-vim:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: joshdick/onedark-vim # 名字随便起
|
||||
uses: Yikun/hub-mirror-action@v1.2 # 使用Yikun/hub-mirror-action
|
||||
with:
|
||||
src: github/joshdick # 源端账户名(github)
|
||||
dst: gitee/dictxiong # 目的端账户名(gitee)
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} # SSH密钥对中的私钥
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }} # Gitee账户的私人令牌
|
||||
src_account_type: user
|
||||
dst_account_type: user # 账户类型
|
||||
clone_style: "https" # 使用https方式进行clone,也可以使用ssh
|
||||
debug: true # 启用后会显示所有执行命令
|
||||
force_update: true # 启用后,强制同步,即强制覆盖目的端仓库
|
||||
static_list: "onedark.vim" # 静态同步列表,在此填写需要同步的仓库名称,可填写多个
|
||||
timeout: '600s' # git超时设置,超时后会自动重试git操作
|
||||
name: sync dependencies to gitee
|
||||
on:
|
||||
schedule:
|
||||
- cron: 0 4 * * *
|
||||
workflow_dispatch: ~
|
||||
jobs:
|
||||
ohmyzsh:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: ohmyzsh repo
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
with:
|
||||
src: github/ohmyzsh
|
||||
dst: gitee/dictxiong
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }}
|
||||
src_account_type: org
|
||||
dst_account_type: user
|
||||
clone_style: "https" # https/ssh
|
||||
debug: true # print all commands
|
||||
force_update: true
|
||||
static_list: "ohmyzsh"
|
||||
timeout: '600s'
|
||||
zsh-users:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: zsh-users repos
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
with:
|
||||
src: github/zsh-users
|
||||
dst: gitee/dictxiong
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }}
|
||||
src_account_type: org
|
||||
dst_account_type: user
|
||||
clone_style: "https"
|
||||
debug: true
|
||||
force_update: true
|
||||
static_list: "antigen,zsh-syntax-highlighting,zsh-autosuggestions,zsh-completions"
|
||||
timeout: '600s'
|
||||
zdharma-continuum:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: zdharma-continuum repos
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
with:
|
||||
src: github/zdharma-continuum
|
||||
dst: gitee/dictxiong
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }}
|
||||
src_account_type: org
|
||||
dst_account_type: user
|
||||
clone_style: "https"
|
||||
debug: true
|
||||
force_update: true
|
||||
static_list: "fast-syntax-highlighting"
|
||||
timeout: '600s'
|
||||
tmux-mem-cpu-load:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: thewtex/tmux-mem-cpu-load
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
with:
|
||||
src: github/thewtex
|
||||
dst: gitee/dictxiong
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }}
|
||||
src_account_type: user
|
||||
dst_account_type: user
|
||||
clone_style: "https"
|
||||
debug: true
|
||||
force_update: true
|
||||
static_list: "tmux-mem-cpu-load"
|
||||
timeout: '600s'
|
||||
tmux-plugins:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: tmux-plugins
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
with:
|
||||
src: github/tmux-plugins
|
||||
dst: gitee/dictxiong
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }}
|
||||
src_account_type: org
|
||||
dst_account_type: user
|
||||
clone_style: "https"
|
||||
debug: true
|
||||
force_update: true
|
||||
static_list: "tpm,tmux-resurrect,tmux-yank"
|
||||
timeout: '600s'
|
||||
vundle-vim:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: VundleVim/Vundle-vim
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
with:
|
||||
src: github/VundleVim
|
||||
dst: gitee/dictxiong
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }}
|
||||
src_account_type: org
|
||||
dst_account_type: user
|
||||
clone_style: "https"
|
||||
debug: true
|
||||
force_update: true
|
||||
static_list: "Vundle.vim"
|
||||
timeout: '600s'
|
||||
onedark-vim:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: joshdick/onedark-vim
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
with:
|
||||
src: github/joshdick
|
||||
dst: gitee/dictxiong
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }}
|
||||
src_account_type: user
|
||||
dst_account_type: user
|
||||
clone_style: "https"
|
||||
debug: true
|
||||
force_update: true
|
||||
static_list: "onedark.vim"
|
||||
timeout: '600s'
|
||||
fzf:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: junegunn/fzf
|
||||
uses: Yikun/hub-mirror-action@v1.4
|
||||
with:
|
||||
src: github/junegunn
|
||||
dst: gitee/dictxiong
|
||||
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
|
||||
dst_token: ${{ secrets.GITEE_TOKEN }}
|
||||
src_account_type: user
|
||||
dst_account_type: user
|
||||
clone_style: "https"
|
||||
debug: true
|
||||
force_update: true
|
||||
static_list: "fzf"
|
||||
timeout: '600s'
|
||||
|
|
131
.github/workflows/test.yml
vendored
Normal file
131
.github/workflows/test.yml
vendored
Normal file
|
@ -0,0 +1,131 @@
|
|||
name: test
|
||||
on:
|
||||
push: ~
|
||||
workflow_dispatch: ~
|
||||
jobs:
|
||||
test-ubuntu:
|
||||
name: test on ubuntu
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout repo
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: install dfs
|
||||
run: |
|
||||
rev=`git rev-parse HEAD`
|
||||
pwd
|
||||
set -x
|
||||
DFS_NO_WALL=0 ./install.sh -adl
|
||||
test `git rev-parse HEAD` = "$rev"
|
||||
|
||||
- name: antigen build
|
||||
shell: /bin/zsh -ileo PIPE_FAIL {0}
|
||||
run: |
|
||||
echo $SHELL
|
||||
antigen list
|
||||
|
||||
- name: run tests and reset
|
||||
shell: /bin/zsh -ileo PIPE_FAIL {0}
|
||||
run: |
|
||||
source tools/test.zsh
|
||||
antigen reset
|
||||
rm -rf $ANTIGEN $HOME/.antigen $HOME/.config/dotfiles
|
||||
./install.sh -dl
|
||||
|
||||
- name: antigen build with DFS_NO_WALL
|
||||
shell: /bin/zsh -ileo PIPE_FAIL {0}
|
||||
run: |
|
||||
echo $SHELL
|
||||
antigen list
|
||||
|
||||
- name: run tests
|
||||
shell: /bin/zsh -ileo PIPE_FAIL {0}
|
||||
run: source tools/test.zsh
|
||||
|
||||
test-macos:
|
||||
name: test on macos
|
||||
runs-on: macos-12
|
||||
steps:
|
||||
- name: checkout repo
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: install dfs
|
||||
run: |
|
||||
rev=`git rev-parse HEAD`
|
||||
pwd
|
||||
set -x
|
||||
DFS_NO_WALL=0 ./install.sh -adl
|
||||
test `git rev-parse HEAD` = "$rev"
|
||||
|
||||
- name: antigen build
|
||||
shell: /bin/zsh -ileo PIPE_FAIL {0}
|
||||
run: |
|
||||
echo $SHELL
|
||||
antigen list
|
||||
|
||||
- name: run tests and reset
|
||||
shell: /bin/zsh -ileo PIPE_FAIL {0}
|
||||
run: |
|
||||
source tools/test.zsh
|
||||
antigen reset
|
||||
rm -rf $ANTIGEN $HOME/.antigen $HOME/.config/dotfiles
|
||||
./install.sh -dl
|
||||
|
||||
- name: antigen build with DFS_NO_WALL
|
||||
shell: /bin/zsh -ileo PIPE_FAIL {0}
|
||||
run: |
|
||||
echo $SHELL
|
||||
antigen list
|
||||
|
||||
- name: run tests
|
||||
shell: /bin/zsh -ileo PIPE_FAIL {0}
|
||||
run: source tools/test.zsh
|
||||
|
||||
test-autodep:
|
||||
name: test of auto-install dependencies
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: remove dependencies
|
||||
run: |
|
||||
sudo apt-get -y remove curl vim python3
|
||||
|
||||
- name: checkout repo
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: install dfs
|
||||
run: |
|
||||
rev=`git rev-parse HEAD`
|
||||
set -x
|
||||
./install.sh -dal
|
||||
test `git rev-parse HEAD` = "$rev"
|
||||
|
||||
- name: antigen build
|
||||
shell: /bin/zsh -ileo PIPE_FAIL {0}
|
||||
run: |
|
||||
echo $SHELL
|
||||
antigen list
|
||||
|
||||
test-get-dotfiles-cn:
|
||||
name: test of get.dotfiles.cn script
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout repo
|
||||
uses: actions/checkout@v4
|
||||
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
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
*.zwc
|
||||
update.sh
|
||||
|
|
|
@ -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
|
||||
sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAIGdLJYOrBhWERmkQ+sNM8tGzJ37UBEKkEuhbtE9B65mOAAAABHNzaDo= sk0/fido
|
||||
|
||||
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
|
||||
|
||||
|
@ -19,10 +12,17 @@ ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFO4k0tJ+Bfu95Uavg/5P3EXMKNcq+bMqaTqzkvRZ7ji
|
|||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN8g34WHLEix6Qt0J/ClYbZeb9wh+p1IOcZkz/vNbZrv ltp1/windows
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBN24pvN1RMN+iSZyHPdyExA1Rvt8pdr3e6ih6iX+KrQ ltp2
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGZFTyR+R86fUpZBDkDR9yYzJpmeNsIv2CMHTh6EuEeq pc0/windows
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID8WHIpwdZl7+HIZfQpwIAhpxT1huI9sd6Ydeokilg5l pc1/windows
|
||||
|
||||
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJ/+BWSTv3w1Ru9ksfse3EUbu4ukJruUU94fCG7Sk+5g3+F80KqJGykP9tHueU07iZfAuaYj7Zcy+IWx9Ih+eYA= ph0/sep
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHLYgVj+NPino6sOmahULN7SbAMaVAgzqPfDjz2S8zDv pc1/windows
|
||||
|
||||
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNvHya5i3GNniGww9Yx5ikos4Z5jevu8zz8hCQi05++SgejFPnbw9UjbHFjODK2M+ZHuhRF5mdf996r4/BxWyP8= pad0/sep
|
||||
|
||||
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBC5gu+U4picxVvCNYjLlmxGLpJl7svj3LklO7jSpwqdrNxlE+/xkx07PJx76AbA77dDM1Dxmm/VOvVQCKTRLTgk= ip14/sep
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIF52mPmbLEriZ+DfmrMHFtvg2kiO2JpRpitvs7PbJowh home0
|
||||
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKhS4voo3K/Dvzqckr0bouO1WkCI5XxswstHWnuuyKBz ltp1-bd
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
set -g prefix ^a
|
||||
set -g mouse off
|
||||
set -g mouse on
|
||||
set -g set-clipboard on
|
||||
set -g default-terminal "xterm-256color"
|
||||
set -g history-limit 10000
|
||||
|
||||
|
@ -25,6 +26,7 @@ bind | split-window -h -c "#{pane_current_path}"
|
|||
# other key bindings
|
||||
bind r source-file ~/.tmux.conf \; display-message "tmux.conf reloaded"
|
||||
bind m run 'old=$(tmux show -gv mouse); new="off"; if [ "$old" = "off" ]; then new="on"; fi; tmux set -g mouse $new && tmux display-message toggle\ mouse\ mode\ $new'
|
||||
bind C-x set-window-option synchronize-panes\; display-message "synchronize-panes is now #{?pane_synchronized,on,off}"
|
||||
|
||||
# styles
|
||||
# status bar
|
||||
|
@ -50,4 +52,4 @@ set -g window-style fg=colour248
|
|||
set -g window-active-style fg=white
|
||||
|
||||
# better mouse scrolling. see: https://superuser.com/questions/1622812/mouse-scrolling-in-mobaxterm-tmux
|
||||
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
|
||||
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
|
||||
|
|
59
.update.sh
Normal file
59
.update.sh
Normal file
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
THIS_FILE=$(basename "${BASH_SOURCE}")
|
||||
source "$THIS_DIR/tools/common.sh"
|
||||
|
||||
DFS_UPDATED_RET=${DFS_UPDATED_RET:-0}
|
||||
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
|
||||
cd $DOTFILES
|
||||
git fetch --all --prune
|
||||
if [[ -n "$(git status -s)" ]]; then
|
||||
fmt_error "directory not clean"
|
||||
apost_beacon "dfs.dirty"
|
||||
exit
|
||||
fi
|
||||
|
||||
# get the specified commit id
|
||||
case $DFS_UPDATE_CHANNEL in
|
||||
"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) ;;
|
||||
"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" ;;
|
||||
esac
|
||||
if [[ ${#DFS_COMMIT} != 40 ]]; then
|
||||
fmt_error "invalid commit id"
|
||||
apost_beacon "dfs.invalid-commit"
|
||||
apost_log "ERROR" "$THIS_FILE" "invalid commit id: ${DFS_COMMIT}"
|
||||
exit
|
||||
fi
|
||||
|
||||
# update
|
||||
if [[ "$(git rev-parse HEAD)" == "$DFS_COMMIT" ]]; then
|
||||
fmt_info "nothing to do"
|
||||
else
|
||||
fmt_info "checking out to commit $DFS_COMMIT ..."
|
||||
if [[ -z "$DFS_DEV" || "$DFS_DEV" == "0" ]]; then
|
||||
post_beacon "dfs.updated"
|
||||
git -c advice.detachedHead=false checkout $DFS_COMMIT
|
||||
cp ./.update.sh ./update.sh && chmod +x ./update.sh && exit $DFS_UPDATED_RET
|
||||
else
|
||||
fmt_warning "won't really checkout in dev mode"
|
||||
fi
|
||||
fi
|
7
.vimrc2
7
.vimrc2
|
@ -10,12 +10,14 @@ filetype plugin indent on
|
|||
" end vundle
|
||||
colorscheme onedark
|
||||
|
||||
syntax on
|
||||
set cursorline
|
||||
set syntax=on
|
||||
set autoindent
|
||||
set smartindent
|
||||
set tabstop=4
|
||||
set expandtab "spaces instead of tabs
|
||||
set tabstop=4 softtabstop=4 shiftwidth=4
|
||||
autocmd FileType c,cpp,nix,yaml setlocal tabstop=2 softtabstop=2 shiftwidth=2
|
||||
set backspace=indent,eol,start
|
||||
set number "line numbers
|
||||
set history=1000
|
||||
set ignorecase "when searching
|
||||
|
@ -30,6 +32,7 @@ hi User3 ctermfg=15 ctermbg=2
|
|||
au InsertEnter * hi User3 ctermfg=15 ctermbg=5
|
||||
au InsertLeave * hi User3 ctermfg=15 ctermbg=2
|
||||
set statusline=%3*\ %{mode()}\ %*[%n][%F](%{\"\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\"+\":\"\").\"\"},%{&ff},%Y)%2*%r%1*%m%*%<%=\'0x%B\'\ [Line:%l/%L,Col:%c][%p%%]
|
||||
nnoremap <silent> <C-n> :let [&nu, &rnu] = [!&rnu, &nu+&rnu==1]<cr>
|
||||
|
||||
" When editing a file, always jump to the last known cursor position.
|
||||
" Don't do it when the position is invalid, when inside an event handler
|
||||
|
|
265
.zshrc2
265
.zshrc2
|
@ -1,123 +1,202 @@
|
|||
# env for shell
|
||||
export TERM="xterm-256color"
|
||||
export LC_ALL=C.UTF-8
|
||||
export LANG=C.UTF-8
|
||||
if (command -v locale >/dev/null) && ( locale -a | grep -qxE "C.UTF-8|C.utf8" ); then
|
||||
export LC_ALL=C.UTF-8
|
||||
export LANG=C.UTF-8
|
||||
else
|
||||
export LC_ALL=en_US.UTF-8
|
||||
export LANG=en_US.UTF-8
|
||||
fi
|
||||
export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
export PATH="$PATH:$DOTFILES/scripts"
|
||||
export EDITOR='vim'
|
||||
# env for apps
|
||||
export PYTHONIOENCODING='UTF-8'
|
||||
export GPG_TTY=$(tty)
|
||||
export LESS_TERMCAP_md=$'\E[01;33m'
|
||||
export VIRTUAL_ENV_DISABLE_PROMPT=1
|
||||
# env for dfs
|
||||
if [[ -f ~/.config/dotfiles/env ]]; then set -a; source ~/.config/dotfiles/env; set +a; fi
|
||||
export DFS_OS_TYPE="$("$DOTFILES/tools/common.sh" get_os_type)"
|
||||
|
||||
# antigen
|
||||
|
||||
# if test -z "$NO_WALL"; then
|
||||
# ANTIGEN_OMZ_REPO_URL="https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git"
|
||||
# ANTIGEN_URL="https://raw.fastgit.org/zsh-users/antigen/master/bin/antigen.zsh"
|
||||
# GIHUB_PROXY="https://hub.fastgit.xyz/"
|
||||
# else
|
||||
# ANTIGEN_URL="git.io/antigen"
|
||||
# GIHUB_PROXY=""
|
||||
# fi
|
||||
# antigen bundle ${GIHUB_PROXY}zsh-users/zsh-syntax-highlighting
|
||||
# antigen bundle ${GIHUB_PROXY}zsh-users/zsh-completions
|
||||
# antigen bundle ${GIHUB_PROXY}zsh-users/zsh-autosuggestions
|
||||
ANTIGEN_OMZ_REPO_URL="https://gitee.com/dictxiong/ohmyzsh.git"
|
||||
ANTIGEN_URL="https://gitee.com/dictxiong/antigen/raw/develop/bin/antigen.zsh"
|
||||
if [[ "$DFS_NO_WALL" == "1" ]]; then
|
||||
ANTIGEN_URL="https://raw.githubusercontent.com/zsh-users/antigen/develop/bin/antigen.zsh"
|
||||
ANTIGEN_OMZ_REPO_URL="https://github.com/ohmyzsh/ohmyzsh.git"
|
||||
ANTIGEN_PLUGINS=(
|
||||
"https://github.com/zdharma-continuum/fast-syntax-highlighting"
|
||||
"https://github.com/zsh-users/zsh-completions"
|
||||
"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/fast-syntax-highlighting"
|
||||
"https://gitee.com/dictxiong/zsh-completions"
|
||||
"https://gitee.com/dictxiong/zsh-autosuggestions"
|
||||
)
|
||||
fi
|
||||
ANTIGEN="$HOME/antigen.zsh"
|
||||
# Install antigen.zsh if not exist
|
||||
if [ ! -f "$ANTIGEN" ]; then
|
||||
echo "Installing antigen ..."
|
||||
TMPFILE="/tmp/antigen.zsh"
|
||||
if [ -x "$(which curl)" ]; then
|
||||
curl -L "$ANTIGEN_URL" -o "$TMPFILE"
|
||||
elif [ -x "$(which wget)" ]; then
|
||||
wget "$ANTIGEN_URL" -O "$TMPFILE"
|
||||
else
|
||||
echo "ERROR: please install curl or wget before installation !!"
|
||||
exit
|
||||
fi
|
||||
if [ ! $? -eq 0 ]; then
|
||||
echo ""
|
||||
echo "ERROR: downloading antigen.zsh ($ANTIGEN_URL) failed !!"
|
||||
exit
|
||||
fi;
|
||||
echo "move $TMPFILE to $ANTIGEN"
|
||||
mv "$TMPFILE" "$ANTIGEN"
|
||||
echo "Installing antigen ..."
|
||||
TMPFILE="/tmp/antigen.zsh"
|
||||
if [ -x "$(which curl)" ]; then
|
||||
curl -L "$ANTIGEN_URL" -o "$TMPFILE"
|
||||
elif [ -x "$(which wget)" ]; then
|
||||
wget "$ANTIGEN_URL" -O "$TMPFILE"
|
||||
else
|
||||
echo "ERROR: please install curl or wget before installation !!"
|
||||
exit
|
||||
fi
|
||||
if [ ! $? -eq 0 ]; then
|
||||
echo ""
|
||||
echo "ERROR: downloading antigen.zsh ($ANTIGEN_URL) failed !!"
|
||||
exit
|
||||
fi;
|
||||
echo "move $TMPFILE to $ANTIGEN"
|
||||
mv "$TMPFILE" "$ANTIGEN"
|
||||
fi
|
||||
# config and enable antigen
|
||||
source "$ANTIGEN"
|
||||
antigen use oh-my-zsh
|
||||
# enable plugins
|
||||
antigen_plugins=( \
|
||||
"command-not-found" \
|
||||
"docker" \
|
||||
"extract" \
|
||||
"fzf" \
|
||||
"git" \
|
||||
"ripgrep" \
|
||||
"thefuck" \
|
||||
"tmux" \
|
||||
"ufw" \
|
||||
"z" \
|
||||
"https://gitee.com/dictxiong/zsh-syntax-highlighting" \
|
||||
"https://gitee.com/dictxiong/zsh-completions" \
|
||||
"https://gitee.com/dictxiong/zsh-autosuggestions" \
|
||||
antigen use oh-my-zsh
|
||||
ANTIGEN_PLUGINS+=(
|
||||
"command-not-found"
|
||||
"docker"
|
||||
"extract"
|
||||
"fzf"
|
||||
"git"
|
||||
"magic-enter"
|
||||
"per-directory-history"
|
||||
"pip"
|
||||
"podman"
|
||||
"python"
|
||||
"ripgrep"
|
||||
"rsync"
|
||||
"systemd"
|
||||
"timer"
|
||||
"tmux"
|
||||
"ufw"
|
||||
"z"
|
||||
)
|
||||
for i in ${antigen_plugins[*]}
|
||||
do
|
||||
for i in ${ANTIGEN_PLUGINS[*]}; do
|
||||
if [[ -z $ANTIGEN_EXCLUDE || ! $i =~ $ANTIGEN_EXCLUDE ]]; then
|
||||
antigen bundle $i
|
||||
fi
|
||||
done
|
||||
# select theme
|
||||
antigen theme ${ZSH_THEME:-ys}
|
||||
TMP_THEME=ys
|
||||
if [[ -e /.dockerenv ]]; then
|
||||
TMP_THEME=robbyrussell
|
||||
echo "==========================="
|
||||
echo "This is in docker container"
|
||||
echo "==========================="
|
||||
fi
|
||||
antigen theme ${ZSH_THEME:-$TMP_THEME}
|
||||
# apply
|
||||
antigen apply
|
||||
# end of antigen config
|
||||
|
||||
# functions
|
||||
export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
|
||||
SUDO=''
|
||||
if (( $EUID != 0 )); then
|
||||
SUDO='sudo'
|
||||
# beacon
|
||||
if [[ -z "$DFS_INITED" && -z "$CI" ]]; then
|
||||
if [[ "$EUID" == "0" ]]; then
|
||||
"$DOTFILES/tools/common.sh" apost_beacon "sys.login.root" "$(who am i | sed -E 's/ +/ /g' | awk '$1=$1')" 2>/dev/null
|
||||
else
|
||||
"$DOTFILES/tools/common.sh" apost_beacon "sys.login.user" "$(who am i | sed -E 's/ +/ /g' | awk '$1=$1')" 2>/dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
dfs()
|
||||
{
|
||||
case $1 in
|
||||
update ) (cd "$DOTFILES" && git pull) ;;
|
||||
force-update ) (cd "$DOTFILES" && git fetch --all && git reset --hard origin/main && git pull) ;;
|
||||
reset )
|
||||
antigen reset 1> /dev/null
|
||||
rm -rf $HOME/.antigen
|
||||
$DOTFILES/install.sh -r
|
||||
dfs update
|
||||
$DOTFILES/install.sh -i
|
||||
echo 'Done. Please open a new shell to see the changes.'
|
||||
;;
|
||||
cd ) cd "$DOTFILES" ;;
|
||||
* ) echo "unknown command \"$1\". available: update, force-update, reset, cd" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
dogo()
|
||||
{
|
||||
if [[ -z "$1" || "$1" =~ "-h|--help" ]]; then
|
||||
echo "usage: dogo <container>"
|
||||
else
|
||||
$SUDO docker exec -it $1 zsh
|
||||
fi
|
||||
}
|
||||
|
||||
# alias
|
||||
alias "pls"='sudo $(fc -ln -1)'
|
||||
alias "se"='sudo -sE'
|
||||
alias "sl"='sudo zsh -l'
|
||||
alias "cps"='rsync -avh --info=progress2'
|
||||
alias "mvs"='rsync -avh --info=progress2 --remove-source-files'
|
||||
if [[ "$DFS_OS_TYPE" == "linux" ]]; then alias "ping"='ping -n'; alias "ping6"='ping6 -n'; fi
|
||||
if [[ "$DFS_OS_TYPE" == "msys" ]]; then alias "tmux"='script -qO /dev/null -c "tmux -u"'; fi
|
||||
alias "pbd"='ping baidu.com'
|
||||
alias "p114"='ping 114.114.114.114'
|
||||
alias "p666"='ping6 2001:da8::666'
|
||||
alias l='ls -lAGh --time-style="+%y-%m-%d %H:%M"'
|
||||
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))"'
|
||||
alias "ls"='ls --color=tty --time-style="+%y-%m-%d %H:%M"'
|
||||
alias "l"='ls -lAGh'
|
||||
alias "jc"='journalctl'
|
||||
alias "jce"='jc -e'
|
||||
alias "jceu"='jc -eu'
|
||||
alias "jcf"='jc -f'
|
||||
alias "jcfu"='jc -fu'
|
||||
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 }
|
||||
sagt() { eval "$($DOTFILES/tools/sagent.sh $@)" }
|
||||
|
||||
# key bindings
|
||||
bindkey "^b" beginning-of-line
|
||||
bindkey "^e" end-of-line
|
||||
bindkey "^[[H" beginning-of-line
|
||||
bindkey "^[[F" end-of-line
|
||||
bindkey "^[[1~" beginning-of-line
|
||||
bindkey "^[[4~" end-of-line
|
||||
bindkey "^[OH" beginning-of-line
|
||||
bindkey "^[OF" end-of-line
|
||||
bindkey "^b" beginning-of-line # ctrl+b
|
||||
bindkey "\eOH" beginning-of-line
|
||||
bindkey "\e[H" beginning-of-line # home; termius
|
||||
bindkey "\e[1~" beginning-of-line
|
||||
|
||||
bindkey "^e" end-of-line # ctrl+e
|
||||
bindkey "\eOF" end-of-line
|
||||
bindkey "\e[F" end-of-line # end; termius
|
||||
bindkey "\e[4~" end-of-line
|
||||
|
||||
bindkey "\ef" forward-word # alt+f
|
||||
bindkey "\e[5C" forward-word
|
||||
bindkey "\e\e[C" forward-word # alt+right_arrow; iterm2
|
||||
bindkey "\e[1;5C" forward-word # alt+right_arrow; termius
|
||||
|
||||
bindkey "\eb" backward-word # alt+e
|
||||
bindkey "\e[5D" backward-word
|
||||
bindkey "\e\e[D" backward-word # alt+left_arrow; iterm2
|
||||
bindkey "\e[1;5D" backward-word # alt+left_arrow; termius
|
||||
|
||||
bindkey "\ed" delete-char # alt+d
|
||||
|
||||
# mods
|
||||
autoload zcalc
|
||||
|
||||
# dfs
|
||||
dfs()
|
||||
{
|
||||
setopt local_options err_return pipe_fail
|
||||
case $1 in
|
||||
cd ) cd "$DOTFILES" ;;
|
||||
update ) "$DOTFILES/update.sh" ;;
|
||||
version ) (cd "$DOTFILES" && git rev-parse HEAD) ;;
|
||||
vversion ) (cd "$DOTFILES" && git show) ;;
|
||||
config )
|
||||
mkdir -p ~/.config/dotfiles
|
||||
$EDITOR ~/.config/dotfiles/env
|
||||
;;
|
||||
force-update ) (
|
||||
cd "$DOTFILES"
|
||||
git fetch --all
|
||||
ref=$(git symbolic-ref --short HEAD 2> /dev/null) || ref=$(git rev-parse --short HEAD 2> /dev/null) || return 0
|
||||
for i in $(git for-each-ref refs/heads --format='%(refname)') ; do git checkout ${i#refs/heads/} ; git pull --ff-only ; done
|
||||
git checkout -c advice.detachedHead=false $ref)
|
||||
;;
|
||||
reset )
|
||||
antigen reset 1> /dev/null
|
||||
rm -rf $HOME/.antigen
|
||||
"$DOTFILES/install.sh" -r
|
||||
dfs update
|
||||
"$DOTFILES/install.sh" -i
|
||||
echo 'Done. Please open a new shell to see the changes.'
|
||||
;;
|
||||
log ) "$DOTFILES/tools/common.sh" "post_log" "INFO" "dfs" "$2" ;;
|
||||
beacon ) "$DOTFILES/tools/common.sh" "post_beacon" "$2" "$3" ;;
|
||||
* ) echo "unknown command \"$1\". available: update, force-update, version, reset, cd, log" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# motd
|
||||
if [[ "$DFS_INITED" != "1" && -n "$DFS_UPDATE_CHANNEL" && "$DFS_UPDATE_CHANNEL" != "main" ]]; then
|
||||
echo dotfiles not in the main channel. use with caution.
|
||||
fi
|
||||
|
||||
# clean
|
||||
unset i
|
||||
export DFS_INITED=1
|
||||
|
|
479
install.sh
479
install.sh
|
@ -1,243 +1,338 @@
|
|||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
source "$THIS_DIR/tools/common.sh"
|
||||
|
||||
# Color settings
|
||||
# Source: https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
|
||||
if [ -t 1 ]; then
|
||||
is_tty() {
|
||||
true
|
||||
}
|
||||
else
|
||||
is_tty() {
|
||||
false
|
||||
}
|
||||
|
||||
if [[ ! "$DOTFILES" == "${HOME}"* ]]; then
|
||||
fmt_fatal "\"$DOTFILES\" is not under \"$HOME\". aborting ..."
|
||||
fi
|
||||
DOTFILE_TILDE=${DOTFILES/"$HOME"/\~}
|
||||
|
||||
supports_truecolor() {
|
||||
case "$COLORTERM" in
|
||||
truecolor|24bit) return 0 ;;
|
||||
esac
|
||||
CRON_JOB="0 * * * * ${DOTFILES}/update.sh"
|
||||
declare -a DFS_CONFIGS
|
||||
declare -a HOME_FILES_PATH
|
||||
declare -a HOME_FILES_CONTENT
|
||||
HOME_FILES_PATH[0]=".zshrc"
|
||||
HOME_FILES_CONTENT[0]="source ${DOTFILE_TILDE}/.zshrc2"
|
||||
HOME_FILES_PATH[1]=".tmux.conf"
|
||||
HOME_FILES_CONTENT[1]="source-file ${DOTFILE_TILDE}/.tmux.conf2"
|
||||
HOME_FILES_PATH[2]=".vimrc"
|
||||
HOME_FILES_CONTENT[2]="source ${DOTFILE_TILDE}/.vimrc2"
|
||||
HOME_FILES_PATH[3]=".gitconfig"
|
||||
HOME_FILES_CONTENT[3]="[include] path = \"${DOTFILE_TILDE}/.gitconfig2\""
|
||||
|
||||
case "$TERM" in
|
||||
iterm |\
|
||||
tmux-truecolor |\
|
||||
linux-truecolor |\
|
||||
xterm-truecolor |\
|
||||
screen-truecolor) return 0 ;;
|
||||
esac
|
||||
declare -a HOME_SYMLINKS_SRC
|
||||
declare -a HOME_SYMLINKS_DST
|
||||
HOME_SYMLINKS_SRC[0]=".ssh/authorized_keys2"
|
||||
HOME_SYMLINKS_DST[0]=".ssh/authorized_keys2"
|
||||
HOME_SYMLINKS_SRC[1]=".eid/authorized_certificates"
|
||||
HOME_SYMLINKS_DST[1]=".eid/authorized_certificates"
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
fmt_fatal() {
|
||||
printf '%sfatal: %s%s\n' "${FMT_BOLD}${FMT_RED}" "$*" "$FMT_RESET" >&2
|
||||
exit
|
||||
}
|
||||
|
||||
fmt_error() {
|
||||
printf '%serror: %s%s\n' "${FMT_RED}" "$*" "$FMT_RESET" >&2
|
||||
}
|
||||
|
||||
fmt_warning() {
|
||||
echo "${FMT_YELLOW}warning: $1 ${FMT_RESET}"
|
||||
}
|
||||
|
||||
fmt_note() {
|
||||
echo "${FMT_GREEN}$1 ${FMT_RESET}"
|
||||
}
|
||||
|
||||
setup_color() {
|
||||
# Only use colors if connected to a terminal
|
||||
if ! is_tty; then
|
||||
FMT_RAINBOW=""
|
||||
FMT_RED=""
|
||||
FMT_GREEN=""
|
||||
FMT_YELLOW=""
|
||||
FMT_BLUE=""
|
||||
FMT_BOLD=""
|
||||
FMT_RESET=""
|
||||
return
|
||||
fi
|
||||
|
||||
if supports_truecolor; then
|
||||
FMT_RAINBOW="
|
||||
$(printf '\033[38;2;255;0;0m')
|
||||
$(printf '\033[38;2;255;97;0m')
|
||||
$(printf '\033[38;2;247;255;0m')
|
||||
$(printf '\033[38;2;0;255;30m')
|
||||
$(printf '\033[38;2;77;0;255m')
|
||||
$(printf '\033[38;2;168;0;255m')
|
||||
$(printf '\033[38;2;245;0;172m')
|
||||
"
|
||||
else
|
||||
FMT_RAINBOW="
|
||||
$(printf '\033[38;5;196m')
|
||||
$(printf '\033[38;5;202m')
|
||||
$(printf '\033[38;5;226m')
|
||||
$(printf '\033[38;5;082m')
|
||||
$(printf '\033[38;5;021m')
|
||||
$(printf '\033[38;5;093m')
|
||||
$(printf '\033[38;5;163m')
|
||||
"
|
||||
fi
|
||||
|
||||
FMT_RED=$(printf '\033[31m')
|
||||
FMT_GREEN=$(printf '\033[32m')
|
||||
FMT_YELLOW=$(printf '\033[33m')
|
||||
FMT_BLUE=$(printf '\033[34m')
|
||||
FMT_BOLD=$(printf '\033[1m')
|
||||
FMT_RESET=$(printf '\033[0m')
|
||||
}
|
||||
# END of color settings
|
||||
|
||||
dotfile_path=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
home_slashes=${HOME//\//\\\/}
|
||||
if [[ ! $dotfile_path == ${home_slashes}* ]]; then
|
||||
fmt_fatal "\"$dotfile_path\" is not under \"$HOME\". aborting ..."
|
||||
fi
|
||||
dotfile_home_path=${dotfile_path/${home_slashes}/\~}
|
||||
dotfile_relative_path=${dotfile_path#${home_slashes}\/}
|
||||
crontab_job="0 * * * * cd ${dotfile_path} && env git pull"
|
||||
|
||||
ask_for_yN()
|
||||
install_dependencies()
|
||||
{
|
||||
while true; do
|
||||
read -p "${FMT_YELLOW}$1${FMT_RESET} [yN]: " yn
|
||||
case $yn in
|
||||
[Yy]* ) return 1;;
|
||||
[Nn]* ) return 0;;
|
||||
* ) return 0;;
|
||||
esac
|
||||
local ret=0
|
||||
fmt_note "installing dependencies ..."
|
||||
set +e
|
||||
case $(get_os_name) in
|
||||
"ubuntu"|"debian" )
|
||||
$SUDOE "$DOTFILES/tools/ubuntu.sh" apt-install
|
||||
ret=$?
|
||||
;;
|
||||
"alpine" )
|
||||
$SUDOE "$DOTFILES/tools/alpine.sh" apk-add
|
||||
ret=$?
|
||||
;;
|
||||
"macos" )
|
||||
"$DOTFILES/tools/macos.sh" brew-install
|
||||
ret=$?
|
||||
;;
|
||||
"msys" )
|
||||
"$DOTFILES/tools/msys2.sh" pacman-S
|
||||
ret=$?
|
||||
;;
|
||||
* ) fmt_error "dfs auto-install is not implemented on OS: $(get_os_name). skipping ..."
|
||||
esac
|
||||
set -e
|
||||
if [[ "$ret" != "0" ]]; then
|
||||
fmt_error "failed to install dependencies."
|
||||
fi
|
||||
}
|
||||
|
||||
preinstall_check()
|
||||
{
|
||||
fmt_note "checking requirements ..."
|
||||
local mandatory_commands=( "git" "zsh" "curl" "grep" "cat" "cp" "bash" "mkdir" )
|
||||
local optional_commands=( "vim" "tmux" "ping" )
|
||||
for i in "${mandatory_commands[@]}"; do
|
||||
if ! command -v $i 1>/dev/null; then
|
||||
fmt_info "all this utils are required: ${mandatory_commands[@]}"
|
||||
fmt_info "install them manually or check scripts in tools/"
|
||||
fmt_fatal "\"$i\" not found. aborting ..."
|
||||
fi
|
||||
done
|
||||
for i in "${optional_commands[@]}"; do
|
||||
if ! command -v $i 1>/dev/null; then
|
||||
fmt_warning "\"$i\" not found"
|
||||
yn=$(ask_for_Yn "continue anyway?")
|
||||
if [[ "$yn" == "0" ]]; then
|
||||
fmt_info "all this utils are suggested: ${optional_commands[@]}"
|
||||
fmt_info "install them manually or check scripts in tools/"
|
||||
fmt_fatal "aborting ..."
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
insert_if_not_exist()
|
||||
prepare_config()
|
||||
{
|
||||
filename=$1
|
||||
line=$2
|
||||
fmt_note "installing \"$line\" into \"$filename\" ..."
|
||||
mkdir -p $(dirname "$filename")
|
||||
if [ ! -f "$filename" ]; then
|
||||
touch $filename
|
||||
local remote=$(cd "$DOTFILES" && git remote get-url origin)
|
||||
if [[ -z "$DFS_NO_WALL" && $remote == *github* ]]; then
|
||||
DFS_CONFIGS+=("DFS_NO_WALL=1")
|
||||
fi
|
||||
grep -qxF -- "$line" "$filename" || echo "$line" >> "$filename"
|
||||
}
|
||||
|
||||
delete_if_exist()
|
||||
{
|
||||
filename=$1
|
||||
line=$2
|
||||
fmt_note "removing \"$line\" from \"$filename\" ..."
|
||||
if [ -f "$filename" ]; then
|
||||
grep -vxF -- "$line" "$filename" | tee "$filename"
|
||||
if [[ ${#DFS_CONFIGS[@]} == 0 ]]; then
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
create_symlink()
|
||||
{
|
||||
src=$1
|
||||
dest=$2
|
||||
fmt_note "creating symlink \"$dest\" --> \"$src\" ..."
|
||||
if [ ! -f "$src" ]; then
|
||||
fmt_error "\"$src\" does not exist! aborting this job ..."
|
||||
return 1
|
||||
fi
|
||||
mkdir -p $(dirname "$dest")
|
||||
if [ -f "$dest" ]; then
|
||||
if [ "$(readlink $dest)" -ef "$src" ]; then
|
||||
return 0
|
||||
fi
|
||||
fmt_warning "\"$dest\" already exists! stat output:"
|
||||
echo ----------
|
||||
stat $dest
|
||||
echo ----------
|
||||
ask_for_yN "would you like to replace ${dest}?"
|
||||
if [ $? -eq 1 ]; then
|
||||
rm $dest
|
||||
fmt_note "preparing dotfiles configurations ..."
|
||||
local key value
|
||||
for i in "${DFS_CONFIGS[@]}"; do
|
||||
if [[ "$i" == *"="* ]]; then
|
||||
key=${i%%=*}
|
||||
value=${i#*=}
|
||||
else
|
||||
fmt_error "\"$dest\" already exists! aborting this job ..."
|
||||
return 1
|
||||
key=$i
|
||||
value=$(eval echo \$$key)
|
||||
fi
|
||||
fi
|
||||
ln -s $src $dest
|
||||
return $?
|
||||
HOME_FILES_PATH+=(".config/dotfiles/env")
|
||||
HOME_FILES_CONTENT+=("$key=$value")
|
||||
echo -n "$key=$value "
|
||||
export $key=$value
|
||||
done
|
||||
echo
|
||||
}
|
||||
|
||||
delete_link_if_match()
|
||||
append_hist()
|
||||
{
|
||||
src=$1
|
||||
dest=$2
|
||||
if [ "$(readlink $dest)" -ef "$src" ]; then
|
||||
fmt_note "removing symlink \"$dest\" ..."
|
||||
echo ----------
|
||||
stat $dest
|
||||
echo ----------
|
||||
rm $dest
|
||||
fmt_note "appending zsh history ..."
|
||||
"$DOTFILES/tools/append_zsh_hist.sh" "$@"
|
||||
}
|
||||
|
||||
install_file_content()
|
||||
{
|
||||
fmt_note "installing file content ..."
|
||||
for ((i=0; i<${#HOME_FILES_PATH[@]}; i++)); do
|
||||
local filename="$HOME/${HOME_FILES_PATH[$i]}"
|
||||
local content="${HOME_FILES_CONTENT[$i]}"
|
||||
fmt_info "installing \"$content\" into \"$filename\" ..."
|
||||
mkdir -p $(dirname "$filename")
|
||||
if [ ! -f "$filename" ]; then
|
||||
touch $filename
|
||||
fi
|
||||
grep -qxF -- "$content" "$filename" || echo "$content" >> "$filename"
|
||||
done
|
||||
}
|
||||
|
||||
uninstall_file_content()
|
||||
{
|
||||
fmt_note "uninstalling file content ..."
|
||||
for ((i=0; i<${#HOME_FILES_PATH[@]}; i++)); do
|
||||
local filename="$HOME/${HOME_FILES_PATH[$i]}"
|
||||
local content=${HOME_FILES_CONTENT[$i]}
|
||||
fmt_info "removing \"$content\" from \"$filename\" ..."
|
||||
if [ -f "$filename" ]; then
|
||||
grep -vxF -- "$content" "$filename" | tee "$filename"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
install_symlink()
|
||||
{
|
||||
fmt_note "installing symlinks ..."
|
||||
for ((i=0; i<${#HOME_SYMLINKS_SRC[@]}; i++)); do
|
||||
if [[ -z "${HOME_SYMLINKS_SRC[$i]}" ]]; then
|
||||
continue
|
||||
fi
|
||||
local src="$DOTFILES/${HOME_SYMLINKS_SRC[$i]}"
|
||||
local dst="$HOME/${HOME_SYMLINKS_DST[$i]}"
|
||||
fmt_info "creating symlink \"$dst\" --> \"$src\" ..."
|
||||
if [ ! -f "$src" ]; then
|
||||
fmt_error "\"$src\" does not exist! aborting this job ..."
|
||||
continue
|
||||
fi
|
||||
mkdir -p $(dirname "$dst")
|
||||
if [ -f "$dst" ]; then
|
||||
if [ "$(readlink $dst)" -ef "$src" ]; then
|
||||
continue
|
||||
fi
|
||||
fmt_warning "\"$dst\" already exists! stat output:"
|
||||
echo ----------
|
||||
stat $dst
|
||||
echo ----------
|
||||
yn=$(ask_for_yN "would you like to replace ${dst}?")
|
||||
if [[ "$yn" == "1" ]]; then
|
||||
rm $dst
|
||||
else
|
||||
fmt_error "aborting this job ..."
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
ln -s $src $dst
|
||||
done
|
||||
}
|
||||
|
||||
uninstall_symlink()
|
||||
{
|
||||
fmt_note "uninstalling symlinks ..."
|
||||
local src
|
||||
for src in "${!HOME_SYMLINKS[@]}"; do
|
||||
local dst=${HOME_SYMLINKS[$src]}
|
||||
src="$DOTFILES/$src"
|
||||
dst="$HOME/$dst"
|
||||
if [ "$(readlink $dst)" -ef "$src" ]; then
|
||||
fmt_info "removing symlink \"$dst\" ..."
|
||||
echo ----------
|
||||
stat $dst
|
||||
echo ----------
|
||||
rm $dst
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
install_crontab()
|
||||
{
|
||||
if [[ -x $(command -v crontab) ]]; then
|
||||
fmt_note "installing \"$CRON_JOB\" to crontab ..."
|
||||
if [[ -z "$(crontab -l 2>/dev/null || true)" ]]; then
|
||||
echo "$CRON_JOB" | crontab -
|
||||
elif !( crontab -l | grep -qxF "${CRON_JOB}"); then
|
||||
( crontab -l; echo "$CRON_JOB" ) | crontab -
|
||||
fi
|
||||
else
|
||||
fmt_warning "crontab does not exist. skipping ..."
|
||||
fi
|
||||
}
|
||||
|
||||
install_crontab(){
|
||||
fmt_note "installing \"$crontab_job\" to crontab ..."
|
||||
( crontab -l | grep -vxF "${crontab_job}" | grep -v "no crontab for"; echo "$crontab_job" ) | crontab -
|
||||
uninstall_crontab()
|
||||
{
|
||||
if [[ -x $(command -v crontab) ]]; then
|
||||
fmt_note "removing \"$CRON_JOB\" from crontab ..."
|
||||
( crontab -l | grep -vxF "$CRON_JOB" ) | crontab -
|
||||
else
|
||||
fmt_note "crontab does not exist. skipping ..."
|
||||
fi
|
||||
}
|
||||
|
||||
uninstall_crontab(){
|
||||
fmt_note "removing \"$crontab_job\" from crontab ..."
|
||||
( crontab -l | grep -vxF "$crontab_job" ) | crontab -
|
||||
}
|
||||
|
||||
install_tmux_tpm(){
|
||||
install_tmux_tpm()
|
||||
{
|
||||
TMUX_TPM="$HOME/.tmux/plugins/tpm"
|
||||
if [[ -x $(command -v tmux) && ! -d "$TMUX_TPM" ]]; then
|
||||
fmt_note "installing tmux tpm ..."
|
||||
git clone https://gitee.com/dictxiong/tpm "$TMUX_TPM"
|
||||
if [[ -x $(command -v g++) && -x $(command -v cmake) && -x $(command -v make) ]]; then
|
||||
fmt_note "initializing tmux plugins ..."
|
||||
~/.tmux/plugins/tpm/bin/install_plugins
|
||||
if [[ -z "$DFS_LITE" || "$DFS_LITE" == "0" ]]; then
|
||||
fmt_note "initializing tmux plugins ..."
|
||||
~/.tmux/plugins/tpm/bin/install_plugins
|
||||
else
|
||||
fmt_warning "in lite mode, tmux plugins are downloaded but not complied"
|
||||
fmt_info "try <prefix + I> or ~/.tmux/plugins/tpm/bin/install_plugins to complie manually"
|
||||
fi
|
||||
else
|
||||
fmt_warning "pls install g++,cmake,make and then init tmux plugins by <prefix + I> or ~/.tmux/plugins/tpm/bin/install_plugins"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
install_vim_vundle(){
|
||||
install_vim_vundle()
|
||||
{
|
||||
VIM_VUNDLE="$HOME/.vim/bundle/Vundle.vim"
|
||||
if [[ -x $(command -v vim) && ! -d "$VIM_VUNDLE" ]]; then
|
||||
fmt_note "installing vim vundle ..."
|
||||
git clone https://gitee.com/dictxiong/Vundle.vim "$VIM_VUNDLE"
|
||||
fmt_note "initializing vim plugins ..."
|
||||
vim +PluginInstall +qall
|
||||
echo | vim +PluginInstall +qall
|
||||
fi
|
||||
}
|
||||
|
||||
install(){
|
||||
install_update()
|
||||
{
|
||||
fmt_note "installing update.sh ..."
|
||||
cp "${DOTFILES}/.update.sh" "${DOTFILES}/update.sh"
|
||||
chmod +x "${DOTFILES}/update.sh"
|
||||
fmt_note "running update.sh ..."
|
||||
set +e
|
||||
DFS_UPDATED_RET=85 ${DOTFILES}/update.sh
|
||||
RET=$?
|
||||
if [[ $RET == 85 ]]; then
|
||||
fmt_note "dfs updated. re-running install.sh ..."
|
||||
"${DOTFILES}/install.sh" "${ORIGIN_ARGS[@]}" && exit
|
||||
elif [[ $RET != 0 ]]; then
|
||||
fmt_fatal "update.sh failed with exit code $RET"
|
||||
fi
|
||||
set -e
|
||||
}
|
||||
|
||||
uninstall_update()
|
||||
{
|
||||
fmt_note "removing update.sh ..."
|
||||
rm "${DOTFILES}/update.sh"
|
||||
}
|
||||
|
||||
install()
|
||||
{
|
||||
if [[ "$INSTALL_DEP" == "1" ]]; then install_dependencies; fi
|
||||
prepare_config
|
||||
install_update
|
||||
preinstall_check
|
||||
install_crontab
|
||||
insert_if_not_exist "${HOME}/.zshrc" "source ${dotfile_home_path}/.zshrc2"
|
||||
insert_if_not_exist "${HOME}/.tmux.conf" "source-file ${dotfile_home_path}/.tmux.conf2"
|
||||
insert_if_not_exist "${HOME}/.vimrc" "source ${dotfile_home_path}/.vimrc2"
|
||||
insert_if_not_exist "${HOME}/.gitconfig" "[include] path = \"${dotfile_home_path}/.gitconfig2\""
|
||||
create_symlink "${dotfile_path}/.ssh/authorized_keys2" "${HOME}/.ssh/authorized_keys2"
|
||||
install_file_content
|
||||
install_symlink
|
||||
apost_beacon "dfs.installed"
|
||||
# those that won't be uninstalled in the future
|
||||
install_tmux_tpm
|
||||
install_vim_vundle
|
||||
if [[ -n "$DFS_HIST" ]]; then append_hist "$DFS_HIST"; fi
|
||||
fmt_note "done installing!"
|
||||
}
|
||||
|
||||
uninstall(){
|
||||
ask_for_yN "do you really want to uninstall?"
|
||||
if [[ $? == 1 ]]; then
|
||||
uninstall_crontab
|
||||
delete_if_exist "${HOME}/.zshrc" "source ${dotfile_home_path}/.zshrc2"
|
||||
delete_if_exist "${HOME}/.tmux.conf" "source-file ${dotfile_home_path}/.tmux.conf2"
|
||||
delete_if_exist "${HOME}/.vimrc" "source ${dotfile_home_path}/.vimrc2"
|
||||
delete_if_exist "${HOME}/.gitconfig" "[include] path = \"${dotfile_home_path}/.gitconfig2\""
|
||||
delete_link_if_match "${dotfile_path}/.ssh/authorized_keys2" "${HOME}/.ssh/authorized_keys2"
|
||||
fmt_note "done uninstalling!"
|
||||
uninstall()
|
||||
{
|
||||
yn=$(ask_for_yN "do you really want to uninstall?")
|
||||
if [[ "$yn" != "1" ]]; then
|
||||
fmt_fatal "aborting this job ..."
|
||||
fi
|
||||
uninstall_update
|
||||
uninstall_crontab
|
||||
uninstall_file_content
|
||||
uninstall_symlink
|
||||
apost_beacon "dfs.uninstalled"
|
||||
fmt_note "done uninstalling!"
|
||||
}
|
||||
|
||||
setup_color
|
||||
case $1 in
|
||||
""|-i ) install ;;
|
||||
-r ) uninstall ;;
|
||||
* ) fmt_warning "unknown command \"$1\". available: -i, -r" ;;
|
||||
esac
|
||||
echo "this is the dotfiles installer, version $(cd "$DOTFILES" && git describe --tags --always --dirty)"
|
||||
echo "install options:" "${GOT_OPTS[@]}"
|
||||
FUNC=install
|
||||
INSTALL_DEP=0
|
||||
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
|
||||
-i ) FUNC=install ;;
|
||||
-r ) FUNC=uninstall ;;
|
||||
-a|--auto ) INSTALL_DEP=1 ;;
|
||||
-H|--hist|--history ) store_hist=1 ;;
|
||||
-x ) store_config=1 ;;
|
||||
--no-auth-info ) HOME_SYMLINKS_SRC=(); HOME_SYMLINKS_DST=() ;;
|
||||
* ) fmt_fatal "unknown option \"$i\"" ;;
|
||||
esac
|
||||
done
|
||||
$FUNC
|
||||
|
|
63
riot-config.sh
Normal file
63
riot-config.sh
Normal file
|
@ -0,0 +1,63 @@
|
|||
#!/bin/false
|
||||
|
||||
# remotes
|
||||
j.remote() {
|
||||
remote=ssh.beardic.cn
|
||||
RET_PORT=${RET_PORT:-24022}
|
||||
RET_USERNAME=${RET_USERNAME:-root}
|
||||
RET_TRUST_SERVER=1
|
||||
}
|
||||
|
||||
nasp.remote() {
|
||||
remote=nasp.fit
|
||||
RET_PORT=${RET_PORT:-36022}
|
||||
RET_USERNAME=${RET_USERNAME:-root}
|
||||
RET_TRUST_SERVER=1
|
||||
}
|
||||
|
||||
# domains
|
||||
.domain() {
|
||||
RET_USERNAME=${RET_USERNAME:-root}
|
||||
}
|
||||
|
||||
dxng.domain() {
|
||||
RET_HOSTNAME=$host.dxng.net
|
||||
RET_PORT=${RET_PORT:-12022}
|
||||
RET_USERNAME=${RET_USERNAME:-root}
|
||||
RET_TRUST_SERVER=1
|
||||
}
|
||||
|
||||
i.domain() {
|
||||
RET_HOSTNAME=$host.ibd.ink
|
||||
RET_PORT=${RET_PORT:-12022}
|
||||
RET_USERNAME=${RET_USERNAME:-root}
|
||||
RET_TRUST_SERVER=1
|
||||
}
|
||||
|
||||
42.domain() {
|
||||
RET_HOSTNAME=$host.i.bd.dn42
|
||||
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:-root}
|
||||
RET_JUMP_SERVER="ssh@nasp.fit:36022"
|
||||
RET_TRUST_SERVER=1
|
||||
}
|
||||
|
||||
default.domain() {
|
||||
dxng.domain
|
||||
}
|
30
scripts/dogo
Executable file
30
scripts/dogo
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
source "$THIS_DIR/../tools/common.sh"
|
||||
|
||||
DOCKER_FORMAT="{{.ID}} {{.Image}} {{.Names}}"
|
||||
if [[ -z "$1" || "$1" =~ ^(-h|--help)$ ]]; then
|
||||
fmt_info "usage: $0 <container> or -[0-9]*"
|
||||
exit
|
||||
elif [[ "$1" =~ ^-[0-9]*$ ]]; then
|
||||
LAST="${1:1}"
|
||||
if [[ "$LAST" == "0" ]]; then
|
||||
# the latest running container
|
||||
CONTAINER_META=($($SUDO docker container ls -l --filter "status=running" --format "$DOCKER_FORMAT"))
|
||||
else
|
||||
# the last nth container (all status)
|
||||
CONTAINER_META=($($SUDO docker container ls -n ${LAST:-1} --format "$DOCKER_FORMAT" | tail -n 1))
|
||||
fi
|
||||
CONTAINER=${CONTAINER_META[0]}
|
||||
else
|
||||
CONTAINER_META="$1"
|
||||
CONTAINER="$1"
|
||||
fi
|
||||
|
||||
if [[ -z "$CONTAINER" ]]; then
|
||||
fmt_fatal "container not found"
|
||||
else
|
||||
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'
|
||||
fi
|
25
scripts/doll
Executable file
25
scripts/doll
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
source "$THIS_DIR/../tools/common.sh"
|
||||
|
||||
DOCKER_FORMAT="{{.ID}} {{.Repository}}:{{.Tag}}"
|
||||
if [[ -z "$1" || "$1" =~ ^(-h|--help)$ ]]; then
|
||||
fmt_info "usage: $0 <image> or -[0-9]*"
|
||||
exit
|
||||
elif [[ "$1" =~ ^-[0-9]*$ ]]; then
|
||||
LAST="${1:1}"
|
||||
# the last nth image
|
||||
IMAGE_META=($($SUDO docker image ls --format "$DOCKER_FORMAT" | head -n ${LAST:-1} | tail -n 1))
|
||||
IMAGE=${IMAGE_META[0]}
|
||||
else
|
||||
IMAGE_META="$1"
|
||||
IMAGE="$1"
|
||||
fi
|
||||
|
||||
if [[ -z "$IMAGE" ]]; then
|
||||
fmt_fatal "image not found"
|
||||
else
|
||||
fmt_note "--> ${IMAGE_META[@]}"
|
||||
$SUDO docker run ${2:+"--name"} $2 -itd --restart=unless-stopped $IMAGE sh
|
||||
fi
|
44
scripts/pbin
Executable file
44
scripts/pbin
Executable file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env 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[@]}"
|
265
scripts/riot
Executable file
265
scripts/riot
Executable file
|
@ -0,0 +1,265 @@
|
|||
#!/usr/bin/env 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}
|
||||
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
|
||||
test $1 -lt 65536 -a $1 -gt 0 || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
# check if username valid
|
||||
check_username() {
|
||||
( echo $1 | grep -qxE "^[a-z][-a-z0-9_]*\$" ) || return 1
|
||||
return 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#*@}
|
||||
check_username $RET_USERNAME || fmt_warning \"$RET_USERNAME\" is not a valid unix username
|
||||
fi
|
||||
# if in the form ...:22
|
||||
if [[ "$remote" == "["*"]":* || ( "$remote" != "["*"]" && "$remote" == *:* ) ]]; then
|
||||
RET_PORT=${remote##*:}
|
||||
remote=${remote%:*}
|
||||
check_port $RET_PORT || fmt_fatal invalid port number \"$RET_PORT\"
|
||||
fi
|
||||
# presets -- match remote
|
||||
local remote_func="$remote.remote"
|
||||
if is_function "$remote_func"; then
|
||||
"$remote_func"
|
||||
fi
|
||||
# presets -- match domain
|
||||
RET_HOSTNAME=${remote}
|
||||
local domain=${remote##*.}
|
||||
local host=${remote%.*}
|
||||
# if there's no dot
|
||||
if [[ "$host" == "$domain" && "$host" != "["*"]" ]]; then
|
||||
domain="default"
|
||||
fi
|
||||
local domain_func="$domain.domain"
|
||||
if is_function "$domain_func"; then
|
||||
"$domain_func"
|
||||
elif is_function ".domain"; then
|
||||
".domain"
|
||||
fi
|
||||
}
|
||||
|
||||
parse_remote() {
|
||||
# remote setting, including jump servers
|
||||
# called for every remote
|
||||
# provides:
|
||||
SERVER=""
|
||||
TRUST_SERVER=1
|
||||
PORT="" # optional
|
||||
USERNAME="" # optional
|
||||
SSH_OPTIONS="" # optional
|
||||
if [[ "$RIOT_TRUST_CLIENT" == "1" ]]; then
|
||||
SSH_OPTIONS='-o PermitLocalCommand=yes'
|
||||
if [[ "$(get_os_type)" != "msys" ]]; then
|
||||
test "$DFS_DRY_RUN" = "1" || mkdir -p ~/.ssh/master-socket
|
||||
SSH_OPTIONS="$SSH_OPTIONS -o ControlMaster=auto -o ControlPath=~/.ssh/master-socket/%C"
|
||||
fi
|
||||
fi
|
||||
# handle input
|
||||
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 $RIOT_EXTRA_OPTIONS $SCP_SRC $USERNAME${USERNAME:+@}$SERVER $SCP_DST ${@:2}"
|
||||
}
|
||||
|
||||
# ssh
|
||||
run_ssh()
|
||||
{
|
||||
local cmd="$(prepare_ssh_cmd $@)"
|
||||
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
|
||||
local port=$(get_free_port)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
# sshd
|
||||
run_sshd()
|
||||
{
|
||||
local port=$(get_free_port)
|
||||
|
||||
SSH_OPTIONS="$SSH_OPTIONS -NC -D $port"
|
||||
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
|
||||
|
||||
while [[ "$1" == -* ]]; do
|
||||
RIOT_EXTRA_OPTIONS="$RIOT_EXTRA_OPTIONS $1"
|
||||
if [[ "$1" == "-o" ]]; then
|
||||
RIOT_EXTRA_OPTIONS="$RIOT_EXTRA_OPTIONS $2"
|
||||
shift
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
IFS=',' read -ra remotes <<< "$1"
|
||||
for remote in "${remotes[@]}"; do
|
||||
if [[ -z "$remote" ]]; then
|
||||
continue
|
||||
fi
|
||||
parse_remote "$remote"
|
||||
case $2 in
|
||||
ssh|"" )
|
||||
run_ssh ssh "${@:3}"
|
||||
;;
|
||||
ping|ping6 )
|
||||
run_ssh ssh "${@:2}"
|
||||
;;
|
||||
zssh )
|
||||
run_ssh zssh
|
||||
;;
|
||||
sftp )
|
||||
run_ssh sftp
|
||||
;;
|
||||
sshl )
|
||||
test -n "$3" || fmt_fatal "no target address provided"
|
||||
run_sshl "$3"
|
||||
;;
|
||||
sshd )
|
||||
run_sshd
|
||||
;;
|
||||
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
|
||||
done
|
||||
}
|
||||
|
||||
router "${GOT_OPTS[@]}"
|
|
@ -1,29 +1,23 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [[ $USER != "root" ]]; then
|
||||
echo "must run as root!"
|
||||
exit 1
|
||||
fi
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
source "$THIS_DIR/common.sh"
|
||||
|
||||
set_mirror()
|
||||
{
|
||||
#MIRROR=${1:="mirrors.tuna.tsinghua.edu.cn"}
|
||||
#MIRROR=${MIRROR//\//\\\/}
|
||||
#sed -i 's/(archive|security).ubuntu.com/${MIRROR}/g' /etc/apt/sources.list
|
||||
echo "to-do ..."
|
||||
MIRROR=${1:-"mirrors.tuna.tsinghua.edu.cn"}
|
||||
sed -i "s@dl-cdn.alpinelinux.org@${MIRROR}@g" /etc/apk/repositories
|
||||
}
|
||||
|
||||
apk_add()
|
||||
{
|
||||
apk update
|
||||
|
||||
# mass installation
|
||||
apk add zsh git tmux vim curl wget bash python3 htop gcc g++ cmake make fzf perl linux-headers bind-tools iputils man-db
|
||||
#for i in {fzf,ripgrep}; do apk add $i -y; done
|
||||
|
||||
# who am i
|
||||
git config --global user.email "me@beardic.cn"
|
||||
git config --global user.name "Dict Xiong"
|
||||
# lite
|
||||
apk add zsh bash git tmux vim curl fzf iputils coreutils util-linux
|
||||
# full
|
||||
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
|
||||
fi
|
||||
}
|
||||
|
||||
set_timezone()
|
||||
|
@ -39,9 +33,9 @@ router()
|
|||
case $1 in
|
||||
apk-add ) apk_add ;;
|
||||
set-timezone | set-tz ) set_timezone ;;
|
||||
#set-mirror ) set_mirror $2 ;;
|
||||
* ) echo unknown command "$1". available: apk-add, set-timezone;;
|
||||
set-mirror ) set_mirror $2 ;;
|
||||
* ) echo unknown command \"$1\". available: apk-add, set-timezone;;
|
||||
esac
|
||||
}
|
||||
|
||||
router $@
|
||||
router "${GOT_OPTS[@]}"
|
||||
|
|
33
tools/append_zsh_hist.sh
Executable file
33
tools/append_zsh_hist.sh
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env 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[@]}"
|
276
tools/common.sh
Executable file
276
tools/common.sh
Executable file
|
@ -0,0 +1,276 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
THIS_DIR_COMMON_SH=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
export DOTFILES=$( cd "$THIS_DIR_COMMON_SH/.." && pwd )
|
||||
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
|
||||
# Source: https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
|
||||
if [[ -t 1 || "$DFS_COLOR" == "1" ]]; then
|
||||
is_tty() {
|
||||
true
|
||||
}
|
||||
else
|
||||
is_tty() {
|
||||
false
|
||||
}
|
||||
fi
|
||||
|
||||
supports_truecolor() {
|
||||
case "$COLORTERM" in
|
||||
truecolor|24bit) return 0 ;;
|
||||
esac
|
||||
|
||||
case "$TERM" in
|
||||
iterm |\
|
||||
tmux-truecolor |\
|
||||
linux-truecolor |\
|
||||
xterm-truecolor |\
|
||||
screen-truecolor) return 0 ;;
|
||||
esac
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
fmt_fatal() {
|
||||
printf '%sfatal: %s%s\n' "${FMT_BOLD}${FMT_RED}" "$*" "${FMT_RESET}" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
fmt_error() {
|
||||
printf '%serror: %s%s\n' "${FMT_RED}" "$*" "${FMT_RESET}" >&2
|
||||
}
|
||||
|
||||
fmt_warning() {
|
||||
printf '%swarning: %s%s\n' "${FMT_YELLOW}" "$*" "${FMT_RESET}" >&2
|
||||
}
|
||||
|
||||
fmt_info() {
|
||||
printf '%sinfo: %s\n' "${FMT_RESET}" "$*" >&2
|
||||
}
|
||||
|
||||
fmt_note() {
|
||||
printf '%s%s%s\n' "${FMT_GREEN}" "$*" "${FMT_RESET}" >&2
|
||||
}
|
||||
|
||||
setup_color() {
|
||||
# Only use colors if connected to a terminal
|
||||
if ! is_tty; then
|
||||
FMT_RAINBOW=""
|
||||
FMT_RED=""
|
||||
FMT_GREEN=""
|
||||
FMT_YELLOW=""
|
||||
FMT_BLUE=""
|
||||
FMT_BOLD=""
|
||||
FMT_RESET=""
|
||||
return
|
||||
fi
|
||||
|
||||
if supports_truecolor; then
|
||||
FMT_RAINBOW="
|
||||
$(printf '\033[38;2;255;0;0m')
|
||||
$(printf '\033[38;2;255;97;0m')
|
||||
$(printf '\033[38;2;247;255;0m')
|
||||
$(printf '\033[38;2;0;255;30m')
|
||||
$(printf '\033[38;2;77;0;255m')
|
||||
$(printf '\033[38;2;168;0;255m')
|
||||
$(printf '\033[38;2;245;0;172m')
|
||||
"
|
||||
else
|
||||
FMT_RAINBOW="
|
||||
$(printf '\033[38;5;196m')
|
||||
$(printf '\033[38;5;202m')
|
||||
$(printf '\033[38;5;226m')
|
||||
$(printf '\033[38;5;082m')
|
||||
$(printf '\033[38;5;021m')
|
||||
$(printf '\033[38;5;093m')
|
||||
$(printf '\033[38;5;163m')
|
||||
"
|
||||
fi
|
||||
|
||||
FMT_RED=$(printf '\033[31m')
|
||||
FMT_GREEN=$(printf '\033[32m')
|
||||
FMT_YELLOW=$(printf '\033[33m')
|
||||
FMT_BLUE=$(printf '\033[34m')
|
||||
FMT_BOLD=$(printf '\033[1m')
|
||||
FMT_RESET=$(printf '\033[0m')
|
||||
}
|
||||
# END of color settings
|
||||
|
||||
SUDO=''
|
||||
SUDOE=''
|
||||
if [[ "$EUID" != "0" && -x $(command -v sudo) ]]; then
|
||||
SUDO='sudo'
|
||||
SUDOE='sudo -E'
|
||||
fi
|
||||
|
||||
ask_for_yN()
|
||||
{
|
||||
if [[ "$DFS_QUIET" == "1" ]]; then
|
||||
echo 0
|
||||
else
|
||||
read -p "${FMT_YELLOW}$1${FMT_RESET} [yN]: " yn
|
||||
case $yn in
|
||||
[Yy]* ) echo 1;;
|
||||
* ) echo 0;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
ask_for_Yn()
|
||||
{
|
||||
if [[ "$DFS_QUIET" == "1" ]]; then
|
||||
echo 1
|
||||
else
|
||||
read -p "${FMT_YELLOW}$1${FMT_RESET} [Yn]: " yn
|
||||
case $yn in
|
||||
[Nn]* ) echo 0;;
|
||||
* ) echo 1;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
post_log()
|
||||
{
|
||||
if [[ $# != 3 || -z "$1" || -z "$2" || -z "$3" ]]; then
|
||||
fmt_fatal "usage: post_log <level> <section> <content>"
|
||||
fi
|
||||
"${DOTFILES}/tools/frigg-client.sh" "log" "[$1][$2] $3"
|
||||
}
|
||||
|
||||
apost_log()
|
||||
{
|
||||
post_log "$@" 1>/dev/null &
|
||||
}
|
||||
|
||||
post_beacon()
|
||||
{
|
||||
if [[ $# < 1 || -z "$1" ]]; then
|
||||
fmt_fatal "usage: post_beacon <beacon>"
|
||||
fi
|
||||
"${DOTFILES}/tools/frigg-client.sh" "beacon" "$1" "$2"
|
||||
}
|
||||
|
||||
apost_beacon()
|
||||
{
|
||||
post_beacon "$@" 1>/dev/null &
|
||||
}
|
||||
|
||||
get_os_type()
|
||||
{
|
||||
test -z "$DFS_OS_TYPE" || { echo "$DFS_OS_TYPE"; return; }
|
||||
local ans="unknown"
|
||||
case "$(uname -s)" in
|
||||
Darwin*) ans="MacOS";;
|
||||
CYGWIN*) ans="Cygwin";;
|
||||
MSYS* ) ans="MSYS";;
|
||||
Linux* ) ans="Linux";;
|
||||
*) ans="unknown";;
|
||||
esac
|
||||
export DFS_OS_TYPE="$ans"
|
||||
echo $ans | tr '[:upper:]' '[:lower:]'
|
||||
}
|
||||
|
||||
get_linux_dist()
|
||||
{
|
||||
test -z "$DFS_LINUX_DIST" || { echo "$DFS_LINUX_DIST"; return; }
|
||||
local ans="unknown"
|
||||
if [ -f /etc/os-release ]; then
|
||||
. /etc/os-release
|
||||
ans="$ID"
|
||||
elif type lsb_release >/dev/null 2>&1; then
|
||||
ans="$(lsb_release -si)"
|
||||
elif [ -f /etc/lsb-release ]; then
|
||||
. /etc/lsb-release
|
||||
ans="$DISTRIB_ID"
|
||||
elif [ -f /etc/debian_version ]; then
|
||||
ans="Debian"
|
||||
elif [ -f /etc/SuSe-release ]; then
|
||||
ans="SUSE"
|
||||
elif [ -f /etc/redhat-release ]; then
|
||||
ans="RedHat"
|
||||
else
|
||||
ans="unknown"
|
||||
fi
|
||||
export DFS_LINUX_DIST="$ans"
|
||||
echo $ans | tr '[:upper:]' '[:lower:]'
|
||||
}
|
||||
|
||||
get_os_name()
|
||||
{
|
||||
local ans=$(get_os_type)
|
||||
if [[ "$ans" == "linux" ]]; then
|
||||
ans=$(get_linux_dist)
|
||||
fi
|
||||
echo $ans
|
||||
}
|
||||
|
||||
is_port_free() {
|
||||
( echo $1 | grep -qxE "[1-9][0-9]{0,4}" ) || false
|
||||
local cmd
|
||||
case $(get_os_type) in
|
||||
macos ) cmd="netstat -van | grep -q \".$1\"" ;;
|
||||
cygwin|msys ) cmd="netstat -ano | grep -q \":$1\"" ;;
|
||||
*) cmd="netstat -tuanp | grep -q \":$1\"" ;;
|
||||
esac
|
||||
if eval $cmd; then
|
||||
return 2
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
get_free_port() {
|
||||
while
|
||||
local port=$(shuf -n 1 -i 49152-65535)
|
||||
! is_port_free $port
|
||||
do
|
||||
continue
|
||||
done
|
||||
echo $port
|
||||
}
|
||||
|
||||
is_function() {
|
||||
test "$(type -t "$1")" = "function"
|
||||
}
|
||||
|
||||
# if bash-ed, else source-d
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
$1 "${@:2}"
|
||||
else
|
||||
setup_color
|
||||
fi
|
||||
|
||||
unset THIS_DIR_COMMON_SH
|
166
tools/frigg-client.sh
Executable file
166
tools/frigg-client.sh
Executable file
|
@ -0,0 +1,166 @@
|
|||
#!/usr/bin/env 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"
|
||||
api_url="https://api4.beardic.cn"
|
||||
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
63
tools/get.dotfiles.cn
Normal file
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/env 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
|
|
@ -1,21 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
declare -A install_commands
|
||||
install_commands=(\
|
||||
[git]="apt update && apt install git" \
|
||||
[fzf]="git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install" \
|
||||
[acme.sh]="curl https://get.acme.sh | sh -s email=${EMAIL:-me@beardic.cn}" \
|
||||
[oh-my-zsh]='sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"' \
|
||||
[oh-my-tuna]='wget https://tuna.moe/oh-my-tuna/oh-my-tuna.py && sudo python oh-my-tuna.py --global' \
|
||||
[v2ray]="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' \
|
||||
[docker-ce]='curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh #--mirror Aliyun #--dry-run' \
|
||||
[lemonbench]='curl -fsSL https://ilemonra.in/LemonBenchIntl | bash -s fast # or full' \
|
||||
)
|
||||
|
||||
install()
|
||||
{
|
||||
echo -e ${install_commands[$1]}
|
||||
}
|
||||
|
||||
install $1
|
20
tools/macos.sh
Executable file
20
tools/macos.sh
Executable file
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
source "$THIS_DIR/common.sh"
|
||||
|
||||
brew_install()
|
||||
{
|
||||
# brew update
|
||||
brew install git zsh curl tmux vim util-linux coreutils
|
||||
}
|
||||
|
||||
router()
|
||||
{
|
||||
case $1 in
|
||||
brew-install ) brew_install ;;
|
||||
* ) echo unknown command \"$1\". available: brew-install;;
|
||||
esac
|
||||
}
|
||||
|
||||
router "${GOT_OPTS[@]}"
|
|
@ -1,9 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [[ $USER != "root" ]]; then
|
||||
echo "must run as root!"
|
||||
exit 1
|
||||
fi
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
source "$THIS_DIR/common.sh"
|
||||
|
||||
set_mirror()
|
||||
{
|
||||
|
@ -16,16 +14,21 @@ set_mirror()
|
|||
pacman_S()
|
||||
{
|
||||
pacman -Syu
|
||||
pacman -S tmux git zsh curl vim wget base-devel mingw-w64-x86_64-toolchain make cmake gcc zip unzip
|
||||
# lite
|
||||
pacman -S tmux git zsh bash curl vim
|
||||
# full
|
||||
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
|
||||
fi
|
||||
}
|
||||
|
||||
router()
|
||||
{
|
||||
case $1 in
|
||||
pacman-S ) pacman_S ;;
|
||||
pacman-S ) pacman_S ;;
|
||||
set-mirror ) set_mirror $2 ;;
|
||||
* ) echo unknown command "$1". available: pacman-S, set-mirror ;;
|
||||
* ) echo unknown command \"$1\". available: pacman-S, set-mirror ;;
|
||||
esac
|
||||
}
|
||||
|
||||
router $@
|
||||
router "${GOT_OPTS[@]}"
|
||||
|
|
111
tools/sagent.sh
Executable file
111
tools/sagent.sh
Executable file
|
@ -0,0 +1,111 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
export DFS_COLOR=1
|
||||
source "$THIS_DIR/common.sh"
|
||||
|
||||
|
||||
SO_PATHS=(
|
||||
"/usr/lib/x86_64-linux-gnu/opensc-pkcs11.so" # ubuntu 22.04
|
||||
"/run/current-system/sw/lib/opensc-pkcs11.so" # nixos 23.05
|
||||
"/Library/OpenSC/lib/opensc-pkcs11.so" # macos 13.4
|
||||
)
|
||||
|
||||
find_so_file()
|
||||
{
|
||||
local SO_FILE
|
||||
for SO_FILE in ${SO_PATHS[*]}; do
|
||||
if [[ -f "$SO_FILE" ]]; then
|
||||
echo "$SO_FILE"
|
||||
return
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
create_agent()
|
||||
{
|
||||
local IFS=","
|
||||
ssh-agent -P "${SO_PATHS[*]},/nix/store/*"
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
test -d ~/.ssh || mkdir ~/.ssh
|
||||
local agent_file=~/.ssh/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
21
tools/test-getopts.sh
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env 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
|
76
tools/test.zsh
Normal file
76
tools/test.zsh
Normal file
|
@ -0,0 +1,76 @@
|
|||
#!/bin/false "This script should be sourced in zsh, not executed directly"
|
||||
|
||||
set -ex
|
||||
trap "dfs beacon gh.ci.fail" ERR
|
||||
|
||||
# fix for macos
|
||||
dfs cd
|
||||
if [[ $(./tools/common.sh get_os_type) == "macos" ]]; then
|
||||
export PATH="/usr/local/opt/coreutils/libexec/gnubin:/opt/homebrew/opt/coreutils/libexec/gnubin:${PATH}"
|
||||
fi
|
||||
|
||||
# check files
|
||||
cd /
|
||||
l
|
||||
cd ~
|
||||
l
|
||||
dfs cd
|
||||
l
|
||||
pwd
|
||||
test -f .zshrc2
|
||||
diff -q ./.ssh/authorized_keys2 ~/.ssh/authorized_keys2
|
||||
diff -q ./.eid/authorized_certificates ~/.eid/authorized_certificates
|
||||
grep -q ".zshrc2" ~/.zshrc
|
||||
if [[ -x $(command -v crontab) ]]; then
|
||||
crontab -l | grep -qxF "0 * * * * ${DOTFILES}/update.sh"
|
||||
fi
|
||||
|
||||
# check scripts and functions
|
||||
dfs version
|
||||
dfs log 1
|
||||
dfs beacon gh.ci $GITHUB_SHA
|
||||
z ~
|
||||
test ~ -ef "$(pwd)"
|
||||
dogo
|
||||
doll
|
||||
dfs cd
|
||||
tools/test-getopts.sh
|
||||
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,another@host scp /tmp/ ./tmp -D 2>/dev/null)" = 'scp -P 12022 -o PermitLocalCommand=yes -o ControlMaster=auto -o ControlPath=~/.ssh/master-socket/%C -o ProxyJump=time@is.impt:2222,yes@you-r.right,you@are.really.recht.,root@ibd. -r try@it.dxng.net:"/tmp/" "./tmp"
|
||||
scp -P 12022 -o PermitLocalCommand=yes -o ControlMaster=auto -o ControlPath=~/.ssh/master-socket/%C -o ForwardX11=yes -o ForwardAgent=yes -r another@host.dxng.net:"/tmp/" "./tmp"'
|
||||
|
||||
# check alias
|
||||
alias p114
|
||||
alias cbds
|
||||
which riot
|
||||
sagt
|
||||
test -f ~/.ssh/agent-$(whoami)
|
||||
gbes || which gbes
|
||||
|
||||
# check update
|
||||
DFS_VERSION=`dfs version`
|
||||
dfs update
|
||||
dfs version
|
||||
test `git rev-parse HEAD` = `curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id`
|
||||
|
||||
# clean
|
||||
git reset --hard $DFS_VERSION
|
||||
|
||||
# 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
|
||||
dfs version
|
||||
test `git rev-parse HEAD` = `curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id`
|
||||
|
||||
# clean
|
||||
git reset --hard $DFS_VERSION
|
||||
|
||||
set +x
|
23
tools/to-install.sh
Executable file
23
tools/to-install.sh
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
declare -A INSTALL_COMMANDS
|
||||
INSTALL_COMMANDS=(\
|
||||
[git]="apt update && apt install git" \
|
||||
[fzf]="git clone --depth 1 https://gitee.com/dictxiong/fzf.git ~/.fzf && ~/.fzf/install" \
|
||||
[acme.sh]="curl https://get.acme.sh | sh -s email=${EMAIL:-me@beardic.cn}" \
|
||||
[oh-my-zsh]='sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"' \
|
||||
[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" \
|
||||
[zerotier-one]='curl -s https://install.zerotier.com | sudo bash' \
|
||||
[docker-ce]='curl -fsSL https://get.docker.com | sudo bash -s - --mirror Aliyun #--dry-run' \
|
||||
[lemonbench]='curl -fsSL https://raw.githubusercontent.com/LemonBench/LemonBench/main/LemonBench.sh | bash -s fast # or full' \
|
||||
[nix]='sh <(curl -L https://nixos.org/nix/install) #--daemon' \
|
||||
[alist]='curl -fsSL "https://alist.nn.ci/v3.sh" | bash -s install' \
|
||||
)
|
||||
|
||||
install()
|
||||
{
|
||||
echo -e ${INSTALL_COMMANDS[$1]}
|
||||
}
|
||||
|
||||
install $1
|
|
@ -1,26 +1,25 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [[ $USER != "root" ]]; then
|
||||
echo "must run as root!"
|
||||
exit 1
|
||||
fi
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
source "$THIS_DIR/common.sh"
|
||||
|
||||
set_mirror()
|
||||
{
|
||||
MIRROR=${1:-"mirrors.tuna.tsinghua.edu.cn"}
|
||||
MIRROR=${MIRROR//\//\\\/}
|
||||
sed -i 's/(archive|security).ubuntu.com/${MIRROR}/g' /etc/apt/sources.list
|
||||
sed -i "s@http://.*archive.ubuntu.com@https://${MIRROR}@g" /etc/apt/sources.list
|
||||
sed -i "s@http://.*security.ubuntu.com@https://${MIRROR}@g" /etc/apt/sources.list
|
||||
}
|
||||
|
||||
apt_install()
|
||||
{
|
||||
# basic packages
|
||||
apt update
|
||||
for i in {man-db,vim,ca-certificates}; do apt install $i -y; done
|
||||
|
||||
# mass installation
|
||||
apt install git tmux zsh curl wget dialog net-tools dnsutils netcat traceroute sudo python3 python3-pip cron inetutils-ping openssh-client openssh-server htop gcc g++ cmake make zip
|
||||
for i in {fzf,ripgrep}; do apt install $i -y; done
|
||||
apt-get update -y
|
||||
# lite
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y git zsh bash tmux vim curl iputils-ping less bsdmainutils
|
||||
# full
|
||||
if [[ -z "$DFS_LITE" || "$DFS_LITE" == "0" ]]; then
|
||||
DEBIAN_FRONTEND=noninteractive 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 DEBIAN_FRONTEND=noninteractive apt-get install -y $i; done
|
||||
fi
|
||||
}
|
||||
|
||||
set_timezone()
|
||||
|
@ -36,8 +35,8 @@ router()
|
|||
set-mirror ) set_mirror $2 ;;
|
||||
set-timezone\
|
||||
| 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
|
||||
}
|
||||
|
||||
router $@
|
||||
router "${GOT_OPTS[@]}"
|
||||
|
|
Loading…
Reference in New Issue
Block a user