-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·145 lines (123 loc) · 5.53 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
#!/bin/bash
# https://unix.stackexchange.com/questions/196603/can-someone-explain-in-detail-what-set-m-does
set -m
EXTRAS=false
VERBOSE=false
while getopts 'ev' flag; do
case "${flag}" in
e) EXTRAS=true ;;
v) VERBOSE=true ;;
esac
done
# 0 to 7 = black, red, green, yellow, blue, magenta, cyan, white
MOVE_UP=`tput cuu 1`
CLEAR_LINE=`tput el 1`
BOLD=`tput bold`
UNDERLINE=`tput smul`
RED_TEXT=`tput setaf 1`
GREEN_TEXT=`tput setaf 2`
YELLOW_TEXT=`tput setaf 3`
BLUE_TEXT=`tput setaf 4`
MAGENTA_TEXT=`tput setaf 5`
CYAN_TEXT=`tput setaf 6`
WHITE_TEXT=`tput setaf 7`
RESET=`tput sgr0`
# https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script
SOURCE=${BASH_SOURCE[0]}
while [ -L "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
SOURCE=$(readlink "$SOURCE")
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DOTFILES_FOLDER=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
if [[ $DOTFILES_FOLDER != "$HOME/dotfiles" ]] ; then
# if the current script is not being run from the home directory, we want to move to the home directory.
rm -rf $HOME/dotfiles
git clone https://github.com/ayubun/dotfiles.git $HOME/dotfiles
cd $HOME/dotfiles
./install.sh
exit 0
fi
echo ""
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS_PATH=ubuntu
OS_NAME=Ubuntu
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS_PATH=mac
OS_NAME=Mac
else
echo "Unsupported OS"
exit 1
fi
rm -rf $DOTFILES_FOLDER/tmp
mkdir $DOTFILES_FOLDER/tmp
unlock-apt() {
sudo rm -f /tmp/apt-fast.lock &>/dev/null
sudo rm -f $HOME/dotfiles/tmp/apt.lock &>/dev/null
sudo rm -f /var/lib/apt/lists/lock &>/dev/null
sudo rm -f /var/cache/apt/archives/lock &>/dev/null
sudo rm -f /var/lib/dpkg/lock* &>/dev/null
}
export -f unlock-apt
fix-apt() {
sudo apt --fix-broken install -y &>/dev/null
sudo apt --fix-missing install -y &>/dev/null
sudo apt install -f -y &>/dev/null
}
export -f fix-apt
safer-apt() {
timeout -t 900 sudo DEBIAN_FRONTEND=noninteractive apt "$@" -y 2>/dev/null || unlock-apt && fix-apt && timeout -t 900 sudo DEBIAN_FRONTEND=noninteractive apt "$@" -y 2>/dev/null || unlock-apt
}
export -f safer-apt
safer-apt-fast() {
timeout -t 900 sudo DEBIAN_FRONTEND=noninteractive apt-fast "$@" -yV 2>/dev/null || unlock-apt && fix-apt && timeout -t 900 sudo DEBIAN_FRONTEND=noninteractive apt-fast "$@" -y 2>/dev/null || unlock-apt
}
export -f safer-apt-fast
# Install dependencies (i.e. GNU parallel)
find $DOTFILES_FOLDER/dependencies -maxdepth 1 -mindepth 1 -type f -name "*.sh" -print | \
while read file; do
file=$(basename ${file})
echo "${RESET}${YELLOW_TEXT}[${BOLD}Dependencies${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Running ${UNDERLINE}${file}${RESET}"
. $DOTFILES_FOLDER/dependencies/$file
done
find $DOTFILES_FOLDER/dependencies/$OS_PATH -maxdepth 1 -mindepth 1 -type f -name "*.sh" -print | \
while read file; do
file=$(basename ${file})
echo "${RESET}${YELLOW_TEXT}[${BOLD}$OS_NAME Dependencies${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Running ${UNDERLINE}${file}${RESET}"
. $DOTFILES_FOLDER/dependencies/$OS_PATH/$file
done
find $DOTFILES_FOLDER/configs -maxdepth 1 -mindepth 1 -type f \( -name ".*" -o -name "personalize" \) -print | \
while read file; do
file=$(basename ${file})
echo "${RESET}${YELLOW_TEXT}[${BOLD}Dotfiles${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Symlinking ${UNDERLINE}${file}${RESET}"
rm -rf $HOME/$file
ln -s $DOTFILES_FOLDER/configs/$file $HOME/$file
done
# OS-specific programs
if [[ $EXTRAS = true ]] ; then
echo -e "\n${RESET}${YELLOW_TEXT}[${BOLD}$OS_NAME${RESET}${YELLOW_TEXT}] [${BOLD}Extras${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Running scripts...${RESET}\n"
find $DOTFILES_FOLDER/programs/$OS_PATH $DOTFILES_FOLDER/programs/$OS_PATH/extras -maxdepth 1 -mindepth 1 -type f -name "*.sh" | parallel --tty -j+0 --no-notice -I% --max-args 1 . %
else
echo -e "\n${RESET}${YELLOW_TEXT}[${BOLD}$OS_NAME${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Running scripts...${RESET}\n"
find $DOTFILES_FOLDER/programs/$OS_PATH -maxdepth 1 -mindepth 1 -type f -name "*.sh" | parallel --tty -j+0 --no-notice -I% --max-args 1 . %
fi
# OS-independent programs
if [[ $EXTRAS = true ]] ; then
echo -e "\n${RESET}${YELLOW_TEXT}[${BOLD}OS-Independent${RESET}${YELLOW_TEXT}] [${BOLD}Extras${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Running scripts...${RESET}\n"
find $DOTFILES_FOLDER/programs $DOTFILES_FOLDER/programs/extras -maxdepth 1 -mindepth 1 -type f -name "*.sh" | parallel --tty -j+0 --no-notice -I% --max-args 1 . %
else
echo -e "\n${RESET}${YELLOW_TEXT}[${BOLD}OS-Independent${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Running scripts...${RESET}\n"
find $DOTFILES_FOLDER/programs -maxdepth 1 -mindepth 1 -type f -name "*.sh" | parallel --tty -j+0 --no-notice -I% --max-args 1 . %
fi
rm -rf $DOTFILES_FOLDER/tmp
echo ""
echo ""
echo "${RESET}${GREEN_TEXT}${BOLD} Installation is complete! (* ^ ω ^)"
if [[ $EXTRAS = true ]] ; then
echo ""
echo "${RESET}${GREEN_TEXT} ヽ(*・ω・)ノ Extra programs have been included"
fi
echo ""
echo "${RESET}${YELLOW_TEXT} Be sure to install the necessary fonts for Powerlevel10k:"
echo "${RESET}${YELLOW_TEXT} https://github.com/romkatv/powerlevel10k/blob/master/font.md"
echo "${RESET}"