Make all installers idempotent

This commit is contained in:
David Heinemeier Hansson 2024-05-26 16:09:34 -07:00
parent 5670aba806
commit 6190b4d1e8
12 changed files with 112 additions and 80 deletions

View File

@ -1,5 +1,7 @@
cd ~/Downloads if ! command -v google-chrome &>/dev/null; then
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb cd ~/Downloads
sudo dpkg -i google-chrome-stable_current_amd64.deb wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
rm google-chrome-stable_current_amd64.deb sudo dpkg -i google-chrome-stable_current_amd64.deb
cd - rm google-chrome-stable_current_amd64.deb
cd -
fi

View File

@ -1,11 +1,13 @@
DOCKER_COMPOSE_VERSION="2.27.0" if ! command -v docker &>/dev/null; then
sudo apt install -y docker.io docker-buildx DOCKER_COMPOSE_VERSION="2.27.0"
sudo apt install -y docker.io docker-buildx
sudo usermod -aG docker ${USER} sudo usermod -aG docker ${USER}
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker} DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v$DOCKER_COMPOSE_VERSION/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose curl -SL https://github.com/docker/compose/releases/download/v$DOCKER_COMPOSE_VERSION/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
sudo docker create -d --restart unless-stopped -p 3306:3306 --name=mysql8 -e MYSQL_ROOT_PASSWORD= -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql:8 sudo docker create -d --restart unless-stopped -p 3306:3306 --name=mysql8 -e MYSQL_ROOT_PASSWORD= -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql:8
sudo docker create -d --restart unless-stopped -p 6379:6379 --name=redis redis sudo docker create -d --restart unless-stopped -p 6379:6379 --name=redis redis
fi

View File

