-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·101 lines (66 loc) · 1.84 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
#!/bin/bash
set -e
set -o nounset
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
INSTALL_DIR="${INSTALL_DIR:-${HOME}}"
SCRIPT_DIR_REL=${SCRIPT_DIR#"${HOME}/"}
function run_cmd() {
cmd="${@}"
echo ${cmd}
eval ${cmd}
}
pushd ${SCRIPT_DIR}
pushd to_link
# Normal files
files_list=($(find * -type f -print))
# Symbolic links
files_list+=($(find * -type l -print))
popd
for f in ${files_list[*]}; do
new_dot_file="${INSTALL_DIR}/.${f}"
new_dir="$(dirname ${new_dot_file})"
mkdir -p ${new_dir}
link_type="-s" # Symbolic link
# link_type="" # Hard link
if [[ -f ${new_dot_file} ]]; then
echo "WARNING: File ${new_dot_file} already exists. Skipping."
else
if [[ -L ${new_dot_file} ]]; then
echo "WARNING: Symbolic link ${new_dot_file} already exists. Overwriting."
rm -f ${new_dot_file}
fi
cmd="ln ${link_type} ${SCRIPT_DIR}/to_link/${f} ${new_dot_file}"
run_cmd ${cmd}
fi
done
pushd to_append
# Normal files
files_list=($(find * -type f -print))
popd
for f in ${files_list[*]}; do
append_dot_file="${INSTALL_DIR}/.${f}"
append_dir="$(dirname ${new_dot_file})"
read -p "About to append 'to_append/${f}' to ${append_dot_file}. Proceed? [y/N] " answer
case ${answer} in
[Yy] ) ;;
* ) echo "Skipping."; continue;;
esac
cmd="mkdir -p ${append_dir}"
run_cmd ${cmd}
cmd="cat to_append/${f} >> ${append_dot_file}"
run_cmd ${cmd}
done
pushd to_run
# Normal files
files_list=($(find * -type f -print))
popd
export INSTALL_DIR=${INSTALL_DIR}
for f in ${files_list[*]}; do
read -p "About to execute 'to_run/${f}'. Proceed? [y/N] " answer
case ${answer} in
[Yy] ) ;;
* ) echo "Skipping."; continue;;
esac
cmd="${SCRIPT_DIR}/to_run/${f}"
run_cmd ${cmd}
done