mirror of
https://github.com/DictXiong/dotfiles.git
synced 2026-11-02 10:08:15 +08:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 |
15
.gitconfig2
15
.gitconfig2
@@ -3,3 +3,18 @@
|
|||||||
name = Dict Xiong
|
name = Dict Xiong
|
||||||
[core]
|
[core]
|
||||||
editor = vim
|
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
|
||||||
|
[branch]
|
||||||
|
# Show most recently changed branches first.
|
||||||
|
sort = -committerdate
|
||||||
|
[help]
|
||||||
|
autocorrect = 1
|
||||||
|
[init]
|
||||||
|
defaultBranch = main
|
||||||
|
[log]
|
||||||
|
date = iso
|
||||||
|
|||||||
5
.github/workflows/gitee_sync.yml
vendored
5
.github/workflows/gitee_sync.yml
vendored
@@ -1,9 +1,6 @@
|
|||||||
name: sync repos to gitee
|
name: sync repos to gitee
|
||||||
on:
|
on:
|
||||||
push:
|
push: ~
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- dev
|
|
||||||
schedule:
|
schedule:
|
||||||
- cron: 10 4 * * *
|
- cron: 10 4 * * *
|
||||||
workflow_dispatch: ~
|
workflow_dispatch: ~
|
||||||
|
|||||||
17
.github/workflows/gitee_sync_dependencies.yml
vendored
17
.github/workflows/gitee_sync_dependencies.yml
vendored
@@ -106,3 +106,20 @@ jobs:
|
|||||||
force_update: true # 启用后,强制同步,即强制覆盖目的端仓库
|
force_update: true # 启用后,强制同步,即强制覆盖目的端仓库
|
||||||
static_list: "onedark.vim" # 静态同步列表,在此填写需要同步的仓库名称,可填写多个
|
static_list: "onedark.vim" # 静态同步列表,在此填写需要同步的仓库名称,可填写多个
|
||||||
timeout: '600s' # git超时设置,超时后会自动重试git操作
|
timeout: '600s' # git超时设置,超时后会自动重试git操作
|
||||||
|
fzf:
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- name: junegunn/fzf # 名字随便起
|
||||||
|
uses: Yikun/hub-mirror-action@v1.2 # 使用Yikun/hub-mirror-action
|
||||||
|
with:
|
||||||
|
src: github/junegunn # 源端账户名(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: "fzf" # 静态同步列表,在此填写需要同步的仓库名称,可填写多个
|
||||||
|
timeout: '600s' # git超时设置,超时后会自动重试git操作
|
||||||
118
.github/workflows/test.yml
vendored
Normal file
118
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
name: test
|
||||||
|
on:
|
||||||
|
push: ~
|
||||||
|
workflow_dispatch: ~
|
||||||
|
jobs:
|
||||||
|
test-ubuntu:
|
||||||
|
name: test on ubuntu
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: checkout repo
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: install dfs
|
||||||
|
run: |
|
||||||
|
rev=`git rev-parse HEAD`
|
||||||
|
pwd
|
||||||
|
set -x
|
||||||
|
./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
|
||||||
|
./install.sh -dl
|
||||||
|
|
||||||
|
- name: antigen build with DFS_NO_WALL
|
||||||
|
shell: /bin/zsh -ileo PIPE_FAIL {0}
|
||||||
|
env:
|
||||||
|
DFS_NO_WALL: 1
|
||||||
|
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@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: install dfs
|
||||||
|
run: |
|
||||||
|
rev=`git rev-parse HEAD`
|
||||||
|
pwd
|
||||||
|
set -x
|
||||||
|
./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
|
||||||
|
./install.sh -dl
|
||||||
|
|
||||||
|
- name: antigen build with DFS_NO_WALL
|
||||||
|
shell: /bin/zsh -ileo PIPE_FAIL {0}
|
||||||
|
env:
|
||||||
|
DFS_NO_WALL: 1
|
||||||
|
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@v3
|
||||||
|
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 with DFS_NO_WALL
|
||||||
|
shell: /bin/zsh -ileo PIPE_FAIL {0}
|
||||||
|
env:
|
||||||
|
DFS_NO_WALL: 1
|
||||||
|
run: |
|
||||||
|
echo $SHELL
|
||||||
|
antigen list
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
*.zwc
|
*.zwc
|
||||||
|
update.sh
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFO4k0tJ+Bfu95Uavg/5P3EXMKNcq+bMqaTqzkvRZ7ji
|
|||||||
|
|
||||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN8g34WHLEix6Qt0J/ClYbZeb9wh+p1IOcZkz/vNbZrv ltp1/windows
|
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN8g34WHLEix6Qt0J/ClYbZeb9wh+p1IOcZkz/vNbZrv ltp1/windows
|
||||||
|
|
||||||
|
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBN24pvN1RMN+iSZyHPdyExA1Rvt8pdr3e6ih6iX+KrQ ltp2
|
||||||
|
|
||||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGZFTyR+R86fUpZBDkDR9yYzJpmeNsIv2CMHTh6EuEeq pc0/windows
|
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGZFTyR+R86fUpZBDkDR9yYzJpmeNsIv2CMHTh6EuEeq pc0/windows
|
||||||
|
|
||||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID8WHIpwdZl7+HIZfQpwIAhpxT1huI9sd6Ydeokilg5l pc1/windows
|
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID8WHIpwdZl7+HIZfQpwIAhpxT1huI9sd6Ydeokilg5l pc1/windows
|
||||||
@@ -26,3 +28,5 @@ ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID8WHIpwdZl7+HIZfQpwIAhpxT1huI9sd6Ydeokilg5l
|
|||||||
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJ/+BWSTv3w1Ru9ksfse3EUbu4ukJruUU94fCG7Sk+5g3+F80KqJGykP9tHueU07iZfAuaYj7Zcy+IWx9Ih+eYA= ph0/sep
|
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJ/+BWSTv3w1Ru9ksfse3EUbu4ukJruUU94fCG7Sk+5g3+F80KqJGykP9tHueU07iZfAuaYj7Zcy+IWx9Ih+eYA= ph0/sep
|
||||||
|
|
||||||
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNvHya5i3GNniGww9Yx5ikos4Z5jevu8zz8hCQi05++SgejFPnbw9UjbHFjODK2M+ZHuhRF5mdf996r4/BxWyP8= pad0/sep
|
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNvHya5i3GNniGww9Yx5ikos4Z5jevu8zz8hCQi05++SgejFPnbw9UjbHFjODK2M+ZHuhRF5mdf996r4/BxWyP8= pad0/sep
|
||||||
|
|
||||||
|
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBC5gu+U4picxVvCNYjLlmxGLpJl7svj3LklO7jSpwqdrNxlE+/xkx07PJx76AbA77dDM1Dxmm/VOvVQCKTRLTgk= ip14/sep
|
||||||
|
|||||||
45
.update.sh
Normal file
45
.update.sh
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#!/bin/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"}
|
||||||
|
|
||||||
|
# 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 -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" ]]; 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
|
||||||
1
.vimrc2
1
.vimrc2
@@ -16,6 +16,7 @@ set autoindent
|
|||||||
set smartindent
|
set smartindent
|
||||||
set tabstop=4
|
set tabstop=4
|
||||||
set expandtab "spaces instead of tabs
|
set expandtab "spaces instead of tabs
|
||||||
|
set backspace=indent,eol,start
|
||||||
set number "line numbers
|
set number "line numbers
|
||||||
set history=1000
|
set history=1000
|
||||||
set ignorecase "when searching
|
set ignorecase "when searching
|
||||||
|
|||||||
213
.zshrc2
213
.zshrc2
@@ -1,22 +1,38 @@
|
|||||||
|
# env for shell
|
||||||
export TERM="xterm-256color"
|
export TERM="xterm-256color"
|
||||||
|
if (command -v locale >/dev/null) && ( locale -a | grep -qxE "C.UTF-8|C.utf8" ); then
|
||||||
export LC_ALL=C.UTF-8
|
export LC_ALL=C.UTF-8
|
||||||
export LANG=C.UTF-8
|
export LANG=C.UTF-8
|
||||||
|
else
|
||||||
|
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'
|
||||||
|
|
||||||
# antigen
|
# antigen
|
||||||
|
if [[ -z "$DFS_NO_WALL" ]]; then
|
||||||
# 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"
|
ANTIGEN_URL="https://gitee.com/dictxiong/antigen/raw/develop/bin/antigen.zsh"
|
||||||
|
ANTIGEN_OMZ_REPO_URL="https://gitee.com/dictxiong/ohmyzsh.git"
|
||||||
|
ANTIGEN_PLUGINS=(
|
||||||
|
"https://gitee.com/dictxiong/zsh-syntax-highlighting"
|
||||||
|
"https://gitee.com/dictxiong/zsh-completions"
|
||||||
|
"https://gitee.com/dictxiong/zsh-autosuggestions"
|
||||||
|
)
|
||||||
|
else
|
||||||
|
ANTIGEN_URL="https://raw.githubusercontent.com/zsh-users/antigen/develop/bin/antigen.zsh"
|
||||||
|
ANTIGEN_OMZ_REPO_URL="https://github.com/ohmyzsh/ohmyzsh.git"
|
||||||
|
ANTIGEN_PLUGINS=(
|
||||||
|
"https://github.com/zsh-users/zsh-syntax-highlighting"
|
||||||
|
"https://github.com/zsh-users/zsh-completions"
|
||||||
|
"https://github.com/zsh-users/zsh-autosuggestions"
|
||||||
|
)
|
||||||
|
fi
|
||||||
ANTIGEN="$HOME/antigen.zsh"
|
ANTIGEN="$HOME/antigen.zsh"
|
||||||
# Install antigen.zsh if not exist
|
# Install antigen.zsh if not exist
|
||||||
if [ ! -f "$ANTIGEN" ]; then
|
if [ ! -f "$ANTIGEN" ]; then
|
||||||
@@ -40,69 +56,43 @@ if [ ! -f "$ANTIGEN" ]; then
|
|||||||
fi
|
fi
|
||||||
# config and enable antigen
|
# config and enable antigen
|
||||||
source "$ANTIGEN"
|
source "$ANTIGEN"
|
||||||
antigen use oh-my-zsh
|
|
||||||
# enable plugins
|
# enable plugins
|
||||||
antigen_plugins=( \
|
antigen use oh-my-zsh
|
||||||
"command-not-found" \
|
ANTIGEN_PLUGINS+=(
|
||||||
"docker" \
|
"command-not-found"
|
||||||
"extract" \
|
"docker"
|
||||||
"fzf" \
|
"extract"
|
||||||
"git" \
|
"fzf"
|
||||||
"ripgrep" \
|
"git"
|
||||||
"thefuck" \
|
"ripgrep"
|
||||||
"tmux" \
|
"tmux"
|
||||||
"ufw" \
|
"ufw"
|
||||||
"z" \
|
"z"
|
||||||
"https://gitee.com/dictxiong/zsh-syntax-highlighting" \
|
|
||||||
"https://gitee.com/dictxiong/zsh-completions" \
|
|
||||||
"https://gitee.com/dictxiong/zsh-autosuggestions" \
|
|
||||||
)
|
)
|
||||||
for i in ${antigen_plugins[*]}
|
for i in ${ANTIGEN_PLUGINS[*]}; do
|
||||||
do
|
|
||||||
if [[ -z $ANTIGEN_EXCLUDE || ! $i =~ $ANTIGEN_EXCLUDE ]]; then
|
if [[ -z $ANTIGEN_EXCLUDE || ! $i =~ $ANTIGEN_EXCLUDE ]]; then
|
||||||
antigen bundle $i
|
antigen bundle $i
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
# select theme
|
# select theme
|
||||||
antigen theme ${ZSH_THEME:-ys}
|
TMP_THEME=ys
|
||||||
|
if [[ -e /.dockerenv ]]; then
|
||||||
|
TMP_THEME=blinks
|
||||||
|
echo "==========================="
|
||||||
|
echo "This is in docker container"
|
||||||
|
echo "==========================="
|
||||||
|
fi
|
||||||
|
antigen theme ${ZSH_THEME:-$TMP_THEME}
|
||||||
# apply
|
# apply
|
||||||
antigen apply
|
antigen apply
|
||||||
# end of antigen config
|
# end of antigen config
|
||||||
|
|
||||||
# functions
|
# beacon
|
||||||
export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
if [[ "$EUID" == "0" ]]; then
|
||||||
|
"$DOTFILES/tools/common.sh" apost_beacon "sys.login.root"
|
||||||
SUDO=''
|
|
||||||
if (( $EUID != 0 )); then
|
|
||||||
SUDO='sudo'
|
|
||||||
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
|
else
|
||||||
$SUDO docker exec -it $1 zsh
|
"$DOTFILES/tools/common.sh" apost_beacon "sys.login.user"
|
||||||
fi
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
# alias
|
# alias
|
||||||
alias "pls"='sudo $(fc -ln -1)'
|
alias "pls"='sudo $(fc -ln -1)'
|
||||||
@@ -110,14 +100,93 @@ alias "se"='sudo -sE'
|
|||||||
alias "pbd"='ping baidu.com'
|
alias "pbd"='ping baidu.com'
|
||||||
alias "p114"='ping 114.114.114.114'
|
alias "p114"='ping 114.114.114.114'
|
||||||
alias "p666"='ping6 2001:da8::666'
|
alias "p666"='ping6 2001:da8::666'
|
||||||
alias l='ls -lAGh --time-style="+%y-%m-%d %H:%M"'
|
alias "gdebug"='git add -A; git commit -m "bug fix"'
|
||||||
|
case $(bash "$DOTFILES/tools/common.sh" get_os_type) in
|
||||||
|
macos ) alias l='ls -lAGh -D "%y-%m-%d %H:%M"' ;;
|
||||||
|
* ) alias l='ls -lAGh --time-style="+%y-%m-%d %H:%M"' ;;
|
||||||
|
esac
|
||||||
|
if [[ -x $(command -v trash) ]]; then
|
||||||
|
alias "rm"="echo use the full path i.e. '/bin/rm'\; consider using trash"
|
||||||
|
fi
|
||||||
|
sibd() { ssh -p 12022 root@$1${1:+.}ibd.ink }
|
||||||
|
sob() { ssh -p 24022 root@$1${1:+.}ob.ac.cn }
|
||||||
|
snasp() { ssh -o ProxyJump="ssh@nasp.ob.ac.cn:36022" dictxiong@$1 }
|
||||||
|
gbes() { git for-each-ref --sort=-committerdate refs/heads refs/remotes --format="%(authordate:format:%y-%m-%d.%a %H:%M %z)|%(color:red)%(objectname:short)|%(color:yellow)%(refname:short)%(color:reset)|%(color:reset)%(authorname): %(color:green)%(subject)" --color=always | column -ts"|" | less -FX }
|
||||||
|
piv-agent()
|
||||||
|
{
|
||||||
|
eval $(ssh-agent -k)
|
||||||
|
# they are: ubuntu, macos, respectively
|
||||||
|
local SO_PATHS=( "/usr/lib64/opensc-pkcs11.so" "/usr/local/lib/opensc-pkcs11.so" )
|
||||||
|
for i in ${SO_PATHS[*]}; do
|
||||||
|
if [[ -f "$i" ]]; then
|
||||||
|
echo "using: $i"
|
||||||
|
eval $(ssh-agent -P "$i")
|
||||||
|
ssh-add -s "$i"
|
||||||
|
echo "now available keys:"
|
||||||
|
ssh-add -l
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "opensc-pkcs11.so not found"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
# key bindings
|
# key bindings
|
||||||
bindkey "^b" beginning-of-line
|
bindkey "^b" beginning-of-line # ctrl+b
|
||||||
bindkey "^e" end-of-line
|
bindkey "\eOH" beginning-of-line
|
||||||
bindkey "^[[H" beginning-of-line
|
bindkey "\e[H" beginning-of-line # home; termius
|
||||||
bindkey "^[[F" end-of-line
|
bindkey "\e[1~" beginning-of-line
|
||||||
bindkey "^[[1~" beginning-of-line
|
|
||||||
bindkey "^[[4~" end-of-line
|
bindkey "^e" end-of-line # ctrl+e
|
||||||
bindkey "^[OH" beginning-of-line
|
bindkey "\eOF" end-of-line
|
||||||
bindkey "^[OF" 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
|
||||||
|
|
||||||
|
# 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" ;;
|
||||||
|
* ) echo "unknown command \"$1\". available: update, force-update, version, reset, cd, log" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# clean
|
||||||
|
unset i
|
||||||
|
|||||||
361
install.sh
361
install.sh
@@ -1,243 +1,272 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Color settings
|
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||||
# Source: https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
|
source "$THIS_DIR/tools/common.sh"
|
||||||
if [ -t 1 ]; then
|
|
||||||
is_tty() {
|
|
||||||
true
|
if [[ ! "$DOTFILES" == "${HOME}"* ]]; then
|
||||||
}
|
fmt_fatal "\"$DOTFILES\" is not under \"$HOME\". aborting ..."
|
||||||
else
|
|
||||||
is_tty() {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
|
DOTFILE_TILDE=${DOTFILES/"$HOME"/\~}
|
||||||
|
|
||||||
supports_truecolor() {
|
CRON_JOB="0 * * * * ${DOTFILES}/update.sh"
|
||||||
case "$COLORTERM" in
|
declare -a HOME_FILES_PATH
|
||||||
truecolor|24bit) return 0 ;;
|
declare -a HOME_FILES_CONTENT
|
||||||
esac
|
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
|
declare -a HOME_SYMLINKS_SRC
|
||||||
iterm |\
|
declare -a HOME_SYMLINKS_DST
|
||||||
tmux-truecolor |\
|
HOME_SYMLINKS_SRC[0]=".ssh/authorized_keys2"
|
||||||
linux-truecolor |\
|
HOME_SYMLINKS_DST[0]=".ssh/authorized_keys2"
|
||||||
xterm-truecolor |\
|
|
||||||
screen-truecolor) return 0 ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
return 1
|
install_dependencies()
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
while true; do
|
fmt_note "installing dependencies ..."
|
||||||
read -p "${FMT_YELLOW}$1${FMT_RESET} [yN]: " yn
|
case $(get_os_name) in
|
||||||
case $yn in
|
"ubuntu"|"debian" )
|
||||||
[Yy]* ) return 1;;
|
$SUDO "$DOTFILES/tools/ubuntu.sh" apt-install
|
||||||
[Nn]* ) return 0;;
|
;;
|
||||||
* ) return 0;;
|
"alpine" )
|
||||||
|
$SUDO "$DOTFILES/tools/alpine.sh" apk-add
|
||||||
|
;;
|
||||||
|
"macos" )
|
||||||
|
"$DOTFILES/tools/macos.sh" brew-install
|
||||||
|
;;
|
||||||
|
"msys" )
|
||||||
|
"$DOTFILES/tools/msys2.sh" pacman-S
|
||||||
|
;;
|
||||||
|
* ) fmt_error "dfs auto-install is not implemented on OS: $(get_os_name)"
|
||||||
esac
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
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"
|
||||||
|
ask_for_Yn "continue anyway?"
|
||||||
|
if [[ "$?" == "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
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
insert_if_not_exist()
|
install_file_content()
|
||||||
{
|
{
|
||||||
filename=$1
|
fmt_note "installing file content ..."
|
||||||
line=$2
|
for ((i=0; i<${#HOME_FILES_PATH[@]}; i++)); do
|
||||||
fmt_note "installing \"$line\" into \"$filename\" ..."
|
local filename="$HOME/${HOME_FILES_PATH[$i]}"
|
||||||
|
local content=${HOME_FILES_CONTENT[$i]}
|
||||||
|
fmt_info "installing \"$content\" into \"$filename\" ..."
|
||||||
mkdir -p $(dirname "$filename")
|
mkdir -p $(dirname "$filename")
|
||||||
if [ ! -f "$filename" ]; then
|
if [ ! -f "$filename" ]; then
|
||||||
touch $filename
|
touch $filename
|
||||||
fi
|
fi
|
||||||
grep -qxF -- "$line" "$filename" || echo "$line" >> "$filename"
|
grep -qxF -- "$content" "$filename" || echo "$content" >> "$filename"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_if_exist()
|
uninstall_file_content()
|
||||||
{
|
{
|
||||||
filename=$1
|
fmt_note "uninstalling file content ..."
|
||||||
line=$2
|
for ((i=0; i<${#HOME_FILES_PATH[@]}; i++)); do
|
||||||
fmt_note "removing \"$line\" from \"$filename\" ..."
|
local filename="$HOME/${HOME_FILES_PATH[$i]}"
|
||||||
|
local content=${HOME_FILES_CONTENT[$i]}
|
||||||
|
fmt_info "removing \"$content\" from \"$filename\" ..."
|
||||||
if [ -f "$filename" ]; then
|
if [ -f "$filename" ]; then
|
||||||
grep -vxF -- "$line" "$filename" | tee "$filename"
|
grep -vxF -- "$content" "$filename" | tee "$filename"
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
create_symlink()
|
install_symlink()
|
||||||
{
|
{
|
||||||
src=$1
|
fmt_note "installing symlinks ..."
|
||||||
dest=$2
|
for ((i=0; i<${#HOME_SYMLINKS_SRC[@]}; i++)); do
|
||||||
fmt_note "creating symlink \"$dest\" --> \"$src\" ..."
|
local src="$DOTFILES/${HOME_SYMLINKS_SRC[$i]}"
|
||||||
|
local dst="$HOME/${HOME_SYMLINKS_DST[$i]}"
|
||||||
|
fmt_info "creating symlink \"$dst\" --> \"$src\" ..."
|
||||||
if [ ! -f "$src" ]; then
|
if [ ! -f "$src" ]; then
|
||||||
fmt_error "\"$src\" does not exist! aborting this job ..."
|
fmt_error "\"$src\" does not exist! aborting this job ..."
|
||||||
return 1
|
continue
|
||||||
fi
|
fi
|
||||||
mkdir -p $(dirname "$dest")
|
mkdir -p $(dirname "$dst")
|
||||||
if [ -f "$dest" ]; then
|
if [ -f "$dst" ]; then
|
||||||
if [ "$(readlink $dest)" -ef "$src" ]; then
|
if [ "$(readlink $dst)" -ef "$src" ]; then
|
||||||
return 0
|
continue
|
||||||
fi
|
fi
|
||||||
fmt_warning "\"$dest\" already exists! stat output:"
|
fmt_warning "\"$dst\" already exists! stat output:"
|
||||||
echo ----------
|
echo ----------
|
||||||
stat $dest
|
stat $dst
|
||||||
echo ----------
|
echo ----------
|
||||||
ask_for_yN "would you like to replace ${dest}?"
|
ask_for_yN "would you like to replace ${dst}?"
|
||||||
if [ $? -eq 1 ]; then
|
if [ $? -eq 1 ]; then
|
||||||
rm $dest
|
rm $dst
|
||||||
else
|
else
|
||||||
fmt_error "\"$dest\" already exists! aborting this job ..."
|
fmt_error "aborting this job ..."
|
||||||
return 1
|
continue
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
ln -s $src $dest
|
ln -s $src $dst
|
||||||
return $?
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_link_if_match()
|
uninstall_symlink()
|
||||||
{
|
{
|
||||||
src=$1
|
fmt_note "uninstalling symlinks ..."
|
||||||
dest=$2
|
local src
|
||||||
if [ "$(readlink $dest)" -ef "$src" ]; then
|
for src in "${!HOME_SYMLINKS[@]}"; do
|
||||||
fmt_note "removing symlink \"$dest\" ..."
|
local dst=${HOME_SYMLINKS[$src]}
|
||||||
|
src="$DOTFILES/$src"
|
||||||
|
dst="$HOME/$dst"
|
||||||
|
if [ "$(readlink $dst)" -ef "$src" ]; then
|
||||||
|
fmt_info "removing symlink \"$dst\" ..."
|
||||||
echo ----------
|
echo ----------
|
||||||
stat $dest
|
stat $dst
|
||||||
echo ----------
|
echo ----------
|
||||||
rm $dest
|
rm $dst
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
install_crontab()
|
||||||
|
{
|
||||||
|
if [[ -x $(command -v crontab) ]]; then
|
||||||
|
fmt_note "installing \"$CRON_JOB\" to crontab ..."
|
||||||
|
( crontab -l | grep -vxF "${CRON_JOB}" | grep -v "no crontab for"; echo "$CRON_JOB" ) | crontab -
|
||||||
|
else
|
||||||
|
fmt_warning "crontab does not exist. skipping ..."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
install_crontab(){
|
uninstall_crontab()
|
||||||
fmt_note "installing \"$crontab_job\" to crontab ..."
|
{
|
||||||
( crontab -l | grep -vxF "${crontab_job}" | grep -v "no crontab for"; echo "$crontab_job" ) | 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(){
|
install_tmux_tpm()
|
||||||
fmt_note "removing \"$crontab_job\" from crontab ..."
|
{
|
||||||
( crontab -l | grep -vxF "$crontab_job" ) | crontab -
|
|
||||||
}
|
|
||||||
|
|
||||||
install_tmux_tpm(){
|
|
||||||
TMUX_TPM="$HOME/.tmux/plugins/tpm"
|
TMUX_TPM="$HOME/.tmux/plugins/tpm"
|
||||||
if [[ -x $(command -v tmux) && ! -d "$TMUX_TPM" ]]; then
|
if [[ -x $(command -v tmux) && ! -d "$TMUX_TPM" ]]; then
|
||||||
fmt_note "installing tmux tpm ..."
|
fmt_note "installing tmux tpm ..."
|
||||||
git clone https://gitee.com/dictxiong/tpm "$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
|
if [[ -x $(command -v g++) && -x $(command -v cmake) && -x $(command -v make) ]]; then
|
||||||
|
if [[ -z "$DFS_LITE" || "$DFS_LITE" == "0" ]]; then
|
||||||
fmt_note "initializing tmux plugins ..."
|
fmt_note "initializing tmux plugins ..."
|
||||||
~/.tmux/plugins/tpm/bin/install_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
|
else
|
||||||
fmt_warning "pls install g++,cmake,make and then init tmux plugins by <prefix + I> or ~/.tmux/plugins/tpm/bin/install_plugins"
|
fmt_warning "pls install g++,cmake,make and then init tmux plugins by <prefix + I> or ~/.tmux/plugins/tpm/bin/install_plugins"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
install_vim_vundle(){
|
install_vim_vundle()
|
||||||
|
{
|
||||||
VIM_VUNDLE="$HOME/.vim/bundle/Vundle.vim"
|
VIM_VUNDLE="$HOME/.vim/bundle/Vundle.vim"
|
||||||
if [[ -x $(command -v vim) && ! -d "$VIM_VUNDLE" ]]; then
|
if [[ -x $(command -v vim) && ! -d "$VIM_VUNDLE" ]]; then
|
||||||
fmt_note "installing vim vundle ..."
|
fmt_note "installing vim vundle ..."
|
||||||
git clone https://gitee.com/dictxiong/Vundle.vim "$VIM_VUNDLE"
|
git clone https://gitee.com/dictxiong/Vundle.vim "$VIM_VUNDLE"
|
||||||
fmt_note "initializing vim plugins ..."
|
fmt_note "initializing vim plugins ..."
|
||||||
vim +PluginInstall +qall
|
echo | vim +PluginInstall +qall
|
||||||
fi
|
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
|
||||||
|
install_update
|
||||||
|
preinstall_check
|
||||||
install_crontab
|
install_crontab
|
||||||
insert_if_not_exist "${HOME}/.zshrc" "source ${dotfile_home_path}/.zshrc2"
|
install_file_content
|
||||||
insert_if_not_exist "${HOME}/.tmux.conf" "source-file ${dotfile_home_path}/.tmux.conf2"
|
install_symlink
|
||||||
insert_if_not_exist "${HOME}/.vimrc" "source ${dotfile_home_path}/.vimrc2"
|
apost_beacon "dfs.installed"
|
||||||
insert_if_not_exist "${HOME}/.gitconfig" "[include] path = \"${dotfile_home_path}/.gitconfig2\""
|
|
||||||
create_symlink "${dotfile_path}/.ssh/authorized_keys2" "${HOME}/.ssh/authorized_keys2"
|
|
||||||
# those that won't be uninstalled in the future
|
# those that won't be uninstalled in the future
|
||||||
install_tmux_tpm
|
install_tmux_tpm
|
||||||
install_vim_vundle
|
install_vim_vundle
|
||||||
fmt_note "done installing!"
|
fmt_note "done installing!"
|
||||||
}
|
}
|
||||||
|
|
||||||
uninstall(){
|
uninstall()
|
||||||
|
{
|
||||||
ask_for_yN "do you really want to uninstall?"
|
ask_for_yN "do you really want to uninstall?"
|
||||||
if [[ $? == 1 ]]; then
|
if [[ $? != 1 ]]; then
|
||||||
uninstall_crontab
|
fmt_error "aborting this job ..."
|
||||||
delete_if_exist "${HOME}/.zshrc" "source ${dotfile_home_path}/.zshrc2"
|
return
|
||||||
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!"
|
|
||||||
fi
|
fi
|
||||||
|
uninstall_update
|
||||||
|
uninstall_crontab
|
||||||
|
uninstall_file_content
|
||||||
|
uninstall_symlink
|
||||||
|
apost_beacon "dfs.uninstalled"
|
||||||
|
fmt_note "done uninstalling!"
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_color
|
ORIGIN_ARGS="$@"
|
||||||
case $1 in
|
parse_arg "$@"
|
||||||
""|-i ) install ;;
|
FUNC=install
|
||||||
-r ) uninstall ;;
|
INSTALL_DEP=0
|
||||||
* ) fmt_warning "unknown command \"$1\". available: -i, -r" ;;
|
for i in ${PARSE_ARG_RET[@]}; do
|
||||||
|
case $i in
|
||||||
|
-i ) FUNC=install ;;
|
||||||
|
-r ) FUNC=uninstall ;;
|
||||||
|
-d|--dev ) export DFS_DEV=1 ;;
|
||||||
|
-l|--lite ) export DFS_LITE=1 ;;
|
||||||
|
-a|--auto ) INSTALL_DEP=1 ;;
|
||||||
|
-s|--secure ) export DFS_DEV=0 ;;
|
||||||
|
* ) fmt_fatal "unknown option \"$i\". available: -i, -r, -q, -d, -l, -a, -s" ;;
|
||||||
esac
|
esac
|
||||||
|
done
|
||||||
|
$FUNC
|
||||||
|
|||||||
30
scripts/dogo
Executable file
30
scripts/dogo
Executable file
@@ -0,0 +1,30 @@
|
|||||||
|
#!/bin/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
|
||||||
|
echo "--> ${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 @@
|
|||||||
|
#!/bin/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
|
||||||
|
echo "--> ${IMAGE_META[@]}"
|
||||||
|
$SUDO docker run ${2:+"--name"} $2 -itd $IMAGE sh
|
||||||
|
fi
|
||||||
@@ -1,29 +1,23 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
if [[ $USER != "root" ]]; then
|
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||||
echo "must run as root!"
|
source "$THIS_DIR/common.sh"
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
set_mirror()
|
set_mirror()
|
||||||
{
|
{
|
||||||
#MIRROR=${1:="mirrors.tuna.tsinghua.edu.cn"}
|
MIRROR=${1:-"mirrors.tuna.tsinghua.edu.cn"}
|
||||||
#MIRROR=${MIRROR//\//\\\/}
|
sed -i "s@dl-cdn.alpinelinux.org@${MIRROR}@g" /etc/apk/repositories
|
||||||
#sed -i 's/(archive|security).ubuntu.com/${MIRROR}/g' /etc/apt/sources.list
|
|
||||||
echo "to-do ..."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
apk_add()
|
apk_add()
|
||||||
{
|
{
|
||||||
apk update
|
apk update
|
||||||
|
# lite
|
||||||
# mass installation
|
apk add zsh bash git tmux vim curl fzf iputils coreutils util-linux
|
||||||
apk add zsh git tmux vim curl wget bash python3 htop gcc g++ cmake make fzf perl linux-headers bind-tools iputils man-db
|
# full
|
||||||
#for i in {fzf,ripgrep}; do apk add $i -y; done
|
if [[ -z "$DFS_LITE" ]]; then
|
||||||
|
apk add wget python3 py3-pip htop gcc g++ cmake make perl linux-headers bind-tools man-db
|
||||||
# who am i
|
fi
|
||||||
git config --global user.email "me@beardic.cn"
|
|
||||||
git config --global user.name "Dict Xiong"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set_timezone()
|
set_timezone()
|
||||||
@@ -39,7 +33,7 @@ router()
|
|||||||
case $1 in
|
case $1 in
|
||||||
apk-add ) apk_add ;;
|
apk-add ) apk_add ;;
|
||||||
set-timezone | set-tz ) set_timezone ;;
|
set-timezone | set-tz ) set_timezone ;;
|
||||||
#set-mirror ) set_mirror $2 ;;
|
set-mirror ) set_mirror $2 ;;
|
||||||
* ) echo unknown command "$1". available: apk-add, set-timezone;;
|
* ) echo unknown command "$1". available: apk-add, set-timezone;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|||||||
227
tools/common.sh
Executable file
227
tools/common.sh
Executable file
@@ -0,0 +1,227 @@
|
|||||||
|
#!/bin/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
|
||||||
|
|
||||||
|
# Color settings
|
||||||
|
# Source: https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
|
||||||
|
if [ -t 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}" "$*" >&1
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt_note() {
|
||||||
|
printf '%s%s%s\n' "${FMT_GREEN}" "$*" "${FMT_RESET}" >&1
|
||||||
|
}
|
||||||
|
|
||||||
|
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=''
|
||||||
|
if [[ "$EUID" != "0" && -x $(command -v sudo) ]]; then
|
||||||
|
SUDO='sudo'
|
||||||
|
fi
|
||||||
|
|
||||||
|
parse_arg()
|
||||||
|
{
|
||||||
|
local ARG=""
|
||||||
|
PARSE_ARG_RET=()
|
||||||
|
while [[ $# > 0 || -n "$ARG" ]]; do
|
||||||
|
if [[ -z "$ARG" ]]; then ARG=$1; shift; fi
|
||||||
|
case $ARG in
|
||||||
|
-q*|--quite ) export DFS_QUIET=1 ;;
|
||||||
|
--* ) PARSE_ARG_RET+=("$ARG") ;;
|
||||||
|
-* ) PARSE_ARG_RET+=("${ARG:0:2}") ;;
|
||||||
|
* ) PARSE_ARG_RET+=("$ARG") ;;
|
||||||
|
esac
|
||||||
|
if [[ "$ARG" == "--"* || ! "$ARG" == "-"* || ${#ARG} -le 2 ]]; then
|
||||||
|
ARG=""
|
||||||
|
else
|
||||||
|
ARG=-${ARG:2}
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
ask_for_yN()
|
||||||
|
{
|
||||||
|
while [[ -z "$DFS_QUIET" || "$DFS_QUIET" == "0" ]]; do
|
||||||
|
read -p "${FMT_YELLOW}$1${FMT_RESET} [yN]: " yn
|
||||||
|
case $yn in
|
||||||
|
[Yy]* ) return 1;;
|
||||||
|
* ) return 0;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
ask_for_Yn()
|
||||||
|
{
|
||||||
|
while [[ -z "$DFS_QUIET" || "$DFS_QUIET" == "0" ]]; do
|
||||||
|
read -p "${FMT_YELLOW}$1${FMT_RESET} [Yn]: " yn
|
||||||
|
case $yn in
|
||||||
|
[Nn]* ) return 0;;
|
||||||
|
* ) return 1;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
post_log()
|
||||||
|
{
|
||||||
|
if [[ $# != 3 || -z "$1" || -z "$2" || -z "$3" ]]; then
|
||||||
|
fmt_fatal "usage: post_log <level> <section> <content>"
|
||||||
|
fi
|
||||||
|
"${DOTFILES}/tools/logger.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/logger.sh" "beacon" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
apost_beacon()
|
||||||
|
{
|
||||||
|
post_beacon "$@" 1>/dev/null &
|
||||||
|
}
|
||||||
|
|
||||||
|
get_os_type()
|
||||||
|
{
|
||||||
|
local ans="unknown"
|
||||||
|
case "$(uname -s)" in
|
||||||
|
Darwin*) ans="MacOS";;
|
||||||
|
CYGWIN*) ans="Cygwin";;
|
||||||
|
MSYS* ) ans="MSYS";;
|
||||||
|
Linux* ) ans="Linux";;
|
||||||
|
*) ans="unknown";;
|
||||||
|
esac
|
||||||
|
echo $ans | tr '[:upper:]' '[:lower:]'
|
||||||
|
}
|
||||||
|
|
||||||
|
get_linux_dist()
|
||||||
|
{
|
||||||
|
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
|
||||||
|
echo $ans | tr '[:upper:]' '[:lower:]'
|
||||||
|
}
|
||||||
|
|
||||||
|
get_os_name()
|
||||||
|
{
|
||||||
|
local ans=$(get_os_type)
|
||||||
|
if [[ "$ans" == "linux" ]]; then
|
||||||
|
ans=$(get_linux_dist)
|
||||||
|
fi
|
||||||
|
echo $ans
|
||||||
|
}
|
||||||
|
|
||||||
|
# if bash-ed, else source-d
|
||||||
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||||
|
$1 "${@:2}"
|
||||||
|
else
|
||||||
|
setup_color
|
||||||
|
fi
|
||||||
|
|
||||||
|
unset THIS_DIR_COMMON_SH
|
||||||
100
tools/logger.sh
Executable file
100
tools/logger.sh
Executable file
@@ -0,0 +1,100 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||||
|
source "$THIS_DIR/common.sh"
|
||||||
|
|
||||||
|
if [[ -x $(command -v hostname) ]]; then
|
||||||
|
hostname=$(hostname)
|
||||||
|
elif [[ -x $(command -v uname) ]]; then
|
||||||
|
hostname=$(uname -n)
|
||||||
|
elif [[ -x $(command -v hostnamectl) ]]; then
|
||||||
|
hostname=$(hostnamectl --static)
|
||||||
|
elif [[ -n "$HOSTNAME" ]]; then
|
||||||
|
hostname=$HOSTNAME
|
||||||
|
elif [[ -f /proc/sys/kernel/hostname ]]; then
|
||||||
|
hostname=$(cat /proc/sys/kernel/hostname)
|
||||||
|
elif [[ -f /etc/hostname ]]; then
|
||||||
|
hostname=$(cat /etc/hostname)
|
||||||
|
else
|
||||||
|
fmt_fatal "unable to get hostname"
|
||||||
|
fi
|
||||||
|
|
||||||
|
init_uuid()
|
||||||
|
{
|
||||||
|
if [[ -f ~/.config/dotfiles/uuid ]]; then
|
||||||
|
uuid=$(cat ~/.config/dotfiles/uuid)
|
||||||
|
else
|
||||||
|
if [[ -x $(command -v uuidgen) ]]; then
|
||||||
|
uuid=$(uuidgen)
|
||||||
|
elif [[ -f /proc/sys/kernel/random/uuid ]]; then
|
||||||
|
uuid=$(cat /proc/sys/kernel/random/uuid)
|
||||||
|
else
|
||||||
|
fmt_fatal "unable to generate uuid"
|
||||||
|
fi
|
||||||
|
mkdir -p ~/.config/dotfiles
|
||||||
|
echo "$uuid" > ~/.config/dotfiles/uuid
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
post_beacon()
|
||||||
|
{
|
||||||
|
local beacon_type=$1
|
||||||
|
if [[ -z "$beacon_type" ]]; then
|
||||||
|
fmt_fatal "beacon type is required"
|
||||||
|
fi
|
||||||
|
resp=$(curl -sSL -X POST "https://api.beardic.cn/post-beacon?hostname=$hostname&beacon=$beacon_type")
|
||||||
|
if grep -q "200" <<< "$resp"; then
|
||||||
|
echo $resp
|
||||||
|
else
|
||||||
|
echo $resp >&2
|
||||||
|
fmt_fatal "error posting beacon"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
post_log()
|
||||||
|
{
|
||||||
|
local log_content=$1
|
||||||
|
if [[ -z "$log_content" ]]; then
|
||||||
|
fmt_fatal "log content is required"
|
||||||
|
fi
|
||||||
|
init_uuid
|
||||||
|
resp=$(curl -sSL -X POST -H "Content-Type: text/plain" -d "$1" "https://api.beardic.cn/post-log?hostname=$hostname&uuid=$uuid")
|
||||||
|
if grep -q "200" <<< "$resp"; then
|
||||||
|
echo $resp
|
||||||
|
elif grep -q "403" <<< "$resp"; then
|
||||||
|
echo $resp >&2
|
||||||
|
fmt_error "error posting log: authentification failed"
|
||||||
|
fmt_info "try to register you hostname and uuid"
|
||||||
|
fmt_info "hostname: $hostname"
|
||||||
|
fmt_info "uuid: $uuid"
|
||||||
|
else
|
||||||
|
echo $resp >&2
|
||||||
|
fmt_fatal "error posting log"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
print_help()
|
||||||
|
{
|
||||||
|
fmt_info "usage: $0 <beacon|log> <beacon_type|log_content>"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ $# != 2 ]]; then
|
||||||
|
print_help >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
fmt_info "usage: $0 <beacon|log> <beacon_type|log_content>"
|
||||||
|
;;
|
||||||
|
beacon)
|
||||||
|
post_beacon "$2"
|
||||||
|
;;
|
||||||
|
log)
|
||||||
|
post_log "$2"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
fmt_fatal "invalid argument"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
20
tools/macos.sh
Executable file
20
tools/macos.sh
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/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
|
||||||
|
}
|
||||||
|
|
||||||
|
router()
|
||||||
|
{
|
||||||
|
case $1 in
|
||||||
|
brew-install ) brew_install ;;
|
||||||
|
* ) echo unknown command "$1". available: brew-install;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
router $@
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
if [[ $USER != "root" ]]; then
|
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||||
echo "must run as root!"
|
source "$THIS_DIR/common.sh"
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
set_mirror()
|
set_mirror()
|
||||||
{
|
{
|
||||||
@@ -16,7 +14,12 @@ set_mirror()
|
|||||||
pacman_S()
|
pacman_S()
|
||||||
{
|
{
|
||||||
pacman -Syu
|
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" ]]; then
|
||||||
|
pacman -S wget base-devel mingw-w64-x86_64-toolchain make cmake gcc zip unzip python3 python3-pip man-pages-posix
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
router()
|
router()
|
||||||
|
|||||||
52
tools/test.zsh
Normal file
52
tools/test.zsh
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/bin/false "This script should be sourced in zsh, not executed directly"
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
# check files
|
||||||
|
cd /
|
||||||
|
l
|
||||||
|
cd ~
|
||||||
|
l
|
||||||
|
dfs cd
|
||||||
|
l
|
||||||
|
pwd
|
||||||
|
test -f .zshrc2
|
||||||
|
diff -q ./.ssh/authorized_keys2 ~/.ssh/authorized_keys2
|
||||||
|
grep -q ".zshrc2" ~/.zshrc
|
||||||
|
|
||||||
|
# check scripts and functions
|
||||||
|
dfs version
|
||||||
|
dfs log 1
|
||||||
|
dfs beacon gh.ci
|
||||||
|
z ~
|
||||||
|
test ~ -ef "$(pwd)"
|
||||||
|
dogo
|
||||||
|
doll
|
||||||
|
dfs cd
|
||||||
|
tools/common.sh get_os_type
|
||||||
|
tools/common.sh get_linux_dist
|
||||||
|
|
||||||
|
# check alias
|
||||||
|
alias p114
|
||||||
|
which sibd
|
||||||
|
piv-agent || which piv-agent
|
||||||
|
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 -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
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
declare -A install_commands
|
declare -A INSTALL_COMMANDS
|
||||||
install_commands=(\
|
INSTALL_COMMANDS=(\
|
||||||
[git]="apt update && apt install git" \
|
[git]="apt update && apt install git" \
|
||||||
[fzf]="git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install" \
|
[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}" \
|
[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-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' \
|
[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" \
|
[v2fly]="bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) #--remove" \
|
||||||
[zerotier-one]='curl -s https://install.zerotier.com | sudo bash' \
|
[zerotier-one]='curl -s https://install.zerotier.com | sudo bash' \
|
||||||
[docker-ce]='curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh #--mirror Aliyun #--dry-run' \
|
[docker-ce]='curl -fsSL https://get.docker.com -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' \
|
[lemonbench]='curl -fsSL https://ilemonra.in/LemonBenchIntl | bash -s fast # or full' \
|
||||||
@@ -15,7 +15,7 @@ install_commands=(\
|
|||||||
|
|
||||||
install()
|
install()
|
||||||
{
|
{
|
||||||
echo -e ${install_commands[$1]}
|
echo -e ${INSTALL_COMMANDS[$1]}
|
||||||
}
|
}
|
||||||
|
|
||||||
install $1
|
install $1
|
||||||
@@ -1,26 +1,25 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
if [[ $USER != "root" ]]; then
|
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||||
echo "must run as root!"
|
source "$THIS_DIR/common.sh"
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
set_mirror()
|
set_mirror()
|
||||||
{
|
{
|
||||||
MIRROR=${1:-"mirrors.tuna.tsinghua.edu.cn"}
|
MIRROR=${1:-"mirrors.tuna.tsinghua.edu.cn"}
|
||||||
MIRROR=${MIRROR//\//\\\/}
|
sed -i "s@http://.*archive.ubuntu.com@https://${MIRROR}@g" /etc/apt/sources.list
|
||||||
sed -i 's/(archive|security).ubuntu.com/${MIRROR}/g' /etc/apt/sources.list
|
sed -i "s@http://.*security.ubuntu.com@https://${MIRROR}@g" /etc/apt/sources.list
|
||||||
}
|
}
|
||||||
|
|
||||||
apt_install()
|
apt_install()
|
||||||
{
|
{
|
||||||
# basic packages
|
apt-get update -y
|
||||||
apt update
|
# lite
|
||||||
for i in {man-db,vim,ca-certificates}; do apt install $i -y; done
|
apt-get install -y git zsh bash tmux vim curl inetutils-ping less bsdmainutils
|
||||||
|
# full
|
||||||
# mass installation
|
if [[ -z "$DFS_LITE" ]]; then
|
||||||
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
|
apt-get install wget dialog net-tools dnsutils netcat traceroute sudo python3 python3-pip cron openssh-client openssh-server htop gcc g++ cmake make zip
|
||||||
for i in {fzf,ripgrep}; do apt install $i -y; done
|
for i in {fzf,ripgrep,man-db}; do apt-get install -y $i; done
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
set_timezone()
|
set_timezone()
|
||||||
|
|||||||
Reference in New Issue
Block a user