@ -7,17 +7,28 @@ for entry in dotfiles/*; do
# Any existing files will be renamed .bak # Any existing files will be renamed .bak
if [ -f "$entry" ]; then if [ -f "$entry" ]; then
target=~/."$(basename "$entry")" target=~/."$(basename "$entry")"
[ -e "$target" ] && mv "$target" "$target.bak"
ln -s "$(pwd)/$entry" "$target" if [ -e "$target" ] && [ "$(readlink "$target")" != "$(pwd)/$entry" ]; then
mv "$target" "$target.bak"
fi
if [ ! -e "$target" ]; then
ln -s "$(pwd)/$entry" "$target"
fi
fi fi
# Link all directories in ~/.config/ # Link all directories in ~/.config/
# Any existing directories will be renamed .bak # Any existing directories will be renamed .bak
if [ -d "$entry" ]; then if [ -d "$entry" ]; then
target=~/.config/"$(basename "$entry")" target=~/.config/"$(basename "$entry")"
[ -e "$target" ] && mv "$target" "$target.bak"
ln -s "$(pwd)/$entry" "$target" if [ -e "$target" ] && [ "$(readlink "$target")" != "$(pwd)/$entry" ]; then
mv "$target" "$target.bak"
fi
if [ ! -e "$target" ]; then
ln -s "$(pwd)/$entry" "$target"
fi
fi fi
done done
unset entry unset entry

View File

@ -1,8 +1,10 @@
cd ~/Downloads if ! [ -f "$HOME/.local/share/fonts/CaskaydiaMonoNerdFont-Regular.ttf" ]; then
wget https://github.com/ryanoasis/nerd-fonts/releases/download/v3.1.1/CascadiaMono.zip cd ~/Downloads
unzip CascadiaMono.zip -d CascadiaFont wget https://github.com/ryanoasis/nerd-fonts/releases/download/v3.1.1/CascadiaMono.zip
mkdir -p ~/.local/share/fonts unzip CascadiaMono.zip -d CascadiaFont
cp CascadiaFont/*.ttf ~/.local/share/fonts mkdir -p ~/.local/share/fonts
rm -rf CascadiaMono.zip CascadiaFont cp CascadiaFont/*.ttf ~/.local/share/fonts
fc-cache rm -rf CascadiaMono.zip CascadiaFont
cd - fc-cache
cd -
fi

View File

@ -1,5 +1,7 @@
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && if ! command -v gh &>/dev/null; then
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg && curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg &&
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list >/dev/null && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg &&
sudo apt update && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list >/dev/null &&
sudo apt install gh -y sudo apt update &&
sudo apt install gh -y
fi

View File

@ -1,7 +1,9 @@
cd ~/Downloads if ! command -v lazydocker &>/dev/null; then
LAZYDOCKER_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazydocker/releases/latest" | grep -Po '"tag_name": "v\K[^"]*') cd ~/Downloads
curl -sLo lazydocker.tar.gz "https://github.com/jesseduffield/lazydocker/releases/latest/download/lazydocker_${LAZYDOCKER_VERSION}_Linux_x86_64.tar.gz" LAZYDOCKER_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazydocker/releases/latest" | grep -Po '"tag_name": "v\K[^"]*')
tar -xf lazydocker.tar.gz lazydocker curl -sLo lazydocker.tar.gz "https://github.com/jesseduffield/lazydocker/releases/latest/download/lazydocker_${LAZYDOCKER_VERSION}_Linux_x86_64.tar.gz"
sudo install lazydocker /usr/local/bin tar -xf lazydocker.tar.gz lazydocker
rm lazydocker.tar.gz sudo install lazydocker /usr/local/bin
cd - rm lazydocker.tar.gz
cd -
fi

View File

@ -1,7 +1,9 @@
cd ~/Downloads if ! command -v lazygit &>/dev/null; then
LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep -Po '"tag_name": "v\K[^"]*') cd ~/Downloads
curl -sLo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz" LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | grep -Po '"tag_name": "v\K[^"]*')
tar -xf lazygit.tar.gz lazygit curl -sLo lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz"
sudo install lazygit /usr/local/bin tar -xf lazygit.tar.gz lazygit
rm lazygit.tar.gz sudo install lazygit /usr/local/bin
cd - rm lazygit.tar.gz
cd -
fi

View File

@ -1,4 +1,6 @@
sudo add-apt-repository -y ppa:neovim-ppa/stable if ! command -v neovim &>/dev/null; then
sudo apt update -y sudo add-apt-repository -y ppa:neovim-ppa/stable
sudo apt install -y neovim sudo apt update -y
git clone https://github.com/LazyVim/starter ~/.config/nvim sudo apt install -y neovim
git clone https://github.com/LazyVim/starter ~/.config/nvim
fi

View File

@ -1,12 +1,13 @@
git clone https://github.com/nodenv/nodenv.git ~/.nodenv if ! command -v nodenv &>/dev/null; then
sudo ln -vs ~/.nodenv/bin/nodenv /usr/local/bin/nodenv git clone https://github.com/nodenv/nodenv.git ~/.nodenv
cd ~/.nodenv sudo ln -vs ~/.nodenv/bin/nodenv /usr/local/bin/nodenv
src/configure && make -C src || true cd ~/.nodenv
cd ~/ src/configure && make -C src || true
mkdir -p "$(nodenv root)"/plugins cd ~/
git clone https://github.com/nodenv/node-build.git "$(nodenv root)"/plugins/node-build mkdir -p "$(nodenv root)"/plugins
git clone https://github.com/nodenv/nodenv-aliases.git $(nodenv root)/plugins/nodenv-aliases git clone https://github.com/nodenv/node-build.git "$(nodenv root)"/plugins/node-build
nodenv install 20.11.1 git clone https://github.com/nodenv/nodenv-aliases.git $(nodenv root)/plugins/nodenv-aliases
nodenv global 20.11.1 nodenv install 20.11.1
sudo ln -vs $(nodenv root)/shims/* /usr/local/bin/ nodenv global 20.11.1
sudo ln -vs $(nodenv root)/shims/* /usr/local/bin/
fi

View File

@ -1,6 +1,8 @@
DEFAULT_RUBY_VERSION="3.3.1" if ! command -v rbenv &>/dev/null; then
DEFAULT_RUBY_VERSION="3.3.1"
sudo apt install -y rbenv sudo apt install -y rbenv
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
rbenv install $DEFAULT_RUBY_VERSION rbenv install $DEFAULT_RUBY_VERSION
rbenv global $DEFAULT_RUBY_VERSION rbenv global $DEFAULT_RUBY_VERSION
fi

View File

@ -1,9 +1,11 @@
sudo snap install typora if ! command -v typora &>/dev/null; then
cd ~/Downloads sudo snap install typora
git clone https://github.com/dhh/ia_typora cd ~/Downloads
mkdir -p ~/.local/share/fonts git clone https://github.com/dhh/ia_typora
cp ia_typora/fonts/iAWriterMonoS-* ~/.local/share/fonts/ mkdir -p ~/.local/share/fonts
fc-cache cp ia_typora/fonts/iAWriterMonoS-* ~/.local/share/fonts/
mkdir -p ~/snap/typora/88/.config/Typora/themes/ fc-cache
cp ia_typora/ia_typora*.css ~/snap/typora/88/.config/Typora/themes/ mkdir -p ~/snap/typora/88/.config/Typora/themes/
cd - cp ia_typora/ia_typora*.css ~/snap/typora/88/.config/Typora/themes/
cd -
fi

View File

@ -1,4 +1,6 @@
sudo add-apt-repository universe -y if ! command -v ulauncher &>/dev/null; then
sudo add-apt-repository ppa:agornostal/ulauncher -y sudo add-apt-repository universe -y
sudo apt update -y sudo add-apt-repository ppa:agornostal/ulauncher -y
sudo apt install -y ulauncher sudo apt update -y
sudo apt install -y ulauncher
fi