Skip to content

Commit 8c64041

Browse files
committed
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
1 parent bd4ba60 commit 8c64041

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

README

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ do.cleanup=0 will keep the zip from removing it's working directory in /tmp/anyk
3232
dump_boot
3333
backup_file <file>
3434
replace_string <file> <if search string> <original string> <replacement string>
35+
replace_section <file> <begin search string> <end search string> <replacement string>
3536
insert_line <file> <if search string> <before|after> <line match string> <inserted line>
3637
replace_line <file> <line replace string> <replacement line>
3738
remove_line <file> <line match string>
3839
prepend_file <file> <if search string> <patch file>
3940
insert_file <file> <if search string> <before|after> <line match string> <patch file>
4041
append_file <file> <if search string> <patch file>
4142
replace_file <file> <permissions> <patch file>
42-
patch_fstab <fstab file> <mount match name> <fs match type> <block|mount|fstype|options|flags> <if search string> <replacement string>
43+
patch_fstab <fstab file> <mount match name> <fs match type> <block|mount|fstype|options|flags> <original string> <replacement string>
4344
write_boot
4445

4546
"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.
4647

47-
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.
48+
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.
4849

4950
"before|after" requires you simply specify "before" or "after" for the placement of the inserted line, in relation to "line match string".
5051

anykernel.sh

+10-3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ replace_string() {
108108
fi;
109109
}
110110

111+
# replace_section <file> <begin search string> <end search string> <replacement string>
112+
replace_section() {
113+
line=`grep -n "$2" $1 | cut -d: -f1`;
114+
sed -i "/${2}/,/${3}/d" $1;
115+
sed -i "${line}s;^;${4}\n;" $1;
116+
}
117+
111118
# insert_line <file> <if search string> <before|after> <line match string> <inserted line>
112119
insert_line() {
113120
if [ -z "$(grep "$2" $1)" ]; then
@@ -171,10 +178,10 @@ replace_file() {
171178
chmod $2 $1;
172179
}
173180

174-
# patch_fstab <fstab file> <mount match name> <fs match type> <block|mount|fstype|options|flags> <if search string> <replacement string>
181+
# patch_fstab <fstab file> <mount match name> <fs match type> <block|mount|fstype|options|flags> <original string> <replacement string>
175182
patch_fstab() {
176183
entry=$(grep "$2" $1 | grep "$3");
177-
if [ -z "$(echo "$entry" | grep "$5")" ]; then
184+
if [ -z "$(echo "$entry" | grep "$6")" ]; then
178185
case $4 in
179186
block) part=$(echo "$entry" | awk '{ print $1 }');;
180187
mount) part=$(echo "$entry" | awk '{ print $2 }');;
@@ -225,7 +232,7 @@ fi;
225232
backup_file fstab.tuna;
226233
patch_fstab fstab.tuna /system ext4 options "nodiratime,barrier=0" "nodev,noatime,nodiratime,barrier=0,data=writeback,noauto_da_alloc,discard";
227234
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";
228-
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";
235+
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";
229236
append_file fstab.tuna "usbdisk" fstab;
230237

231238
# end ramdisk changes

0 commit comments

Comments
 (0)