init/Makefile: make user customizable

This commit is contained in:
Saxon Nelson-Milton 2022-05-26 16:47:42 +09:30
parent 47028b70c2
commit 7a397ff96f
3 changed files with 15 additions and 7 deletions

View File

@ -3,6 +3,9 @@
# MA and DK can be optionally passed to Make, e.g, for a hard (first-time) installation: # MA and DK can be optionally passed to Make, e.g, for a hard (first-time) installation:
# sudo MA=mac DK=dk install_hard # sudo MA=mac DK=dk install_hard
# NB: The default (soft) install does not override conf files. # NB: The default (soft) install does not override conf files.
# USR can also be passsed to customise user under which the code is housed.
# For example, if you're trying to make rv on your laptop instead of a pi,
# set USR=<your user name>.
USER := $(shell whoami) USER := $(shell whoami)
PATH := /usr/local/go/bin:$(PATH) PATH := /usr/local/go/bin:$(PATH)
ifeq ($(MA),) ifeq ($(MA),)
@ -11,6 +14,9 @@ endif
ifeq ($(DK),) ifeq ($(DK),)
DK := 0 DK := 0
endif endif
ifeq ($(USR),)
USR := "pi"
endif
.SILENT:make_dirs .SILENT:make_dirs
.SILENT:soft_copy_files .SILENT:soft_copy_files
@ -32,6 +38,8 @@ as_root:
ifneq ($(USER),root) ifneq ($(USER),root)
$(error Must run as superuser!) $(error Must run as superuser!)
endif endif
sed -i 's/pi/$(USR)/' rv.service
sed -i 's/pi/$(USR)/' run.sh
make_dirs: make_dirs:
if [ ! -d /var/netsender ] ; then \ if [ ! -d /var/netsender ] ; then \
@ -50,12 +58,12 @@ soft_copy_files:
cp rv.service /etc/systemd/system; \ cp rv.service /etc/systemd/system; \
fi fi
systemctl enable rv.service systemctl enable rv.service
chmod +x pi_run.sh chmod +x run.sh
if [ -f /etc/netsender.conf ] ; then \ if [ -f /etc/netsender.conf ] ; then \
echo "/etc/netsender.conf left unmodified" ; \ echo "/etc/netsender.conf left unmodified" ; \
else \ else \
printf "ma $(MA)\ndk $(DK)\n" > /etc/netsender.conf; \ printf "ma $(MA)\ndk $(DK)\n" > /etc/netsender.conf; \
chown pi /etc/netsender.conf; \ chown $(USR) /etc/netsender.conf; \
fi fi
hard_copy_files: hard_copy_files:
@ -64,13 +72,13 @@ hard_copy_files:
fi fi
cp -f rv.service /etc/systemd/system cp -f rv.service /etc/systemd/system
systemctl enable rv.service systemctl enable rv.service
chmod +x pi_run.sh chmod +x run.sh
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
chown pi /etc/netsender.conf chown $(USR) /etc/netsender.conf
hard_copy_files_treat: hard_copy_files_treat:
if [ -f /etc/systemd/system/treatment.service ] ; then \ if [ -f /etc/systemd/system/treatment.service ] ; then \
@ -84,7 +92,7 @@ hard_copy_files_treat:
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
chown pi /etc/netsender.conf chown $(USR) /etc/netsender.conf
set_mac: set_mac:
printf "ip link set eth0 address $(MA)\n" > /etc/dhcpcd.enter-hook printf "ip link set eth0 address $(MA)\n" > /etc/dhcpcd.enter-hook

0
init/pi_run.sh → init/run.sh Normal file → Executable file
View File

View File

@ -3,7 +3,7 @@ Description=Netsender Client for Media Collection and Forwarding
[Service] [Service]
Type=simple Type=simple
ExecStart=/home/pi/go/src/bitbucket.org/ausocean/av/init/pi_run.sh ExecStart=/home/pi/go/src/bitbucket.org/ausocean/av/init/run.sh
Restart=on-failure Restart=on-failure
[Install] [Install]