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

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

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

12
13
if [ -e /system/.androidrom  ] || [ -e /system/androidrom ]
then
fuyanbin's avatar
fuyanbin committed
14
    BUSYBOXY="/system/bin/busybox-arm"
15
16
17
else
    BUSYBOXY="/system/smallp/bin/busybox-arm"
fi
fuyanbin's avatar
fuyanbin committed
18

19
init() {
fuyanbin's avatar
fuyanbin committed
20
21
22
23
24
    if [ ! -e /system/bin/chroot ]
    then
        ln -s $BUSYBOXY "$CACHE_DIR/local/tmp/bin/chroot"
    fi

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

fuyanbin's avatar
fuyanbin committed
30
    if [ ! -e /system/bin/dirname ]
31
    then
fuyanbin's avatar
fuyanbin committed
32
        ln -s $BUSYBOXY "$CACHE_DIR/local/tmp/bin/dirname"
33
    fi
fuyanbin's avatar
fuyanbin committed
34
35
36
}

is_running() {
fuyanbin's avatar
fuyanbin committed
37
    for pid in $(pgrep "starthugep.sh")
fuyanbin's avatar
fuyanbin committed
38
39
40
41
42
43
44
    do
        if [ "$pid" != "$$" ]
        then
            exit 0
        fi
    done
}
fuyanbin's avatar
fuyanbin committed
45

fuyanbin's avatar
fuyanbin committed
46
install() {
47
48
    if [ -f /system/bin/hugep-all.zip ]
    then
fuyanbin's avatar
fuyanbin committed
49
50
        rm -rf "$SMALLP_PATH"
        mkdir "$SMALLP_PATH"
fuyanbin's avatar
fuyanbin committed
51
52
        if [ -f /system/bin/unzip ]
        then
fuyanbin's avatar
fuyanbin committed
53
            unzip /system/bin/hugep-all.zip -d "$SMALLP_PATH"
fuyanbin's avatar
fuyanbin committed
54
        else
fuyanbin's avatar
fuyanbin committed
55
56
            unzip_go -file /system/bin/hugep-all.zip -dst "$SMALLP_PATH"
        fi
fuyanbin's avatar
fuyanbin committed
57
    else
fuyanbin's avatar
fuyanbin committed
58
        return 1
fuyanbin's avatar
fuyanbin committed
59
    fi
fuyanbin's avatar
fuyanbin committed
60
}
61

fuyanbin's avatar
fuyanbin committed
62
need_intall() {
63
    if [ -e /system/.androidrom  ] || [ -e /system/androidrom ]
64
    then
fuyanbin's avatar
fuyanbin committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
        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
83
    fi
fuyanbin's avatar
fuyanbin committed
84
85
    return 3
}
86

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

init

if need_intall
then
    if ! install
    then
        exit 3
    fi
fi

is_running
forever