AnyKernel2: fix patch_fstab, add replace_section

- correct typo that was breaking patch_fstab
- add function to replace entire sections of files by selecting the first and last lines of the section using search strings and replacing it entirely with a new string
This commit is contained in:
osm0sis committed 2016-01-10 04:15:24 -04:00
1 parent bd4ba60cc5
commit 8c64041208
2 files changed
+13 -5

No files matched your search

+3 -2
View File
@@ -32,6 +32,7 @@ do.cleanup=0 will keep the zip from removing it's working directory in /tmp/anyk
dump_boot dump_boot
backup_file <file> backup_file <file>
replace_string <file> <if search string> <original string> <replacement string> replace_string <file> <if search string> <original string> <replacement string>
replace_section <file> <begin search string> <end search string> <replacement string>
insert_line <file> <if search string> <before|after> <line match string> <inserted line> insert_line <file> <if search string> <before|after> <line match string> <inserted line>
replace_line <file> <line replace string> <replacement line> replace_line <file> <line replace string> <replacement line>
remove_line <file> <line match string> remove_line <file> <line match string>
@@ -39,12 +40,12 @@ prepend_file <file> <if search string> <patch file>
insert_file <file> <if search string> <before|after> <line match string> <patch file> insert_file <file> <if search string> <before|after> <line match string> <patch file>
append_file <file> <if search string> <patch file> append_file <file> <if search string> <patch file>
replace_file <file> <permissions> <patch file> replace_file <file> <permissions> <patch file>
patch_fstab <fstab file> <mount match name> <fs match type> <block|mount|fstype|options|flags> <if search string> <replacement string> patch_fstab <fstab file> <mount match name> <fs match type> <block|mount|fstype|options|flags> <original string> <replacement string>
write_boot write_boot
"if search string" is the string it looks for to decide whether it needs to add the tweak or not, so generally something to indicate the tweak already exists. "if search string" is the string it looks for to decide whether it needs to add the tweak or not, so generally something to indicate the tweak already exists.
Similarly, "line match string" and "line replace string" are the search strings that locate where the modification needs to be made for those commands, and "mount match name" and "fs match type" are both required to narrow the patch_fstab command down to the correct entry. Similarly, "line match string" and "line replace string" are the search strings that locate where the modification needs to be made for those commands, "begin search string" and "end search string" are both required to select the first and last lines of the script block to be replaced for replace_section, and "mount match name" and "fs match type" are both required to narrow the patch_fstab command down to the correct entry.
"before|after" requires you simply specify "before" or "after" for the placement of the inserted line, in relation to "line match string". "before|after" requires you simply specify "before" or "after" for the placement of the inserted line, in relation to "line match string".
+10 -3
View File
@@ -108,6 +108,13 @@ replace_string() {
fi; fi;
} }
# replace_section <file> <begin search string> <end search string> <replacement string>
replace_section() {
line=`grep -n "$2" $1 | cut -d: -f1`;
sed -i "/${2}/,/${3}/d" $1;
sed -i "${line}s;^;${4}\n;" $1;
}
# insert_line <file> <if search string> <before|after> <line match string> <inserted line> # insert_line <file> <if search string> <before|after> <line match string> <inserted line>
insert_line() { insert_line() {
if [ -z "$(grep "$2" $1)" ]; then if [ -z "$(grep "$2" $1)" ]; then
@@ -171,10 +178,10 @@ replace_file() {
chmod $2 $1; chmod $2 $1;
} }
# patch_fstab <fstab file> <mount match name> <fs match type> <block|mount|fstype|options|flags> <if search string> <replacement string> # patch_fstab <fstab file> <mount match name> <fs match type> <block|mount|fstype|options|flags> <original string> <replacement string>
patch_fstab() { patch_fstab() {
entry=$(grep "$2" $1 | grep "$3"); entry=$(grep "$2" $1 | grep "$3");
if [ -z "$(echo "$entry" | grep "$5")" ]; then if [ -z "$(echo "$entry" | grep "$6")" ]; then
case $4 in case $4 in
block) part=$(echo "$entry" | awk '{ print $1 }');; block) part=$(echo "$entry" | awk '{ print $1 }');;
mount) part=$(echo "$entry" | awk '{ print $2 }');; mount) part=$(echo "$entry" | awk '{ print $2 }');;
@@ -225,7 +232,7 @@ fi;
backup_file fstab.tuna; backup_file fstab.tuna;
patch_fstab fstab.tuna /system ext4 options "nodiratime,barrier=0" "nodev,noatime,nodiratime,barrier=0,data=writeback,noauto_da_alloc,discard"; patch_fstab fstab.tuna /system ext4 options "nodiratime,barrier=0" "nodev,noatime,nodiratime,barrier=0,data=writeback,noauto_da_alloc,discard";
patch_fstab fstab.tuna /cache ext4 options "barrier=0,nomblk_io_submit" "nosuid,nodev,noatime,nodiratime,errors=panic,barrier=0,nomblk_io_submit,data=writeback,noauto_da_alloc"; patch_fstab fstab.tuna /cache ext4 options "barrier=0,nomblk_io_submit" "nosuid,nodev,noatime,nodiratime,errors=panic,barrier=0,nomblk_io_submit,data=writeback,noauto_da_alloc";
patch_fstab fstab.tuna /userdata ext4 options "nomblk_io_submit,data=writeback" "nosuid,nodev,noatime,errors=panic,nomblk_io_submit,data=writeback,noauto_da_alloc"; patch_fstab fstab.tuna /data ext4 options "nomblk_io_submit,data=writeback" "nosuid,nodev,noatime,errors=panic,nomblk_io_submit,data=writeback,noauto_da_alloc";
append_file fstab.tuna "usbdisk" fstab; append_file fstab.tuna "usbdisk" fstab;
# end ramdisk changes # end ramdisk changes