make install - updated

main
Steffen Pohle 3 weeks ago
parent 526e29739f
commit df5e657068

1
.gitignore vendored

@ -1,4 +1,5 @@
*.o *.o
gmon.out
miniwebcam miniwebcam
config.h config.h

@ -8,6 +8,14 @@ DATAPREFIX=/var/lib
RUNPID=/var/run/miniwebcam.pid RUNPID=/var/run/miniwebcam.pid
ETCPREFIX=/etc ETCPREFIX=/etc
SYSTEMDUNITDIR=$(ETCPREFIX)/systemd/system SYSTEMDUNITDIR=$(ETCPREFIX)/systemd/system
CONFIGDIR=$(ETCPREFIX)/miniwebcam
CONFIGFILE=$(CONFIGDIR)/miniwebcam.conf
LEGACYCONFIG=$(ETCPREFIX)/miniwebcam.conf
SSLKEY=$(CONFIGDIR)/ssl-key.pem
SSLCERT=$(CONFIGDIR)/ssl-cert.pem
SERVICEUSER=minicamuser
INSTALLSTATEDIR=$(DATAPREFIX)/miniwebcam
USERCREATEDMARKER=$(INSTALLSTATEDIR)/.make-created-user
DEFAULT_SERVERPORT=20010 DEFAULT_SERVERPORT=20010
ARCH=$(shell uname -m) ARCH=$(shell uname -m)
CXX=g++ CXX=g++
@ -29,18 +37,54 @@ else
endif endif
rm -rf assets.tar rm -rf assets.tar
miniwebcam: $(OBJFILES) assets.obj miniwebcam: config $(OBJFILES) assets.obj
$(CXX) $(OBJFILES) -o $@ assets.obj -L./ -I./ $(LDFLAGS) $(CXX) $(OBJFILES) -o $@ assets.obj -L./ -I./ $(LDFLAGS)
rm -rf assets.obj rm -rf assets.obj
install: miniwebcam install: miniwebcam
install -d $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(SYSTEMDUNITDIR) set -e; \
install -m 755 miniwebcam $(DESTDIR)$(PREFIX)/bin/miniwebcam if [ -z "$(DESTDIR)" ] && ! getent passwd "$(SERVICEUSER)" >/dev/null; then \
sed 's|@PREFIX@|$(PREFIX)|g' miniwebcam.service > $(DESTDIR)$(SYSTEMDUNITDIR)/miniwebcam.service install -d "$(INSTALLSTATEDIR)"; \
useradd --system --user-group --no-create-home --home-dir /nonexistent --shell /usr/sbin/nologin "$(SERVICEUSER)"; \
touch "$(USERCREATEDMARKER)"; \
fi; \
install -d "$(DESTDIR)$(PREFIX)/bin" "$(DESTDIR)$(SYSTEMDUNITDIR)" "$(DESTDIR)$(CONFIGDIR)"; \
chmod 750 "$(DESTDIR)$(CONFIGDIR)"; \
if [ -z "$(DESTDIR)" ]; then service_group=$$(id -gn "$(SERVICEUSER)"); chown root:"$$service_group" "$(DESTDIR)$(CONFIGDIR)"; fi; \
install -m 755 miniwebcam "$(DESTDIR)$(PREFIX)/bin/miniwebcam"; \
if [ ! -e "$(DESTDIR)$(CONFIGFILE)" ]; then \
if [ -f "$(DESTDIR)$(LEGACYCONFIG)" ]; then \
install -m 640 "$(DESTDIR)$(LEGACYCONFIG)" "$(DESTDIR)$(CONFIGFILE)"; \
rm -f "$(DESTDIR)$(LEGACYCONFIG)"; \
else \
install -m 640 /dev/null "$(DESTDIR)$(CONFIGFILE)"; printf '{}\n' > "$(DESTDIR)$(CONFIGFILE)"; \
fi; \
fi; \
if [ -z "$(DESTDIR)" ]; then chown root:"$$service_group" "$(DESTDIR)$(CONFIGFILE)"; fi; \
chmod 640 "$(DESTDIR)$(CONFIGFILE)"; \
if [ ! -e "$(DESTDIR)$(SSLKEY)" ] && [ ! -e "$(DESTDIR)$(SSLCERT)" ]; then \
umask 077; openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -subj "/CN=localhost" -keyout "$(DESTDIR)$(SSLKEY)" -out "$(DESTDIR)$(SSLCERT)"; \
elif [ ! -f "$(DESTDIR)$(SSLKEY)" ] || [ ! -f "$(DESTDIR)$(SSLCERT)" ]; then \
echo "Error: SSL key/certificate pair is incomplete; refusing to overwrite either file." >&2; exit 1; \
fi; \
chmod 640 "$(DESTDIR)$(SSLKEY)"; chmod 644 "$(DESTDIR)$(SSLCERT)"; \
if [ -z "$(DESTDIR)" ]; then chown root:"$$service_group" "$(DESTDIR)$(SSLKEY)"; chown root:root "$(DESTDIR)$(SSLCERT)"; fi; \
sed 's|@PREFIX@|$(PREFIX)|g' miniwebcam.service > "$(DESTDIR)$(SYSTEMDUNITDIR)/miniwebcam.service"
uninstall: uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/miniwebcam set -e; \
rm -f $(DESTDIR)$(SYSTEMDUNITDIR)/miniwebcam.service if [ -z "$(DESTDIR)" ] && command -v systemctl >/dev/null 2>&1; then \
if systemctl is-active --quiet miniwebcam.service; then systemctl stop miniwebcam.service; fi; \
if systemctl is-enabled --quiet miniwebcam.service; then systemctl disable miniwebcam.service; fi; \
fi; \
rm -f "$(DESTDIR)$(PREFIX)/bin/miniwebcam" "$(DESTDIR)$(SYSTEMDUNITDIR)/miniwebcam.service" "$(DESTDIR)$(CONFIGFILE)" "$(DESTDIR)$(SSLKEY)" "$(DESTDIR)$(SSLCERT)"; \
rmdir "$(DESTDIR)$(CONFIGDIR)" 2>/dev/null || true; \
if [ -z "$(DESTDIR)" ] && [ -f "$(USERCREATEDMARKER)" ]; then \
userdel "$(SERVICEUSER)"; \
rm -f "$(USERCREATEDMARKER)"; \
rmdir "$(INSTALLSTATEDIR)" 2>/dev/null || true; \
fi; \
if [ -z "$(DESTDIR)" ] && command -v systemctl >/dev/null 2>&1; then systemctl daemon-reload; fi
config: config:
echo "#ifndef _CONFIG_H_" > config.h echo "#ifndef _CONFIG_H_" > config.h
@ -59,7 +103,7 @@ config:
rebuild: clean all rebuild: clean all
dep: dep: config
$(CXX) -MM `ls *.cc` $(CXXFLAGS) > $(DEPENDFILE) $(CXX) -MM `ls *.cc` $(CXXFLAGS) > $(DEPENDFILE)
keygen: keygen:

