guowenxue
2023-07-10 5e9d03d507aad324a803eb8795e0eed6fb671761
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
#!/bin/bash
 
#+--------------------------------------------------------------------------------------------
#|Description:  This shell script used download and compile cJSON for RaspberryPi
#|     Author:  GuoWenxue <guowenxue@gmail.com>
#|  ChangeLog:
#|           1, Initialize 1.0.0 on 2021.04.12
#+--------------------------------------------------------------------------------------------
 
PREFIX_PATH=/usr
LYFTP_SRC=ftp://master.iot-yun.club/src/
 
function msg_banner()
{
    echo ""
    echo "+-----------------------------------------------------------------------"
    echo "|  $1 "
    echo "+-----------------------------------------------------------------------"
    echo ""
}
 
function check_result()
{
    if [ $? != 0 ] ; then
       echo ""
       echo "+-----------------------------------------------------------------------"
       echo "|  $1 "
       echo "+-----------------------------------------------------------------------"
       echo ""
       exit ;
    fi
}
 
function compile_cJSON()
{
    SRC_NAME=cJSON-1.7.15
    PACK_SUFIX=tar.gz
    IMG_NAME=ipt
 
    if [ -f ${PREFIX_PATH}/lib/libcjson.so ] ; then
        msg_banner "$SRC_NAME already compile and installed"
        return 0;
    fi
 
    msg_banner "Start compile $SRC_NAME "
 
    if [ ! -f ${SRC_NAME}.${PACK_SUFIX} ] ; then
        #wget https://github.com/downloads/libevent/libevent/${SRC_NAME}.${PACK_SUFIX}
        wget ${LYFTP_SRC}/${SRC_NAME}.${PACK_SUFIX}
        check_result "ERROR: download ${SRC_NAME} failure"
    fi
 
    tar -xzf ${SRC_NAME}.${PACK_SUFIX}
    check_result "ERROR: decompress ${SRC_NAME} failure"
 
    cd ${SRC_NAME}
 
    make  && sudo make install
    check_result "ERROR: compile ${SRC_NAME} failure"
 
    cd -
}
 
compile_cJSON