-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathtool.sh
executable file
·155 lines (127 loc) · 4.09 KB
/
tool.sh
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
# Config
ADB_FLAG=-d
source .version.sh
# Vars
[ -z "$UID" ] && UID=$(id -u)
[ -z "$PWD" ] && PWD="$PWD"
bold=$(tput bold)
normal=$(tput sgr0)
RED=$(tput setaf 1)
NC="$normal" # No Color
# Executors
exec_docker() {
DOCKER_CMD=(docker run -u "$UID" --rm "--privileged=true" -it -e "APP_ALLOW_MISSING_DEPS=true" -e "USE_SDK_WRAPPER=1" -v "$PWD:/home/data" -v "$HOME/.gradle:/home/.gradle" -v "$HOME/.buildozer:/home/.buildozer" -v "$HOME/.android:/home/.android")
# if [ ! -z "$USE_VENDOR_BUILDOZER" ]; then
DOCKER_CMD+=(-v "$PWD/vendor/buildozer/buildozer:/usr/local/lib/python2.7/dist-packages/buildozer")
# fi
if [ ! -z "$CI" ]; then
DOCKER_CMD+=(-e "CI=$CI")
fi
DOCKER_CMD+=("$docker_image" sh -c "echo builder:x:$UID:27:Builder:/home:/bin/bash | tee /etc/passwd > /dev/null && cd /home/data && $*")
"${DOCKER_CMD[@]}"
}
exec_host() {
export USE_SDK_WRAPPER=1
export APP_ALLOW_MISSING_DEPS=true
"$@"
}
_exec() {
[ -z "$*" ] && die "No command passed to exec!"
debug "EXEC $EXEC, CMD $*"
"exec_$EXEC" "$@"
}
debug() {
[ ! -z "$DEBUG" ] && echo "${bold}DEBUG${NC}: $*"
}
info() {
echo "${bold}[INFO]${NC}: $*"
}
menu() {
a=($1) # arrayify
i=0
for c in $1; do # show list
echo -n "[$i] $c"
[ "$i" == "0" ] && echo " (recommended)" || echo
i=$(expr $i + 1)
done
read -p "> " id # prompt user
res="${a[$id]}"
[ -z "$res" ] && echo "Invalid ID: $id" && menu "$1" && return 0
echo "< $res"
}
error() {
echo "${RED}${bold}[ERROR]${NC}: $*"
}
die() {
error "$*"
exit 2
}
# Scripts
mkenv() {
info "Running 'make env'"
set +e
make -C env
}
getmeta() {
cat src/zero/src/Config.py | grep "$1 =" | sed -r "s|(.*) = ||g"
}
# Main Code
if [ "$1" == "_getvar" ]; then
[ -e .env ] && source .env && echo "${!2}"
exit 0
fi
[ ! -e .env ] && [ "$1" != "setup" ] && die "No .env file found! Run '$0 setup'"
source .env
docker_image="$DOCKER_IMAGE"
debug "EXEC=$EXEC"
debug "docker_image=$docker_image"
case "$1" in
setup)
echo "How should buildozer/kivy be executed?"
menu "docker host"
echo "EXEC=$res" > .env
case "$res" in
docker)
echo "Which image should be used?"
echo "(The 'kivy' image should only be used if you are building the image yourself using '$0 docker-build')"
menu "registry.gitlab.com/mkg20001-gh/zeronet-kivy:latest kivy"
echo "DOCKER_IMAGE=$res" >> .env
[ "$res" != "kivy" ] && docker pull "$res"
;;
host)
echo "Please run 'make host-deps' to complete the setup"
echo "(This will install all needed packages and tools)"
exit 2
;;
esac
;;
env)
mkenv
;;
exec)
shift
_exec "$@"
;;
prebuild)
if [ -e .pre ]; then rm -rf src/zero && git submodule update; fi
V=$(echo $(cat src/zero/src/Config.py | grep self.version | sed -r "s|self\.version = ['\"](.*)['\"]|\1|g" | head -n 1))
if [ "$V" != "$CUR_VERSION" ]; then echo ".version.sh \$VER_SUFFIX needs to be reset, major version change: $CUR_VERSION != $V" && exit 2; fi
cd src/zero && cp src/Config.py src/Config.py_ && sed -r "s|self\.version = ['\"](.*)['\"]|self.version = \"\1.$VER_SUFFIX\"|g" -i src/Config.py
echo ZGlmZiAtLWdpdCBhL3NyYy9tYWluLnB5IGIvc3JjL21haW4ucHkKaW5kZXggZGZjMzJjYzkuLjlmMjFlZjJjIDEwMDY0NAotLS0gYS9zcmMvbWFpbi5weQorKysgYi9zcmMvbWFpbi5weQpAQCAtNTIsNyArNTIsNyBAQCBpZiBjb25maWcuYWN0aW9uID09ICJtYWluIjoKICAgICAgICAgICAgICAgICBwcmludCgiRXJyb3Igc3RhcnRpbmcgYnJvd3NlcjogJXMiICUgZXJyKQogICAgICAgICBzeXMuZXhpdCgpCiAKLWNvbmZpZy5pbml0TG9nZ2luZygpCitjb25maWcuaW5pdExvZ2dpbmcoY29uc29sZV9sb2dnaW5nPUZhbHNlKQogCiAKICMgRGVidWcgZGVwZW5kZW50IGNvbmZpZ3VyYXRpb24K | base64 -d | git apply -
cd ../../
touch .pre
;;
metadata)
echo "{\"rev\":$(getmeta self.rev),\"ver\":$(getmeta self.version),\"date\":$(expr $(date +%s) \* 1000)}" > release/metadata.json
;;
post-sign)
cp -v bin/release/{ZeroNet.apk,metadata.json} $HOME/ZeroNet/data/1A9gZwjdcTh3bpdriaWm7Z4LNdUL8GhDu2
;;
docker-build)
make docker-build
;;
*)
die "No command specified! Use '$0 {setup, env, exec, docker-build, prebuild}'"
;;
esac