-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_env.sh
More file actions
executable file
·136 lines (126 loc) · 4.25 KB
/
git_env.sh
File metadata and controls
executable file
·136 lines (126 loc) · 4.25 KB
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
#! /bin/sh
### Loader fuer base-libraries
homedir=~
base_configuration_directory=~/etc/base_configuration
if [ -d ${base_configuration_directory} ]
then
. ${base_configuration_directory}/base_presets.sh
. ${base_configuration_directory}/git_presets.sh
else
. ./base_functions.sh
. ./presets.sh
fi
git_settings_repo="git@github.com:msc1917/settings_git_repo.git"
my_git_repos="github.com:msc1917"
for library_file in git_library.sh visuals_library.sh
do
. ${default_functions_dir}/${library_file}
done
###
intend()
{
while read LINE;
do
echo "${col_act} ${LINE}${col_off}"
done
}
if which tput > /dev/null
then
echo "tput-mode"
export col_act=$(tput setaf 3)
export col_inact=$(tput setaf 6)
export col_err=$(tput setaf 1)
export col_bold=$(tput bold)
export col_off=$(tput sgr0)
fi
printf "${col_act}${col_bold}\nPreparing...\n${col_off}"
if [ ! -d ${default_config_dir}/git_list.d ]
then
printf "${col_act} ==> Getting settings from Github (${git_settings_repo})\n${col_off}"
git clone ${git_settings_repo} ${default_config_dir}/git_list.d 2>&1 | intend
else
if [ -d ${default_config_dir}/git_list.d/.git -a -f ${default_config_dir}/git_list.d/.git/FETCH_HEAD ]
then
if [ $(expr $(date "+%s") - 600) -gt $(stat -c %Y ${default_config_dir}/git_list.d/.git/FETCH_HEAD) ]
then
printf "${col_act} ==> Actualize settings from Github (${git_settings_repo})${col_off}\n"
git -C ${default_config_dir}/git_list.d push 2>&1 | intend
git -C ${default_config_dir}/git_list.d pull 2>&1 | intend
touch ${default_config_dir}/git_list.d/.git/FETCH_HEAD
else
echo "${col_inact} ==> Last pull least 10 Min ago Github (${git_settings_repo})${col_off}"
fi
else
echo "${col_err} ==> [Error]: ${default_config_dir}/git_list.d seems to be no git repository for ${git_settings_repo}${col_off}"
fi
fi
# find ${default_config_dir}/git_list.d/ -type f -name *.list | while read filename;
for filename in $(find ${default_config_dir}/git_list.d/ -type f -name *.list)
do
ignore=true
cat ${filename} | grep -v "^ *$" | grep -v "^ *#" | while read LINE;
do
if echo ${LINE} | grep -q "^ *\[[^]][^]]*\].*"
then
git_category="$(echo "${LINE}" | sed "s/^ *\[\([^]][^]]*\)\].*$/\1/g")"
if [ "${#}" -gt 0 ]
then
line_in_parameters=false
for item in ${*}
do
# echo "${git_category} ${item}"
if echo "${git_category}" |grep -q ${item}
then
line_in_parameters=true
fi
done
if ${line_in_parameters}
then
ignore=false
echo "${col_act}${col_bold}\nKathegorie: \"${git_category}\"${col_off}"
else
ignore=true
echo "${col_inact}${col_bold}\nKathegorie: \"${git_category}\" (Wird ignoriert)${col_off}"
fi
else
ignore=false
echo "${col_act}${col_bold}\nKathegorie: \"${git_category}\"${col_off}"
fi
else
git_branch=[]
github_address="$(echo ${LINE} | cut -f 1 -d " ")"
target_path="$(echo ${LINE} | cut -f 2 -d " ")"
git_branch="$(echo ${LINE} | cut -f 3 -d " ")"
if [ "${git_branch}" != "" ]
then
git_branch="[${git_branch}]"
fi
if ${ignore}
then
echo "${col_inact} ==> ${github_address}${git_branch} -> ${target_path} (Wird ignoriert)${col_off}"
else
if [ ! -d "${target_path}" ]
then
if [ -d $(echo "${target_path}" | sed "s#^~#${HOME}#") ]
then
echo "${col_act} ==> ${github_address}${git_branch} -> ${target_path} (Pull Repository)${col_off}"
git -C $(echo "${target_path}" | sed "s#^~#${HOME}#") pull 2>&1 | intend
if echo "${my_git_repos}" | grep -q "$(echo ${github_address} | sed "s#^[^@][^@]*@\([^/][^/]*\)/.*#\1#")"
then
git -C $(echo "${target_path}" | sed "s#^~#${HOME}#") push 2>&1 | intend
else
echo "${col_noact}No automatic push from ${github_address}...${col_off}" | intend
fi
else
echo "${col_act} ==> ${github_address}${git_branch} -> ${target_path} (Klone Repository)${col_off}"
git clone ${github_address} $(echo "${target_path}" | sed "s#^~#${HOME}#") 2>&1 | intend
fi
# git clone ${github_address}${git_branch} $(echo "${target_path}" | sed "s#^~#${HOME}#")
else
echo "${col_inact} ==> ${github_address}${git_branch} -> ${target_path} (Repository bereits Vorhanden)${col_off}"
fi
fi
fi
done
done
echo "${col_act}${col_bold}Fertig${col_off}"