-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·168 lines (139 loc) · 4.33 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
set -e
DOTFILES_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export DOTFILES_ROOT
export DOTFILES_LOG_FILE="/tmp/dotfiles.log"
DOTFILES_ONLY_DOTFILES=false
DOTFILES_NO_INTERACTION=false
DOTFILES_ACCEPT_MSCOREFONTS_EULA=false
DOTFILES_ARG_ROOT=false
DOTFILES_ARG_HELP=false
export overwrite_all=false
export backup_all=false
export skip_all=false
# source: https://stackoverflow.com/a/14203146
for i in "$@"
do
case $i in
--dotfiles)
DOTFILES_ONLY_DOTFILES=true
;;
--no-interaction)
DOTFILES_NO_INTERACTION=true
export overwrite_all=true
;;
--accept-mscorefonts-eula)
DOTFILES_ACCEPT_MSCOREFONTS_EULA=true
;;
--root)
DOTFILES_ARG_ROOT=true
;;
-h|--help)
DOTFILES_ARG_HELP=true
;;
--log-path=*)
export DOTFILES_LOG_FILE="${i#*=}"
shift # skip =* value
;;
*)
# unknown options
;;
esac
done
export DOTFILES_NO_INTERACTION
export DOTFILES_ACCEPT_MSCOREFONTS_EULA
function cleanup() {
if [ -d "/tmp/dotfiles" ]; then
rm -rf /tmp/dotfiles
fi
}
function beforeExit() {
echo -e "\n======================================="
echo "[ERROR] One or more commands failed!"
echo "[ERROR] Log file: $DOTFILES_LOG_FILE"
echo "Deleting temporary files..."
cleanup
}
echo " ------------------------------------------------------------"
echo "< Dotfiles - Felix Häusler - https://github.com/fxha/dotfiles >"
echo " ------------------------------------------------------------"
echo ""
echo " __ __ ____ __ "
echo " ___/ /__ / /_/ _(_) /__ ___"
echo " / _ / _ \/ __/ _/ / / -_|_-<"
echo " \_,_/\___/\__/_//_/_/\__/___/"
echo ""
if [[ "$DOTFILES_ARG_HELP" = true ]]; then
cat <<EOF
Usage: $(basename "$0") [options]
Options:
-h, --help Print this help message
--root Install dotfiles for the root user
Please execute with 'sudo' or 'sudo su -'
--dotfiles Only install dotfiles
--no-interaction Automatically full installation without user interaction
--accept-mscorefonts-eula Accept the Microsoft's TrueType core fonts license
--log-path=%file% Set log directory
See the README for documentation.
EOF
exit 0
fi
trap beforeExit EXIT
trap 'echo -e "\nAborting..."; cleanup; trap - EXIT; exit 1' INT
echo -e "dotfile setup started: $(date +'%Y-%m-%d %H:%M:%S')\n" > "$DOTFILES_LOG_FILE"
if [[ "$(id -u)" = 0 ]]; then
if [[ -n "$SUDO_USER" && "$DOTFILES_ARG_ROOT" = false ]]; then
echo "The script need to be run without root permissions." >&2
trap - EXIT
exit 1
else
echo -e "\x1b[33mCurrent installation path is '$HOME'. Please run the setup without root permissions to install to local user if needed.\x1b[0m"
fi
elif [[ "$(id -u)" != 0 && "$DOTFILES_ARG_ROOT" = true ]]; then
echo "The script need to be run with root permissions." >&2
trap - EXIT
exit 1
fi
# Bash on Windows (cygwin or mingw)
if [[ "$(uname)" == "CYGWIN"* || "$(uname)" == "MINGW"* ]]; then
echo -e " windows"
echo ""
if [ "$DOTFILES_NO_INTERACTION" = false ]; then
read -p "Do you want install dotfiles? (y/n) " -n 1 -r
echo ""
else
REPLY="y"
fi
if [[ $REPLY =~ ^[Yy]$ ]]; then
"$DOTFILES_ROOT/scripts/install_dotfiles_windows.sh"
fi
trap - EXIT
exit 0
fi
# ask for root permissions
sudo -v
# keep-alive: update existing sudo time stamp if set, otherwise do nothing.
# source: https://gist.github.com/cowboy/3118588
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
if [ "$DOTFILES_NO_INTERACTION" = false ]; then
read -p "Do you want install dotfiles? (y/n) " _installDotfiles
else
_installDotfiles="y"
fi
if [[ "$_installDotfiles" = "y" ]]; then
"$DOTFILES_ROOT/scripts/install_dotfiles.sh"
fi
# reload bash profile
. ~/.bashrc
if [ "$DOTFILES_NO_INTERACTION" = false ]; then
read -p "Do you want install additional software and/or system configuration? (y/n) " _installApps
elif [ "$DOTFILES_ONLY_DOTFILES" = false ]; then
_installApps="y"
fi
if [[ "$_installApps" = "y" ]]; then
"$DOTFILES_ROOT/scripts/install_packages.sh"
fi
echo "Deleting temporary files..."
cleanup
trap - EXIT
exit 0