-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-profile
executable file
·131 lines (108 loc) · 3.95 KB
/
install-profile
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
#!/usr/bin/env bash
# install-profile
# used for running group of installation scripts as a profile located in ./meta/profiles/ folder
# Ex: install script for MacOS, debian
# Usage: ./install-profile <profile ...>
# ./install-profile mac
# ./install-profile debian-terminal
# ./install-profile debian-terminal debian-gui
#
# ------------------------------------------------------------------------------------------------ #
#
# files in ./meta/profiles/ folder are plain text files that have config filename(no file extenstion).
# check example: https://github.com/ecarlson94/dotbot-template/blob/main/meta/profiles/exampleOS1
# Ex:
# ./meta/profiles/macos contains
# nvim
# tmux
# homebrew
#
# ------------------------------------------------------------------------------------------------ #
#
# NOTE: to run a config in sudo, then add '-sudo' as a suffix of the config to run.
# Ex: ./meta/profiles/debian contains
# apt-sudo
#
# ------------------------------------------------------------------------------------------------ #
#
# to ignore a line in a profile, add '#' at the beginning of that line
# Ex: ./meta/profiles/macos contains
# nvim
# tmux
# homebrew
# # astronvim
#
# This will ignore 'astronvim' config
#
# ------------------------------------------------------------------------------------------------ #
#
# check example: https://github.com/ecarlson94/dotbot-template/blob/main/meta/profiles/exampleOS1
# check: https://github.com/ecarlson94/dotbot-template#for-installing-single-configurations
#
# obtained from https://github.com/anishathalye/dotbot/wiki/Tips-and-Tricks#install-profile
# author ecarlson94
set -e
META_DIR="meta"
PROFILES_DIR="profiles"
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${BASE_DIR}"
git submodule update --init --recursive
# ------------------------------------------------------------------------------------------------ #
# Utility functions
# print line banner
# used for segmenting when a profile configs is being executed.
# For VISUAL purposes
printLineBanner() {
# print a line depending on the terminal width
# https://unix.stackexchange.com/a/425158
# https://stackoverflow.com/a/17030976/3053548
#
# print ANSI color using printf
# https://stackoverflow.com/a/26873040/3053548
printf '\e[1;34m%0.s#\e[0m' $(seq 1 $(stty size | awk '{print $2}'))
}
# ------------------------------------------------------------------------------------------------ #
# Verify dotbot profile exists
# Checks if the file exists in meta/profiles/ folder
exitIfProfileNotFound=false # used as a flag to exit IF a profile is NOT found
for profile in ${@}; do
# check if the profile filepath doesn't exist
# print message
# flag variable to exit
profileFilepath="${BASE_DIR}/${META_DIR}/${PROFILES_DIR}/${profile}"
if [[ ! -e $profileFilepath ]]; then
echo -e "Dotbot profile \\033[1;31m$profileFilepath \\033[0mNOT found"
exitIfProfileNotFound=true
fi
done
# exit if a profile filepath is NOT found
if [[ $exitIfProfileNotFound == true ]]; then
echo -e "\nexiting"
exit 1
fi
# cleanup variables
unset exitIfProfileNotFound
# ------------------------------------------------------------------------------------------------ #
# Running profile
# loop through each argument
# extract dotbot configs to run
# run dotbot configs using ./install-standalone
for profile in ${@}; do
# extract dotbot configs to run
while IFS= read -r config; do
CONFIGS+=" ${config}"
# read lines that DON'T start with #
# obtained from https://stackoverflow.com/a/8197412/3053548
done < <(grep -v '^#' "${META_DIR}/${PROFILES_DIR}/$profile")
# print line banner multiple times
# https://serverfault.com/a/273241
for i in `seq 2`; do printLineBanner; done
echo ""
echo -e "\nRunning profile \x1b[31m $profile \x1b[0m\n"
# run profile configs
source ./install-standalone ${CONFIGS}
# cleanup variables
unset CONFIGS
done
# cd "${BASE_DIR}"
# echo "Restart your terminal..."