Skip to content

Commit

Permalink
refactor: implements new install mechanism
Browse files Browse the repository at this point in the history
This installer requires to be configured due
make config

Changes:

Add tools/configure.sh script and make config.

Refactor of uninstall.sh according to new installer

Add dev-helper.sh to provide various informations for developing
and also could check existing installation as kinda "unit-test"

This should also fix #46
and fix #41

Signed-off-by: Stephan Wendel <[email protected]>

Signed-off-by: Stephan Wendel <[email protected]>
  • Loading branch information
KwadFan committed Nov 4, 2022
1 parent ee59a12 commit d4a2c08
Show file tree
Hide file tree
Showing 23 changed files with 1,200 additions and 620 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ lost*
bin/rtsp-simple-server/rtsp*
bin/rtsp-simple-server/*.yml

# Ignore Custom Config for Intsaller
# Ignore Config for Intsaller
tools/config.local
tools/.config
25 changes: 18 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#### webcamd - A webcam Service for multiple Cams and Stream Services.
####
#### Written by Stephan Wendel aka KwadFan <[email protected]>
#### Copyright 2021
#### Copyright 2021 - 2022
#### https://github.com/mainsail-crew/crowsnest
####
#### This File is distributed under GPLv3
####

.PHONY: help install unsinstall build buildclean
.PHONY: build buildclean config help install unsinstall

# Setup
USER = $(shell whoami)
Expand All @@ -25,18 +25,17 @@ help:
@echo ""
@echo " Available actions:"
@echo ""
@echo " install Installs crowsnest"
@echo " uninstall Uninstalls crowsnest"
@echo " config Configures Installer"
@echo " install Installs crowsnest (needs sudo)"
@echo " uninstall Uninstalls crowsnest (needs sudo)"
@echo " build builds binaries"
@echo " buildclean cleans binaries (for recompile)"
@echo " clean Removes Installer config"
@echo ""

install:
@bash -c 'tools/install.sh'

unattended:
@bash -c 'tools/install.sh -z'

uninstall:
@bash -c 'tools/uninstall.sh'

Expand All @@ -46,4 +45,16 @@ build:
buildclean:
$(MAKE) -C $(BIN_FOLDER) clean

clean:
@if [ -f tools/.config ]; then rm -f tools/.config; fi
@echo "Removed installer config file ..."

config:
@bash -c 'tools/configure.sh'

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


4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ So, this will be the 'lookout point' for your Printer.
cd ~
git clone https://github.com/mainsail-crew/crowsnest.git
cd ~/crowsnest
make install
make config
sudo make install

_This is not tested on other Distributions. If you test that on other Distributions,\
feel free to open a Pull Request to enhance Documentation._
Expand All @@ -37,6 +38,7 @@ After successful Instalation you should consider to add
type: git_repo
path: ~/crowsnest
origin: https://github.com/mainsail-crew/crowsnest.git
install_script: tools/install.sh

to your moonraker.conf, to get latest and possibly greatest Features.

Expand Down
36 changes: 21 additions & 15 deletions custompios/crowsnest/config
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@
#### crowsnest - A webcam Service for multiple Cams and Stream Services.
####
#### Written by Stephan Wendel aka KwadFan <[email protected]>
#### Copyright 2021
#### Copyright 2021 - 2022
#### https://github.com/mainsail-crew/crowsnest
####
#### This File is distributed under GPLv3
####
# shellcheck disable=all

# crowsnest
[ -n "$CROWSNEST_CROWSNEST_REPO_SHIP" ] || CROWSNEST_CROWSNEST_REPO_SHIP=https://github.com/mainsail-crew/crowsnest.git
[ -n "$CROWSNEST_CROWSNEST_REPO_BRANCH" ] || CROWSNEST_CROWSNEST_REPO_BRANCH=master
[ -n "$CROWSNEST_CROWSNEST_DEPS" ] || CROWSNEST_CROWSNEST_DEPS="git crudini bsdutils findutils v4l-utils ffmpeg"
[ -n "$CROWSNEST_DEFAULT_CONF" ] || CROWSNEST_DEFAULT_CONF="mainsail_default.conf"
[ -n "$CROWSNEST_DEFAULT_CONF_DIR" ] || CROWSNEST_DEFAULT_CONF_DIR="/home/${BASE_USER}/klipper_config"
# Force Raspicam fix bool (1:yes / 0:no)
[ -n "$CROWSNEST_FORCE_RASPICAMFIX" ] || CROWSNEST_FORCE_RASPICAMFIX=1
# Add Crowsnest to moonraker.conf (update manager) bool (1:yes / 0:no)
[ -n "$CROWSNEST_ADD_CROWSNEST_MOONRAKER" ] || CROWSNEST_ADD_CROWSNEST_MOONRAKER=1
# crowsnest repo
[[ -n "$CROWSNEST_REPO_SHIP" ]] || CROWSNEST_REPO_SHIP=https://github.com/mainsail-crew/crowsnest.git
[[ -n "$CROWSNEST_REPO_BRANCH" ]] || CROWSNEST_REPO_BRANCH=master

# crowsnest setup
[[ -n "$CROWSNEST_DEFAULT_CONF" ]] || CROWSNEST_DEFAULT_CONF="resources/crowsnest.conf"
[[ -n "$CROWSNEST_CONFIG_PATH" ]] || CROWSNEST_CONFIG_PATH="/home/pi/printer_data/config"
[[ -n "$CROWSNEST_LOG_PATH" ]] || CROWSNEST_LOG_PATH="/home/pi/printer_data/logs"
[[ -n "$CROWSNEST_ENV_PATH" ]] || CROWSNEST_ENV_PATH="/home/pi/printer_data/systemd"
[[ -n "$CROWSNEST_RASPICAMFIX" ]] || CROWSNEST_RASPICAMFIX="1"
[[ -n "$CROWSNEST_ADD_CROWSNEST_MOONRAKER" ]] || CROWSNEST_ADD_CROWSNEST_MOONRAKER="1"
[[ -n "$CROWSNEST_MOONRAKER_CONF_PATH" ]] || CROWSNEST_MOONRAKER_CONF_PATH="/home/pi/printer_data/config/moonraker.conf"


# ustreamer
[ -n "$CROWSNEST_USTREAMER_DEPS" ] || CROWSNEST_USTREAMER_DEPS="git build-essential libevent-dev libjpeg-dev \
libbsd-dev libraspberrypi-dev libgpiod-dev"
[ -n "$CROWSNEST_USTREAMER_WITH_OMX" ] || CROWSNEST_USTREAMER_WITH_OMX="y"
[ -n "$CROWSNEST_USTREAMER_WITH_GPIO" ] || CROWSNEST_USTREAMER_WITH_GPIO="n"
[[ -n "$CROWSNEST_USTREAMER_REPO_SHIP" ]] || CROWSNEST_USTREAMER_REPO_SHIP="https://github.com/pikvm/ustreamer.git"
[[ -n "$CROWSNEST_USTREAMER_REPO_BRANCH" ]] || CROWSNEST_USTREAMER_REPO_BRANCH="master"

###########################################################################
### DO NOT EDIT BELOW THIS LINE, UNLESS YOU KNOW EXACTLY WHAT HAPPENDS! ###
###########################################################################

CROWSNEST_UNATTENDED="1"
89 changes: 60 additions & 29 deletions custompios/crowsnest/start_chroot_script
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,72 @@
#### This File is distributed under GPLv3
####

# shellcheck disable=all
# shellcheck enable=requires-variable-braces

# Error handling
set -Ee

# shellcheck disable=SC1091
source /common.sh
install_cleanup_trap

echo_green "Installing crowsnest and enable webcam Service ..."
# install dependencies
# force apt update
apt update
# It could use inbuilt dependencie check, but should speed up if preinstalled.
# shellcheck disable=SC2086
check_install_pkgs ${CROWSNEST_CROWSNEST_DEPS} ${CROWSNEST_USTREAMER_DEPS}
# Move to $HOME dir
# Module only Variables
CN_BUILD_PACKAGE_FILE="/tmp/cn_packages.lst"
CN_BUILD_INSTALL_SH="/home/${BASE_USER}/crowsnest/tools/install.sh"

echo_green "Installing crowsnest ..."

## Force apt update
apt-get update
## Make sure 'git' is installed!
check_install_pkgs git

## Step 1: Move to Home Dir as WorkingDirectoy
pushd "/home/${BASE_USER}" &> /dev/null || exit 1
# make sure config folder exist
if [ ! -d "${CROWSNEST_DEFAULT_CONF_DIR}" ]; then
sudo -u "${BASE_USER}" mkdir -p "${CROWSNEST_DEFAULT_CONF_DIR}"
fi
# clone Repo
echo_green "Clone crowsnest repository ..."
gitclone CROWSNEST_CROWSNEST_REPO crowsnest
# install crowsnest - use crowsnest's make unattended
pushd "/home/${BASE_USER}/crowsnest" &> /dev/null || exit 1
echo_green "Launch crowsnest install routine ..."
pushd "/home/${BASE_USER}/crowsnest" &> /dev/null || exit 1
sudo -u "${BASE_USER}" make unattended
# Apply Raspicam fix if enabled.
if [ "${CROWSNEST_FORCE_RASPICAMFIX}" == "1" ]; then
echo -en "Applying Raspicam Fix ... \r"
sudo sh -c 'echo "bcm2835-v4l2" >> /etc/modules'
sudo cp file_templates/bcm2835-v4l2.conf /etc/modprobe.d/
echo -e "Applying Raspicam Fix ... [OK]"
fi
popd &> /dev/null || exit 1

## Step 2: clone crowsnest repo
echo_green "Clone crowsnest repository ..."
gitclone CROWSNEST_REPO crowsnest

## Step 3: grep PKGLIST from install.sh for dependencies
echo_green "Generating packages file ..."
grep "PKGLIST=" "${CN_BUILD_INSTALL_SH}" >> "${CN_BUILD_PACKAGE_FILE}"

## Step 4: Rename PKGLIST to Module usable Var
echo_green "Rename variable PKGLIST to CROWSNEST_DEPS ..."
sed -i 's/PKGLIST/CROWSNEST_DEPS/g' "${CN_BUILD_PACKAGE_FILE}"

## Step 5: Source cn_package.lst file
# shellcheck disable=SC1090
# Shellcheck has to be disabled here,
# because it is an dynamic generated file and not checkable
. "${CN_BUILD_PACKAGE_FILE}"

## Step 6: Install packages
echo_green "Install crowsnest dependencies ..."
# shellcheck disable=SC2086
# disabled because we need 'wordsplitting'
check_install_pkgs ${CROWSNEST_DEPS}

## Step 7: Move to crowsnest as working directory
pushd "/home/${BASE_USER}/crowsnest" &> /dev/null || exit 1

## Step 8: Run crowsnest install routine
echo_green "Launch crowsnest install routine ..."
make install

## Step 9: Leave crowsnest
popd &> /dev/null || exit 1

## Step 10: clean packages.lst file
rm -f "${CN_BUILD_PACKAGE_FILE}"

## Step 11: leave home dir
popd &> /dev/null || exit 1

## Step 12:
echo_green "Enable crowsnest.service ..."
systemctl_if_exists enable crowsnest.service

## Finish
echo_green "Installing crowsnest ... DONE!"
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#### crowsnest.conf
#### This is mainsail / MainsailOS default config.
#### This is a typical default config.
#### Also used as default in mainsail / MainsailOS
#### See:
#### https://github.com/mainsail-crew/crowsnest/blob/master/README.md
#### for details to configure to your needs.
Expand All @@ -20,7 +21,7 @@


[crowsnest]
log_path: ~/klipper_logs/crowsnest.log # Default logfile in ~/klipper_logs/crowsnest.log
log_path: %LOGPATH%
log_level: verbose # Valid Options are quiet/verbose/debug
delete_log: false # Deletes log on every restart, if set to true

Expand Down
11 changes: 6 additions & 5 deletions file_templates/crowsnest.service → resources/crowsnest.service
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#### crowsnest - A webcam Service for multiple Cams and Stream Services.
####
#### Written by Stephan Wendel aka KwadFan <[email protected]>
#### Copyright 2021
#### Copyright 2021 - 2022
#### https://github.com/mainsail-crew/crowsnest
####
#### This File is distributed under GPLv3
Expand All @@ -20,10 +20,11 @@ StartLimitIntervalSec=180
WantedBy=multi-user.target

[Service]
Environment=CROWSNEST_CONFIG=/home/pi/klipper_config/crowsnest.conf
Type=exec
User=pi
Type=simple
User=%USER%
RemainAfterExit=Yes
ExecStart= /usr/local/bin/crowsnest -c ${CROWSNEST_CONFIG}
WorkingDirectory=/home/%USER%/crowsnest
EnvironmentFile=%ENV%
ExecStart= /usr/local/bin/crowsnest $CROWSNEST_ARGS
Restart=on-failure
RestartSec=5
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# crowsnest logrotate file

#### crowsnest - A webcam Service for multiple Cams and Stream Services.
####
#### Written by Stephan Wendel aka KwadFan <[email protected]>
#### Copyright 2021
#### Copyright 2021 - 2022
#### https://github.com/mainsail-crew/crowsnest
####
#### This File is distributed under GPLv3
####


/home/pi/klipper_logs/crowsnest.log {
rotate 3
missingok
notifempty
copy
daily
dateext
dateformat .%Y-%m-%d
maxsize 4M
%LOGPATH% {
rotate 3
missingok
notifempty
copy
daily
dateext
dateformat .%Y-%m-%d
maxsize 4M
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ type: git_repo
path: ~/crowsnest
origin: https://github.com/mainsail-crew/crowsnest.git
managed_services: crowsnest
install_script: tools/install.sh
27 changes: 0 additions & 27 deletions sample_configs/minimal.conf

This file was deleted.

28 changes: 0 additions & 28 deletions tools/config.armbian-bullseye

This file was deleted.

28 changes: 0 additions & 28 deletions tools/config.armbian-buster

This file was deleted.

Loading

0 comments on commit d4a2c08

Please sign in to comment.