mirror of
https://github.com/DictXiong/dotfiles.git
synced 2026-10-23 05:08:16 +08:00
[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:
@@ -4,10 +4,9 @@ set -e
|
||||
|
||||
set_mirror()
|
||||
{
|
||||
#MIRROR=${1:="mirrors.tuna.tsinghua.edu.cn"}
|
||||
#MIRROR=${MIRROR//\//\\\/}
|
||||
#sed -i 's/(archive|security).ubuntu.com/${MIRROR}/g' /etc/apt/sources.list
|
||||
echo "to-do ..."
|
||||
MIRROR=${1:-"mirrors.tuna.tsinghua.edu.cn"}
|
||||
MIRROR=${MIRROR//\//\\\/}
|
||||
sed -i "s/dl-cdn.alpinelinux.org/$MIRROR/g" /etc/apk/repositories
|
||||
}
|
||||
|
||||
apk_add()
|
||||
@@ -32,7 +31,7 @@ router()
|
||||
case $1 in
|
||||
apk-add ) apk_add ;;
|
||||
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;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
export DOTFILES=$( cd "$THIS_DIR/.." && pwd )
|
||||
THIS_DIR_COMMON_SH=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
export DOTFILES=$( cd "$THIS_DIR_COMMON_SH/.." && pwd )
|
||||
|
||||
SUDO=''
|
||||
if (( $EUID != 0 )); then
|
||||
@@ -38,7 +38,7 @@ supports_truecolor() {
|
||||
|
||||
fmt_fatal() {
|
||||
printf '%sfatal: %s%s\n' "${FMT_BOLD}${FMT_RED}" "$*" "${FMT_RESET}" >&2
|
||||
exit
|
||||
exit 1
|
||||
}
|
||||
|
||||
fmt_error() {
|
||||
@@ -103,14 +103,26 @@ setup_color() {
|
||||
|
||||
ask_for_yN()
|
||||
{
|
||||
while true; do
|
||||
while [[ -z "$DFS_QUIET" ]]; do
|
||||
read -p "${FMT_YELLOW}$1${FMT_RESET} [yN]: " yn
|
||||
case $yn in
|
||||
[Yy]* ) return 1;;
|
||||
[Nn]* ) return 0;;
|
||||
* ) return 0;;
|
||||
esac
|
||||
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()
|
||||
@@ -119,6 +131,7 @@ post_log()
|
||||
}
|
||||
|
||||
get_os_type() {
|
||||
local ans="unknown"
|
||||
case "$(uname -s)" in
|
||||
Darwin*) ans="MacOS";;
|
||||
CYGWIN*) ans="Cygwin";;
|
||||
@@ -130,26 +143,28 @@ get_os_type() {
|
||||
}
|
||||
|
||||
get_linux_dist() {
|
||||
local ans="unknown"
|
||||
if [ -f /etc/os-release ]; then
|
||||
. /etc/os-release
|
||||
ans=$ID
|
||||
ans="$ID"
|
||||
elif type lsb_release >/dev/null 2>&1; then
|
||||
ans=$(lsb_release -si)
|
||||
ans="$(lsb_release -si)"
|
||||
elif [ -f /etc/lsb-release ]; then
|
||||
. /etc/lsb-release
|
||||
ans=$DISTRIB_ID
|
||||
ans="$DISTRIB_ID"
|
||||
elif [ -f /etc/debian_version ]; then
|
||||
ans=Debian
|
||||
ans="Debian"
|
||||
elif [ -f /etc/SuSe-release ]; then
|
||||
ans=SUSE
|
||||
ans="SUSE"
|
||||
elif [ -f /etc/redhat-release ]; then
|
||||
ans=RedHat
|
||||
ans="RedHat"
|
||||
else
|
||||
ans=unknown
|
||||
ans="unknown"
|
||||
fi
|
||||
echo $ans | tr '[:upper:]' '[:lower:]'
|
||||
}
|
||||
|
||||
# if bash-ed, else source-d
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
$1 "${@:2}"
|
||||
else
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
declare -A install_commands
|
||||
install_commands=(\
|
||||
declare -A INSTALL_COMMANDS
|
||||
INSTALL_COMMANDS=(\
|
||||
[git]="apt update && apt install git" \
|
||||
[fzf]="git clone --depth 1 https://gitee.com/dictxiong/fzf.git ~/.fzf && ~/.fzf/install" \
|
||||
[acme.sh]="curl https://get.acme.sh | sh -s email=${EMAIL:-me@beardic.cn}" \
|
||||
@@ -15,7 +15,7 @@ install_commands=(\
|
||||
|
||||
install()
|
||||
{
|
||||
echo -e ${install_commands[$1]}
|
||||
echo -e ${INSTALL_COMMANDS[$1]}
|
||||
}
|
||||
|
||||
install $1
|
||||
|
||||
@@ -13,13 +13,13 @@ set_mirror()
|
||||
pacman_S()
|
||||
{
|
||||
pacman -Syu
|
||||
pacman -S tmux git zsh curl vim wget base-devel mingw-w64-x86_64-toolchain make cmake gcc zip unzip
|
||||
pacman -S tmux git zsh curl vim wget base-devel mingw-w64-x86_64-toolchain make cmake gcc zip unzip python3 python3-pip
|
||||
}
|
||||
|
||||
router()
|
||||
{
|
||||
case $1 in
|
||||
pacman-S ) pacman_S ;;
|
||||
pacman-S ) pacman_S ;;
|
||||
set-mirror ) set_mirror $2 ;;
|
||||
* ) echo unknown command "$1". available: pacman-S, set-mirror ;;
|
||||
esac
|
||||
|
||||
@@ -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
|
||||
|
||||
# check files
|
||||
cd /
|
||||
l
|
||||
cd ~
|
||||
l
|
||||
dfs cd
|
||||
l
|
||||
pwd
|
||||
test -f .zshrc2
|
||||
diff -q ./.ssh/authorized_keys2 ~/.ssh/authorized_keys2
|
||||
@@ -13,8 +17,10 @@ grep -q ".zshrc2" ~/.zshrc
|
||||
# check scripts and functions
|
||||
dfs version
|
||||
dfs log 1
|
||||
l
|
||||
z ~
|
||||
test ~ -ef "$(pwd)"
|
||||
dogo
|
||||
dfs cd
|
||||
tools/common.sh get_os_type
|
||||
tools/common.sh get_linux_dist
|
||||
|
||||
@@ -22,6 +28,12 @@ tools/common.sh get_linux_dist
|
||||
alias p114 > /dev/null
|
||||
|
||||
# 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
|
||||
dfs cd
|
||||
git reset --hard $DFS_VERSION
|
||||
set +x
|
||||
@@ -6,7 +6,8 @@ set_mirror()
|
||||
{
|
||||
MIRROR=${1:-"mirrors.tuna.tsinghua.edu.cn"}
|
||||
MIRROR=${MIRROR//\//\\\/}
|
||||
sed -i 's/(archive|security).ubuntu.com/${MIRROR}/g' /etc/apt/sources.list
|
||||
sed -i "s@http://.*archive.ubuntu.com@https://${MIRROR}@g" /etc/apt/sources.list
|
||||
sed -i "s@http://.*security.ubuntu.com@https://${MIRROR}@g" /etc/apt/sources.list
|
||||
}
|
||||
|
||||
apt_install()
|
||||
|
||||
Reference in New Issue
Block a user