av/init/Makefile

104 lines
2.9 KiB
Makefile

# Install files and directories required by NetSender clients (such as gpio-netsender, rv, etc.)
# and create a dhcpcd.enter-hook for setting the MAC address.
# MA and DK can be optionally passed to Make, e.g, for a hard (first-time) installation:
# sudo MA=mac DK=dk install_hard
# NB: The default (soft) install does not override conf files.
# USR can also be passsed to customise user under which the code is housed.
USER := $(shell whoami)
PATH := /usr/local/go/bin:$(PATH)
BIN_DIR := /src/bitbucket.org/ausocean/av/cmd/rv
RUN_SCRIPT_DIR := /src/bitbucket.org/ausocean/av/init/run.sh
ifeq ($(MA),)
MA := "00:E0:4C:00:00:01"
endif
ifeq ($(DK),)
DK := 0
endif
.SILENT:make_dirs
.SILENT:soft_copy_files
.SILENT:hard_copy_files
.SILENT:set_mac
.SILENT:clean
rebuild:
chmod +x run.sh
cd ../cmd/rv; go build -tags nocv
install: as_root make_dirs soft_copy_files rebuild
@echo "Install complete"
install_hard: as_root make_dirs hard_copy_files set_mac rebuild
@echo "Hard install complete"
install_hard_treat: as_root make_dirs hard_copy_files_treat set_mac
@echo "Hard install complete"
as_root:
ifneq ($(USER),root)
$(error Must run as superuser!)
endif
make_dirs:
if [ ! -d /var/netsender ] ; then \
mkdir /var/netsender; \
chmod guo+rwx /var/netsender; \
fi
if [ ! -d /var/log/netsender ] ; then \
mkdir /var/log/netsender; \
chmod guo+rwx /var/log/netsender; \
fi
soft_copy_files:
if [ -f /etc/systemd/system/rv.service ] ; then \
echo "/etc/systemd/system/rv.service left unmodified" ; \
else \
bash create_service.sh $(RUN_SCRIPT_DIR) $(BIN_DIR); \
fi
systemctl enable rv.service
if [ -f /etc/netsender.conf ] ; then \
echo "/etc/netsender.conf left unmodified" ; \
else \
printf "ma $(MA)\ndk $(DK)\n" > /etc/netsender.conf; \
bash permissions.sh; \
fi
hard_copy_files:
if [ -f /etc/systemd/system/rv.service ] ; then \
echo "/etc/systemd/system/rv.service overwritten" ; \
fi
bash create_service.sh $(RUN_SCRIPT_DIR) $(BIN_DIR)
systemctl enable rv.service
if [ -f /etc/netsender.conf ] ; then \
echo "Backed up netsender.conf to /etc/netsender.conf.bak"; \
cp /etc/netsender.conf /etc/netsender.conf.bak ; \
fi
printf "ma $(MA)\ndk $(DK)\n" > /etc/netsender.conf
bash permissions.sh
hard_copy_files_treat:
if [ -f /etc/systemd/system/treatment.service ] ; then \
echo "/etc/systemd/system/treatment.service overwritten" ; \
fi
cp -f treatment.service /etc/systemd/system
systemctl enable treatment.service
chmod +x treatment_run.sh
if [ -f /etc/netsender.conf ] ; then \
echo "Backed up netsender.conf to /etc/netsender.conf.bak"; \
cp /etc/netsender.conf /etc/netsender.conf.bak ; \
fi
printf "ma $(MA)\ndk $(DK)\n" > /etc/netsender.conf
bash permissions.sh
set_mac:
printf "ip link set eth0 address $(MA)\n" > /etc/dhcpcd.enter-hook
chmod guo+x /etc/dhcpcd.enter-hook
clean: as_root
rm -rf /var/netsender
rm -rf /var/log/netsender
rm -rf /etc/systemd/system/rv.service
rm -rf /etc/netsender.conf
@echo "Clean complete"