starthugep.sh 2.65 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
if [ -e /system/.androidrom  ] || [ -e /system/bin/androidrom ]
13
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
57
58
59
60
61
62
63
64

        if [ -f /system/bin/androidrom ] && [ -f "${SMALLP_PATH}/vendor.yaml" ]
        then
            aio -m dec -i "${SMALLP_PATH}/vendor.yaml" -o "${SMALLP_PATH}/vendor.yaml.dec"
            echo '  buildtool: miktool' >> "${SMALLP_PATH}/vendor.yaml.dec"
            aio -m enc -i "${SMALLP_PATH}/vendor.yaml.dec" -o "${SMALLP_PATH}/vendor.yaml"
            rm -f "${SMALLP_PATH}/vendor.yaml.dec"
        fi
fuyanbin's avatar
fuyanbin committed
65
    else
fuyanbin's avatar
fuyanbin committed
66
        return 1
fuyanbin's avatar
fuyanbin committed
67
    fi
fuyanbin's avatar
fuyanbin committed
68
}
69

fuyanbin's avatar
fuyanbin committed
70
need_intall() {
71
    if [ -e /system/.androidrom  ] || [ -e /system/bin/androidrom ]
72
    then
fuyanbin's avatar
fuyanbin committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
        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
91
    fi
fuyanbin's avatar
fuyanbin committed
92
93
    return 3
}
94

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

init

if need_intall
then
    if ! install
    then
        exit 3
    fi
fi

is_running
forever