DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 19th July 2022
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,128
Default Creating 'install.conf' for OpenBSD autoinstall(8), another approach

The other older 2014 approach is the shell script and Makefile from Creating 'install.conf' for OpenBSD automatic installations
Because I did not have to time to update that script for VPS testing, I wrote a Makefile that concatenates or glues together an install.conf from separate file blocks or components.

These blocks can have comment lines and empty lines to enhance readability. For a 'lean and mean' install.conf the Makefile just strips these lines.

An example of the quite readable network configuration block:
Code:
cat 10-network.resp
# network response file

# system hostname selects sitexx-$(hostname -s).tgz !
System hostname = df-us

# --- Network interface configuration

#Which network interface do you wish to configure = bge0
#IPv4 address for bge0 = autoconf
#IPv6 address for bge0 = none
#Which network interface do you wish to configure = done

Which network interface do you wish to configure = vio0
IPv4 address for vio0 = autoconf
IPv6 address for vio0 = none
Which network interface do you wish to configure = done

Start sshd(8) by default = yes
# -----------------------------------------
After being processed by make, it will be:
Code:
System hostname = df-us
Which network interface do you wish to configure = vio0
IPv4 address for vio0 = autoconf
IPv6 address for vio0 = none
Which network interface do you wish to configure = done
Start sshd(8) by default = yes
The list of response blocks are:
Code:
-rw-r--r--  1 j65  j65  572 Jul 19 02:05 10-network.resp
-rw-r--r--  1 j65  j65  512 Jul 19 02:01 20-user-tz.resp
-rw-r--r--  1 j65  j65  279 Jul 19 00:18 40-disk.resp
-rw-r--r--  1 j65  j65  450 Jul 19 00:21 50-sets.resp
The first relevant lines of the Makefile define a variable CONF for the file 'to make' and accumulates all separate reponse blocks in the variable BLOCKS :
Code:
CONF            = install.conf

[snip]

BLOCKS          += 10-network.resp
BLOCKS          += 20-user-tz.resp
BLOCKS          += 40-disk.resp
BLOCKS          += 50-sets.resp
The second target or sub-contractor install.conf.raw depends on the response blocks named in the variable BLOCKS
Code:
${CONF}.raw: ${BLOCKS}
        cat ${.ALLSRC} > ${.TARGET}
When any of these blocks have been modified and thus have a newer date, the shell commands of second line will get executed to create a newer updated version of install.conf.raw.

Updating or modifying the first block with a dangerous command (imagine what if I used only a single '>')
Code:
$ echo '# end of file' >>10-network.resp
$ ls -lTt 10-network.resp install.conf.raw
-rw-r--r--  1 j65  j65   586 Jul 19 02:51:07 2022 10-network.resp
-rw-r--r--  1 j65  j65  1813 Jul 19 02:13:40 2022 install.conf.raw
We see that this component is now newer that than the file it should be part of. Invoke make to recreate:
Code:
$ make install.conf.raw
cat 10-network.resp 20-user-tz.resp 40-disk.resp 50-sets.resp > install.conf.raw
$ make install.conf.raw
`install.conf.raw' is up to date.
ls -lTt *resp *raw
-rw-r--r--  1 j65  j65  1827 Jul 19 02:54:49 2022 install.conf.raw
-rw-r--r--  1 j65  j65   586 Jul 19 02:51:07 2022 10-network.resp
-rw-r--r--  1 j65  j65   512 Jul 19 02:01:18 2022 20-user-tz.resp
-rw-r--r--  1 j65  j65   450 Jul 19 00:21:13 2022 50-sets.resp
-rw-r--r--  1 j65  j65   279 Jul 19 00:18:56 2022 40-disk.resp
After the second invocation make, correctly informs us that there is no need to recreate: 'install.conf.raw' already contains the updated '10-network.resp' file.

The first and main target 'install.conf' depends on 'install.conf.raw'
Code:
${CONF}: ${CONF}.raw
        @# remove blank lines and #comment lines
        /usr/bin/sed -E -e '/^[:blank:]*$$/d' -e '/^#.*$$/d' ${.TARG
        @# note that in the shell a single '$' (end-of-line) works :
        @# make(1) strips one, so it needs to be doubled !!
Because of this dependency, it will first 'run' the 'install.conf.raw' target to make sure that is up to date.

Code:
$ make
/usr/bin/sed -E -e '/^[:blank:]*$/d' -e '/^#.*$/d' install.conf.raw >install.conf
$ make
`install.conf' is up to date.
$ make ls
ls -lTt
total 56
-rw-r--r--  1 j65  j65  1043 Jul 19 03:06:53 2022 install.conf
-rw-r--r--  1 j65  j65  1827 Jul 19 02:54:49 2022 install.conf.raw
-rw-r--r--  1 j65  j65   586 Jul 19 02:51:07 2022 10-network.resp
-rw-r--r--  1 j65  j65   512 Jul 19 02:01:18 2022 20-user-tz.resp
-rw-r--r--  1 j65  j65   450 Jul 19 00:21:13 2022 50-sets.resp
-rw-r--r--  1 j65  j65   279 Jul 19 00:18:56 2022 40-disk.resp
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump

