-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·115 lines (98 loc) · 2.34 KB
/
install.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/sh
BASE_DIR=`dirname $(readlink -f $0)`
check_file_difference() {
if [ "$#" != "2" ]; then
echo "Need 2 arguments, but $# are given"
exit 1
fi
diff -rq $1 $2 > /dev/null 2>&1
return
}
backup_file() {
for file in $@
do
backup_filename="${file}.bk.`date +"%y.%m.%d"`"
echo "Backup file ${file} to ${backup_filename}"
mv ${file} ${backup_filename}
done
}
link_file() {
if [ "$#" != "2" ]; then
echo "Need 2 arguments, but $# are given"
exit 1
fi
TARGET=$1
DESTINATION=$2
ln -s $1 $2
}
unlink_file() {
for file in $@
do
echo "Unlink the file ${file}"
unlink ${file}
done
}
install_dotfiles() {
if [ "$#" != "2" -a "$#" != "3" -a "$#" != "4" ]; then
echo "Wrong number of arguments"
exit 1
fi
if [ -z "$3" ]; then
DESTINATION_DIR=${HOME}
else
DESTINATION_DIR=$3
[ ! -d ${DESTINATION_DIR} ] && mkdir -p ${DESTINATION_DIR}
fi
PREFIX=$1
SOURCE_FILES=$2
NO_PREPENDED_DOT=$4
for file in $SOURCE_FILES
do
if [ -n "${NO_PREPENDED_DOT}" ]; then
DESTINATION_FILE_PATH="${DESTINATION_DIR}/${file}"
else
DESTINATION_FILE_PATH="${DESTINATION_DIR}/.${file}"
fi
SOURCE_FILE_PATH="${BASE_DIR}/${PREFIX}/${file}"
if [ -e ${DESTINATION_FILE_PATH} ]; then
check_file_difference "${DESTINATION_FILE_PATH}" "${SOURCE_FILE_PATH}"
RETURN_VALUE=$?
if [ "$RETURN_VALUE" != "0" ]; then
backup_file "${DESTINATION_FILE_PATH}"
link_file "${SOURCE_FILE_PATH}" "${DESTINATION_FILE_PATH}"
fi
else
link_file "${SOURCE_FILE_PATH}" "${DESTINATION_FILE_PATH}"
fi
done
echo "Complete installing ${PREFIX} dotfiles"
}
install_vim_dotfiles() {
install_dotfiles "vim" "vimrc"
install_dotfiles "nvim" "init.vim" "${HOME}/.config/nvim" "Y"
}
install_screen_dotfiles() {
install_dotfiles "screen" "screenrc"
}
install_tmux_dotfiles() {
install_dotfiles "tmux" "tmux.conf"
}
main() {
echo "This script will install the configuration files for the following softwares:"
echo "1. vim, also neovim"
echo "2. screen"
echo "3. tmux"
read -p "Do you want to install ? [Y/n] " install_decision
case $install_decision in
[Yy])
echo "Start installing"
;;
*)
echo "Quit the installation script"
;;
esac
install_vim_dotfiles
install_screen_dotfiles
install_tmux_dotfiles
}
main