-
Notifications
You must be signed in to change notification settings - Fork 4
/
project.sh
executable file
·88 lines (72 loc) · 2.01 KB
/
project.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
#!/bin/bash
if [ -n "$PREFIX" ] && [ "$PREFIX" = "/data/data/com.termux/files/usr" ]
then
_IS_TERMUX=1
else
_IS_TERMUX=0
fi
log_info() {
echo -e "🤖 \e[0;33m${1}\e[0;0m"
}
command_exists() {
command -v "$1" &> /dev/null
}
init() {
export PROJECT_DIR=$(pwd)
export ZRB_INIT_SCRIPTS=""
export ZRB_INIT_MODULES=""
log_info "Setting project directory to ${PROJECT_DIR}"
if ! command_exists poetry
then
log_info 'Install poetry'
pip install --upgrade pip setuptools
pip install "poetry"
fi
if [ ! -d "${PROJECT_DIR}/.venv" ]
then
log_info 'Creating virtual environment'
python -m venv "${PROJECT_DIR}/.venv"
fi
log_info 'Activating virtual environment'
source "${PROJECT_DIR}/.venv/bin/activate"
}
reload() {
if [ ! -f "${PROJECT_DIR}/.env" ]
then
log_info 'Creating project configuration (.env)'
cp "${PROJECT_DIR}/template.env" "${PROJECT_DIR}/.env"
fi
log_info 'Loading project configuration (.env)'
source "${PROJECT_DIR}/.env"
if [ "$_IS_TERMUX" = "1" ]
then
log_info 'Updating Build Flags'
_OLD_CFLAGS="$CFLAGS"
_OLD_LDFLAGS="$LDFLAGS"
CFLAGS+=" -U__ANDROID_API__ -D__ANDROID_API__=30 -include unistd.h -Wno-incompatible-function-pointer-types"
LDFLAGS+=" -llog"
# export CFLAGS="$_OLD_CFLAGS -Wno-incompatible-function-pointer-types" # ruamel.yaml need this.
fi
log_info 'Install'
poetry lock --no-update
poetry install
if [ "$_IS_TERMUX" = "1" ]
then
log_info 'Restoring Build Flags'
export CFLAGS="$_OLD_CFLAGS"
export LDFLAGS="$_OLD_LDFLAGS"
fi
case $(ps -p $$ | awk 'NR==2 {print $4}') in
*zsh)
log_info "Setting up shell completion for zsh"
source <(zrb shell autocomplete zsh)
;;
*bash)
log_info "Setting up shell completion for bash"
source <(zrb shell autocomplete bash)
;;
esac
}
init
reload
log_info 'Happy Coding :)'