[refactor] clean, readable (#19)

* rebase zshrc, introduce DFS_NO_WALL

* improve ci

* improve ci

* improve ci

* update antigen url for DFS_NO_WALL

* OK

* improve ci for macos

* improve test.zsh

* staged

* fix ci

* fix ci

* use local vars

* introduce DFS_QUIET

* mass mod install.sh

* minor change

* set DFS_DEV=1 to prevent update

* debug: done -> fi

* fix DFS_DEV

* ubuntu.sh: set-mirror (ref: tuna)

* preinstall_check

* install.sh: -q to be quiet

* install.sh: -d to DFS_DEV

Co-authored-by: xiongdian.me <xiongdian.me@bytedance.com>
This commit is contained in:
Dict Xiong 2022-11-05 19:45:21 +08:00 committed by GitHub
parent 0739410aef
commit b6ff4116c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 260 additions and 142 deletions

View File

@ -22,7 +22,7 @@ jobs:
run: | run: |
rev=`git rev-parse HEAD` rev=`git rev-parse HEAD`
pwd pwd
export DFS_NO_COMPILE=1 DFS_NO_UPDATE=1 export DFS_NO_COMPILE=1 DFS_DEV=1
./install.sh ./install.sh
test `git rev-parse HEAD` = "$rev" test `git rev-parse HEAD` = "$rev"
@ -32,6 +32,21 @@ jobs:
echo $SHELL echo $SHELL
antigen list 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
- 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 - name: run tests
shell: /bin/zsh -ileo PIPE_FAIL {0} shell: /bin/zsh -ileo PIPE_FAIL {0}
run: source tools/test.zsh run: source tools/test.zsh
@ -55,7 +70,7 @@ jobs:
run: | run: |
rev=`git rev-parse HEAD` rev=`git rev-parse HEAD`
pwd pwd
export DFS_NO_COMPILE=1 DFS_NO_UPDATE=1 export DFS_NO_COMPILE=1 DFS_DEV=1
./install.sh ./install.sh
test `git rev-parse HEAD` = "$rev" test `git rev-parse HEAD` = "$rev"
@ -65,6 +80,21 @@ jobs:
echo $SHELL echo $SHELL
antigen list 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
- 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 - name: run tests
shell: /bin/zsh -ileo PIPE_FAIL {0} shell: /bin/zsh -ileo PIPE_FAIL {0}
run: source tools/test.zsh run: source tools/test.zsh

View File

@ -25,7 +25,11 @@ if [[ "$(git rev-parse HEAD)" == "$dfs_commit" ]]; then
post_log "INFO" "$THIS_FILE" "nothing to do" post_log "INFO" "$THIS_FILE" "nothing to do"
else else
fmt_info "checking out to commit $dfs_commit ..." fmt_info "checking out to commit $dfs_commit ..."
git -c advice.detachedHead=false checkout $dfs_commit if [[ -z "$DFS_DEV" ]]; then
git -c advice.detachedHead=false checkout $dfs_commit
else
fmt_warning "won't really checkout in dev mode"
fi
post_log "INFO" "$THIS_FILE" "will check out to commit $dfs_commit" post_log "INFO" "$THIS_FILE" "will check out to commit $dfs_commit"
cp ./.update.sh ./update.sh && chmod +x ./update.sh && exit cp ./.update.sh ./update.sh && chmod +x ./update.sh && exit
fi fi

48
.zshrc2
View File

@ -1,22 +1,29 @@
# env
export TERM="xterm-256color" export TERM="xterm-256color"
export LC_ALL=C.UTF-8 export LC_ALL=C.UTF-8
export LANG=C.UTF-8 export LANG=C.UTF-8
export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
export PATH="$PATH:$DOTFILES/scripts"
export LESS="-N"
# antigen # antigen
if [[ -z "$DFS_NO_WALL" ]]; then
# if test -z "$NO_WALL"; then ANTIGEN_URL="https://gitee.com/dictxiong/antigen/raw/develop/bin/antigen.zsh"
# ANTIGEN_OMZ_REPO_URL="https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git" ANTIGEN_OMZ_REPO_URL="https://gitee.com/dictxiong/ohmyzsh.git"
# ANTIGEN_URL="https://raw.fastgit.org/zsh-users/antigen/master/bin/antigen.zsh" ANTIGEN_PLUGINS=( \
# GIHUB_PROXY="https://hub.fastgit.xyz/" "https://gitee.com/dictxiong/zsh-syntax-highlighting" \
# else "https://gitee.com/dictxiong/zsh-completions" \
# ANTIGEN_URL="git.io/antigen" "https://gitee.com/dictxiong/zsh-autosuggestions" \
# GIHUB_PROXY="" )
# fi else
# antigen bundle ${GIHUB_PROXY}zsh-users/zsh-syntax-highlighting ANTIGEN_URL="https://raw.githubusercontent.com/zsh-users/antigen/develop/bin/antigen.zsh"
# antigen bundle ${GIHUB_PROXY}zsh-users/zsh-completions ANTIGEN_OMZ_REPO_URL="https://github.com/ohmyzsh/ohmyzsh.git"
# antigen bundle ${GIHUB_PROXY}zsh-users/zsh-autosuggestions ANTIGEN_PLUGINS=( \
ANTIGEN_OMZ_REPO_URL="https://gitee.com/dictxiong/ohmyzsh.git" "https://github.com/zsh-users/zsh-syntax-highlighting" \
ANTIGEN_URL="https://gitee.com/dictxiong/antigen/raw/develop/bin/antigen.zsh" "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,9 +47,9 @@ 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
ANTIGEN_PLUGINS+=( \
"command-not-found" \ "command-not-found" \
"docker" \ "docker" \
"extract" \ "extract" \
@ -52,11 +59,8 @@ antigen_plugins=( \
"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
@ -75,10 +79,6 @@ antigen theme ${ZSH_THEME:-$TMP_THEME}
antigen apply antigen apply
# end of antigen config # end of antigen config
# env
export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
export PATH=$PATH:$DOTFILES/scripts
# alias # alias
alias "pls"='sudo $(fc -ln -1)' alias "pls"='sudo $(fc -ln -1)'
alias "se"='sudo -sE' alias "se"='sudo -sE'

View File

@ -3,87 +3,144 @@
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd ) THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/tools/common.sh" source "$THIS_DIR/tools/common.sh"
home_slashes=${HOME//\//\\\/}
if [[ ! $DOTFILES == ${home_slashes}* ]]; then if [[ ! "$DOTFILES" == "${HOME}"* ]]; then
fmt_fatal "\"$DOTFILES\" is not under \"$HOME\". aborting ..." fmt_fatal "\"$DOTFILES\" is not under \"$HOME\". aborting ..."
fi fi
dotfile_home_path=${DOTFILES/${home_slashes}/\~} DOTFILE_TILDE=${DOTFILES/"$HOME"/\~}
dotfile_relative_path=${DOTFILES#${home_slashes}\/}
crontab_job="0 * * * * ${DOTFILES}/update.sh"
insert_if_not_exist() CRON_JOB="0 * * * * ${DOTFILES}/update.sh"
{ declare -a HOME_FILES_PATH
filename=$1 declare -a HOME_FILES_CONTENT
line=$2 HOME_FILES_PATH[0]=".zshrc"
fmt_note "installing \"$line\" into \"$filename\" ..." HOME_FILES_CONTENT[0]="source ${DOTFILE_TILDE}/.zshrc2"
mkdir -p $(dirname "$filename") HOME_FILES_PATH[1]=".tmux.conf"
if [ ! -f "$filename" ]; then HOME_FILES_CONTENT[1]="source-file ${DOTFILE_TILDE}/.tmux.conf2"
touch $filename HOME_FILES_PATH[2]=".vimrc"
fi HOME_FILES_CONTENT[2]="source ${DOTFILE_TILDE}/.vimrc2"
grep -qxF -- "$line" "$filename" || echo "$line" >> "$filename" HOME_FILES_PATH[3]=".gitconfig"
} HOME_FILES_CONTENT[3]="[include] path = \"${DOTFILE_TILDE}/.gitconfig2\""
delete_if_exist() declare -a HOME_SYMLINKS_SRC
{ declare -a HOME_SYMLINKS_DST
filename=$1 HOME_SYMLINKS_SRC[0]=".ssh/authorized_keys2"
line=$2 HOME_SYMLINKS_DST[0]=".ssh/authorized_keys2"
fmt_note "removing \"$line\" from \"$filename\" ..."
if [ -f "$filename" ]; then
grep -vxF -- "$line" "$filename" | tee "$filename"
fi
}
create_symlink()
preinstall_check()
{ {
src=$1 mandatory_commands=( "git" "zsh" "curl" "ping" )
dest=$2 optional_commands=( "python3" "vim" "tmux" )
fmt_note "creating symlink \"$dest\" --> \"$src\" ..." for i in "${mandatory_commands[@]}"; do
if [ ! -f "$src" ]; then if [[ ! -x "$(command -v $i)" ]]; then
fmt_error "\"$src\" does not exist! aborting this job ..." fmt_info "all this utils are required: ${mandatory_commands[@]}"
return 1 fmt_info "install them manually or check scripts in tools/"
fi fmt_fatal "\"$i\" not found. aborting ..."
mkdir -p $(dirname "$dest")
if [ -f "$dest" ]; then
if [ "$(readlink $dest)" -ef "$src" ]; then
return 0
fi fi
fmt_warning "\"$dest\" already exists! stat output:" done
echo ---------- for i in "${optional_commands[@]}"; do
stat $dest if [[ ! -x "$(command -v $i)" ]]; then
echo ---------- fmt_warning "\"$i\" not found"
ask_for_yN "would you like to replace ${dest}?" ask_for_Yn "continue anyway?"
if [ $? -eq 1 ]; then if [[ "$?" == "0" ]]; then
rm $dest fmt_info "all this utils are suggested: ${optional_commands[@]}"
else fmt_info "install them manually or check scripts in tools/"
fmt_error "\"$dest\" already exists! aborting this job ..." fmt_fatal "aborting ..."
return 1 fi
fi fi
fi done
ln -s $src $dest
return $?
} }
delete_link_if_match() install_file_content()
{ {
src=$1 for ((i=0; i<${#HOME_FILES_PATH[@]}; i++)); do
dest=$2 local filename="$HOME/${HOME_FILES_PATH[$i]}"
if [ "$(readlink $dest)" -ef "$src" ]; then local content=${HOME_FILES_CONTENT[$i]}
fmt_note "removing symlink \"$dest\" ..." fmt_note "installing \"$content\" into \"$filename\" ..."
echo ---------- mkdir -p $(dirname "$filename")
stat $dest if [ ! -f "$filename" ]; then
echo ---------- touch $filename
rm $dest fi
fi grep -qxF -- "$content" "$filename" || echo "$content" >> "$filename"
done
}
uninstall_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_note "removing \"$content\" from \"$filename\" ..."
if [ -f "$filename" ]; then
grep -vxF -- "$content" "$filename" | tee "$filename"
fi
done
}
install_symlink()
{
for ((i=0; i<${#HOME_SYMLINKS_SRC[@]}; i++)); do
local src="$DOTFILES/${HOME_SYMLINKS_SRC[$i]}"
local dst="$HOME/${HOME_SYMLINKS_DST[$i]}"
fmt_note "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 ----------
ask_for_yN "would you like to replace ${dst}?"
if [ $? -eq 1 ]; then
rm $dst
else
fmt_error "aborting this job ..."
continue
fi
fi
ln -s $src $dst
done
}
uninstall_symlink()
{
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_note "removing symlink \"$dst\" ..."
echo ----------
stat $dst
echo ----------
rm $dst
fi
done
} }
install_crontab(){ install_crontab(){
fmt_note "installing \"$crontab_job\" to crontab ..." if [[ -x $(command -v crontab) ]]; then
( crontab -l | grep -vxF "${crontab_job}" | grep -v "no crontab for"; echo "$crontab_job" ) | crontab - 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
} }
uninstall_crontab(){ uninstall_crontab(){
fmt_note "removing \"$crontab_job\" from crontab ..." if [[ -x $(command -v crontab) ]]; then
( crontab -l | grep -vxF "$crontab_job" ) | crontab - fmt_note "removing \"$CRON_JOB\" from crontab ..."
( crontab -l | grep -vxF "$CRON_JOB" ) | crontab -
else
fmt_note "crontab does not exist. skipping ..."
fi
} }
install_tmux_tpm(){ install_tmux_tpm(){
@ -118,10 +175,8 @@ install_update(){
fmt_note "installing update.sh ..." fmt_note "installing update.sh ..."
cp "${DOTFILES}/.update.sh" "${DOTFILES}/update.sh" cp "${DOTFILES}/.update.sh" "${DOTFILES}/update.sh"
chmod +x "${DOTFILES}/update.sh" chmod +x "${DOTFILES}/update.sh"
if [[ -z "$DFS_NO_UPDATE" ]]; then fmt_note "running update.sh ..."
fmt_note "running update.sh ..." ${DOTFILES}/update.sh
${DOTFILES}/update.sh
fi
} }
uninstall_update(){ uninstall_update(){
@ -130,13 +185,11 @@ uninstall_update(){
} }
install(){ install(){
preinstall_check
install_update install_update
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"
insert_if_not_exist "${HOME}/.gitconfig" "[include] path = \"${dotfile_home_path}/.gitconfig2\""
create_symlink "${DOTFILES}/.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
@ -145,21 +198,26 @@ install(){
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_update fmt_error "aborting this job ..."
uninstall_crontab return
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 "${DOTFILES}/.ssh/authorized_keys2" "${HOME}/.ssh/authorized_keys2"
fmt_note "done uninstalling!"
fi fi
uninstall_update
uninstall_crontab
uninstall_file_content
uninstall_symlink
fmt_note "done uninstalling!"
} }
BIN=install
case $1 in while [[ $# > 0 ]]; do
""|-i ) install ;; case $1 in
-r ) uninstall ;; -i ) BIN=install ;;
* ) fmt_warning "unknown command \"$1\". available: -i, -r" ;; -r ) BIN=uninstall ;;
esac -q ) export DFS_QUIET=1 ;;
-d ) export DFS_DEV=1 ;;
* ) fmt_warning "unknown command \"$1\". available: -i, -r, -q, -d"; exit 1 ;;
esac
shift
done
$BIN

View File

@ -1,8 +1,7 @@
#!/bin/bash #!/bin/bash
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd ) THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
DOTFILES=${DOTFILES:-$( cd "$THIS_DIR/.." && pwd )} source "$THIS_DIR/../tools/common.sh"
source "$DOTFILES/tools/common.sh"
if [[ -z "$1" || "$1" =~ "-h|--help" ]]; then if [[ -z "$1" || "$1" =~ "-h|--help" ]]; then
fmt_info "usage: dogo <container>" fmt_info "usage: dogo <container>"

View File

@ -4,10 +4,9 @@ set -e
set_mirror() set_mirror()
{ {
#MIRROR=${1:="mirrors.tuna.tsinghua.edu.cn"} MIRROR=${1:-"mirrors.tuna.tsinghua.edu.cn"}
#MIRROR=${MIRROR//\//\\\/} MIRROR=${MIRROR//\//\\\/}
#sed -i 's/(archive|security).ubuntu.com/${MIRROR}/g' /etc/apt/sources.list sed -i "s/dl-cdn.alpinelinux.org/$MIRROR/g" /etc/apk/repositories
echo "to-do ..."
} }
apk_add() apk_add()
@ -32,7 +31,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
} }

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd ) THIS_DIR_COMMON_SH=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
export DOTFILES=$( cd "$THIS_DIR/.." && pwd ) export DOTFILES=$( cd "$THIS_DIR_COMMON_SH/.." && pwd )
SUDO='' SUDO=''
if (( $EUID != 0 )); then if (( $EUID != 0 )); then
@ -38,7 +38,7 @@ supports_truecolor() {
fmt_fatal() { fmt_fatal() {
printf '%sfatal: %s%s\n' "${FMT_BOLD}${FMT_RED}" "$*" "${FMT_RESET}" >&2 printf '%sfatal: %s%s\n' "${FMT_BOLD}${FMT_RED}" "$*" "${FMT_RESET}" >&2
exit exit 1
} }
fmt_error() { fmt_error() {
@ -103,14 +103,26 @@ setup_color() {
ask_for_yN() ask_for_yN()
{ {
while true; do while [[ -z "$DFS_QUIET" ]]; do
read -p "${FMT_YELLOW}$1${FMT_RESET} [yN]: " yn read -p "${FMT_YELLOW}$1${FMT_RESET} [yN]: " yn
case $yn in case $yn in
[Yy]* ) return 1;; [Yy]* ) return 1;;
[Nn]* ) return 0;;
* ) return 0;; * ) return 0;;
esac esac
done done
return 0
}
ask_for_Yn()
{
while [[ -z "$DFS_QUIET" ]]; do
read -p "${FMT_YELLOW}$1${FMT_RESET} [Yn]: " yn
case $yn in
[Nn]* ) return 0;;
* ) return 1;;
esac
done
return 1
} }
post_log() post_log()
@ -119,6 +131,7 @@ post_log()
} }
get_os_type() { get_os_type() {
local ans="unknown"
case "$(uname -s)" in case "$(uname -s)" in
Darwin*) ans="MacOS";; Darwin*) ans="MacOS";;
CYGWIN*) ans="Cygwin";; CYGWIN*) ans="Cygwin";;
@ -130,26 +143,28 @@ get_os_type() {
} }
get_linux_dist() { get_linux_dist() {
local ans="unknown"
if [ -f /etc/os-release ]; then if [ -f /etc/os-release ]; then
. /etc/os-release . /etc/os-release
ans=$ID ans="$ID"
elif type lsb_release >/dev/null 2>&1; then elif type lsb_release >/dev/null 2>&1; then
ans=$(lsb_release -si) ans="$(lsb_release -si)"
elif [ -f /etc/lsb-release ]; then elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release . /etc/lsb-release
ans=$DISTRIB_ID ans="$DISTRIB_ID"
elif [ -f /etc/debian_version ]; then elif [ -f /etc/debian_version ]; then
ans=Debian ans="Debian"
elif [ -f /etc/SuSe-release ]; then elif [ -f /etc/SuSe-release ]; then
ans=SUSE ans="SUSE"
elif [ -f /etc/redhat-release ]; then elif [ -f /etc/redhat-release ]; then
ans=RedHat ans="RedHat"
else else
ans=unknown ans="unknown"
fi fi
echo $ans | tr '[:upper:]' '[:lower:]' echo $ans | tr '[:upper:]' '[:lower:]'
} }
# if bash-ed, else source-d
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
$1 "${@:2}" $1 "${@:2}"
else else

