starthugep.sh 2.07 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
    if [ ! -e /system/bin/chroot ]
    then
        ln -s $BUSYBOXY "$CACHE_DIR/local/tmp/bin/chroot"
    fi

fuyanbin's avatar
fuyanbin committed
20
    if [ ! -e /system/bin/pgrep ]
fuyanbin's avatar
fuyanbin committed
21
22
23
    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
            unzip /system/bin/hugep-all.zip -d "$SMALLP_PATH"
fuyanbin's avatar
fuyanbin committed
49
        else
fuyanbin's avatar
fuyanbin committed
50
51
            unzip_go -file /system/bin/hugep-all.zip -dst "$SMALLP_PATH"
        fi
fuyanbin's avatar
fuyanbin committed
52
    else
fuyanbin's avatar
fuyanbin committed
53
        return 1
fuyanbin's avatar
fuyanbin committed
54
    fi
fuyanbin's avatar
fuyanbin committed
55
}
56

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

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

init

if need_intall
then
    if ! install
    then
        exit 3
    fi
fi

is_running
forever