-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-setup.sh
executable file
·192 lines (181 loc) · 6.67 KB
/
git-setup.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/bin/bash
function init_gitignore
{
echo "Creating .gitignore file for files larger than 49M"
rm .gitignore
find * -size +49M | cat >> .gitignore
}
function split_files_gitignore
{
read_file=${1};
echo "reading file: " ${read_file}
cat ${read_file}| while read line
do
echo "splitting file >> " ${line};
filedirname=${line} # file
filedir=$(sed "s/\/[^\/]*$/\//g" <<< ${line} | sed "s/\ /\\\ /g"); # directory
filename=$(sed "s;${filedir};;g" <<< ${line});
split -b 49M "$filedirname" ./"${filedir}""part:""$filename"".";
done
}
function merge_files_gitignore
{
read_file=${1};
echo "reading file: " ${read_file}
cat ${read_file}| while read line
do
echo "merging file >> " ${line};
filedirname=${line} # file
filedir=$(sed "s/\/[^\/]*$/\//g" <<< ${line} | sed "s/\ /\\\ /g"); # directory
filename=$(sed "s;${filedir};;g" <<< ${line});
cat ./"${filedir}""part:""$filename""."* > "$filedirname"
done
}
function rm_files_gitignore
{
read_file=${1};
echo "reading file: " ${read_file}
cat ${read_file}| while read line
do
filedirname=${line} # file
filedir=$(sed "s/\/[^\/]*$/\//g" <<< ${line} | sed "s/\ /\\\ /g"); # directory
filename=$(sed "s;${filedir};;g" <<< ${line});
echo "rm ./""${filedir}""part:""$filename"".*"
rm ./"${filedir}""part:""$filename""."*
done
}
function checkout_files_gitignore
{
read_file=${1};
echo "reading file: " ${read_file}
cat ${read_file}| while read line
do
filedirname=${line} # file
filedir=$(sed "s/\/[^\/]*$/\//g" <<< ${line} | sed "s/\ /\\\ /g"); # directory
filename=$(sed "s;${filedir};;g" <<< ${line});
echo "git checkout ./""${filedir}""part:""$filename"".*"
git checkout ./"${filedir}""part:""$filename""."*
done
}
function print_version
{
echo "version 0.1"
}
function help_menu
{
echo " -- What this script does --"
echo ""
echo " This is a script file made to deal with large binary files on github. With "
echo "this simple script, you will be able to push many files with sizes larger than "
echo "100MB, and pull them back and use, without worrying of how how many larger files"
echo "you currently have. Git have a really annoying... \"feature\". If you commit a "
echo "larger than 100MB file, it will just say that you did, after it tries to pull it"
echo "and fail... and for a larger file, it takes a lot of time... If you have a lot"
echo "of files, it takes a LOT more, to pull ~nothing~. So you have all your"
echo "morning wasted(or even more). Well.... not anymore!"
echo ""
echo ""
echo " -- How to use it --"
echo ""
echo " - Basic Usage -"
echo ""
echo " Usually, you will need to use just two commands:"
echo "./git-setup.sh --setup : this will create a gitignore file for files larger"
echo " 49MB (Github advises for files smaller than 50MB), and will break all"
echo " these files on smaller than 49MB ones."
echo "./git-setup.sh --merge: this command will combine all pieces, and recreate"
echo " the original files."
echo ""
echo " For example, you just clonned this repository. Use --merge on the root, to"
echo "recreate the original files:"
echo "$ ./git-setup.sh --merge"
echo " After that, you runned some experiments, and some more larger files were "
echo "generated. Use --setup to prepare the .gitignore, and break the larger files into"
echo "pieces:"
echo "$ ./git-setup.sh --setup"
echo " Now, you may procedure with the git commands on the root:"
echo "git add ."
echo "git commit -m \"some comment\""
echo "git push"
echo ""
echo " - Other commands-"
echo ""
echo " You may want to clean up you local repository form the part-files. Use:"
echo "$ ./git-setup.sh --rm"
echo " To restore the part files before commit, just use again: "
echo "$ ./git-setup.sh --setup"
echo " To retrieve back from the repository the original part files (if you used"
echo "the --merge first, for example) just use --checkout to rollback from the last"
echo "commit:"
echo "$ ./git-setup.sh --checkout"
echo " You may want to checkout, for exemple, executed a --rm by mistake."
echo " Is better to NEVER execute a --rm just after you clonned your directory."
echo " Is better to, just after you clonned it, execute a --setup. Than, you may "
echo "freely execute --rm, if the part files anoy you. You will be safe, since the"
echo "actual files are already on your repo, and you may retrive the parts executing"
echo "a --setup again. But we prepared a --checkout just in case."
echo " If, for any reason you just want to generate the gitignore file, use:"
echo "$ ./git-setup.sh --init"
echo " Also, if you just want to break the files listed on .gitignore into pieces, "
echo "but does not want to recreate a new .gitignoreit, use:"
echo "$ ./git-setup.sh --split"
echo " In fact, --setup just execut an --init and than a --split.. That means:"
echo "$ ./git-setup.sh --setup"
echo " Is equivalent to:"
echo "$ ./git-setup.sh --init"
echo "$ ./git-setup.sh --split"
echo " Since (probably) there is no much reasons to execute a --init and than a "
echo "is better to just --setup."
echo " To display this help menu, use:"
echo "$ ./git-setup.sh --help"
echo " Finally, to show the script version:"
echo "$ ./git-setup.sh --version"
echo ""
echo ""
echo " -- Options --"
echo ""
echo "--init : create the .gitignore file for files larger than 49MB."
echo "--split : break files on .gitignore files on pieces smaller than 49MB."
echo "--merge : combine all part-files (created by --split or --setup) on the "
echo " original ones."
echo "--setup : create the .gitignore file for files larger than 49MB, and than"
echo " break all."
echo " into part files smaller than 49MB."
echo "--rm : remove all part-files."
echo "--checkout : retrieve from repository all part files."
echo "--version : display the script version."
echo "--help : show this help menu."
echo ""
}
function main
{
option=${1}
if [[ "$option" == "--init" ]]; then
init_gitignore;
elif [[ "$option" == "--split" ]]; then
# split_files_gitignore test_file;
split_files_gitignore .gitignore
elif [[ "$option" == "--merge" ]]; then
# merge_files_gitignore test_file;
merge_files_gitignore .gitignore;
elif [[ "$option" == "--setup" ]]; then
init_gitignore;
split_files_gitignore .gitignore;
elif [[ "$option" == "--rm" ]]; then
rm_files_gitignore .gitignore;
elif [[ "$option" == "--checkout" ]]; then
checkout_files_gitignore .gitignore;
elif [[ "$option" == "--version" ]]; then
print_version;
else
help_menu;
fi
}
if [[ "$1" != "--source" ]]
then
main ${1}
# main "--init";
# main "--split";
# main "--merge";
# read_line test_file;
fi