carbon-config

config submodule of carbon-core-system
git clone https://ccx.te2000.cz/git/carbon-config
Log | Files | Refs

postinstall.aat (3388B)


      1 @include common.aat
      2 |### Functions ###
      3 |function passwd_user(line,    grep1) {
      4 /etc/passwd	f	+
      5 !f	awk 'BEGIN { FS=OFS=":"; seen=0; line="{{line}}"; split(line, a) }
      6 	{ uids[$3] = $0 }
      7 	$1 == a[1] {
      8 		for(n in a) {
      9 			if(a[n] != $n) {
     10 				print "error: differing present and requested lines" >>"/dev/stderr"
     11 				print "requested: " line >>"/dev/stderr"
     12 				print "present:   " $0 >>"/dev/stderr"
     13 				exit 1
     14 			}
     15 		}
     16 		seen = 1
     17 	}
     18 	{ print $0 }
     19 	END {
     20 		if(seen == 0) {
     21 			if(a[3] in uids) {
     22 				print "error: user record with requested UID already present" >>"/dev/stderr"
     23 				print "requested: " line >>"/dev/stderr"
     24 				print "present:   " uids[a[3]] >>"/dev/stderr"
     25 				exit 1
     26 			}
     27 			print line
     28 		}
     29 	}'
     30 |}
     31 |function shadow_user(line) {
     32 /etc/shadow	f	+
     33 !f	awk 'BEGIN { FS=OFS=":"; seen=0; line="{{line}}"; split(line, a) }
     34 	$1 == a[1] {
     35 		for(n in a) {
     36 			if(a[n] != $n) {
     37 				print "error: differing present and requested lines" >>"/dev/stderr"
     38 				print "requested: " line >>"/dev/stderr"
     39 				print "present:   " $0 >>"/dev/stderr"
     40 				exit 1
     41 			}
     42 		}
     43 		seen = 1
     44 	}
     45 	{ print $0 }
     46 	END {
     47 		if(seen == 0) {
     48 			print line
     49 		}
     50 	}'
     51 |}
     52 |function line_append_file(pre, match_str, post, pre_re, post_re,    regex, grep1) {
     53 |	regex = escape_regex(match_str)
     54 |	grep1 = escape_regex(pre match_str post)
     55 ?	grep -qEe '^{{grep1}}$' "$fname"
     56 !	if grep -qEe '{{pre_re regex post_re}}' "$fname"; then
     57 		sed -ire 's|{{pre_re regex post_re}}|{{pre match_str post}}|' "$fname"
     58 	else
     59 		printf '%s\n' '{{pre match_str post}}' >> "$fname"
     60 	fi
     61 |}
     62 |### postinstall.fileset ###
     63 |END{
     64 |#/boot	+
     65 |#/boot/extlinux.conf	+
     66 |#CN	# Managed by /usr/src/core-system
     67 |#	DEFAULT menu.c32
     68 |#	PROMPT 0
     69 |#	MENU TITLE Alpine/Linux Boot Menu
     70 |#	#MENU HIDDEN
     71 |#	#MENU AUTOBOOT Alpine will be booted automatically in # seconds.
     72 |#	TIMEOUT 30
     73 |#	
     74 |#	LABEL virt
     75 |#	  MENU LABEL Current linux-virt
     76 |#	  LINUX vmlinuz-virt
     77 |#	  INITRD initramfs-virt
     78 |#	  APPEND root=/dev/mapper/vg-spark_root init=/current/init/bin/init modules=sd-mod,usb-storage,ext4,xfs,lvm rootflags=noatime
     79 |#	
     80 |#	LABEL virt-previous
     81 |#	  MENU LABEL Previous linux-virt
     82 |#	  LINUX vmlinuz-virt
     83 |#	  INITRD initramfs-virt
     84 |#	  APPEND root=/dev/mapper/vg-spark_root init=/previous/init/bin/init modules=sd-mod,usb-storage,ext4,xfs,lvm rootflags=noatime
     85 |#|split("libutil.c32 libcom32.c32 mboot.c32 menu.c32 vesamenu.c32", extlinux_modules, " ")
     86 |#|for(n in extlinux_modules) {
     87 |#|	mod = extlinux_modules[n]
     88 |#/boot/{{mod}}	+
     89 |#?	cmp "$fname" '/usr/share/syslinux/{{mod}}'
     90 |#!	cp -va '/usr/share/syslinux/{{mod}}' "$fname"
     91 |#|}
     92 
     93 /etc	+
     94 /etc/group	+
     95 |line_append_file("sshd:x", ":22:", "", "^[^:]*:[^:]*")
     96 |line_append_file("dhcpcd:x", ":546:", "", "^[^:]*:[^:]*")
     97 |line_append_file("ccx:x", ":1000:", "", "^[^:]*:[^:]*")
     98 # Groups for /dev permissions (mdevd.conf): disk, input, uucp
     99 |line_append_file("disk:x", ":6:", "root,adm", "^[^:]*:[^:]*")
    100 |line_append_file("input:x", ":966:", "xorg", "^[^:]*:[^:]*")
    101 |line_append_file("uucp:x", ":14:", "ccx", "^[^:]*:[^:]*")
    102 
    103 /etc/passwd	f	+
    104 ?i	grep -q '^root:.*:{<root_shell>}$'
    105 !f	sed -Ee 's|^(root:.*:)[^:]*$|\1{<root_shell>}|'
    106 
    107 |passwd_user("sshd:x:22:22:sshd:/dev/null:/sbin/nologin")
    108 |shadow_user("sshd:!::0:::::")
    109 
    110 |passwd_user("dhcpcd:x:546:546:sshd:/dev/null:/sbin/nologin")
    111 |shadow_user("dhcpcd:!::0:::::")
    112 
    113 |passwd_user("ccx:x:1000:1000:Jan Pobrislo:/home/ccx:/bin/zsh")
    114 |#shadow_user("ccx:*:10000::::::")
    115 
    116 |}