init/Makefile: force the install to use a MAC address

There's no scenario where a netsender shouldn't have MAC address associated with it.
This commit is contained in:
trekhopton 2024-05-03 16:05:21 +09:30
parent 9f56bee095
commit 1a34d7fe5a
1 changed files with 29 additions and 58 deletions

View File

@ -1,9 +1,7 @@
# Install files and directories required by NetSender clients (such as gpio-netsender, rv, etc.) # 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. # Optionally you can create a dhcpcd.enter-hook for setting the MAC address. (install_set_mac).
# MA and DK can be optionally passed to Make, e.g, for a hard (first-time) installation: # MA and DK must be passed to Make for an installation:
# sudo MA=mac DK=dk install_hard # sudo make install MA=mac DK=dk
# 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) USER := $(shell whoami)
PATH := /usr/local/go/bin:$(PATH) PATH := /usr/local/go/bin:$(PATH)
BIN_NAME := rv BIN_NAME := rv
@ -13,36 +11,28 @@ RUN_SCRIPT_DIR := /src/bitbucket.org/ausocean/av/init/run.sh
# Change this to withcv if you wish to use CV. # Change this to withcv if you wish to use CV.
BUILD_TAG := BUILD_TAG :=
ifeq ($(MA),)
MA := "00:E0:4C:00:00:01"
endif
ifeq ($(DK),)
DK := 0
endif
.SILENT:make_dirs .SILENT:make_dirs
.SILENT:soft_copy_files
.SILENT:hard_copy_files .SILENT:hard_copy_files
.SILENT:set_mac .SILENT:set_mac
.SILENT:clean .SILENT:clean
rebuild: rebuild:
chmod +x run.sh @chmod +x run.sh
cd ../cmd/$(BIN_NAME); \ @cd ../cmd/$(BIN_NAME); \
if [ -z "$(BUILD_TAG)" ]; then \ if [ -z "$(BUILD_TAG)" ]; then \
go build; \ go build; \
else \ else \
go build -tags $(BUILD_TAG); \ go build -tags $(BUILD_TAG); \
fi fi
install: as_root make_dirs soft_copy_files rebuild syncreboot install: as_root make_dirs hard_copy_files rebuild syncreboot
@echo "Install complete" @echo "Install complete"
install_hard: as_root make_dirs hard_copy_files set_mac rebuild syncreboot install_no_rebuild: as_root make_dirs hard_copy_files syncreboot
@echo "Hard install complete" @echo "Install complete"
install_hard_treat: as_root make_dirs hard_copy_files_treat set_mac syncreboot install_set_mac: as_root make_dirs hard_copy_files set_mac rebuild syncreboot
@echo "Hard install complete" @echo "Install complete, MAC address set to $(MA)"
as_root: as_root:
ifneq ($(USER),root) ifneq ($(USER),root)
@ -50,67 +40,48 @@ ifneq ($(USER),root)
endif endif
make_dirs: make_dirs:
if [ ! -d /var/netsender ] ; then \ @if [ ! -d /var/netsender ] ; then \
mkdir /var/netsender; \ mkdir /var/netsender; \
chmod guo+rwx /var/netsender; \ chmod guo+rwx /var/netsender; \
fi fi
if [ ! -d /var/log/netsender ] ; then \ @if [ ! -d /var/log/netsender ] ; then \
mkdir /var/log/netsender; \ mkdir /var/log/netsender; \
chmod guo+rwx /var/log/netsender; \ chmod guo+rwx /var/log/netsender; \
fi fi
soft_copy_files:
if [ -f /etc/systemd/system/$(BIN_NAME).service ] ; then \
echo "/etc/systemd/system/$(BIN_NAME).service left unmodified" ; \
else \
bash create_service.sh $(RUN_SCRIPT_DIR) $(BIN_DIR); \
fi
systemctl enable $(BIN_NAME).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: hard_copy_files:
ifeq ($(MA),)
$(error "Must provide MAC using MA=")
endif
ifeq ($(DK),)
$(error "Must provide device key using DK=")
endif
if [ -f /etc/systemd/system/$(BIN_NAME).service ] ; then \ if [ -f /etc/systemd/system/$(BIN_NAME).service ] ; then \
echo "/etc/systemd/system/$(BIN_NAME).service overwritten" ; \ echo "/etc/systemd/system/$(BIN_NAME).service overwritten" ; \
fi fi
bash create_service.sh $(RUN_SCRIPT_DIR) $(BIN_DIR) bash create_service.sh $(RUN_SCRIPT_DIR) $(BIN_DIR)
systemctl enable $(BIN_NAME).service @systemctl enable $(BIN_NAME).service
if [ -f /etc/netsender.conf ] ; then \ @if [ -f /etc/netsender.conf ] ; then \
echo "Backed up netsender.conf to /etc/netsender.conf.bak"; \ echo "Backed up netsender.conf to /etc/netsender.conf.bak"; \
cp /etc/netsender.conf /etc/netsender.conf.bak ; \ cp /etc/netsender.conf /etc/netsender.conf.bak ; \
fi fi
printf "ma $(MA)\ndk $(DK)\n" > /etc/netsender.conf @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 bash permissions.sh
set_mac: set_mac:
printf "ip link set eth0 address $(MA)\n" > /etc/dhcpcd.enter-hook ifeq ($(MA),)
chmod guo+x /etc/dhcpcd.enter-hook $(error "Must provide MAC using MA=")
endif
@printf "ip link set eth0 address $(MA)\n" > /etc/dhcpcd.enter-hook
@chmod guo+x /etc/dhcpcd.enter-hook
syncreboot: syncreboot:
if [ -e ../../utils ]; then \ @if [ -e ../../utils ]; then \
cd ../../utils; git checkout -f master; git pull; \ cd ../../utils; git checkout -f master; git pull; \
else \ else \
cd ../../; git clone https://bitbucket.org/ausocean/utils; \ cd ../../; git clone https://bitbucket.org/ausocean/utils; \
fi fi
cd ../../utils/cmd/syncreboot; make; make install @cd ../../utils/cmd/syncreboot; make; make install
clean: as_root clean: as_root
rm -rf /var/netsender rm -rf /var/netsender