[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 ..."
if [[ -z "$DFS_DEV" ]]; then
git -c advice.detachedHead=false checkout $dfs_commit 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

46
.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_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,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
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\""
declare -a HOME_SYMLINKS_SRC
declare -a HOME_SYMLINKS_DST
HOME_SYMLINKS_SRC[0]=".ssh/authorized_keys2"
HOME_SYMLINKS_DST[0]=".ssh/authorized_keys2"
preinstall_check()
{ {
filename=$1 mandatory_commands=( "git" "zsh" "curl" "ping" )
line=$2 optional_commands=( "python3" "vim" "tmux" )
fmt_note "installing \"$line\" into \"$filename\" ..." for i in "${mandatory_commands[@]}"; do
if [[ ! -x "$(command -v $i)" ]]; 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 [[ ! -x "$(command -v $i)" ]]; 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
}
install_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 "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 for ((i=0; i<${#HOME_FILES_PATH[@]}; i++)); do
line=$2 local filename="$HOME/${HOME_FILES_PATH[$i]}"
fmt_note "removing \"$line\" from \"$filename\" ..." local content=${HOME_FILES_CONTENT[$i]}
fmt_note "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 for ((i=0; i<${#HOME_SYMLINKS_SRC[@]}; i++)); do
dest=$2 local src="$DOTFILES/${HOME_SYMLINKS_SRC[$i]}"
fmt_note "creating symlink \"$dest\" --> \"$src\" ..." local dst="$HOME/${HOME_SYMLINKS_DST[$i]}"
fmt_note "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 local src
dest=$2 for src in "${!HOME_SYMLINKS[@]}"; do
if [ "$(readlink $dest)" -ef "$src" ]; then local dst=${HOME_SYMLINKS[$src]}
fmt_note "removing symlink \"$dest\" ..." src="$DOTFILES/$src"
dst="$HOME/$dst"
if [ "$(readlink $dst)" -ef "$src" ]; then
fmt_note "removing symlink \"$dst\" ..."
echo ---------- echo ----------
stat $dest stat $dst
echo ---------- echo ----------
rm $dest rm $dst
fi 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
fmt_error "aborting this job ..."
return
fi
uninstall_update uninstall_update
uninstall_crontab uninstall_crontab
delete_if_exist "${HOME}/.zshrc" "source ${dotfile_home_path}/.zshrc2" uninstall_file_content
delete_if_exist "${HOME}/.tmux.conf" "source-file ${dotfile_home_path}/.tmux.conf2" uninstall_symlink
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!" fmt_note "done uninstalling!"
fi
} }
BIN=install
while [[ $# > 0 ]]; do
case $1 in case $1 in
""|-i ) install ;; -i ) BIN=install ;;
-r ) uninstall ;; -r ) BIN=uninstall ;;
* ) fmt_warning "unknown command \"$1\". available: -i, -r" ;; -q ) export DFS_QUIET=1 ;;
-d ) export DFS_DEV=1 ;;
* ) fmt_warning "unknown command \"$1\". available: -i, -r, -q, -d"; exit 1 ;;
esac 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,7 +13,7 @@ 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()

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()