-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·46 lines (42 loc) · 1.32 KB
/
init.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
#!/bin/bash
export C_BOLD=`tput bold`
export C_RED=`tput setaf 1`
export C_GREEN=`tput setaf 2`
export C_GRAY=`tput setaf 7`
export C_RESET=`tput sgr0`
export C_LINE=`tput el`
echo -e "${C_RESET}"
echo "Checking repositories..."
for repositoryId in $(cat git-repositories.json | jq -r '.repositories | keys[]'); do
if [ ! -d repo/$repositoryId ]; then
repositoryUrl=`cat git-repositories.json | jq -r ".repositories[\"$repositoryId\"].url"`
echo -e "-> Cloning repository ${C_BOLD}${repositoryId}${C_RESET} [${repositoryUrl}]..."
echo -en "${C_GRAY}"
git clone "${repositoryUrl}" "repo/${repositoryId}"
echo -e "${C_RESET}"
else
echo -e "-> Fetching repository ${C_BOLD}${repositoryId}${C_RESET}..."
pushd repo/$repositoryId > /dev/null
git fetch
popd > /dev/null
echo -e "${C_RESET}"
fi
done
echo -e "${C_RESET}"
echo "Apply local Git config..."
for configKey in $(cat git-config.json | jq -r '.config | keys[]'); do
configVal=`cat git-config.json | jq -r ".config[\"$configKey\"]"`
echo " - Setting ${C_BOLD}${configKey}${C_RESET}"
# for myself
git config --local $configKey "${configVal}"
# for all repo
for d in repo/*; do
if [[ -d ${d} && ${d}/.git ]]; then
pushd ${d}/.git > /dev/null
git config --local $configKey "${configVal}"
popd > /dev/null
fi
done
done
echo " Done."
echo -e "${C_RESET}"