-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·102 lines (85 loc) · 2.24 KB
/
install
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
#!/bin/bash
usage() {
cat << EOF
usage: install [OPTIONS]
-l | --link Link dotfiles to home directory
-s | --server Install server packages (Root required)
-d | --desktop Install desktop packages (Root required)
-h | --help Show this help message
EOF
}
check_root() {
if [ $(id -u) -ne 0 ]; then
echo "Option requires superuser privileges"
usage
exit 1
fi
}
link_files() {
source_files=$1
for file in $( find ${source_files} -type f ); do
destination=${HOME}${file#"${source_files}"}
# If link exists, skip. If file exists, move to ~filename.ext
if [ -L ${destination} ] && [ $(readlink -f ${destination}) == "${file}" ]; then
echo -e "'${destination}' -> '${file}' \033[1;33mexists\033[0m"
continue
elif [ -e ${destination} ] ; then
echo "'${destination}' exists as a file, moving it to ~$(basename ${destination})"
mv "${destination}" "$(dirname ${destination})/~$(basename ${destination})"
fi
mkdir -p $( dirname ${destination} )
echo -e "$(ln -sfv "${file}" "${destination}") \033[0;32mlinked\033[0m"
done
source ~/.bash_profile
}
install_packages() {
apt-get update -y && apt-get upgrade -y
xargs apt-get install -y < $1
apt-get autoremove -y
}
while [[ $# -gt 0 ]]; do
case $1 in
-l | --link )
link=$1
;;
-s | --server )
server=$1
;;
-d | --desktop )
desktop=$1
;;
-h | --help )
usage
exit
;;
* )
usage
exit 1
esac
shift
done
if [[ -z ${link} && -z ${server} && -z ${desktop} ]]; then
echo "Please specify at least one option."
usage
exit 1
fi
if [ $(basename ${PWD}) == "dotfiles" ]; then
mv ../dotfiles ../.dotfiles
cd ../.dotfiles
fi
if [ -n "${link}" ]; then
if [ $(id -u) -eq 0 ]; then
export -f link_files
su ${SUDO_USER:-$USER} -c "link_files ${PWD}/home"
else
link_files ${PWD}/home
fi
fi
if [ -n "${server}" ]; then
check_root
install_packages ./server_packages
fi
if [ -n "${desktop}" ]; then
check_root
install_packages ./desktop_packages
fi