@ -8,7 +8,7 @@ the following devices:
## Configuration ## Configuration
The configuration is loaded in the following order. The configuration is loaded in the following order.
- systemwide configuration file [/etc/miniwebcam.conf] - systemwide configuration file [/etc/miniwebcam/miniwebcam.conf]
- program parameters - program parameters
- user defined configurtion file defined in the program parameters - user defined configurtion file defined in the program parameters
@ -17,15 +17,30 @@ daemon, or `-F` to explicitly run in the foreground. Daemon mode redirects
standard input, output, and error to `/dev/null`; use `-debug` only when running standard input, output, and error to `/dev/null`; use `-debug` only when running
in the foreground if you need to see debug output. in the foreground if you need to see debug output.
The default system configuration file is `/etc/miniwebcam.conf`. `make install` The default configuration file is `/etc/miniwebcam/miniwebcam.conf`. `make install`
installs the executable and a systemd service unit. After installing, reload installs the executable and a systemd system unit named `miniwebcam.service`.
systemd and enable/start the service with: The system service runs as the unprivileged `minicamuser` account (not as root)
and has access to devices in the `video` group. `make install` creates the
system account if it does not exist and creates the configuration directory
with root-owned files readable by the service account. If the configuration is
absent, an existing `/etc/miniwebcam.conf` is moved into the new directory;
otherwise it is initialized with empty JSON defaults. If the SSL key and
certificate are absent, installation generates a self-signed certificate and
stores both in `/etc/miniwebcam/`; existing configuration and certificates are
preserved. The generated certificate is self-signed, so HTTPS clients will not
trust it by default. Run installation as root, for example `sudo make install`.
After installing, enable/start the service with:
```sh ```sh
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl enable --now miniwebcam.service sudo systemctl enable --now miniwebcam.service
``` ```
`make uninstall` stops and disables the service, removes the installed
executable, unit, configuration, and SSL key/certificate, and removes
`minicamuser` if `make install` created that account. An account that existed
before installation is retained.
# INFORMATION # INFORMATION
here are some usefull commands, maybe it helps to set the resolution to a readonable value here are some usefull commands, maybe it helps to set the resolution to a readonable value

@ -10,7 +10,7 @@
#define DEFAULT_HTTP_PORT 8080 #define DEFAULT_HTTP_PORT 8080
#define DEFAULT_HTTPS_PORT 8081 #define DEFAULT_HTTPS_PORT 8081
#define DEFAULT_CONFIG_FILE "/etc/miniwebcam.conf" #define DEFAULT_CONFIG_FILE "/etc/miniwebcam/miniwebcam.conf"
#define DEFAULT_SSL_KEY "/etc/miniwebcam/ssl-key.pem" #define DEFAULT_SSL_KEY "/etc/miniwebcam/ssl-key.pem"
#define DEFAULT_SSL_CERT "/etc/miniwebcam/ssl-cert.pem" #define DEFAULT_SSL_CERT "/etc/miniwebcam/ssl-cert.pem"
#define DEFAULT_VDEV_IOMODE 1 #define DEFAULT_VDEV_IOMODE 1

@ -4,6 +4,8 @@ After=network.target
[Service] [Service]
Type=simple Type=simple
User=minicamuser
SupplementaryGroups=video
ExecStart=@PREFIX@/bin/miniwebcam -F ExecStart=@PREFIX@/bin/miniwebcam -F
Restart=on-failure Restart=on-failure

Loading…
Cancel
Save