Last active
August 29, 2015 14:00
-
-
Save weirongxu/11203629 to your computer and use it in GitHub Desktop.
rsync dotfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hosts | |
/etc/hosts | |
# dotfile | |
~/.config/smplayer/smplayer.ini | |
~/compiz_bacpup.profile | |
~/_gdbinit | |
~/.remmina/ | |
~/.bashrc | |
~/.zshrc | |
~/.shrc | |
~/.bypy.json | |
~/.ctags | |
~/.gitconfig | |
~/.npmrc | |
~/.evernote-devtoken | |
~/.record/ | |
# nginx | |
/etc/nginx/nginx.conf | |
/etc/nginx/sites-available/default | |
/etc/nginx/sites-enabled/default | |
/etc/nginx/fastcgi.conf | |
/etc/nginx/proxy_params | |
# themes | |
~/.themes/FlatStudioGray/ | |
~/.themes/Win8-03-Anakiwa/ | |
~/.themes/Numix/ | |
~/.themes/Numix-Darker/ | |
# vim | |
~/.vim/ | |
~/.vimrc | |
~/.nvimrc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
rsync_file='rsync -ai' | |
rsync_dir='rsync -ai --delete' | |
target_dir='dotfile' | |
start_num=0 | |
while read line | |
do | |
((start_num++)) | |
front=${line:0:2} | |
front1=${front:0:1} | |
back=${line:0-1:1} | |
if [[ -z "$line" || "$front1" = '#' ]]; then | |
# useless line | |
continue | |
elif [[ "$front" = '~/' ]]; then | |
# generate target | |
target=$target_dir/${line#*/} | |
elif [[ "$front1" = '/' ]]; then | |
target=$target_dir/root/${line#*/} | |
# elif [[ "$front1" = '!' ]]; then | |
# TODO exclude file | |
else | |
# error | |
echo -e "\e[00;31mline: $start_num, '$line' must start with '~/' or '/'.\e[00m" | |
read -n 1 -p '(Enter)' | |
break | |
fi | |
source=${line/#~/$HOME} | |
if [[ $back = '/' ]]; then | |
# dir | |
echo $rsync_dir "$source" "$target" | |
$rsync_dir "$source" "$target" | |
elif [[ -d $source ]]; then | |
# dir | |
echo $rsync_dir "$source" "$target/" | |
$rsync_dir "$source" "$target/" | |
elif [[ -e $source ]]; then | |
# file | |
echo $rsync_file "$source" "$target" | |
dir=`dirname $target` | |
if [[ ! -d $dir ]]; then | |
mkdir -p $dir | |
fi | |
$rsync_file "$source" "$target" | |
else | |
# error | |
echo -e "\e[00;31mline: $start_num, '$line' file not exist.\e[00m" | |
read -n 1 -p '(Enter)' | |
break | |
fi | |
done < rsync-list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment