116 lines
3.1 KiB
Bash
Executable File
116 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
scriptdir=$(dirname $(realpath $0))
|
|
tempdir=$(mktemp -d)
|
|
|
|
# ============================================================
|
|
|
|
. $scriptdir/utils.sh
|
|
|
|
# ============================================================
|
|
|
|
configure_ssh() {
|
|
[ -f ~/.ssh/authorized_keys ] && return
|
|
|
|
if confirm_action "要配置 authorized_keys 吗?" "N"; then
|
|
mkdir -p ~/.ssh
|
|
cp $scriptdir/files/authorized_keys ~/.ssh/authorized_keys
|
|
fi
|
|
}
|
|
|
|
configure_ssh_keygen() {
|
|
[ -f ~/.ssh/id_ed25519.pub ] && return
|
|
[ -f ~/.ssh/id_rsa.pub ] && return
|
|
|
|
if confirm_action "要生成 sshkey 吗?" "N"; then
|
|
mkdir -p ~/.ssh
|
|
read -p "sshkey 的名字: " sshkeyname
|
|
ssh-keygen -t ed25519 -C $sshkeyname
|
|
fi
|
|
}
|
|
|
|
configure_git() {
|
|
[ -f ~/.gitconfig ] && return
|
|
|
|
if confirm_action "要配置 git 吗?" "Y"; then
|
|
cp $scriptdir/files/.gitconfig ~/.gitconfig
|
|
fi
|
|
}
|
|
|
|
configure_miniconda() {
|
|
[ -d ~/.miniconda3 ] && return
|
|
[ $offline -eq 1 ] && return
|
|
[[ $(uname -m) == "aarch64" ]] && return
|
|
|
|
if confirm_action "要安装 miniconda 吗?" "N"; then
|
|
wget "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-$(uname -m).sh" -O $tempdir/miniconda.sh
|
|
bash $tempdir/miniconda.sh -b -p ~/.miniconda3
|
|
rm $tempdir/miniconda.sh
|
|
~/.miniconda3/bin/conda init zsh
|
|
~/.miniconda3/bin/conda config --set changeps1 False
|
|
~/.miniconda3/bin/conda install -c conda-forge mamba
|
|
~/.miniconda3/bin/mamba init
|
|
fi
|
|
}
|
|
|
|
configure_miniforge() {
|
|
[ -d ~/.miniforge3 ] && return
|
|
[ $offline -eq 1 ] && return
|
|
[[ $(uname -m) != "aarch64" ]] && return
|
|
|
|
if confirm_action "要安装 miniforge 吗?" "N"; then
|
|
wget "$github/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-$(uname -m).sh" -O $tempdir/miniforge.sh
|
|
bash $tempdir/miniforge.sh -b -p ~/.miniforge3
|
|
rm $tempdir/miniforge.sh
|
|
~/.miniforge3/bin/conda config --set changeps1 False
|
|
~/.miniforge3/bin/mamba init zsh
|
|
fi
|
|
}
|
|
|
|
configure_nvm() {
|
|
[ -d ~/.nvm/.git ] && return
|
|
[ $offline -eq 1 ] && return
|
|
|
|
if confirm_action "要安装 nvm / nodejs 吗?" "N"; then
|
|
git_clone nvm-sh/nvm ~/.nvm --depth=1
|
|
\. $scriptdir/files/install-nvm.sh
|
|
\. ~/.nvm/nvm.sh
|
|
\. ~/.nvm/bash_completion
|
|
nvm install lts/iron
|
|
nvm alias default lts/iron
|
|
nvm install-latest-npm
|
|
if [ $abroad -ne 1 ]; then
|
|
echo "registry=https://registry.npmmirror.com" >~/.npmrc
|
|
fi
|
|
fi
|
|
}
|
|
|
|
configure_gpg() {
|
|
[ -d ~/.gnupg ] && [ -f ~/.gnupg/gpg.conf ] && return
|
|
|
|
if confirm_action "要配置 gpg 吗?" "Y"; then
|
|
mkdir -p ~/.gnupg
|
|
chmod 700 ~/.gnupg
|
|
cp $scriptdir/files/gpg.conf ~/.gnupg/gpg.conf
|
|
fi
|
|
}
|
|
|
|
# ============================================================
|
|
|
|
if [ $# -ne 0 ]; then
|
|
for func in $@; do
|
|
declare -F configure_$func >/dev/null || continue
|
|
echo "Configuring $func..."
|
|
eval "configure_$func"
|
|
done
|
|
return
|
|
fi
|
|
|
|
configure_ssh
|
|
configure_ssh_keygen
|
|
configure_git
|
|
configure_miniconda
|
|
configure_miniforge
|
|
configure_nvm
|
|
configure_gpg
|