-
Notifications
You must be signed in to change notification settings - Fork 1
/
step.sh
executable file
·213 lines (165 loc) · 6.68 KB
/
step.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
set -e
import_url_params=""
should_import=true
export_url_params=""
should_export=true
export_url_path=""
export_archive=false
rm -rf "/tmp/loco/"
unarchived_path="/tmp/loco/unarchived/"
download_folder="/tmp/loco/downloads/"
download_filename="Loco.zip"
download_path="${download_folder}${download_filename}"
has_not_imported_or_exported=true
if [ ! -z $import_index ] ; then
import_url_params="${import_url_params}?index=${import_index}"
fi
if [ ! -z $import_locale ] ; then
import_url_params="${import_url_params}&locale=${import_locale}"
fi
if [ ! -z $import_async ] ; then
import_url_params="${import_url_params}&async=${import_async}"
fi
if [ ! -z $import_source_path ] ; then
import_url_params="${import_url_params}&path=${import_source_path}"
fi
if [ ! -z $import_ignore_new ] ; then
import_url_params="${import_url_params}&ignore-new=${import_ignore_new}"
fi
if [ ! -z $import_ignore_existing ] ; then
import_url_params="${import_url_params}&ignore-existing=${import_ignore_existing}"
fi
if [ ! -z $import_delete_absent ] ; then
import_url_params="${import_url_params}&delete-absent=${import_delete_absent}"
fi
if [ ! -z $import_tag_new ] ; then
import_url_params="${import_url_params}&tag-new=${import_tag_new}"
fi
if [ ! -z $import_tag_all ] ; then
import_url_params="${import_url_params}&tag-all=${import_tag_all}"
fi
if [ ! -z $import_untag_all ] ; then
import_url_params="${import_url_params}&untag-all=${import_untag_all}"
fi
if [ ! -z $import_tag_updated ] ; then
import_url_params="${import_url_params}&tag-updated=${import_tag_updated}"
fi
if [ ! -z $import_untag_updated ] ; then
import_url_params="${import_url_params}&untag-updated=${import_untag_updated}"
fi
if [ ! -z $import_tag_absent ] ; then
import_url_params="${import_url_params}&tag-absent=${import_tag_absent}"
fi
if [ ! -z $import_untag_absent ] ; then
import_url_params="${import_url_params}&untag-absent=${import_untag_absent}"
fi
if [ ! -z $export_format ] && [ "$export_format" != "default" ] ; then
export_url_params="${export_url_params} --data-urlencode format=${export_format}"
fi
if [ ! -z $export_filter ] ; then
export_url_params="${export_url_params} --data-urlencode filter=${export_filter}"
fi
if [ ! -z $export_index ] ; then
export_url_params="${export_url_params} --data-urlencode index=${export_index}"
fi
if [ ! -z $export_source ] ; then
export_url_params="${export_url_params} --data-urlencode source=${export_source}"
fi
if [ ! -z $export_fallback ] ; then
export_url_params="${export_url_params} --data-urlencode fallback=${export_fallback}"
fi
if [ ! -z $export_order ] ; then
export_url_params="${export_url_params} --data-urlencode order=${export_order}"
fi
if [ ! -z $export_printf ] && [ "$export_printf" != "default" ] ; then
export_url_params="${export_url_params} --data-urlencode printf=${export_printf}"
fi
if [ ! -z $export_charset ] ; then
export_url_params="${export_url_params} --data-urlencode charset=${export_charset}"
fi
if [ ! -z $export_breaks ] ; then
export_url_params="${export_url_params} --data-urlencode breaks=${export_breaks}"
fi
if [ ! -z $export_no_comments ] ; then
export_url_params="${export_url_params} --data-urlencode no-comments=${export_no_comments}"
fi
if [ ! -z $export_no_folding ] ; then
export_url_params="${export_url_params} --data-urlencode no-folding=${export_no_folding}"
fi
if [ ! -z $export_namespace ] ; then
export_url_params="${export_url_params} --data-urlencode namespace=${export_namespace}"
fi
if [ ! -z $export_status ] ; then
export_url_params="${export_url_params} --data-urlencode status=${export_status}"
fi
if [ ! -z $export_path ] ; then
export_url_params="${export_url_params} --data-urlencode path=${export_path}"
fi
if [ -z $import_file_path ] ; then
echo "Not importing anything because the path to the import file has not been set."
should_import=false
fi
if [ "$should_import" = true ] && [ -z $import_file_ext ] ; then
echo "Not importing anything because the extension of the import file has not been set."
should_import=false
fi
if [ -z $export_file_ext ] ; then
echo "Not exporting anything because the extension of the export file has not been set."
should_export=false
fi
if [ "$should_export" = true ] && [ -z $export_file_path ] ; then
echo "Not exporting anything because the path to the export file has not been set."
should_export=false
fi
if [ "$should_export" = true ] && [[ $export_file_ext == all* ]] ; then
export_url_end=$(echo $export_file_ext | cut -b5-)
export_url_path=$"all.${export_url_end}"
download_path="${export_file_path}"
fi
if [ "$should_export" = true ] && [[ $export_file_ext == archive* ]] ; then
export_archive=true
export_url_end=$(echo $export_file_ext | cut -b9-)
export_url_path="archive/${export_url_end}.zip"
mkdir -p "$download_folder"
if [ ! -d "$export_file_path" ]; then
echo "export_file_path directory does not exist, creating..."
mkdir -p "$export_file_path"
fi
fi
if [ "$should_export" = true ] && [[ $export_file_ext == locale* ]] ; then
if [ -z $export_locale ] ; then
echo "Not exporting anything because the locale of the export file has not been set but the export extension set is locale."
should_export=false
else
export_url_end=$(echo $export_file_ext | cut -b8-)
export_url_path=$"locale/${export_locale}.${export_url_end}"
download_path="${export_file_path}"
fi
fi
if [ "$should_import" = true ] ; then
echo "Importing ${import_file_path} to Loco..."
echo "Parameters: ${import_file_ext}${import_url_params}"
curl -s -u $loco_api_key: -H "Content-Type: application/octet-stream" --data-binary @$import_file_path "https://localise.biz/api/import/${import_file_ext}${import_url_params}"
has_not_imported_or_exported=false
fi
if [ "$should_export" = true ] ; then
echo "Exporting from Loco..."
echo "Parameters: ${export_url_params}"
curl -s -G -u $loco_api_key: -o $download_path $export_url_params "https://localise.biz/api/export/${export_url_path}"
has_not_imported_or_exported=false
if [ "$export_archive" = true ] ; then
unzip -qq -o -u "$download_path" -d "$unarchived_path"
extracted_files_count=$(ls -1 $unarchived_path | wc -l | sed -e 's/^[ \t]*//')
if [ "$extracted_files_count" -lt 2 ] ; then
unarchived_path=$(find $unarchived_path -mindepth 1 -type d -print -quit)
fi
cp -r "$unarchived_path"/* "$export_file_path"
rm -rf "$unarchived_path"
fi
rm -rf "$download_folder"
fi
if [ "$has_not_imported_or_exported" = true ] ; then
echo "Step did not do anything."
exit 1
fi