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 @@
if ! command -v google-chrome &>/dev/null; then
cd ~/Downloads
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
rm google-chrome-stable_current_amd64.deb
cd -
fi

View File

@ -1,3 +1,4 @@
if ! command -v docker &>/dev/null; then
DOCKER_COMPOSE_VERSION="2.27.0"
sudo apt install -y docker.io docker-buildx
@ -9,3 +10,4 @@ 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 6379:6379 --name=redis redis
fi

View File

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

View File

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

View File

@ -1,5 +1,7 @@
if ! command -v gh &>/dev/null; then
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg &&
sudo chmod go+r /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 apt update &&
sudo apt install gh -y
fi

View File

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

View File

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

View File

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

View File

@ -1,3 +1,4 @@
if ! command -v nodenv &>/dev/null; then
git clone https://github.com/nodenv/nodenv.git ~/.nodenv
sudo ln -vs ~/.nodenv/bin/nodenv /usr/local/bin/nodenv
cd ~/.nodenv
@ -9,4 +10,4 @@ git clone https://github.com/nodenv/nodenv-aliases.git $(nodenv root)/plugins/no
nodenv install 20.11.1
nodenv global 20.11.1
sudo ln -vs $(nodenv root)/shims/* /usr/local/bin/
fi

View File

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

View File

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

View File

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