Bundle the iTerm2 zsh integration for offline use. Let update.sh repair a missing or empty installation using curl with redirect support, falling back to the bundled copy on offline, missing curl, failed downloads, or empty responses. Stage the result beside the target before moving it into place. Append the readability-checked source line to .zshrc only when missing, including when .zshrc does not exist or lacks a final newline. Keep configure_priv.sh and the installation flow unchanged.
82 lines
3.1 KiB
Bash
Executable File
82 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
scriptdir=$(dirname $(realpath $0))
|
|
|
|
# ============================================================
|
|
|
|
update_file() {
|
|
local A="$1"
|
|
local B="$2"
|
|
|
|
if [ -f "$A" ] && [ -f "$B" ] && [ "$(cat "$A")" != "$(cat "$B")" ]; then
|
|
cp "$A" "$B"
|
|
echo "File $B has been updated."
|
|
fi
|
|
}
|
|
|
|
update_file_sudo() {
|
|
local A="$1"
|
|
local B="$2"
|
|
|
|
if [ -f "$A" ] && [ -f "$B" ] && [ "$(cat "$A")" != "$(cat "$B")" ]; then
|
|
sudo cp "$A" "$B"
|
|
echo "File $B has been updated."
|
|
fi
|
|
}
|
|
|
|
update_authorized_keys() {
|
|
[ ! -f ~/.ssh/authorized_keys ] && return
|
|
|
|
local public_keys=$(cat $scriptdir/files/authorized_keys)
|
|
while IFS= read -r public_key; do
|
|
[[ $public_key == \#* ]] && continue
|
|
if ! grep -q "$public_key" ~/.ssh/authorized_keys; then
|
|
echo "$public_key" >> ~/.ssh/authorized_keys
|
|
echo "Added public key to authorized_keys: $public_key"
|
|
fi
|
|
done <<< "$public_keys"
|
|
}
|
|
|
|
update_iterm2_shell_integration() {
|
|
local iterm2_script="$HOME/.iterm2_shell_integration.zsh"
|
|
local bundled_script="$scriptdir/files/zsh/iterm2_shell_integration.zsh"
|
|
local tmp_script
|
|
local source_line='[ -r "$HOME/.iterm2_shell_integration.zsh" ] && source "$HOME/.iterm2_shell_integration.zsh"'
|
|
|
|
if [ ! -s "$iterm2_script" ]; then
|
|
tmp_script=$(mktemp "$HOME/.iterm2_shell_integration.zsh.XXXXXX") || return
|
|
if [ "${offline:-0}" = 1 ] || ! command -v curl >/dev/null 2>&1 ||
|
|
! curl -fsSL -m 15 "https://iterm2.com/shell_integration/zsh" -o "$tmp_script" || [ ! -s "$tmp_script" ]; then
|
|
cp "$bundled_script" "$tmp_script" || { rm -f "$tmp_script"; return 1; }
|
|
fi
|
|
mv -f "$tmp_script" "$iterm2_script" || { rm -f "$tmp_script"; return 1; }
|
|
fi
|
|
|
|
touch "$HOME/.zshrc" || return
|
|
if ! grep -Fxq "$source_line" "$HOME/.zshrc"; then
|
|
printf '\n%s\n' "$source_line" >>"$HOME/.zshrc"
|
|
fi
|
|
}
|
|
|
|
# ============================================================
|
|
|
|
update_file $scriptdir/files/.nanorc ~/.nanorc
|
|
update_file $scriptdir/files/.vimrc ~/.vimrc
|
|
update_file $scriptdir/files/.tmux.conf ~/.tmux.conf
|
|
update_file $scriptdir/files/gpg.conf ~/.gnupg/gpg.conf
|
|
update_file $scriptdir/files/zsh/00-init.zsh ~/.oh-my-zsh/custom/00-init.zsh
|
|
update_file $scriptdir/files/zsh/10-theme.zsh ~/.oh-my-zsh/custom/10-theme.zsh
|
|
update_file $scriptdir/files/zsh/20-function.zsh ~/.oh-my-zsh/custom/20-function.zsh
|
|
update_file $scriptdir/files/zsh/50-env.zsh ~/.oh-my-zsh/custom/50-env.zsh
|
|
update_file $scriptdir/files/zsh/51-alias.zsh ~/.oh-my-zsh/custom/51-alias.zsh
|
|
update_file $scriptdir/files/zsh/80-proxy.zsh ~/.oh-my-zsh/custom/80-proxy.zsh
|
|
update_file $scriptdir/files/zsh/90-other.zsh ~/.oh-my-zsh/custom/90-other.zsh
|
|
update_file $scriptdir/files/zsh/ys-simple.zsh-theme ~/.oh-my-zsh/custom/themes/ys-simple.zsh-theme
|
|
update_authorized_keys
|
|
update_iterm2_shell_integration
|
|
|
|
# sudo_id=$(sudo id -u 2>/dev/null)
|
|
# if [ $? -eq 0 ] && [ "$sudo_id" -eq 0 ]; then
|
|
# update_file_sudo $scriptdir/files/proxychains4.conf /etc/proxychains4.conf
|
|
# fi
|