View File

@ -1,7 +1,7 @@
#!/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://gitee.com/dictxiong/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}" \
@ -15,7 +15,7 @@ install_commands=(\
install() install()
{ {
echo -e ${install_commands[$1]} echo -e ${INSTALL_COMMANDS[$1]}
} }
install $1 install $1

View File

@ -13,13 +13,13 @@ 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 pacman -S tmux git zsh curl vim wget base-devel mingw-w64-x86_64-toolchain make cmake gcc zip unzip python3 python3-pip
} }
router() router()
{ {
case $1 in case $1 in
pacman-S ) pacman_S ;; pacman-S ) pacman_S ;;
set-mirror ) set_mirror $2 ;; set-mirror ) set_mirror $2 ;;
* ) echo unknown command "$1". available: pacman-S, set-mirror ;; * ) echo unknown command "$1". available: pacman-S, set-mirror ;;
esac esac

View File

@ -1,10 +1,14 @@
#!/bin/false "This script should be sourced in a shell, not executed directly" #!/bin/false "This script should be sourced in zsh, not executed directly"
set -ex set -ex
# check files # check files
cd / cd /
l
cd ~
l
dfs cd dfs cd
l
pwd pwd
test -f .zshrc2 test -f .zshrc2
diff -q ./.ssh/authorized_keys2 ~/.ssh/authorized_keys2 diff -q ./.ssh/authorized_keys2 ~/.ssh/authorized_keys2
@ -13,8 +17,10 @@ grep -q ".zshrc2" ~/.zshrc
# check scripts and functions # check scripts and functions
dfs version dfs version
dfs log 1 dfs log 1
l z ~
test ~ -ef "$(pwd)"
dogo dogo
dfs cd
tools/common.sh get_os_type tools/common.sh get_os_type
tools/common.sh get_linux_dist tools/common.sh get_linux_dist
@ -22,6 +28,12 @@ tools/common.sh get_linux_dist
alias p114 > /dev/null alias p114 > /dev/null
# check update # check update
DFS_VERSION=`dfs version`
dfs update dfs update
dfs version dfs version
test `git rev-parse HEAD` = `curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id` test `git rev-parse HEAD` = `curl -fsSL https://api.beardic.cn/get-var/dfs-commit-id`
# clean
dfs cd
git reset --hard $DFS_VERSION
set +x

View File

@ -6,7 +6,8 @@ set_mirror()
{ {
MIRROR=${1:-"mirrors.tuna.tsinghua.edu.cn"} MIRROR=${1:-"mirrors.tuna.tsinghua.edu.cn"}
MIRROR=${MIRROR//\//\\\/} 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() apt_install()