Files
shred.ing-server/Makefile

81 lines
3.5 KiB
Makefile
Raw Normal View History

# Makefile for shred.ing
# make (default, or with: make config)
# prompt for settings unless .env file exists
# create ~/icecast.xml
# make install
# backup the live config to ~/icecast.xml
# install ~/icecast.xml to /etc/icecast2
# not currently used for anything
## make sure to change these
#source_pass := password_to_share_with_casters
#relay_pass := password_for_icecast2_relays
#admin_user := admin_web_and_api_username
#admin_pass := password_for_admin_access
## probably want to change this
#hostname := shred.ing
# the "prompt" port can be left blank so
# this can be left at default
icecast2_port := 8000
##
## More or less internal stuffs
##
ICECAST_CONFIG_TEMPLATE ?= icecast.xml.template
## generate configuration files for icecast2
# these targets aren't associated with files
.PHONEY: config backup-live-config install foo
## main "entry point" makefile targets
config: icecast.xml .env
backup-live-config:
sudo test -r /etc/icecast2/icecast.xml && sudo cp /etc/icecast2/icecast.xml icecast.xml~~
install: config backup-live-config
sudo cp icecast.xml /etc/icecast2/icecast.xml.new
# this will prompt to build a .env file when none exists
.env:
@echo "You will receive a series of prompts to create a .env file."
@echo
@printf "Enter your icecast hostname (or IP): "
@printf "hostname=%s\n" `read i; echo $$i` >.env
@printf "Enter the port for your icecast server ($(icecast2_port)): "
@printf "icecast2_port=%s\n" "$$( i=`read i; echo $$i`; printf "%s" $$( if test -z "$$i" ; then echo "$(icecast2_port)"; else echo "$$i" ; fi ) )" >>.env
@echo "Icecast requires, potentially, several passwords."
@echo "Passwords entered now are echoed to the screen."
@echo "You can pick bogus values and then edit the .env file."
@printf "Enter a source password: "
@printf "source_pass=%s\n" `read i; echo $$i` >>.env
@printf "Enter a relay password: "
@printf "relay_pass=%s\n" `read i; echo $$i` >>.env
@printf "Enter an admin password: "
@printf "admin_pass=%s\n" `read i; echo $$i` >>.env
@echo "Finally, select a username for the admin account:"
@printf "Enter the icecast admin username: "
@printf "admin_user=%s\n" `read i; echo $$i` >>.env
# this ensures the template icecast config exists
$(ICECAST_CONFIG_TEMPLATE):
@printf "The icecast2 configuration file template "'"'"%s"'"'"\n" "$(ICECAST_CONFIG_TEMPLATE)"
@printf "is missing or cannot be read.\n"
@echo "This can be caused by an incomplete or corrupted checkout or"
@echo "an invalid value for the ICECAST_CONFIG_TEMPLATE env variable."
false
### given we have a template and a .env, create the icecast config
icecast.xml: $(ICECAST_CONFIG_TEMPLATE) .env
perl -e 'BEGIN{open my$$FH,q(<),q(.env) or die $$!; for(<$$FH>){ chomp; my($$k,$$v) = split q(=); next unless $$k; $$k =~ s/^\s+|\s+$$//g; next unless $$k; $$v =~ s/^\s+|\s+//g; $$h{lc $$k} = $$v; }}' -pe 's/\@\@([^@]+)\@\@/$$h{lc $$1}/eig;' >icecast.xml <$(ICECAST_CONFIG_TEMPLATE)
# this seems to work, too!
# cat icecast.xml.template | perl -pe 's/\@\@source_pass\@\@/$(source_pass)/ig; s/\@\@relay_pass\@\@/$(relay_pass)/ig; s/\@\@admin_user\@\@/$(admin_user)/ig; s/\@\@admin_pass\@\@/$(admin_pass)/ig; s/\@\@hostname\@\@/$(hostname)/ig; s/\@\@icecast2_port\@\@/$(icecast2_port)/ig;' > icecast.xml
# probably, so does this?
# cat icecast.xml.template | perl -e 'BEGIN{open my$FH,q(<),q(.env) or die $!; for(<$FH>){ chomp; my($k,$v) = split q(=); next unless $k; $k =~ s/^\s+|\s+$//g; next unless $k; $v =~ s/^\s+|\s+//g; $h{lc $k} = $v; }}' -pe 's/\@\@([^@]+)\@\@/$h{lc $1}/eig;' -e 'END { use Data::Dumper; warn Dumper( \%h ) } ' > foo.xml