mirror of
				https://github.com/brain-hackers/brain-config.git
				synced 2025-10-31 04:28:40 +09:00 
			
		
		
		
	be more intelligent about inserting config options
If a config option is already in the file but commented out, modify that line rather than inserting a new one.
This commit is contained in:
		
							
								
								
									
										2
									
								
								debian/control
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								debian/control
									
									
									
									
										vendored
									
									
								
							| @@ -10,5 +10,5 @@ Homepage: https://github.com/asb/raspi-config | |||||||
|  |  | ||||||
| Package: raspi-config | Package: raspi-config | ||||||
| Architecture: all | Architecture: all | ||||||
| Depends: ${misc:Depends}, whiptail, parted | Depends: ${misc:Depends}, whiptail, parted, lua5.1 | ||||||
| Description: Simple configuration for Raspberry Pi | Description: Simple configuration for Raspberry Pi | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								raspi-config
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								raspi-config
									
									
									
									
									
								
							| @@ -70,6 +70,28 @@ EOF | |||||||
| The filesystem will be enlarged upon the next reboot" 20 60 2 | The filesystem will be enlarged upon the next reboot" 20 60 2 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | set_config_var() { | ||||||
|  |   lua - "$1" "$2" "$3" <<EOF > "$3.bak" | ||||||
|  | local key=assert(arg[1]) | ||||||
|  | local value=assert(arg[2]) | ||||||
|  | local fn=assert(arg[3]) | ||||||
|  | local file=assert(io.open(fn)) | ||||||
|  | local made_change=false | ||||||
|  | for line in file:lines() do | ||||||
|  |   if line:match("^#?%s*"..key.."=.*$") then | ||||||
|  |     line=key.."="..value | ||||||
|  |     made_change=true | ||||||
|  |   end | ||||||
|  |   print(line) | ||||||
|  | end | ||||||
|  |  | ||||||
|  | if not made_change then | ||||||
|  |   print(key.."="..value) | ||||||
|  | end | ||||||
|  | EOF | ||||||
|  | mv "$3.bak" "$3" | ||||||
|  | } | ||||||
|  |  | ||||||
| # $1 is 0 to disable overscan, 1 to disable it | # $1 is 0 to disable overscan, 1 to disable it | ||||||
| set_overscan() { | set_overscan() { | ||||||
|   # Stop if /boot is not a mountpoint |   # Stop if /boot is not a mountpoint | ||||||
| @@ -81,13 +103,9 @@ set_overscan() { | |||||||
|  |  | ||||||
|   if [ "$1" -eq 0 ]; then # disable overscan |   if [ "$1" -eq 0 ]; then # disable overscan | ||||||
|     sed /boot/config.txt -i -e "s/^overscan_/#overscan_/" |     sed /boot/config.txt -i -e "s/^overscan_/#overscan_/" | ||||||
|     if grep -q "^disable_overscan" /boot/config.txt; then |     set_config_var disable_overscan 1 /boot/config.txt | ||||||
|       sed -i /boot/config.txt -e "s/^disable_overscan.*$/disable_overscan=1/" |  | ||||||
|     else |  | ||||||
|       printf "disable_overscan=1\n" >> /boot/config.txt |  | ||||||
|     fi |  | ||||||
|   else # enable overscan |   else # enable overscan | ||||||
|     sed -i /boot/config.txt -e "s/^disable_overscan.*$/disable_overscan=0/" |     set_config_var disable_overscan 0 /boot/config.txt | ||||||
|   fi |   fi | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Alex Bradbury
					Alex Bradbury