Added update into dotfiles functions

This commit is contained in:
Thomas Forgione 2018-09-26 17:12:04 +02:00
parent 278677ca86
commit cfa721db33
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
2 changed files with 77 additions and 11 deletions

View File

@ -42,17 +42,6 @@ vfind() {
} }
### Others ### ### Others ###
pull-dotfiles() {
current_dir=$PWD
echo Pulling dotfiles...
cd ~/.config/dotfiles && git pull
echo Pulling scripts...
cd ~/.scripts && git pull
echo Pulling oh-my-zsh
cd ~/.config/oh-my-zsh && git pull
cd $current_dir
}
# Recover a vim backup # Recover a vim backup
recover() { recover() {
if [ -f $1 ]; then if [ -f $1 ]; then
@ -100,6 +89,8 @@ makelatex() {
cp /home/thomas/.script/classgen/Makefile.latex ./Makefile cp /home/thomas/.script/classgen/Makefile.latex ./Makefile
} }
source $HOME/.config/dotfiles/zsh/update.zsh
# cdg : cd to a git repo # cdg : cd to a git repo
if [ -d "$GCLONE_PATH" ]; then if [ -d "$GCLONE_PATH" ]; then

75
zsh/update.zsh Normal file
View File

@ -0,0 +1,75 @@
pull-dotfiles() {
current_dir=$PWD
echo "\033[32;1m=== Updating dotfiles ===\033[0m"
cd ~/.config/dotfiles && git pull
echo "\033[32;1m=== Updating oh-my-zsh ===\033[0m"
cd ~/.config/oh-my-zsh && git pull
cd $current_dir
}
update() {
echo "\033[32;1m=== Starting the update, please enter your password ===\033[0m"
# Ask for sudo right now
sudo true
if [ $? -ne 0 ]; then
echo "Could not get sudo..."
exit 1
fi
echo "\033[32;1m=== Updating system ===\033[0m"
# Debian based systems
command -v apt > /dev/null 2>&1
if [ $? -eq 0 ]; then
sudo apt update -y
if [ $? -eq 0 ]; then
sudo apt upgrade -y
if [ $? -eq 0 ]; then
sudo apt autoremove -y
fi
fi
fi
# Archlinux based systems
command -v yaourt > /dev/null 2>&1
if [ $? -eq 0 ]; then
yaourt -Syu
else
command -v pacman > /dev/null 2>&1
if [ $? -eq 0 ]; then
sudo pacman -Syu
fi
fi
# Fedora based systems
command -v dnf > /dev/null 2>&1
if [ $? -eq 0 ]; then
dnf upgrade
fi
# Update rust if installed
command -v rustup > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "\033[32;1m=== Updating rustup ===\033[0m"
rustup self update
echo "\033[32;1m=== Updating rust ===\033[0m"
rustup update
cargo install-update --help > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "\033[32;1m=== Updating rust packages ===\033[0m"
cargo install-update -ag
fi
fi
# Update the dotfiles
pull-dotfiles
echo "\033[32;1m=== Update finished ===\033[0m"
}