Last active
June 7, 2024 14:28
-
-
Save yonta/c1e341f644e7a1c0482a856a9533d08e to your computer and use it in GitHub Desktop.
Initialize environment script for WSL with Ubuntu or openSUSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
# https://qiita.com/youcune/items/fcfb4ad3d7c1edf9dc96 | |
# -euでエラーか未定義変数でストップする | |
script_dir="$(cd $(dirname $0); pwd -P)" | |
# Color message | |
NORMAL=$(tput sgr0) | |
YELLOW=$(tput setaf 3) | |
GRAY=$(tput setaf 8) | |
function message() { | |
echo -e "$GRAY$*$NORMAL" | |
} | |
function header() { | |
echo -e "$GRAY##### $* ###############$NORMAL" | |
} | |
function warning() { | |
echo -e "$YELLOW$*$NORMAL" | |
} | |
# XDG environment | |
XDG_CONFIG_HOME="${HOME}/.config" | |
XDG_CACHE_HOME="${HOME}/.cache" | |
XDG_DATA_HOME="${HOME}/.local/share" | |
XDG_STATE_HOME="${HOME}/.local/state" | |
# mkdir | |
if [ ! -d "${HOME}/.config" ]; then | |
header "Make XDG Base directories" | |
mkdir -p ${XDG_CONFIG_HOME} ${XDG_CACHE_HOME} ${XDG_DATA_HOME} | |
fi | |
if [ ! -d "${HOME}/git" ]; then | |
header "Make git and tmp directories" | |
cd ${HOME} | |
mkdir -p git | |
mkdir -p tmp | |
fi | |
# ssh-key (First, because of user interaction) | |
keytype="ed25519" | |
if [ ! -f "${HOME}/.ssh/id_${keytype}" ]; then | |
header "Make ssh-key" | |
cd ${HOME} | |
ssh-keygen -P '' -t ${keytype} -f ${HOME}/.ssh/id_${keytype} | |
cat ${HOME}/.ssh/id_${keytype}.pub | |
warning "Press enter key, after register SSH key to GitHub and BitBucket:" | |
read | |
fi | |
# Update soucres list to internal one | |
if grep 'Ubuntu' /etc/os-release > /dev/null 2>&1; then | |
# Ubuntu on WSL | |
if uname -a | grep '\-microsoft' > /dev/null 2>&1; then | |
codename="noble" | |
# Ubuntu | |
elif uname -a | grep '\-Ubuntu' > /dev/null 2>&1; then | |
codename="noble" | |
fi | |
# /etc/apt/source.list.d/ubuntu-jp-mirror.sources | |
if [ ! -f "/etc/apt/sources.list.d/ubuntu-jp-mirror.sources" ]; then | |
header "Update source list" | |
apt_sources="Types: deb | |
URIs: http://jp.archive.ubuntu.com/ubuntu | |
Suites: noble noble-updates noble-backports | |
Components: main universe restricted multiverse | |
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg | |
# Enabled: no | |
Types: deb-src | |
URIs: http://jp.archive.ubuntu.com/ubuntu | |
Suites: noble noble-updates noble-backports | |
Components: main universe restricted multiverse | |
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg | |
# Enabled: no | |
Types: deb | |
URIs: http://security.ubuntu.com/ubuntu | |
Suites: noble-security | |
Components: main restricted universe multiverse | |
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg | |
/etc/apt/sources.list.d/ubuntu.sources | |
Types: deb-src | |
URIs: http://security.ubuntu.com/ubuntu | |
Suites: noble-security | |
Components: main restricted universe multiverse | |
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg | |
/etc/apt/sources.list.d/ubuntu.sources | |
Enabled: no | |
" | |
sudo sh -c "echo \"${apt_sources}\" > /etc/apt/sources.list.d/ubuntu-jp-mirror.sources" | |
fi | |
# /etc/apt/source.list.d/ubuntu-ja.sources | |
if [ ! -f "/etc/apt/sources.list.d/ubuntu-ja.sources" ]; then | |
apt_sources="## Ubuntu Japanese LoCo Team's repository | |
## Please report any bugs to https://bugs.launchpad.net/ubuntu-jp-improvement | |
Types: deb | |
URIs: http://archive.ubuntulinux.jp/ubuntu | |
Suites: noble | |
Components: main | |
Signed-By: /etc/apt/keyrings/ubuntu-jp-ppa-keyring.gpg | |
Types: deb-src | |
URIs: http://archive.ubuntulinux.jp/ubuntu | |
Suites: noble | |
Components: main | |
Enabled: no | |
Signed-By: /etc/apt/keyrings/ubuntu-jp-ppa-keyring.gpg | |
Types: deb | |
URIs: http://archive.ubuntulinux.jp/ubuntu-ja-non-free | |
Suites: noble | |
Components: multiverse | |
Enabled: no | |
Signed-By: /etc/apt/keyrings/ubuntu-ja-archive-keyring.gpg | |
Types: deb-src | |
URIs: http://archive.ubuntulinux.jp/ubuntu-ja-non-free | |
Suites: noble | |
Components: multiverse | |
Enabled: no | |
Signed-By: /etc/apt/keyrings/ubuntu-ja-archive-keyring.gpg | |
" | |
sudo sh -c "echo \"${apt_sources}\" > /etc/apt/sources.list.d/ubuntu-ja.sources" | |
sudo wget https://www.ubuntulinux.jp/ubuntu-jp-ppa-keyring.gpg -P /etc/apt/keyrings/ | |
sudo wget https://www.ubuntulinux.jp/ubuntu-ja-archive-keyring.gpg -P /etc/apt/keyrings/ | |
warning "Press enter key, after disabled ubuntu.sources" | |
read | |
fi | |
fi | |
# package update & upgrade | |
if grep 'Ubuntu' /etc/os-release > /dev/null 2>&1; then | |
# Ubuntu | |
header "Update packages" | |
sudo apt update | |
sudo apt full-upgrade -y | |
elif grep 'openSUSE' /etc/os-release > /dev/null 2>&1; then | |
# openSUSE | |
header "Update packages" | |
sudo zypper update | |
fi | |
# Install needed packages | |
if grep 'Ubuntu' /etc/os-release > /dev/null 2>&1; then | |
# Ubuntu | |
packages="\ | |
aptitude gitk build-essential autoconf automake unzip zip httpie rlwrap clang \ | |
fonts-vlgothic fonts-noto fonts-noto-cjk-extra fonts-noto-color-emoji \ | |
fonts-symbola \ | |
language-pack-ja manpages-ja manpages-ja-dev aptitude-doc-ja \ | |
markdown" | |
# imagemagick graphviz | |
# Ubuntu on WSL | |
if uname -a | grep '\-microsoft' > /dev/null 2>&1 ; then | |
packages+=" x11-xserver-utils x11-xkb-utils wslu" | |
if [ ! -f "/etc/apt/sources.list.d/wslutilities-ubuntu-wslu-noble.sources" ] ; then | |
sudo add-apt-repository ppa:wslutilities/wslu | |
warning "Press enter key, after rewrite /etc/apt/sources.list.d/wslutilities-ubuntu-wslu-jammy.sources with lunar," | |
warning "because there is not noble repository yet." | |
read | |
fi | |
fi | |
if ! dpkg -s ${packages} > /dev/null 2>&1; then | |
header "Install packages" | |
sudo apt install -y ${packages} | |
fi | |
if ! dpkg -l git-delta > /dev/null 2>&1 ; then | |
header "Install git-delta" | |
# v0.17.0 | |
# MEMO: latest binaryを取得できないのでバージョン固定打ち | |
wget https://github.com/dandavison/delta/releases/download/0.17.0/git-delta_0.17.0_amd64.deb --output-document=${HOME}/tmp/git-delta_0.17.0_amd64.deb | |
sudo dpkg -i ${HOME}/tmp/git-delta_0.17.0_amd64.deb | |
fi | |
elif grep 'openSUSE' /etc/os-release > /dev/null 2>&1; then | |
packages="git mercurial emacs doxygen vlgothic-fonts autoconf automake" | |
packages+=" zip unzip rlwrap python-pip" | |
# packages+="fonts-vlgothic libX11-6" | |
if ! rpm --query ${packages} > /dev/null 2>&1; then | |
header "Install packages in suse" | |
sudo zypper --non-interactive install ${packages} | |
# sudo zypper install gmp-devel zlib-devel libedit-devel libyajl-devel | |
fi | |
fi | |
# locale | |
# After this, do `dpkg-reconfigure tzdate`, and change time zone to Tokyo. | |
if locale | grep -v 'LANG=ja_JP.UTF-8' > /dev/null 2>&1; then | |
# If it is not Japanese environment now, this updates locale to Japanese | |
sudo update-locale LANG=ja_JP.UTF-8 | |
fi | |
# Write /etc/wsl.conf | |
if uname -a | grep '\-microsoft' > /dev/null 2>&1 && | |
[ ! -f /etc/wsl.conf ]; then | |
header "Install wsl.conf" | |
wslconf='[boot] | |
systemd = true | |
# command = service docker start | |
[automount] | |
options = "metadata,umask=22,fmask=11" | |
[interop] | |
appendWindowsPath = false | |
[wsl2] | |
memory = 16GB | |
swap = 4GB | |
' | |
sudo sh -c "echo \"${wslconf}\" > /etc/wsl.conf" | |
fi | |
# config | |
if [ ! -d "${HOME}/git/config" ]; then | |
header "Clone config" | |
cd ${HOME}/git | |
git clone --recursive git@github.com:yonta/config.git | |
cd config | |
./sym_link.sh copy | |
fi | |
# SML# | |
# Ubuntu 24.04 nobleではLLVMのバージョン14~18までがサポートで難しい | |
# if grep 'Ubuntu' /etc/os-release > /dev/null 2>&1 && | |
# ! dpkg -s 'smlsharp' > /dev/null 2>&1; then | |
# # Install build dep | |
# packages="llvm-dev libgmp-dev zlib1g-dev libedit-dev libyajl-dev" | |
# if ! dpkg -s ${packages} > /dev/null 2>&1; then | |
# header "Install SML# build dep" | |
# sudo apt install -y ${packages} | |
# fi | |
# # Install compiler from official repository | |
# if grep 'Ubuntu' /etc/os-release > /dev/null 2>&1; then | |
# header "Install SML#" | |
# smlsharpconf='Package: smlsharp | |
# Pin: origin "http://ppa.launchpad.net" | |
# Pin-Priority: 501 | |
# Package: smlsharp | |
# Pin: release o=Ubuntu | |
# Pin-Priority: -1' | |
# sudo sh -c "echo \"${smlsharpconf}\" > /etc/apt/preferences.d/99smlsharp" | |
# sudo apt-add-repository ppa:smlsharp/ppa | |
# sudo apt update | |
# sudo apt install -y smlsharp | |
# # HACK: SML#がjammy対応していないので暫定対処 | |
# sudo cp /usr/lib/x86_64-linux-gnu/smlsharp/llvm/smlsharp_gc-11.0.so /usr/lib/x86_64-linux-gnu/smlsharp/llvm/smlsharp_gc-11.1.so | |
# fi | |
# fi | |
# Build cmigemo | |
if [ ! -f "/usr/local/bin/cmigemo" ]; then | |
header "Build and Install cmigemo" | |
sudo apt install -y nkf | |
cd ${HOME}/git | |
git clone git@github.com:koron/cmigemo.git | |
cd ${HOME}/git/cmigemo | |
./configure | |
make gcc | |
sudo make gcc-install | |
fi | |
# Build Emacs from source | |
emacs_version="29.3" | |
if [ ! -f "/usr/local/bin/emacs-${emacs_version}" ]; then | |
header "Build and Install Emacs" | |
mkdir -p ${HOME}/tmp/emacs | |
cd ${HOME}/tmp/emacs | |
emacs_dir="${HOME}/tmp/emacs/emacs-${emacs_version}" | |
if [ ! -f "${emacs_dir}.tar.xz" ]; then | |
wget http://ftp.jaist.ac.jp/pub/GNU/emacs/emacs-${emacs_version}.tar.xz | |
fi | |
if [ ! -f "${emacs_dir}.tar" ]; then | |
xz -d ${emacs_dir}.tar.xz | |
fi | |
if [ ! -d "${emacs_dir}" ]; then | |
tar xf ${emacs_dir}.tar | |
fi | |
cd ${emacs_dir} | |
sudo apt build-dep -y emacs | |
packages="emacs-mozc-bin aspell-en" # gnome-tweaks libmagick++-dev | |
# WSLではwl-clipboardを入れてWindowsとクリップボードを共有する | |
if uname -a | grep '\-microsoft' > /dev/null 2>&1 ; then | |
packages+=" wl-clipboard" | |
fi | |
if ! dpkg -s ${packages} > /dev/null 2>&1; then | |
sudo apt install -y ${packages} | |
fi | |
# WSL2でXwidgetを使うなら、libwebkit2gtk-4.0-devを入れて、 | |
# export WEBKIT_FORCE_SANDBOX=0を設定し、 | |
# --with-x-toolkit=gtk3 --with-xwidgetsでビルドする必要がある | |
./configure --without-pop --without-mailutils \ | |
--without-xaw3d --without-selinux \ | |
--with-x \ | |
--with-json --with-native-compilation=aot \ | |
--with-tree-sitter | |
# --with-imagemagick | |
make -j | |
sudo make install | |
fi | |
# Install Dcoker | |
if grep 'Ubuntu' /etc/os-release > /dev/null 2>&1 && | |
! dpkg -s 'docker-ce' > /dev/null 2>&1; then | |
header "Install Docker" | |
# Install dependecy | |
packages="ca-certificates curl" | |
if ! dpkg -s ${packages} > /dev/null 2>&1; then | |
sudo apt install -y ${packages} | |
fi | |
# Add Docker's official GPG key | |
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc | |
sudo chmod a+r /etc/apt/keyrings/docker.asc | |
# Add Docker repository to apt sources | |
docker_source="Types: deb | |
URIs: https://download.docker.com/linux/ubuntu | |
Suites: noble | |
Components: stable | |
Signed-By: /etc/apt/keyrings/docker.asc | |
" | |
sudo sh -c "echo \"${docker_source}\" > /etc/apt/sources.list.d/docker.sources" | |
# Install Docker Comunity Edition | |
sudo apt update | |
sudo apt install -y docker-ce docker-compose-plugin | |
fi | |
# Rust | |
if ! type rustup > /dev/null 2>&1; then | |
export RUSTUP_HOME="${XDG_DATA_HOME}/rustup" | |
export CARGO_HOME="${XDG_DATA_HOME}/cargo" | |
header "Install Dependencies" | |
sudo apt install -y libssl-dev cmake | |
header "Install Rust" | |
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh -s -- -y | |
message "Rust and is installed." | |
header "Install Cargo tools" | |
cargo="${CARGO_HOME}/bin/cargo" | |
${cargo} install \ | |
bat bottom cargo-update du-dust eza fd-find hyperfine pipr procs \ | |
ripgrep ripgrep_all starship tokei | |
fi | |
# fzf | |
if [ -d "${HOME}/git/fzf" ]; then | |
header "Clone fzf repository" | |
git clone --depth 1 https://github.com/junegunn/fzf.git ~/git/fzf | |
if [ -d "${XDG_CONFIG_HOME}/fzf" ]; then | |
header "Install fzf" | |
${HOME}/git/fzf/install --xdg --completion --key-bindings --no-update-rc | |
fi | |
fi | |
# Ruby | |
RBENV_ROOT="${XDG_DATA_HOME}/rbenv" | |
if ! type ruby > /dev/null 2>&1; then | |
if [ ! -f "${RBENV_ROOT}/bin/rbenv" ]; then | |
header "Install rbenv" | |
git clone --depth 1 https://github.com/rbenv/rbenv.git ${RBENV_ROOT} | |
rbenv=${RBENV_ROOT}/bin/rbenv | |
header "Install rbenv plugins" | |
mkdir -p "${RBENV_ROOT}/plugins" | |
git clone --depth 1 https://github.com/rbenv/ruby-build.git "${RBENV_ROOT}"/plugins/ruby-build | |
git clone --depth 1 https://github.com/ianheggie/rbenv-binstubs.git "${RBENV_ROOT}"/plugins/rbenv-binstubs | |
git clone --depth 1 https://github.com/meowsus/rbenv-clean "${RBENV_ROOT}"/plugins/rbenv-clean | |
message "rbenv is installed." | |
message "Please restart bash, and run script ./init-ruby.sh" | |
fi | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://qiita.com/youcune/items/fcfb4ad3d7c1edf9dc96 | |
# -euでエラーか未定義変数でストップする | |
script_dir="$(cd $(dirname $0); pwd -P)" | |
# Color message | |
NORMAL=$(tput sgr0) | |
YELLOW=$(tput setaf 3) | |
GRAY=$(tput setaf 8) | |
function message() { | |
echo -e "$GRAY$*$NORMAL" | |
} | |
function header() { | |
echo -e "$GRAY##### $* ###############$NORMAL" | |
} | |
function warning() { | |
echo -e "$YELLOW$*$NORMAL" | |
} | |
header "Install ruby" | |
# for japanese input in REPL | |
sudo apt install libreadline-dev | |
ruby_version="3.3.1" | |
rbenv install ${ruby_version} | |
rbenv global ${ruby_version} | |
gem install yard | |
yard config --gem-install-yri | |
gem install rubocop rufo solargraph seeing_is_believing irb | |
yard gems |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# repl | |
ipython | |
# virutalize pip environment | |
virtualenv | |
# linter, reformatter | |
# flake8 | |
# flake8-quotes | |
# autopep8 | |
# importmagic3 | |
# epc | |
# isort | |
# mypy type stub | |
# mypy | |
# data-science-types | |
# test | |
# pytest | |
# markdown | |
grip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment