starthugep.sh 2.36 KB
Newer Older
fuyanbin's avatar
fuyanbin committed
1
#!/system/bin/sh
2

fuyanbin's avatar
fuyanbin committed
3
4
export PATH="$PATH:/sbin:/system/sbin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin"

fuyanbin's avatar
fuyanbin committed
5
6
7
CACHE_DIR="$1"
[ -z "$CACHE_DIR" ] && CACHE_DIR="/data/"
SMALLP_PATH="$CACHE_DIR/smallp/"
fuyanbin's avatar
fuyanbin committed
8

fuyanbin's avatar
fuyanbin committed
9
10
mkdir -p "$CACHE_DIR/local/tmp/bin"
export PATH="$PATH:$CACHE_DIR/local/tmp/bin"
fuyanbin's avatar
fuyanbin committed
11

fuyanbin's avatar
fuyanbin committed
12
13
init() {
    BUSYBOXY="/system/bin/busybox-arm"
fuyanbin's avatar
fuyanbin committed
14

fuyanbin's avatar
fuyanbin committed
15
16
17
18
19
20
21
22
23
    if [ ! -e /system/bin/chroot ]
    then
        ln -s $BUSYBOXY "$CACHE_DIR/local/tmp/bin/chroot"
    fi

    if [ -e /system/bin/pgrep ]
    then
        ln -s $BUSYBOXY "$CACHE_DIR/local/tmp/bin/pgrep"
    fi
fuyanbin's avatar
fuyanbin committed
24

fuyanbin's avatar
fuyanbin committed
25
    if [ ! -e /system/bin/dirname ]
26
    then
fuyanbin's avatar
fuyanbin committed
27
        ln -s $BUSYBOXY "$CACHE_DIR/local/tmp/bin/dirname"
28
    fi
fuyanbin's avatar
fuyanbin committed
29
30
31
}

is_running() {
fuyanbin's avatar
fuyanbin committed
32
    for pid in $(pgrep "starthugep.sh")
fuyanbin's avatar
fuyanbin committed
33
34
35
36
37
38
39
    do
        if [ "$pid" != "$$" ]
        then
            exit 0
        fi
    done
}
fuyanbin's avatar
fuyanbin committed
40

fuyanbin's avatar
fuyanbin committed
41
install() {
42
43
    if [ -f /system/bin/hugep-all.zip ]
    then
fuyanbin's avatar
fuyanbin committed
44
45
        rm -rf "$SMALLP_PATH"
        mkdir "$SMALLP_PATH"
fuyanbin's avatar
fuyanbin committed
46
47
        if [ -f /system/bin/unzip ]
        then
fuyanbin's avatar
fuyanbin committed
48
49
            unzip /system/bin/hugep-all.zip -d "$SMALLP_PATH"
            unzip /system/bin/manager_bin_file.zip -d "$SMALLP_PATH"
fuyanbin's avatar
fuyanbin committed
50
        else
fuyanbin's avatar
fuyanbin committed
51
52
            unzip_go -file /system/bin/hugep-all.zip -dst "$SMALLP_PATH"
            unzip_go -file /system/bin/manager_bin_file.zip -dst "$SMALLP_PATH"
fuyanbin's avatar
fuyanbin committed
53
54
        fi

fuyanbin's avatar
fuyanbin committed
55
56
57
58
        if [ -e /system/bin/hugep-start.sh ]
        then
            cp /system/bin/hugep-start.sh  "$SMALLP_PATH"/hugep-star.sh
        fi
fuyanbin's avatar
fuyanbin committed
59
    else
fuyanbin's avatar
fuyanbin committed
60
        return 1
fuyanbin's avatar
fuyanbin committed
61
    fi
fuyanbin's avatar
fuyanbin committed
62
}
63

fuyanbin's avatar
fuyanbin committed
64
65
need_intall() {
    if [ -e /system/.androidrom  ]
66
    then
fuyanbin's avatar
fuyanbin committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
        if [ ! -d "$SMALLP_PATH" ]
        then
            return 0
        fi
        version=$(/system/bin/jqgo 'dianxinfs' < "$SMALLP_PATH"/config.json)
        if [ -z "$version" ]
        then
            return 0
        fi
        if [ ! -f "${SMALLP_PATH}/dianxinfs_arm32_${version}/writable/.deviceID" ]
        then
            return 0
        fi

        if ! grep -q "^32_" "${SMALLP_PATH}/dianxinfs_arm32_${version}/writable/.deviceID" 2>/dev/null
        then
            return 0
        fi
85
    fi
fuyanbin's avatar
fuyanbin committed
86
87
    return 3
}
88

fuyanbin's avatar
fuyanbin committed
89
90
91
92
forever() {
    chmod 777 "${SMALLP_PATH}/hugep-start.sh"
    while true
    do
fuyanbin's avatar
fuyanbin committed
93
        pid=$(pgrep "hugep-start.sh")
fuyanbin's avatar
fuyanbin committed
94
        if [ -z "$pid" ]; then
fuyanbin's avatar
fuyanbin committed
95
            "${SMALLP_PATH}"/hugep-start.sh  > /dev/null 2>&1 &
fuyanbin's avatar
fuyanbin committed
96
97
        fi
        sleep 30
fuyanbin's avatar
fuyanbin committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    done
}

init

if need_intall
then
    if ! install
    then
        exit 3
    fi
fi

is_running
forever