Skip to content

Commit 4444ea5

Browse files
committed
refactor: refactor install chain
Includes: * refactor of install.sh, splitting it to libs * fix of custompios module according to install changes * added test script to verify install * refactor of `make config` script Signed-off-by: Stephan Wendel <[email protected]> Signed-off-by: Stephan Wendel <[email protected]>
1 parent 1df3f43 commit 4444ea5

21 files changed

+1009
-696
lines changed

.gitignore

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ ERRORS.txt
1313
# Ignore leftover
1414
leftover*
1515

16-
#Ignore Test Files
17-
test*
18-
1916
# tmp file workaround
2017
lost*
2118

@@ -30,3 +27,6 @@ bin/rtsp-simple-server/*.yml
3027
# Ignore Config for Intsaller
3128
tools/config.local
3229
tools/.config
30+
31+
# Ignore pkglist
32+
tools/pkglist.sh

Makefile

+20-38
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,46 @@
1-
#### webcamd - A webcam Service for multiple Cams and Stream Services.
1+
#### crowsnest - A webcam Service for multiple Cams and Stream Services.
22
####
33
#### Written by Stephan Wendel aka KwadFan <[email protected]>
4-
#### Copyright 2021 - 2022
4+
#### Copyright 2021 - till today
55
#### https://github.com/mainsail-crew/crowsnest
66
####
77
#### This File is distributed under GPLv3
88
####
99

10-
.PHONY: build buildclean config help install unsinstall update
10+
#### Self-Documenting Makefile
11+
#### This is based on https://gellardo.github.io/blog/posts/2021-06-10-self-documenting-makefile/
1112

12-
# Setup
13-
USER = $(shell whoami)
14-
BIN_FOLDER = bin
13+
.DEFAULT_GOAL := help
14+
.PHONY: help
1515

16-
all: help
17-
18-
help:
19-
@echo "This is intended to install crowsnest."
20-
@echo ""
21-
@echo "Some Parts need 'sudo' privileges."
22-
@echo "You'll be asked for password, if needed."
23-
@echo ""
24-
@echo " Usage: make [action]"
25-
@echo ""
26-
@echo " Available actions:"
27-
@echo ""
28-
@echo " config Configures Installer"
29-
@echo " install Installs crowsnest (needs sudo)"
30-
@echo " uninstall Uninstalls crowsnest (needs sudo)"
31-
@echo " build builds binaries"
32-
@echo " buildclean cleans binaries (for recompile)"
33-
@echo " clean Removes Installer config"
34-
@echo " update Pulls latest updates from repository"
35-
@echo ""
36-
37-
install:
16+
install: ## Install crowsnest (needs leading sudo)
3817
@bash -c 'tools/install.sh'
3918

40-
uninstall:
19+
uninstall: ## Uninstall crowsnest
4120
@bash -c 'tools/uninstall.sh'
4221

43-
build:
22+
build: ## Compile backends / streamer
4423
bash -c 'bin/build.sh --build'
4524

46-
buildclean:
25+
buildclean: ## Clean backends / streamer (for rebuilding)
4726
bash -c 'bin/build.sh --clean'
4827

49-
clean:
28+
clean: ## Clean .config
5029
@if [ -f tools/.config ]; then rm -f tools/.config; fi
51-
@echo "Removed installer config file ..."
30+
@printf "Removed installer config file ...\n"
5231

53-
config:
32+
config: ## Configure crowsnest installer
5433
@bash -c 'tools/configure.sh'
5534

56-
update:
35+
help: ## Shows this help
36+
@printf "crowsnest - A webcam Service for multiple Cams and Stream Services.\n"
37+
@printf "Usage:\n\n"
38+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
39+
40+
update: ## Update crowsnest (fetches and pulls repository changes)
5741
@git fetch && git pull
5842

59-
report:
43+
report: ## Generate report.txt
6044
@if [ -f ~/report.txt ]; then rm -f ~/report.txt; fi
6145
@bash -c 'tools/dev-helper.sh -a >> ~/report.txt'
6246
@sed -ri 's/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g' ~/report.txt
63-
64-

custompios/README.md

-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ the folder you configured above.\
2828
Please feel free to Pull Request your config!
2929
I will add them.
3030

31-
To ensure raspicam fix is applied during Image build set
32-
33-
CROWSNEST_RASPICAMFIX="1"
34-
35-
This only works for Raspberry Pi OS! Will modify that in the future to support build images for other SBC's
36-
3731
Last but not least:
3832

3933
CROWSNEST_ADD_CROWSNEST_MOONRAKER="1"

custompios/crowsnest/config

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#### crowsnest - A webcam Service for multiple Cams and Stream Services.
33
####
44
#### Written by Stephan Wendel aka KwadFan <[email protected]>
5-
#### Copyright 2021 - 2022
5+
#### Copyright 2021 - till today
66
#### https://github.com/mainsail-crew/crowsnest
77
####
88
#### This File is distributed under GPLv3

custompios/crowsnest/start_chroot_script

+20-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,25 @@ install_cleanup_trap
2020

2121
# Module only Variables
2222
CN_BUILD_PACKAGE_FILE="/tmp/cn_packages.lst"
23-
CN_BUILD_INSTALL_SH="/home/${BASE_USER}/crowsnest/tools/install.sh"
23+
24+
# Helper Func
25+
is_raspbian() {
26+
if [[ -f /boot/config.txt ]] && [[ -f /etc/rpi-issue ]]; then
27+
echo "1"
28+
else
29+
echo "0"
30+
fi
31+
}
32+
33+
get_pkglist() {
34+
if [[ "$(is_raspbian)" = "1" ]]; then
35+
CN_BUILD_INSTALL_SH="/home/${BASE_USER}/crowsnest/tools/libs/pkglist-rpi.sh"
36+
fi
37+
if [[ "$(is_raspbian)" = "0" ]]; then
38+
CN_BUILD_INSTALL_SH="/home/${BASE_USER}/crowsnest/tools/libs/pkglist-generic.sh"
39+
fi
40+
}
41+
2442

2543
echo_green "Installing crowsnest ..."
2644

@@ -38,6 +56,7 @@ gitclone CROWSNEST_REPO crowsnest
3856

3957
## Step 3: grep PKGLIST from install.sh for dependencies
4058
echo_green "Generating packages file ..."
59+
get_pkglist
4160
grep "PKGLIST=" "${CN_BUILD_INSTALL_SH}" >> "${CN_BUILD_PACKAGE_FILE}"
4261

4362
## Step 4: Rename PKGLIST to Module usable Var

resources/crowsnest.conf

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
log_path: %LOGPATH%
2828
log_level: verbose # Valid Options are quiet/verbose/debug
2929
delete_log: false # Deletes log on every restart, if set to true
30+
no_proxy: false
3031

3132
[cam 1]
3233
mode: mjpg # mjpg/multi - Multi uses webrtc, mjpg and snapshots at the same time

resources/crowsnest.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CROWSNEST_ARGS="-c %CONFPATH%/crowsnest.conf"

resources/crowsnest.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ User=%USER%
2525
RemainAfterExit=Yes
2626
WorkingDirectory=/home/%USER%/crowsnest
2727
EnvironmentFile=%ENV%
28-
ExecStart= /usr/local/bin/crowsnest $CROWSNEST_ARGS
28+
ExecStart=/usr/local/bin/crowsnest $CROWSNEST_ARGS
2929
Restart=on-failure
3030
RestartSec=5

resources/moonraker_update.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ type: git_repo
55
path: ~/crowsnest
66
origin: https://github.com/mainsail-crew/crowsnest.git
77
managed_services: crowsnest
8-
install_script: tools/install.sh
8+
install_script: tools/pkglist.sh

tools/configure.sh

+38-15
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313

1414
# Exit on errors
1515
set -Ee
16+
set -x
17+
1618

1719
# Global Vars
1820
CN_CONFIG_USER=$(whoami)
1921
CN_CONFIG_CONFIGFILE="tools/.config"
2022
CN_CONFIG_ROOTPATH="/home/${CN_CONFIG_USER}/printer_data"
21-
CN_CONFIG_CONFIGPATH="${CN_CONFIG_ROOTPATH}/config"
22-
CN_CONFIG_LOGPATH="${CN_CONFIG_ROOTPATH}/logs"
23-
CN_CONFIG_ENVPATH="${CN_CONFIG_ROOTPATH}/systemd"
24-
CN_MOONRAKER_CONFIG_PATH="${CN_CONFIG_CONFIGPATH}/moonraker.conf"
23+
# CN_CONFIG_CONFIGPATH="${CN_CONFIG_ROOTPATH}/config"
24+
# CN_CONFIG_LOGPATH="${CN_CONFIG_ROOTPATH}/logs"
25+
# CN_CONFIG_ENVPATH="${CN_CONFIG_ROOTPATH}/systemd"
26+
# CN_MOONRAKER_CONFIG_PATH="${CN_CONFIG_CONFIGPATH}/moonraker.conf"
2527
CN_USTREAMER_REPO="https://github.com/pikvm/ustreamer.git"
2628
CN_USTREAMER_BRANCH="master"
2729
CN_CAMERA_STREAMER_REPO="https://github.com/ayufan-research/camera-streamer.git"
@@ -56,6 +58,14 @@ default_path_msg() {
5658
echo -e "Hit ENTER to use default."
5759
}
5860

61+
root_path_msg() {
62+
header_msg
63+
echo -e "Please specify path to your 'printer_data' root path\n"
64+
echo -e "For example: /home/pi/voron_data or /home/kwad/ender_data"
65+
echo -e "\t\e[34mNOTE:\e[0m File names are hardcoded! Also skip trailing backslash!"
66+
echo -e "\tDefault: \e[32m${CN_CONFIG_ROOTPATH}\e[0m\n"
67+
}
68+
5969
config_path_msg() {
6070
header_msg
6171
echo -e "Please specify path to config file (crowsnest.conf)\n"
@@ -149,11 +159,31 @@ create_config_header() {
149159
} >> "${CN_CONFIG_CONFIGFILE}"
150160
}
151161

162+
specify_root_path() {
163+
local reply
164+
root_path_msg
165+
default_path_msg
166+
read -erp "Please enter path: " reply
167+
if [[ -z "${reply}" ]]; then
168+
echo -e "CROWSNEST_CONFIG_PATH=\"${CN_CONFIG_CONFIGPATH}\"" >> \
169+
"${CN_CONFIG_CONFIGFILE}"
170+
return 0
171+
fi
172+
if [[ -n "${reply}" ]]; then
173+
CN_CONFIG_ROOTPATH="${reply}"
174+
CN_CONFIG_CONFIGPATH="${CN_CONFIG_ROOTPATH}/config"
175+
CN_CONFIG_LOGPATH="${CN_CONFIG_ROOTPATH}/logs"
176+
CN_CONFIG_ENVPATH="${CN_CONFIG_ROOTPATH}/systemd"
177+
CN_MOONRAKER_CONFIG_PATH="${CN_CONFIG_CONFIGPATH}/moonraker.conf"
178+
return 0
179+
fi
180+
}
181+
152182
specify_config_path() {
153183
local reply
154184
config_path_msg
155185
default_path_msg
156-
read -erp "Please enter path: " reply
186+
read -erp "Please enter path: " -i "${CN_CONFIG_CONFIGPATH}" reply
157187
if [[ -z "${reply}" ]]; then
158188
echo -e "CROWSNEST_CONFIG_PATH=\"${CN_CONFIG_CONFIGPATH}\"" >> \
159189
"${CN_CONFIG_CONFIGFILE}"
@@ -170,7 +200,7 @@ specify_log_path() {
170200
local reply
171201
log_path_msg
172202
default_path_msg
173-
read -erp "Please enter path: " reply
203+
read -erp "Please enter path: " -i "${CN_CONFIG_LOGPATH}" reply
174204
if [[ -z "${reply}" ]]; then
175205
echo -e "CROWSNEST_LOG_PATH=\"${CN_CONFIG_LOGPATH}\"" >> \
176206
"${CN_CONFIG_CONFIGFILE}"
@@ -186,7 +216,7 @@ specify_env_path() {
186216
local reply
187217
env_path_msg
188218
default_path_msg
189-
read -erp "Please enter path: " reply
219+
read -erp "Please enter path: " -i "${CN_CONFIG_ENVPATH}" reply
190220
if [[ -z "${reply}" ]]; then
191221
echo -e "CROWSNEST_ENV_PATH=\"${CN_CONFIG_ENVPATH}\"" >> \
192222
"${CN_CONFIG_CONFIGFILE}"
@@ -223,22 +253,15 @@ add_moonraker_entry() {
223253

224254
### Main func
225255
main() {
226-
# Step 1: Welcome Message
227256
welcome_msg
228257
continue_config
229-
# Step 2: Check for existing file
230258
check_config_file
231-
# Step 3: Create config header
232259
create_config_header
233-
# Step 4: Specify config file path.
260+
specify_root_path
234261
specify_config_path
235-
# Step 5: Specify log file path.
236262
specify_log_path
237-
# Step 6: Specify env path.
238263
specify_env_path
239-
# Step 7: Moonraker entry
240264
add_moonraker_entry
241-
# Step 8: Display finished message
242265
goodbye_msg
243266
}
244267

0 commit comments

Comments
 (0)