自動環境構築script
仕様
install.sh
terminal起動時にsetup.shが実行されるように設定するscript
設定方法候補
~/.bashrcを差し替える
$ ln -sb ~/git/dotfiles/setup.sh ~/.bashrc
backupを~/.bashrc~に保存する
~/.bashrcに追記する
再現性が保たれなさそう
code:sh
code:install.sh
ln -sb ~/.setup.bash ~/.bashrc
. ~/.bashrc
setup.sh
1からterminalの環境構築を行うscript
GitHubの設定だけは手動でやんないとだめかー
懸念点
パスワード入力とかをどうするか
2021-10-06 12:51:34 全部バッチ処理で済ませられるようにした
References
なんかこれをやったほうが良さそう
2021-10-05 22:41:35 Dockerには手を出さないことにする 常用するには理解がほとんど足らない
shell scriptを学ぶルートのほうが明瞭
時間的猶予も加味して、shell scriptを速習してさっさと書くことにした
2021-10-06
17:28:01 うまくいったっぽい?
WSLをresetして、もう一度最初から試してうまく動くかどうかを確かめる
17:40:41 ここで入力を待たずに次に進んでしまった……なんで? 17:45:52 terminalを起動し直したらまた壊れた
https://gyazo.com/67d5e4806d93d65c15be2993918c6ba2
どこで発生するんだこのエラー
今日中になんとかするのは無理そうだな。諦めるか……takker.icon
code:sh
echo "SSH keys for GitHub aren't found. Creating SSH keys..."
SSH_GITHUB_NAME="~/.ssh/id_github_takker99"
# 秘密鍵の中身を取り出す
copyKey() {
KEY=$(cat "${SSH_GITHUB_NAME}.pub")
if type "clip.exe" > /dev/null 2>&1; then
clip.exe "${KEY}"
else
xsel "${KEY}"
fi
}
mkdir -p ~/.ssh
ssh-keygen -t ed25519 -C "37929109+takker99@users.noreply.github.com" -f "${SSH_GITHUB_NAME}" -P "" -N ""
copyKey
select i in Registered CopyAgain
do
case $i in
Registered) break;;
CopyAgain) copyKey;;
*) echo "Either \"Registered\" or \"CopyAgain\" can be selected.";;
esac
done
fi
if !(-e ~/.ssh/config) ; then
ln -s ~/git/dotfiles/ssh/config ~/.ssh/config
fi
ssh -T github
ln -sb ~/git/dotfiles/.gitconfig ~/.gitconfig
git remote set-url origin git@github.com:takker99/dotfiles.git
popd
fi
例外処理の設定
code:setup.bash
set -eu
catch () {
echo "Some error have occurred. Terminate the installation."
}
trap catch ERR
言語とserver設定
code:setup.bash
sudo sed -i.bak -e \
"s/http:\/\/archive\.ubuntu\.com/http:\/\/jp\.archive\.ubuntu\.com/g" \
/etc/apt/sources.list
13:22:30 sudoをつけても/etc/apt/sources.listを編集できない?なんでだ?
shellそのものにsudoを付けないとだめだったみたい
code:setup.bash
sudo echo Asia/Tokyo > /etc/timezone
sudo dpkg-reconfigure --frontend noninteractive tzdata
aptから先に入れる
code:setup.bash
if [[!(type "nvim" > /dev/null 2>&1) \
|| !(type "batcat" > /dev/null 2>&1) \
|| !(type "unzip" > /dev/null 2>&1) \
|| !(type "fish" > /dev/null 2>&1) \
|| !(type "clang" > /dev/null 2>&1) \
|| !(type "xsel" > /dev/null 2>&1) \
]]; then
echo "Install some apps...";
sudo add-apt-repository ppa:fish-shell/release-3
sudo apt-get update
sudo apt-get install neovim bat unzip fish clang build-essential x11-apps x11-utils x11-xserver-utils dbus-x11 -y
echo "Successfully installed."
fi
code:setup.bash
if !(-d ~/git/dotfiles) ; then
echo "Downloading takker99/dotfiles..."
mkdir -p git
code:setup.bash
SSH_GITHUB_NAME="~/.ssh/id_github_takker99"
# 秘密鍵の中身を取り出す
copyKey() {
KEY=$(cat "${SSH_GITHUB_NAME}.pub")
if type "clip.exe" > /dev/null 2>&1; then
clip.exe "${KEY}"
else
xsel "${KEY}"
fi
}
if !(-e ${SSH_GITHUB_NAME}) || !(-e "${SSH_GITHUB_NAME}.pub"); then
echo "SSH keys for GitHub aren't found. Creating SSH keys..."
ssh-keygen -t ed25519 -C "37929109+takker99@users.noreply.github.com" -f -P "" -N ""
copyKey
select i in Registered CopyAgain
do
case $i in
Registered) break;;
CopyAgain) copyKey;;
*) echo "Either \"Registered\" or \"CopyAgain\" can be selected.";;
esac
done
fi
if !(-e ~/.ssh/config) ; then
ln -s ~/git/dotfiles/ssh/config ~/.ssh/config
fi
Githubとの接続を確認する
code:setup.bash
ssh -T github
code:setup.bash
ln -sb ~/git/dotfiles/.gitconfig ~/.gitconfig
dotfilesのrepoをSSH接続に切り替える
code:setup.bash
git remote set-url origin git@github.com:takker99/dotfiles.git
fi
code:setup.bash
. ~/git/dotfiles/.bashrc
必要なsoftwareのinstall
deno
code:setup.bash
export DENO_INSTALL="$HOME/.deno"
export PATH="$DENO_INSTALL/bin:$PATH"
if !(type "deno" > /dev/null 2>&1); then
echo "deno is not installed. Install deno..."
echo "Successfully installed deno."
fi
nvm
code:setup.bash
# required to install npm
export NVM_DIR="$HOME/.nvm"
if !(type "nvm" > /dev/null 2>&1); then
echo "nvm is not installed. Install nvm..."
echo "Successfully installed nvm."
fi
node
code:setup.bash
# required to install npm
if !(type "node" > /dev/null 2>&1); then
echo "Node.js is not installed. Install Node.js..."
nvm install node
eval "cat <<< \"current Node version: $(node --version)\""
eval "cat <<< \"current npm version: $(npm --version)\""
echo "Successfully installed node and npm."
fi
yarn
code:setup.bash
if !(type "yarn" > /dev/null 2>&1); then
echo "yarn is not installed. Install yarn..."
npm install -g yarn
# use yarn V2
yarn set version berry
echo "Successfully installed yarn."
fi
cargo
code:setup.bash
if !(type "cargo" > /dev/null 2>&1); then
echo "Rust compile tools is not installed. Install rustup and cargo..."
echo "Successfully installed rustup."
fi
export PATH="$HOME/.cargo/bin:$PATH"
exa
code:setup.bash
if !(type "exa" > /dev/null 2>&1); then
echo "exa is not installed. Install exa..."
cargo install exa
echo "Successfully installed exa."
fi
fishを実行する
code:setup.bash
exec fish