homes/common/.config/fish/functions/update-homes.fish

225 lines
6.4 KiB
Fish
Executable File

#!/usr/bin/env fish
function update-homes -d "Update homes configuration"
argparse 'h/help' 'g/git' 'd/desktop' 'r/root' 'R/remove' 'i/install' -- $argv
set -f homes_path ~/homes
set -f homes_private_path ~/homes-private
if set -q HOMES_PATH
set -f homes_path $HOMES_PATH
end
if set -q HOMES_PRIVATE_PATH
set -f homes_private_path $HOMES_PRIVATE_PATH
end
if not test -d $homes_path
echo (set_color c94f6d)"*** ERROR ***"(set_color normal)
echo "*** $homes_path does not exists"
return
end
if not test -n homes_path
echo (set_color c94f6d)"*** ERROR ***"(set_color normal)
echo "*** HOMES_PATH variable is empty"
return
end
if not test -n homes_private_path
echo (set_color c94f6d)"*** ERROR ***"(set_color normal)
echo "*** HOMES_PRIVATE_PATH is empty, unset or change it"
return
end
if not test -d $homes_private_path
echo (set_color f4a261)"*** WARNING ***"(set_color normal)
echo "*** $homes_private_path does not exist"
echo
echo
end
if not functions -q update-homes-secrets
echo (set_color f4a261)"*** WARNING ***"(set_color normal)
echo "*** update-homes-secrets is not defined"
echo
echo
end
if set -q _flag_help
echo "Update home's configuration"
echo
echo "You need to have homes and homes-private in your home directory."
echo "This function launch the two scripts to update your conf."
echo
echo " -g --git"
echo " Pull-rebase before launch script"
echo
echo " -d --desktop"
echo " Update desktop part"
echo
echo " -r --root"
echo " Update root part"
echo
echo " -R --remove"
echo " Remove old configuration"
echo
echo " -i --install"
echo " Install user packages and softwares"
echo
echo " -h --help"
echo " Show this screen"
return
end
if set -q _flag_install
echo
echo
echo (set_color 81b29a)"*** Install user softwares ***"(set_color normal)
echo
echo (set_color 719cd6)"*** Install nvimpager ***"(set_color normal)
echo
mkdir -p ~/.cache
rm -rf ~/.cache/nvimpager-git
git clone --depth 1 https://github.com/lucc/nvimpager ~/.cache/nvimpager-git
pushd ~/.cache/nvimpager-git
make PREFIX=$HOME/.local install
popd
rm -rf ~/.cache/nvimpager-git
end
if set -q _flag_desktop && set -q _flag_install
echo
echo
echo (set_color 719cd6)"*** Install lazydocker ***"(set_color normal)
echo
go install github.com/jesseduffield/lazydocker@latest
echo
echo
echo (set_color 719cd6)"*** Install lazygit ***"(set_color normal)
echo
go install github.com/jesseduffield/lazygit@latest
echo
echo
echo (set_color 719cd6)"*** Install bluetuith ***"(set_color normal)
go install github.com/darkhz/bluetuith@latest
echo
echo
echo (set_color 719cd6)"*** Install poezio-omemo and epr ***"(set_color normal)
echo
pip install --user --break-system-packages -U poezio-omemo epr-reader
echo
echo
echo (set_color 719cd6)"*** Install poezio plugins ***"(set_color normal)
echo
rm -rf ~/.local/share/poezio/plugins
mkdir -p ~/.local/share/poezio
set -l poezio_version $(poezio --version | cut -d " " -f 2)
rm -rf ~/.cache/poezio-git
git clone --depth 1 -b $poezio_version https://codeberg.org/poezio/poezio ~/.cache/poezio-git
pushd ~/.cache/poezio-git
popd
cp -r ~/.cache/poezio-git/plugins ~/.local/share/poezio
rm -rf ~/.cache/poezio-git
end
if set -q _flag_remove
echo (set_color 81b29a)"**** Remove old config ***"(set_color normal)
# Remove zsh
rm ~/.zcompdump
rm -rf ~/.zsh* ~/.local/share/zsh
# Remove old tmux files
rm -f ~/.tmux.conf ~/.tmux-theme
rm -rf ~/.config/aerc
rm -rf ~/.config/fish
rm -rf ~/.config/khal
rm -rf ~/.config/khard
rm -rf ~/.config/lvim
rm -rf ~/.config/neomutt
rm -rf ~/.config/newsboat
rm -rf ~/.config/nvim
rm -rf ~/.config/poezio
rm -rf ~/.config/tmux
rm -rf ~/.config/toot
rm -rf ~/.config/vdirsyncer
end
if set -q _flag_git
echo
echo
echo (set_color 81b29a)"*** Update homes configuration directories ***"(set_color normal)
echo
pushd $homes_path
gitpr
popd
if test -d $homes_private_path
pushd $homes_private_path
gitpr
popd
end
end
echo
echo
echo (set_color 81b29a)"*** Synchronize files ***"(set_color normal)
echo
echo
echo (set_color 719cd6)"*** Copying common part ***"(set_color normal)
echo
if test -d $homes_path/common
pushd $homes_path
rsync --exclude=".*.swp" -av ./common/ ~/
popd
end
if test -d $homes_private_path/common
pushd $homes_private_path
rsync --exclude=".*.swp" -av ./common/ ~/
popd
end
if set -q _flag_root
echo
echo
echo (set_color 719cd6)"*** Copying root part ***"(set_color normal)
echo
if test -d $homes_path/root
pushd $homes_path
rsync --exclude=".*.swp" -av ./root/ ~/
popd
end
if test -d $homes_private_path/root
pushd $homes_private_path
rsync --exclude=".*.swp" -av ./root/ ~/
popd
end
end
if set -q _flag_desktop
echo
echo
echo (set_color 719cd6)"*** Copying desktop part ***"(set_color normal)
echo
if test -d $homes_path/desktop
pushd $homes_path
rsync --exclude=".*.swp" -av ./desktop/ ~/
popd
end
if test -d $homes_private_path/desktop
pushd $homes_private_path
rsync --exclude=".*.swp" -av ./desktop/ ~/
popd
end
end
if functions -q update-homes-secrets
update-homes-secrets $_flag_desktop $_flag_root
end
end