diff --git a/Data/Makefile b/Data/Makefile index c115445..24cddfd 100644 --- a/Data/Makefile +++ b/Data/Makefile @@ -1,37 +1,37 @@ .PHONY: install install: - install -d -g bin -o root -m 0775 $(DATADIR) - install -g bin -o root -m 0664 CCS_Hosts.txt $(DATADIR) - install -g bin -o root -m 0664 DCS_Hosts.txt $(DATADIR) - install -g bin -o root -m 0664 DExtra_Hosts.txt $(DATADIR) - install -g bin -o root -m 0664 DPlus_Hosts.txt $(DATADIR) - install -g bin -o root -m 0664 TIME_de_DE.ambe $(DATADIR) - install -g bin -o root -m 0664 TIME_de_DE.indx $(DATADIR) - install -g bin -o root -m 0664 TIME_en_GB.ambe $(DATADIR) - install -g bin -o root -m 0664 TIME_en_GB.indx $(DATADIR) - install -g bin -o root -m 0664 TIME_en_US.ambe $(DATADIR) - install -g bin -o root -m 0664 TIME_en_US.indx $(DATADIR) - install -g bin -o root -m 0664 TIME_fr_FR.ambe $(DATADIR) - install -g bin -o root -m 0664 TIME_fr_FR.indx $(DATADIR) - install -g bin -o root -m 0664 TIME_se_SE.ambe $(DATADIR) - install -g bin -o root -m 0664 TIME_se_SE.indx $(DATADIR) - install -g bin -o root -m 0664 de_DE.ambe $(DATADIR) - install -g bin -o root -m 0664 de_DE.indx $(DATADIR) - install -g bin -o root -m 0664 dk_DK.ambe $(DATADIR) - install -g bin -o root -m 0664 dk_DK.indx $(DATADIR) - install -g bin -o root -m 0664 en_GB.ambe $(DATADIR) - install -g bin -o root -m 0664 en_GB.indx $(DATADIR) - install -g bin -o root -m 0664 en_US.ambe $(DATADIR) - install -g bin -o root -m 0664 en_US.indx $(DATADIR) - install -g bin -o root -m 0664 es_ES.ambe $(DATADIR) - install -g bin -o root -m 0664 es_ES.indx $(DATADIR) - install -g bin -o root -m 0664 fr_FR.ambe $(DATADIR) - install -g bin -o root -m 0664 fr_FR.indx $(DATADIR) - install -g bin -o root -m 0664 it_IT.ambe $(DATADIR) - install -g bin -o root -m 0664 it_IT.indx $(DATADIR) - install -g bin -o root -m 0664 no_NO.ambe $(DATADIR) - install -g bin -o root -m 0664 no_NO.indx $(DATADIR) - install -g bin -o root -m 0664 pl_PL.ambe $(DATADIR) - install -g bin -o root -m 0664 pl_PL.indx $(DATADIR) - install -g bin -o root -m 0664 se_SE.ambe $(DATADIR) - install -g bin -o root -m 0664 se_SE.indx $(DATADIR) + @install -d -g bin -o dstar -m 0775 $(DATA_DIR) + @install -g bin -o dstar -m 0664 CCS_Hosts.txt $(DATA_DIR) + @install -g bin -o dstar -m 0664 DCS_Hosts.txt $(DATA_DIR) + @install -g bin -o dstar -m 0664 DExtra_Hosts.txt $(DATA_DIR) + @install -g bin -o dstar -m 0664 DPlus_Hosts.txt $(DATA_DIR) + @install -g bin -o dstar -m 0664 TIME_de_DE.ambe $(DATA_DIR) + @install -g bin -o dstar -m 0664 TIME_de_DE.indx $(DATA_DIR) + @install -g bin -o dstar -m 0664 TIME_en_GB.ambe $(DATA_DIR) + @install -g bin -o dstar -m 0664 TIME_en_GB.indx $(DATA_DIR) + @install -g bin -o dstar -m 0664 TIME_en_US.ambe $(DATA_DIR) + @install -g bin -o dstar -m 0664 TIME_en_US.indx $(DATA_DIR) + @install -g bin -o dstar -m 0664 TIME_fr_FR.ambe $(DATA_DIR) + @install -g bin -o dstar -m 0664 TIME_fr_FR.indx $(DATA_DIR) + @install -g bin -o dstar -m 0664 TIME_se_SE.ambe $(DATA_DIR) + @install -g bin -o dstar -m 0664 TIME_se_SE.indx $(DATA_DIR) + @install -g bin -o dstar -m 0664 de_DE.ambe $(DATA_DIR) + @install -g bin -o dstar -m 0664 de_DE.indx $(DATA_DIR) + @install -g bin -o dstar -m 0664 dk_DK.ambe $(DATA_DIR) + @install -g bin -o dstar -m 0664 dk_DK.indx $(DATA_DIR) + @install -g bin -o dstar -m 0664 en_GB.ambe $(DATA_DIR) + @install -g bin -o dstar -m 0664 en_GB.indx $(DATA_DIR) + @install -g bin -o dstar -m 0664 en_US.ambe $(DATA_DIR) + @install -g bin -o dstar -m 0664 en_US.indx $(DATA_DIR) + @install -g bin -o dstar -m 0664 es_ES.ambe $(DATA_DIR) + @install -g bin -o dstar -m 0664 es_ES.indx $(DATA_DIR) + @install -g bin -o dstar -m 0664 fr_FR.ambe $(DATA_DIR) + @install -g bin -o dstar -m 0664 fr_FR.indx $(DATA_DIR) + @install -g bin -o dstar -m 0664 it_IT.ambe $(DATA_DIR) + @install -g bin -o dstar -m 0664 it_IT.indx $(DATA_DIR) + @install -g bin -o dstar -m 0664 no_NO.ambe $(DATA_DIR) + @install -g bin -o dstar -m 0664 no_NO.indx $(DATA_DIR) + @install -g bin -o dstar -m 0664 pl_PL.ambe $(DATA_DIR) + @install -g bin -o dstar -m 0664 pl_PL.indx $(DATA_DIR) + @install -g bin -o dstar -m 0664 se_SE.ambe $(DATA_DIR) + @install -g bin -o dstar -m 0664 se_SE.indx $(DATA_DIR) diff --git a/Makefile b/Makefile index ca834ee..4567717 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,30 @@ -# Copyright (c) 2021 by Geoffrey Merck F4FXL / KC3FRA +# +# Copyright (C) 2021 by Geoffrey Merck F4FXL / KC3FRA +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# -# if you change these locations, make sure the dstargateway.service file is updated! -BIN_DIR=/usr/local/bin -CFG_DIR=/usr/local/etc/dstargateway.d/ +export BIN_DIR=/usr/local/bin +export CFG_DIR=/usr/local/etc/ +export DATA_DIR=/usr/local/share/dstargateway.d/ +export LOG_DIR=/var/log/dstargateway # choose this if you want debugging help -CPPFLAGS=-g -ggdb -W -Wall -std=c++17 -DCFG_DIR=\"$(CFG_DIR)\" +CPPFLAGS=-g -ggdb -W -Wall -std=c++17 # or, you can choose this for a much smaller executable without debugging help -#CPPFLAGS=-W -Wall -std=c++17 -DCFG_DIR=\"$(CFGDIR)\" -DDATA_DIR=\"$(DATA_DIR)" +#CPPFLAGS=-W -Wall -std=c++17 SRCS = $(wildcard *.cpp) OBJS = $(SRCS:.cpp=.o) @@ -22,6 +39,20 @@ dstargateway : GitVersion.h $(OBJS) %.o : %.cpp g++ $(CPPFLAGS) -MMD -MD -c $< -o $@ +GitVersion.h : FORCE +ifneq ("$(wildcard .git/index)","") + @echo "#pragma once\nconst char *gitversion = \"$(shell git rev-parse HEAD)\";" > /tmp/$@ +else + @echo "#pragma once\nconst char *gitversion = \"0000000000000000000000000000000000000000\";" > /tmp/$@ +endif + @cmp -s /tmp/$@ $@; \ + RETVAL=$$?; \ + if [ $$RETVAL -ne 0 ]; then \ + echo "Git version has changed"; \ + cp -f /tmp/$@ $@; \ + fi; \ + rm /tmp/$@; + .PHONY: clean clean: $(RM) GitVersion.h $(OBJS) $(DEPS) dstargateway @@ -29,42 +60,64 @@ clean: -include $(DEPS) # install, uninstall and removehostfiles need root priviledges +.PHONY: newhostfiles newhostfiles : - /usr/bin/wget http://www.pistar.uk/downloads/DExtra_Hosts.txt && sudo /bin/mv -f DExtra_Hosts.txt $(CFGDIR) - /usr/bin/wget http://www.pistar.uk/downloads/DCS_Hosts.txt && sudo /bin/mv -f DCS_Hosts.txt $(CFGDIR) + @echo "Fetching new host files" + @mkdir -p $(DATA_DIR) + @wget http://www.pistar.uk/downloads/DExtra_Hosts.txt -nv -O $(DATA_DIR)/DExtra_Hosts.txt + @wget http://www.pistar.uk/downloads/DCS_Hosts.txt -nv -O $(DATA_DIR)/DCS_Hosts.txt + @wget http://www.pistar.uk/downloads/DPlus_Hosts.txt -nv -O $(DATA_DIR)/DPlus_Hosts.txt +.PHONY: install install : dstargateway - /bin/cp -f dstargateway.cfg $(CFGDIR) - /bin/cp -f dstargateway $(BINDIR) - /bin/cp -f dstargateway.service /lib/systemd/system +# create user for daemon + @useradd --user-group -M --system dstar --shell /bin/false || true + +# Create directories + @mkdir -p $(CFG_DIR) + @mkdir -p $(DATA_DIR) + @mkdir -p $(BIN_DIR) + @mkdir -p $(LOG_DIR) + @chown dstar:dstar $(LOG_DIR) + +# Install data + $(MAKE) -C Data install + @chown -R dstar:dstar $(DATA_DIR) + +# copy and adjust config + @cp -fn example.cfg $(CFG_DIR)/dstargateway.cfg + @sed -i "s|log=.*|log=\"$(LOG_DIR)\"|g" $(CFG_DIR)/dstargateway.cfg + @sed -i "s|data=.*|data=\"$(DATA_DIR)\"|g" $(CFG_DIR)/dstargateway.cfg + +# copy binary + @cp -f dstargateway $(BIN_DIR) + +# SystemD service install + @cp -f debian/dstargateway.service /lib/systemd/system/ + @sed -i "s|%CFG_DIR%|$(CFG_DIR)|g" /lib/systemd/system/dstargateway.service systemctl enable dstargateway.service - systemctl daemon-reload - systemctl start dstargateway.service + @systemctl daemon-reload + @echo "\n\n" + @echo "Install complete, edit $(CFG_DIR)dstargateway.cfg and start the daemon with 'systemctl start dstargateway.service'" + @echo "\n\n" +.PHONY: uninstall uninstall : - systemctl stop dstargateway.service - systemctl disable dstargateway.service - /bin/rm -f /lib/systemd/system/dstargateway.service - systemctl daemon-reload - /bin/rm -f $(BINDIR)/dstargateway - /bin/rm -f $(CFGDIR)/dstargateway.cfg + systemctl stop dstargateway.service || true + systemctl disable dstargateway.service || true + @rm -f /lib/systemd/system/dstargateway.service + @systemctl daemon-reload + @rm -f $(BIN_DIR)/dstargateway +# @rm -f $(CFG_DIR)/dstargateway.cfg +# Only remove folder content + @rm -f $(DATA_DIR)/* +.PHONY: removehostfiles removehostfiles : - /bin/rm -f $(CFGDIR)/DExtra_Hosts.txt - /bin/rm -f $(CFGDIR)/DCS_Hosts.txt + @rm -f $(DATA_DIR)/DExtra_Hosts.txt + @rm -f $(DATA_DIR)/DCS_Hosts.txt + @rm -f $(DATA_DIR)/DPlus_Hosts.txt + -GitVersion.h : FORCE -ifneq ("$(wildcard .git/index)","") - @echo "#pragma once\nconst char *gitversion = \"$(shell git rev-parse HEAD)\";" > /tmp/$@ -else - @echo "#pragma once\nconst char *gitversion = \"0000000000000000000000000000000000000000\";" > /tmp/$@ -endif - @cmp -s /tmp/$@ $@; \ - RETVAL=$$?; \ - if [ $$RETVAL -ne 0 ]; then \ - echo "Git version has changed"; \ - cp -f /tmp/$@ $@; \ - fi; \ - rm /tmp/$@; FORCE: \ No newline at end of file diff --git a/debian/dstargateway.service b/debian/dstargateway.service index ca848d4..b95d804 100644 --- a/debian/dstargateway.service +++ b/debian/dstargateway.service @@ -1,10 +1,17 @@ [Unit] -Description=DStar Gateway -After=systemd-user-session.service +User=dstar +Description=D-STAR Gateway Daemon +After=network.target,network-online.target +Wants=network-online.target +RestartSec=5 +StartLimitIntervalSec=60 +StartLimitBurst=0 + [Service] Type=simple -ExecStart=/usr/local/bin/dstargateway /usr/local/etc/dstargeteway/dstargateway.cfg +ExecStart=/usr/local/bin/dstargateway %CFG_DIR%/dstargateway.cfg [Install] WantedBy=multi-user.target +Requires=network-online.target