-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpost-install.sh
More file actions
97 lines (86 loc) · 4.74 KB
/
Copy pathpost-install.sh
File metadata and controls
97 lines (86 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
# ensure missing properties in `.git/config` will be "synced" by `.gitmodules`
git submodule sync --recursive
# ensure existing properties in `.git/config` will be "updated" from `.gitmodules`
git submodule update --init --recursive
# link ~/.gitconfig to gitconfig_codespaces in GitHub Codespaces
[[ ${CODESPACES:-} == "true" ]] && ln -sf "${REPO_ROOT}/git/gitconfig.codespaces" "${HOME}/.gitconfig"
# link ~/.gitconfig to gitconfig.wsl in Windows Subsystem for Linux
[[ -n ${WSL_DISTRO_NAME:-} ]] && ln -sf "${REPO_ROOT}/git/gitconfig.wsl" "${HOME}/.gitconfig"
is_container() {
# 1) systemd-detect-virt
if command -v systemd-detect-virt >/dev/null 2>&1 \
&& systemd-detect-virt --container --quiet; then
return 0
fi
# 2) cgroup 路径
if grep -qE '/(docker|kubepods|containerd|lxc)/' /proc/1/cgroup 2>/dev/null; then
return 0
fi
# 3) 特定文件 / 环境变量
if [ -f /.dockerenv ] || [ -f /run/.containerenv ] \
|| grep -qa '^container=' /proc/1/environ 2>/dev/null; then
return 0
fi
# 4) PID namespace 差异
if [ "$(stat -c %d /proc/1/ns/pid 2>/dev/null)" != \
"$(stat -c %d /proc/self/ns/pid 2>/dev/null)" ]; then
return 0
fi
return 1
}
if is_container; then
exit 0
fi
if [[ $(uname) == "Darwin" ]]; then
# macOS
# clang -framework Carbon util/reset-input.m -o bin/reset-input
brew update && brew upgrade
brew install --quiet ack ag aria2 bat csvkit curl difftastic direnv duf dust entr eza fd fortune fzf git-delta gitkraken-cli glab glow htop hyperfine jq just lsof ncdu netcat noti prettyping ripgrep sd socat tldr tokei trash-cli tree watchexec wget yq yt-dlp font-droid-sans-mono-nerd-font font-im-writing-nerd-font
elif [[ $(uname) == "Linux" ]]; then
# Other Linux distributions
ARCH=$(uname -m)
case "$ARCH" in
x86_64) RUST_TARGET="x86_64-unknown-linux-gnu"; SD_TARGET="x86_64-unknown-linux-gnu"; GO_ARCH="amd64" ;;
aarch64) RUST_TARGET="aarch64-unknown-linux-gnu"; SD_TARGET="aarch64-unknown-linux-musl"; GO_ARCH="arm64" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac
sudo apt update && sudo apt upgrade -y
sudo apt install -y ack aria2 bat csvkit curl direnv duf entr eza fd-find fortune-mod fzf git git-delta htop hyperfine jq lsof ncdu netcat-openbsd prettyping ripgrep silversearcher-ag socat tldr trash-cli tree wget yt-dlp
# Debian/Ubuntu renames: bat→batcat, fd-find→fdfind
[ -x /usr/bin/batcat ] && sudo ln -sf /usr/bin/batcat /usr/local/bin/bat
[ -x /usr/bin/fdfind ] && sudo ln -sf /usr/bin/fdfind /usr/local/bin/fd
SNAP_TOOLS=(diff-so-fancy difftastic dust gitkraken-cli glab glow just)
# Tools not in standard apt repos — install via snap when available
if command -v snap >/dev/null 2>&1; then
sudo snap install diff-so-fancy difftastic glab glow gitkraken-cli
sudo snap install just --classic
sudo snap install dust # du alternative (apt package `du-dust` does not exist)
else
echo "Warning: snap not found; skipping optional repo-managed tools: ${SNAP_TOOLS[*]}." >&2
echo "Install snapd and rerun ./install if you want those extra CLI tools." >&2
fi
# snap `difftastic` binary is named `difftastic`, alias to `difft`
[ -x /snap/bin/difftastic ] && sudo ln -sf /snap/bin/difftastic /usr/local/bin/difft
# tokei — no pre-built binaries in GitHub releases; install via cargo
if command -v cargo >/dev/null 2>&1; then
cargo install tokei
else
echo "Warning: cargo not found, skipping tokei installation"
fi
# yq v4 (apt `yq` is the legacy Python wrapper, not mikefarah/yq)
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_${GO_ARCH} && sudo chmod +x /usr/local/bin/yq
# sd (sed alternative)
SD_VER=$(curl -fsSL https://api.github.com/repos/chmln/sd/releases/latest | jq -r '.tag_name')
curl -fsSL "https://github.com/chmln/sd/releases/download/${SD_VER}/sd-${SD_VER}-${SD_TARGET}.tar.gz" | sudo tar xz --strip-components=1 -C /usr/local/bin "sd-${SD_VER}-${SD_TARGET}/sd"
# watchexec
WATCHEXEC_VER=$(curl -fsSL https://api.github.com/repos/watchexec/watchexec/releases/latest | jq -r '.tag_name' | sed 's/^v//')
curl -fsSL "https://github.com/watchexec/watchexec/releases/download/v${WATCHEXEC_VER}/watchexec-${WATCHEXEC_VER}-${RUST_TARGET}.tar.xz" | sudo tar xJ --strip-components=1 -C /usr/local/bin
# noti (command notification) — only amd64 binaries available
if [[ "$GO_ARCH" == "amd64" ]]; then
NOTI_VER=$(curl -fsSL https://api.github.com/repos/variadico/noti/releases/latest | jq -r '.tag_name')
curl -fsSL "https://github.com/variadico/noti/releases/download/${NOTI_VER}/noti${NOTI_VER}.linux-amd64.tar.gz" | sudo tar xz -C /usr/local/bin noti
fi
fi