forked from klatremis/esphome-for-deye
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sh
executable file
·112 lines (86 loc) · 2.72 KB
/
build.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
#!/bin/bash
# Define project
project="esphome-for-deye"
# Store current path
currentpath=$(pwd)
# Get Parent path
#parentpath=$(dirname $currentpath)
# Define board
board="esp32-s3-devkitc-1" # Works for Atom S3 Lite
# Define variant
variant="esp32s3" # Works for Atom S3 Lite
# Build folder
buildpath="$HOME/ESPHome"
mkdir -p $buildpath
cd $buildpath
# Create venv
#sudo apt-get -y install python3.11-venv
python3 -m venv ./venv
# Active venv
source venv/bin/activate
# Install ESPHome
pip3 install esphome # Optionally specify the desired version
# Upgrade ESPHome
pip install --upgrade esphome # Force upgrade to latest version
# Clone external component if needed
version=$(date +%Y%m%d)
###git clone https://github.com/syssi/esphome-jk-bms.git esphome-jk-bms-master
###cd esphome-jk-bms-master
###version="1.17.5"
###if [[ ! -f "esphome-jk-bms-can-$version.tar.gz" ]]
###then
### wget https://github.com/Sleeper85/esphome-jk-bms-can/archive/refs/tags/V$version.tar.gz -O esphome-jk-bms-can-$version.tar.gz
###fi
###
###if [[ ! -d "esphome-jk-bms-can-$version" ]]
###then
### tar xvf esphome-jk-bms-can-$version.tar.gz
###fi
###cd $project-$version
mkdir -p $project
cd $project
# Configure Device based on Database
source $currentpath/devices.sh
# Set Secrets
source $currentpath/secrets.sh
# Define ESPHome Configuration File
esphomeconfig="esphome-config-${profile}.yaml"
# Copy required Files to build Folder
cp $currentpath/$esphomeconfig ./$esphomeconfig
cp $currentpath/*.yaml ./
# Copy Required CSS/JS For WebServer into BuildFolder
cp -r $currentpath/web_server ./
# Copy Required Subpackages for Configuration
cp -r $currentpath/boards ./
cp -r $currentpath/config ./
cp -r $currentpath/modules ./
# Execute Text Replacement
source $currentpath/functions.sh
#replace_text "./$esphomeconfig" "board" "$board"
#replace_text "./$esphomeconfig" "variant" "$variant"
files=$(find ./ -iname "*.yaml")
for file in $files
do
replace_text ./$file "board" "${board}"
replace_text ./$file "variant" "${variant}"
replace_text ./$file "mqtt_topic_prefix" "${topic_prefix}"
done
echo "Replaced Text"
# Clean Build Files to make sure all new/updated Entities Appear Correctly
#esphome clean $esphomeconfig
# Build ESPHome
esphome run $esphomeconfig # Normal Mode
#esphome --verbose run $esphomeconfig # Debug Mode
# Manage errors & try again
echo -e "In case of errors, it is suggested to run: esphome clean.\n"
read -p "Do you want to clean the build files & try build again: [Y/N] " tryagain
echo -e "\n"
# Clean build files and try again ?
if [ "$tryagain" == "Y" ] || [ "$tryagain" == "y" ]
then
# Run clean & try again"
esphome clean $esphomeconfig
esphome run $esphomeconfig
fi
# Change back to currentpath
cd $currentpath