confOS/arch_wsl.sh
2023-03-16 12:47:41 +01:00

215 lines
8 KiB
Bash

#!/usr/bin/env bash
set -o errexit # crash the script when a command crash
set -o pipefail # same as above for piped command
set -o nounset # crash when a variable doesnt exist
# TRACE=1 for debug
if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi
cd "$(dirname "$0")" # change script directory
main() {
# === Init pacman ==
sudo pacman-key --init
sudo pacman-key --populate
sudo pacman -Sy --noconfirm archlinux-keyring
# === Update Arch mirrors ==
sudo pacman -S --noconfirm pacman-contrib
curl -s "https://archlinux.org/mirrorlist/?country=FR&country=GB&protocol=https&use_mirror_status=on" | \
sed -e "s/^#Server/Server/" -e "/^#/d" | sudo bash -c "rankmirrors -n 7 - > /etc/pacman.d/mirrorlist"
# === Update Arch ==
sudo pacman -Syyuu --noconfirm
# === Install packages ==
sudo pacman -S --noconfirm git wget zip openssh bat base-devel make \
python-pygments micro git-lfs npm sdl2_image nodejs \
fish autoconf valgrind automake python-virtualenv gdb \
tk sdl2_mixer exa texlive-most fzf glu man-pages-fr \
uwufetch python-pip opam cpanminus unison \
rebuild-detector git-delta sdl2_ttf rustup pulseaudio-alsa
# === Rustup ==
# Init rustup
rustup default stable
# Dev tools
rustup component add rust-analysis rls
# === Colors package manager ==
sudo sed -i "s/#Color/Color/g" /etc/pacman.conf
sudo sed -i "s/#ParallelDownloads = 5/ParallelDownloads = 3/g" /etc/pacman.conf
# === Remove SU password ==
echo -e "# Disable password for specific user\nanri ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers > /dev/null
# === Yay ==
git clone https://aur.archlinux.org/yay.git
cd yay || exit
makepkg -si --noconfirm
# Remove folder
cd ..
rm -rf yay
# Enable *-git package updates
yay -Y --devel --save
# === AUR packages ==
yay -S --noconfirm spim-svn cal8tor
# === Rust ==
# Add Cargo packages from Rust
mkdir -p "$HOME"/.cargo/bin
fish -c "fish_add_path $HOME/.cargo/bin"
# Add cargo packages
cargo install cargo-update cargo-cache
# === Set-up systemd
mkdir subsystemctl
cd subsystemctl || exit
curl -so PKGBUILD https://raw.githubusercontent.com/sorah/arch.sorah.jp/master/aur-sorah/PKGBUILDs/subsystemctl/PKGBUILD
makepkg -si --noconfirm
cd ..
rm -rf subsystemctl
sudo subsystemctl start
# === Locales ==
sudo sed -i "s/#fr_FR.UTF-8 UTF-8/fr_FR.UTF8 UTF-8/g" /etc/locale.gen
sudo locale-gen
subsystemctl exec sudo localectl set-locale fr_FR.UTF-8
# === Shared folders ==
sudo mkdir /mnt/y
# === Fish ==
# Remove motd
fish -c "set -U fish_greeting"
# Reversed search
curl -sL https://git.io/fisher | fish -c "source && fisher install jorgebucaran/fisher"
fish -c "fisher install jethrokuan/fzf"
fish -c "fisher install jorgebucaran/autopair.fish"
# SSH
wget -q https://gitlab.com/kyb/fish_ssh_agent/raw/master/functions/fish_ssh_agent.fish -P "$HOME"/.config/fish/functions/
mkdir "$HOME"/.ssh
# Custom config.fish
wget -q https://git.mylloon.fr/Anri/confOS/raw/branch/main/.config/fish/config_wsl.fish -O "$HOME"/.config/fish/config.fish
# Custom prompt shell (based on https://github.com/fish-shell/fish-shell/blob/master/share/tools/web_config/themes/Base16%20Eighties.theme)
# Modifications: Changed comment color
wget -q https://git.mylloon.fr/Anri/confOS/raw/branch/main/.config/fish/functions/fish_prompt.fish -P "$HOME"/.config/fish/functions/
wget -q https://git.mylloon.fr/Anri/confOS/raw/branch/main/.config/fish/conf.d/promp_color.fish -O "$HOME"/.config/fish/conf.d/promp_color.fish
# EXA colors
fish -c "set -Ux EXA_COLORS 'di=1;36:da=35'"
# Add aliases
wget -q https://git.mylloon.fr/Anri/confOS/raw/branch/main/.config/fish/conf.d/abbr.fish -O "$HOME"/.config/fish/conf.d/abbr.fish
curl -s https://git.mylloon.fr/Anri/confOS/raw/branch/main/.config/fish/conf.d/abbr_wsl.fish >> "$HOME"/.config/fish/conf.d/abbr.fish
# === Micro configuration ==
fish -c "set -Ux EDITOR micro"
mkdir "$HOME"/.config/micro
wget -q --show-progress https://git.mylloon.fr/Anri/confOS/raw/branch/main/.config/micro/settings.json -O "$HOME"/.config/micro/settings.json
micro -plugin install detectindent
# === GL4D ==
# Download, build and installation
git clone https://github.com/noalien/GL4Dummies.git
cd GL4Dummies || exit
make -f Makefile.autotools
./configure
make
sudo make install
cd ..
rm -rf GL4Dummies
# Fix for shared libraries (https://stackoverflow.com/a/9395355)
sudo ldconfig
# Add to path
fish -c "set -Uax LD_LIBRARY_PATH /usr/local/lib"
# === tldr ==
cargo install tealdeer
fish -c "tldr --update"
# Fish completion
local url_tldr
url_tldr=$(curl -s https://api.github.com/repos/dbrgn/tealdeer/releases/latest \
| grep 'browser_download_url": ".*/completions_fish"' \
| cut --delimiter=":" --field=2,3 \
| tr -d \" )
wget -q --show-progress "${url_tldr:1}" -O completions_fish
mv completions_fish ~/.config/fish/completions/tldr.fish
# === Java ==
curl -s "https://get.sdkman.io" | bash
# Temporary disable nounset for SDK
set +o nounset
# shellcheck source=/dev/null
source "$HOME/.sdkman/bin/sdkman-init.sh"
if [ -x "$HOME"/.config/fish ] ; then
if [ ! -f "$HOME"/.config/fish/functions/fisher.fish ] ; then # install fisher if not already installed
curl -sL https://git.io/fisher | fish -c "source && fisher install jorgebucaran/fisher"
fi
fish -c "fisher install reitzig/sdkman-for-fish"
fi
sdk install java 17.0.6-tem # https://whichjdk.com/#adoptium-eclipse-temurin
# Renable nounset
set -o nounset
# === Manual color ==
fish -c "set -Ux MANPAGER \"sh -c 'col -bx | bat -l man -p'\""
# === Git ==
wget -q https://git.mylloon.fr/Anri/confOS/raw/branch/main/dotfiles/.gitconfig -O "$HOME"/.gitconfig
# === Python ==
# Add PIP packages from Python
mkdir "$HOME"/.local/bin
fish -c "fish_add_path $HOME/.local/bin"
# === OCaml ==
# Init Opam and install stuff
echo | opam init
fish -c "yes | opam init"
opam install -y utop ocaml-lsp-server ocamlformat ocamlformat-rpc menhir
wget -q https://git.mylloon.fr/Anri/confOS/raw/branch/main/dotfiles/.ocamlformat -O "$HOME"/.ocamlformat
# Add Opam packages from OCaml
mkdir -p "$HOME"/.opam/default/bin
fish -c "fish_add_path $HOME/.opam/default/bin"
# Fix dlllwt_unix_stubs.so shared object file
fish -c "set -Ux CAML_LD_LIBRARY_PATH $(opam var stublibs)"
# === Clang ==
wget -q https://git.mylloon.fr/Anri/confOS/raw/branch/main/dotfiles/.clang-format -O "$HOME"/.clang-format
# === LaTeX ==
# Pour latexindent
sudo cpanm YAML::Tiny File::HomeDir
# === Valgrind ==
fish -c "set -Ux DEBUGINFOD_URLS https://debuginfod.archlinux.org"
# === Unison ==
mkdir "$HOME"/.unison
wget -q https://git.mylloon.fr/Anri/confOS/raw/branch/main/.unison/default.prf -O "$HOME"/.unison/default.prf
# === Perl ==
# Add perl packages to path
fish -c "fish_add_path /usr/bin/vendor_perl"
# === Clear useless packages
pacman -Qqtd | sudo pacman --noconfirm -Rsn subsystemctl - 2> /dev/null || true
echo -e "\nInstallation terminée !\nIl faut redémarrer WSL (dans Powershell = wsl --shutdown)."
echo -e "---\nPense bien à paramétrer ton terminal, exemple avec Windows Terminal :"
echo "- Ligne de commande = wsl.exe -d Arch fish"
echo "- Profils par défaut => Apparence :"
echo " - Jeu de couleur = One Half Dark"
echo " - Type de police = Caskaydia Cove Nerd Font Complete Mono Windows Compatible"
echo " (à télécharger ici : https://www.nerdfonts.com/font-downloads)"
}
if grep "WSL2" /proc/version > /dev/null;
then
main "$@"
else
echo "Ce script ne fonctionne que sur ArchWSL." >&2
fi