-
Notifications
You must be signed in to change notification settings - Fork 9
/
plan.sh
executable file
·53 lines (42 loc) · 1.44 KB
/
plan.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
#!/bin/bash
# Скрипт импорта JSON файла в Битрикс
# Базовые настройки в файле etc/config
FILE_TO_IMPORT='PlanPrih.json'
cd "$(dirname "$0")"
source etc/config
URI="$SITE/bitrix/admin/1c_exchange.php"
COOK='data/cookiefile.txt'
FILE="data/$FILE_TO_IMPORT"
STEP_CONTINUE=1
CHARSET_IN='cp1251' # кодировка сайта
CHARSET_OUT='utf-8' # кодировка консоли
BASIC_AUTH=`echo -n "$AUTH_LOGIN:$AUTH_PASS" | base64`
function init {
echo 'Init'
curl -s -c $COOK $URI'?type=catalog&mode=checkauth' -H "Authorization: Basic $BASIC_AUTH" > log/01-checkauth.txt
curl -s -c $COOK -b $COOK $URI'?type=catalog&mode=init' -H "Authorization: Basic $BASIC_AUTH" > log/02-init.txt
}
function upload {
echo 'Upload file'
curl -s -c $COOK -b $COOK -X POST --data-binary @- $URI'?type=catalog&mode=file&filename='$FILE_TO_IMPORT -H "Authorization: Basic $BASIC_AUTH" -H 'Content-Type: application/octet-stream' -H 'Expect:' --trace-ascii log/debug.txt < $FILE > log/03-file.txt
}
function step {
curl -s -c $COOK -b $COOK $URI'?type=catalog&mode=import&filename='$FILE_TO_IMPORT -H "Authorization: Basic $BASIC_AUTH" > log/step.txt
if grep -q progress log/step.txt ; then
STEP_CONTINUE=1
else
STEP_CONTINUE=0
fi
echo
cat log/step.txt | iconv -f $CHARSET_IN -t $CHARSET_OUT
echo
}
function run {
while [[ $STEP_CONTINUE == "1" ]]; do
step
done
}
init
upload
run
echo