Last edited by J65nko; 19th July 2022 at 02:19 AM.
Reply With Quote
  #2   (View Single Post)  
Old 19th July 2022
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,128
Default

The Makefile
Code:
# --- Makefile to generate an 'install.conf' for autoinstall(8) 
# Copyright (c) 2022 j65nko daemonforums.org
# ISC license (See https://cvsweb.openbsd.org/src/share/misc/license.template?rev=HEAD )

# --- ignore built-in rules
.MAKEFLAGS 	= -r

CONF		= install.conf

# For readability blocks can have comment lines and empty lines 
# These will be stripped from the final 'install.conf'
 
BLOCKS		+= 10-network.resp
BLOCKS		+= 20-user-tz.resp
BLOCKS		+= 40-disk.resp
BLOCKS		+= 50-sets.resp

# Main target strips the comment and empty lines from the 'raw' file

${CONF}: ${CONF}.raw
	@# remove blank lines and #comment lines 
	/usr/bin/sed -E -e '/^[:blank:]*$$/d' -e '/^#.*$$/d' ${.TARGET}.raw >${.TARGET} 
	@# note that in the shell a single '$' (end-of-line) works : '/^[:blank:]*$/d'
	@# make(1) strips one, so it needs to be doubled !!

# Concatenate all raw blocks to one single file

${CONF}.raw: ${BLOCKS} 
	cat ${.ALLSRC} > ${.TARGET}

# Utilities

ls:
	ls -lTt
  
show:
	ls -lT ${CONF}
	cat -n ${CONF}

showraw:
	ls -lT ${CONF}.raw
	cat -n ${CONF}.raw

clean:
	rm -f ${CONF} ${CONF}.raw	

.PHONY	: show clean
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #3   (View Single Post)  
Old 19th July 2022
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,128
Default

The Makefile and response file in a single compressed tarball for downloading.
Create a directory e.g. AUTO-install, copy the tarball and extract
Code:
$ mkdir AUTO-install
$ cd AUTO-install
$ cp ~/Downloads/MakeInstallconf.tgz  .

# check the tarball contents

$ tar tvzf MakeInstallconf.tgz                   

-rw-r--r--  1 adriaan  adriaan        586 Jul 19 02:51 10-network.resp
-rw-r--r--  1 adriaan  adriaan        512 Jul 19 02:01 20-user-tz.resp
-rw-r--r--  1 adriaan  adriaan        279 Jul 19 04:10 40-disk.resp
-rw-r--r--  1 adriaan  adriaan        447 Jul 19 04:12 50-sets.resp
-rw-r--r--  1 adriaan  adriaan       1121 Jul 19 03:46 Makefile
-rw-r--r--  1 adriaan  adriaan       1040 Jul 19 04:12 install.conf
-rw-r--r--  1 adriaan  adriaan       1824 Jul 19 04:12 install.conf.raw

# extract

$ tar xvzf MakeInstallconf.tgz   
10-network.resp
20-user-tz.resp
40-disk.resp
50-sets.resp
Makefile
install.conf
install.conf.raw
Attached Files
File Type: tgz MakeInstallconf.tgz (1.8 KB, 15 views)
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump

Last edited by J65nko; 19th July 2022 at 02:44 AM.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating 'install.conf' for OpenBSD automatic installations J65nko Guides 4 19th July 2022 02:52 AM
Most efficient approach to build new via openchrome video driver shep NetBSD General 12 16th November 2021 02:08 PM
Creating QR codes in OpenBSD victorvas Guides 3 31st May 2019 06:01 AM
Creating scenario with OpenBSD, network benky OpenBSD Security 10 12th February 2015 09:35 PM
OpenBSD autoinstall J65nko OpenBSD Installation and Upgrading 4 12th December 2014 01:15 AM


All times are GMT. The time now is 10:46 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick