mirror of
				https://gitlab.com/alemaire/image-specs.git
				synced 2025-01-17 17:48:20 +00:00 
			
		
		
		
	Replace "set-sysconf" for a more descriptive "rpi-set-sysconf"
This commit is contained in:
		
							
								
								
									
										49
									
								
								rpi-set-sysconf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								rpi-set-sysconf
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | ||||
| #!/usr/bin/perl | ||||
| use strict; | ||||
| use warnings; | ||||
| use IO::File; | ||||
| use IO::Pipe; | ||||
| use feature 'switch'; | ||||
|  | ||||
| my ($filename, $fh, %conf); | ||||
|  | ||||
| $filename = '/boot/firmware/sysconf.txt'; | ||||
| exit 0 unless -f $filename; | ||||
|  | ||||
| logger('info', "Applying the system configuration settings in $filename"); | ||||
|  | ||||
| $fh = IO::File->new($filename, 'r'); | ||||
| while (my $line = $fh->getline) { | ||||
|     my ($key, $value); | ||||
|     # Allow for comments, and properly ignore them | ||||
|     $line =~ s/#.+//; | ||||
|     if ( ($key, $value) = ($line =~ m/^\s*([^=]+)\s*=\s*(.*)\s*$/)) { | ||||
| 	$key = lc($key); | ||||
| 	if (exists($conf{$key})) { | ||||
| 	    logger('warn', | ||||
| 		   "Repeated configuration key: $key. " . | ||||
| 		   "Overwriting with new value ($value)"); | ||||
| 	} | ||||
| 	$conf{$key} = $value; | ||||
|     } | ||||
| } | ||||
|  | ||||
| if (my $pass = delete($conf{root_pw})) { | ||||
|     my $pipe; | ||||
|     open($pipe, '|-', '/usr/sbin/chpasswd') or die $!; | ||||
|     print $pipe "root:$pass"; | ||||
|     close($pipe); | ||||
| } | ||||
|  | ||||
| if (scalar keys %conf) { | ||||
|     logger('warn', 'Unprocessed keys left in $filename: ' . | ||||
| 	   join(', ', sort keys %conf)); | ||||
| } | ||||
|  | ||||
| exit 0; | ||||
|  | ||||
| sub logger { | ||||
|     my ($prio, $msg) = @_; | ||||
|     system('/bin/logger', '-p', "daemon.$prio", | ||||
| 	   '-t', 'set-sysconf', $msg); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Gunnar Wolf
					Gunnar Wolf