-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotfile-sync.sh
executable file
·90 lines (77 loc) · 2.71 KB
/
dotfile-sync.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
# Author: https://github.com/arush-sal/dotfiles/blob/master/dotfile-sync.sh
# Modified: Nitish Jadia
DOTDIR="$HOME/dotfiles"
LOGFILE="$HOME/dotfiles/dotsync.log"
NTFY_BIN='/home/nitish/.local/bin/ntfy'
DASHLINE='-----------------------------'
echo -e "\n""$DASHLINE$(date)$DASHLINE""\n" >> $LOGFILE
checkdiff() {
if [[ ! -e $2 ]]; then
cp -vrf $1 $2 >> $LOGFILE
fi
if ! diff $1 $2 &> /dev/null; then
echo >> $LOGFILE
echo -e "\t\t$1 has been modified" >> $LOGFILE
echo "$DASHLINE DIFF START $DASHLINE" >> $LOGFILE
echo `diff $1 $2` >> $LOGFILE
echo "$DASHLINE DIFF END $DASHLINE" >> $LOGFILE
echo >> $LOGFILE
#Update repo
cp -vrf $1 $2 >> $LOGFILE
fi
}
## Sync cronjobs
crontab -l -u nitish > /tmp/crontab
checkdiff /tmp/crontab $DOTDIR/crontab
##Files
checkdiff ~/cron/fan_status.py $DOTDIR/scripts/fan_status.py
checkdiff ~/cron/get_fan_speed.py $DOTDIR/scripts/get_fan_speed.py
checkdiff ~/cron/i3-battery-popup.sh $DOTDIR/scripts/i3-battery-popup.sh
checkdiff ~/cron/monitor-setup.sh $DOTDIR/scripts/monitor-setup.sh
checkdiff ~/cron/bg_change.py $DOTDIR/scripts/bg_change.py
checkdiff ~/cron/dpms_toggle.sh $DOTDIR/scripts/dpms_toggle.sh
# Sync .zshrc
mkdir -p $DOTDIR/.oh-my-zsh/custom
checkdiff ~/.zshrc $DOTDIR/.zshrc
checkdiff ~/.oh-my-zsh/custom/func.zsh $DOTDIR/.oh-my-zsh/custom/func.zsh
checkdiff ~/.oh-my-zsh/custom/env.zsh $DOTDIR/.oh-my-zsh/custom/env.zsh
checkdiff ~/.oh-my-zsh/custom/alias.zsh $DOTDIR/.oh-my-zsh/custom/alias.zsh
checkdiff ~/.oh-my-zsh/custom/jpost.zsh $DOTDIR/.oh-my-zsh/custom/jpost.zsh
# Sync .tmux
mkdir -p $DOTDIR/.tmux
checkdiff ~/.tmux/.tmux.conf $DOTDIR/.tmux/.tmux.conf
checkdiff ~/.tmux/.tmux.conf.local $DOTDIR/.tmux/.tmux.conf.local
#checkdiff ~/.tmux/.tmux.conf $DOTDIR/.tmux/.tmux.conf
# Sync .vimrc
checkdiff ~/.vimrc $DOTDIR/.vimrc
# Sync i3
mkdir -p $DOTDIR/i3
checkdiff ~/.config/i3/config $DOTDIR/i3/config
checkdiff ~/.config/i3/status.conf $DOTDIR/i3/status.conf
# Sync X server configuration
checkdiff ~/.xinitrc $DOTDIR/.xinitrc
checkdiff ~/.Xresources $DOTDIR/.Xresources
cd $DOTDIR;
if [[ -n $(git status -s) ]]; then
git status
echo $DASHLINE
git add .
#git yolo
# Wait till machine is online
until ping -c 1 8.8.8.8 &> /dev/null; do sleep 3; done
git commit -s -a -m "$(curl -s https://whatthecommit.com/index.txt)"
if [[ $? -eq 0 ]]; then
git push origin 5402
else
$NTFY_BIN send "FAILED: Dotfiles Commit"
echo "FAILED: Dotfiles Commit" >> $LOGFILE
fi
if [[ $? -eq 0 ]]; then
$NTFY_BIN send "Success: Dotfiles Backup"
echo "Success: Dotfiles Backup" >> $LOGFILE
else
$NTFY_BIN send "FAILED: Dotfiles Backup"
echo "FAILED: Dotfiles Backup" >> $LOGFILE
fi
fi