-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
112 lines (92 loc) · 3.26 KB
/
deploy.sh
File metadata and controls
112 lines (92 loc) · 3.26 KB
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
#!/bin/bash
set -e
# Assign the absolute path of pwd to DEPLOY_DIR
DEPLOY_TOOL_DIR=$(cd `dirname $0`; pwd)
# Update the system
# Install dependencies
sudo apt-get update && sudo apt install build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev \
libffi-dev liblzma-dev supervisor autoconf automake libtool libglib2.0-dev -y
# 安装bluez-tools
retry_count=0
max_retry=3
while [ $retry_count -lt $max_retry ]; do
if [ -d "bluez-tools" ]; then
echo "Directory 'bluez-tools' already exists"
else
git clone https://github.com/khvzak/bluez-tools
fi
cd bluez-tools
./autogen.sh
./configure
make
sudo make install
if [ $? -eq 0 ]; then
break
else
echo "Installation failed, retrying..."
retry_count=$((retry_count+1))
fi
done
if [ $retry_count -eq $max_retry ]; then
echo "Installation failed after $max_retry attempts"
exit 1
fi
# Clone the code repository
cd $HOME
# Check if the "aily-config-service" directory already exists, skip if it does
if [ -d "aily-config-service" ]; then
echo "Directory 'aily-config-service' already exists"
else
git clone -b py2 https://github.com/ailyProject/aily-config-service.git
fi
cd aily-config-service
git config pull.rebase false
git pull
# Create a virtual environment and install dependencies
python3 -m venv .venv
.venv/bin/pip install -r requirements.pip
cp .env.sample .env
if [ -d "../aily" ]; then
echo "Directory 'aily' already exists"
else
mkdir ../aily
cp $DEPLOY_TOOL_DIR/files/aily/.env.sample ../aily/.env
fi
# Get the current Python version
PYTHON_VERSION=$(python3 -V | awk '{print "python" substr($2, 1, length($2)-2)}')
echo "Current Python version: $PYTHON_VERSION"
# # Fix the bug in pybleno
# cp $DEPLOY_TOOL_DIR/files/BluetoothHCI.py .venv/lib/$PYTHON_VERSION/site-packages/pybleno/hci_socket/BluetoothHCI/
# if [ -f "/etc/systemd/system/bluetools.service" ]; then
# echo "Deploy tool file exists"
# else
# sudo cp $HOME/aily-config-service/systemd/bluetools.service /etc/systemd/system/
# sudo systemctl start bluetools.service
# sudo systemctl enable bluetools.service
# fi
# Configure supervisor
SUPERVISOR_CONF_DIR="/etc/supervisor/conf.d"
SUPERVISOR_CONF_FILE="supervisor/ailyconf.conf"
BLUETOOL_CONF_FILE="supervisor/bluetools.conf"
echo "[program: ailyconf]" > $SUPERVISOR_CONF_FILE
echo "command = $HOME/aily-config-service/.venv/bin/python main.py" >> $SUPERVISOR_CONF_FILE
echo "directory = $HOME/aily-config-service" >> $SUPERVISOR_CONF_FILE
echo "user = root" >> $SUPERVISOR_CONF_FILE
echo "autostart = true" >> $SUPERVISOR_CONF_FILE
echo "autorestart = true" >> $SUPERVISOR_CONF_FILE
echo "stdout_logfile = /tmp/ailyconf.log" >> $SUPERVISOR_CONF_FILE
echo "stdout_logfile_maxbytes = 1MB" >> $SUPERVISOR_CONF_FILE
echo "stderr_logfile = /tmp/ailyconf-error.log" >> $SUPERVISOR_CONF_FILE
echo "stderr_logfile_maxbytes = 1MB" >> $SUPERVISOR_CONF_FILE
sudo cp $SUPERVISOR_CONF_FILE $SUPERVISOR_CONF_DIR
# deploy bluetool
sudo cp $BLUETOOL_CONF_FILE $SUPERVISOR_CONF_DIR
sudo supervisorctl reload
# Check if the command executed successfully
if [ $? -eq 0 ]; then
echo "Deployment successful"
else
echo "Deployment failed"
fi