-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmush.sh
1013 lines (867 loc) · 34.2 KB
/
mush.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
get_largest_cros_blockdev() {
local largest size dev_name tmp_size remo
size=0
for blockdev in /sys/block/*; do
dev_name="${blockdev##*/}"
echo "$dev_name" | grep -q '^\(loop\|ram\)' && continue
tmp_size=$(cat "$blockdev"/size)
remo=$(cat "$blockdev"/removable)
if [ "$tmp_size" -gt "$size" ] && [ "${remo:-0}" -eq 0 ]; then
case "$(doas sfdisk -l -o name "/dev/$dev_name" 2>/dev/null)" in
*STATE*KERN-A*ROOT-A*KERN-B*ROOT-B*)
largest="/dev/$dev_name"
size="$tmp_size"
;;
esac
fi
done
echo "$largest"
}
traps() {
set +e
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
trap 'echo \"${last_command}\" command failed with exit code $? - press a key to exit.' EXIT
trap '' INT
}
mush_info() {
echo -ne "\033]0;mush\007"
if [ ! -f /mnt/stateful_partition/custom_greeting ]; then
cat <<-EOF
Welcome to mush, the murkmod developer shell.
If you got here by mistake, don't panic! Just close this tab and carry on.
This shell contains a list of utilities for performing various actions on a murkmodded chromebook.
murkmod is now maintained completely independently from fakemurk. Don't report any bugs you encounter with it to the fakemurk developers.
EOF
else
cat /mnt/stateful_partition/custom_greeting
fi
}
doas() {
ssh -t -p 1337 -i /rootkey -oStrictHostKeyChecking=no [email protected] "$@"
}
runjob() {
clear
trap 'kill -2 $! >/dev/null 2>&1' INT
(
# shellcheck disable=SC2068
$@
)
trap '' INT
clear
}
swallow_stdin() {
while read -t 0 notused; do
read input
done
}
edit() {
if doas which nano 2>/dev/null; then
doas nano "$@"
else
doas vi "$@"
fi
}
locked_main() {
traps
mush_info
while true; do
echo -ne "\033]0;mush\007"
cat <<-EOF
(1) Emergency Revert & Re-Enroll
(2) Soft Disable Extensions
(3) Hard Disable Extensions
(4) Hard Enable Extensions
(5) Enter Admin Mode (Password-Protected)
(6) Check for updates
EOF
swallow_stdin
read -r -p "> (1-5): " choice
case "$choice" in
1) runjob revert ;;
2) runjob softdisableext ;;
3) runjob harddisableext ;;
4) runjob hardenableext ;;
5) runjob prompt_passwd ;;
6) runjob do_updates && exit 0 ;;
*) echo && echo "Invalid option, dipshit." && echo ;;
esac
done
}
main() {
traps
mush_info
while true; do
echo -ne "\033]0;mush\007"
cat <<-EOF
(1) Root Shell
(2) Chronos Shell
(3) Crosh
(4) Plugins
(5) Install plugins
(6) Uninstall plugins
(7) Powerwash
(8) Emergency Revert & Re-Enroll
(9) Soft Disable Extensions
(10) Hard Disable Extensions
(11) Hard Enable Extensions
(12) Automagically Disable Extensions
(13) Edit Pollen
(14) Install Crouton
(15) Start Crouton
(16) Enable dev_boot_usb
(17) Disable dev_boot_usb
(18) Set mush password
(19) Remove mush password
(20) [EXPERIMENTAL] Update ChromeOS
(21) [EXPERIMENTAL] Update Emergency Backup
(22) [EXPERIMENTAL] Restore Emergency Backup Backup
(23) [EXPERIMENTAL] Install Chromebrew
(24) [EXPERIMENTAL] Install Gentoo Boostrap (dev_install)
(25) Check for updates
EOF
swallow_stdin
read -r -p "> (1-25): " choice
case "$choice" in
1) runjob doas bash ;;
2) runjob doas "cd /home/chronos; sudo -i -u chronos" ;;
3) runjob /usr/bin/crosh.old ;;
4) runjob show_plugins ;;
5) runjob install_plugins ;;
6) runjob uninstall_plugins ;;
7) runjob powerwash ;;
8) runjob revert ;;
9) runjob softdisableext ;;
10) runjob harddisableext ;;
11) runjob hardenableext ;;
12) runjob autodisableexts ;;
13) runjob edit /etc/opt/chrome/policies/managed/policy.json ;;
14) runjob install_crouton ;;
15) runjob run_crouton ;;
16) runjob enable_dev_boot_usb ;;
17) runjob disable_dev_boot_usb ;;
18) runjob set_passwd ;;
19) runjob remove_passwd ;;
20) runjob attempt_chromeos_update ;;
21) runjob attempt_backup_update ;;
22) runjob attempt_restore_backup_backup ;;
23) runjob attempt_chromebrew_install ;;
24) runjob attempt_dev_install ;;
25) runjob do_updates && exit 0 ;;
26) runjob do_dev_updates && exit 0 ;;
101) runjob hard_disable_nokill ;;
111) runjob hard_enable_nokill ;;
112) runjob ext_purge ;;
113) runjob list_plugins ;;
114) runjob install_plugin_legacy ;;
115) runjob uninstall_plugin_legacy ;;
201) runjob api_read_file ;;
202) runjob api_write_file ;;
203) runjob api_append_file ;;
204) runjob api_touch_file ;;
205) runjob api_create_dir ;;
206) runjob api_rm_file ;;
207) runjob api_rm_dir ;;
208) runjob api_ls_dir ;;
209) runjob api_cd ;;
*) echo && echo "Invalid option, dipshit." && echo ;;
esac
done
}
api_read_file() {
echo "file to read?"
read -r filename
local contents=$( base64 $filename )
echo "start content: $contents end content"
}
api_write_file() {
echo "file to write to?"
read -r filename
echo "base64 contents?"
read -r contents
base64 -d <<< "$contents" > $filename
}
api_append_file() {
echo "file to write to?"
read -r filename
echo "base64 contents to append?"
read -r contents
base64 -d <<< "$contents" >> $filename
}
api_touch_file() {
echo "filename?"
read -r filename
touch $filename
}
api_create_dir() {
echo "dirname?"
read -r dirname
mkdir -p $dirname
}
api_rm_file() {
echo "filename?"
read -r filename
rm -f $filename
}
api_rm_dir() {
echo "dirname?"
read -r dirname
rm -Rf $dirname
}
api_ls_dir() {
echo "dirname? (or . for current dir)"
read -r dirname
ls $dirname
}
api_cd() {
echo "dir?"
read -r dirname
cd $dirname
}
install_plugin_legacy() {
local raw_url="https://raw.githubusercontent.com/rainestorme/murkmod/main/plugins"
echo "Find a plugin you want to install here: "
echo " https://github.com/rainestorme/murkmod/tree/main/plugins"
echo "Enter the name of a plugin (including the .sh) to install it (or q to quit):"
read -r plugin_name
local plugin_url="$raw_url/$plugin_name"
local plugin_info=$(curl -s $plugin_url)
if [[ $plugin_info == *"Not Found"* ]]; then
echo "Plugin not found"
else
echo "Installing..."
doas "pushd /mnt/stateful_partition/murkmod/plugins && curl https://raw.githubusercontent.com/rainestorme/murkmod/main/plugins/$plugin_name -O && popd" > /dev/null
echo "Installed $plugin_name"
fi
}
uninstall_plugin_legacy() {
local raw_url="https://raw.githubusercontent.com/rainestorme/murkmod/main/plugins"
echo "Enter the name of a plugin (including the .sh) to uninstall it (or q to quit):"
read -r plugin_name
doas "rm -rf /mnt/stateful_partition/murkmod/plugins/$plugin_name"
}
list_plugins() {
plugins_dir="/mnt/stateful_partition/murkmod/plugins"
plugin_files=()
while IFS= read -r -d '' file; do
plugin_files+=("$file")
done < <(find "$plugins_dir" -type f -name "*.sh" -print0)
plugin_info=()
for file in "${plugin_files[@]}"; do
plugin_script=$file
PLUGIN_NAME=$(grep -o 'PLUGIN_NAME=".*"' "$plugin_script" | cut -d= -f2-)
PLUGIN_FUNCTION=$(grep -o 'PLUGIN_FUNCTION=".*"' "$plugin_script" | cut -d= -f2-)
PLUGIN_DESCRIPTION=$(grep -o 'PLUGIN_DESCRIPTION=".*"' "$plugin_script" | cut -d= -f2-)
PLUGIN_AUTHOR=$(grep -o 'PLUGIN_AUTHOR=".*"' "$plugin_script" | cut -d= -f2-)
PLUGIN_VERSION=$(grep -o 'PLUGIN_VERSION=".*"' "$plugin_script" | cut -d= -f2-)
# remove quotes from around each PLUGIN_* variable
PLUGIN_NAME=${PLUGIN_NAME:1:-1}
PLUGIN_FUNCTION=${PLUGIN_FUNCTION:1:-1}
PLUGIN_DESCRIPTION=${PLUGIN_DESCRIPTION:1:-1}
PLUGIN_AUTHOR=${PLUGIN_AUTHOR:1:-1}
if grep -q "menu_plugin" "$plugin_script"; then
plugin_info+=("$PLUGIN_FUNCTION,$PLUGIN_NAME,$PLUGIN_DESCRIPTION,$PLUGIN_AUTHOR,$PLUGIN_VERSION")
fi
done
to_print=""
# Print menu options
for i in "${!plugin_info[@]}"; do
to_print="$to_print[][]${plugin_info[$i]}"
done
echo "$to_print"
}
do_dev_updates() {
echo "Welcome to the secret murkmod developer update menu!"
echo "This utility allows you to install murkmod from a specific branch on the git repo."
echo "If you were trying to update murkmod normally, then don't panic! Just enter 'main' at the prompt and everything will work normally."
read -p "> (branch name, eg. main): " branch
doas "MURKMOD_BRANCH=$branch bash <(curl -SLk https://raw.githubusercontent.com/rainestorme/murkmod/main/murkmod.sh)"
exit
}
disable_ext() {
local extid="$1"
echo "$extid" | grep -qE '^[a-z]{32}$' && chmod 000 "/home/chronos/user/Extensions/$extid" && kill -9 $(pgrep -f "\-\-extension\-process") || "Extension ID $extid is invalid."
}
disable_ext_nokill() {
local extid="$1"
echo "$extid" | grep -qE '^[a-z]{32}$' && chmod 000 "/home/chronos/user/Extensions/$extid" || "Extension ID $extid is invalid."
}
enable_ext_nokill() {
local extid="$1"
echo "$extid" | grep -qE '^[a-z]{32}$' && chmod 777 "/home/chronos/user/Extensions/$extid" || "Invalid extension id."
}
ext_purge() {
kill -9 $(pgrep -f "\-\-extension\-process")
}
hard_disable_nokill() {
read -r -p "Enter extension ID > " extid
disable_ext_nokill $extid
}
hard_enable_nokill() {
read -r -p "Enter extension ID > " extid
enable_ext_nokill $extid
}
autodisableexts() {
echo "Disabling extensions..."
disable_ext_nokill "haldlgldplgnggkjaafhelgiaglafanh" # GoGuardian
disable_ext_nokill "dikiaagfielfbnbbopidjjagldjopbpa" # Clever Plus
disable_ext_nokill "cgbbbjmgdpnifijconhamggjehlamcif" # Gopher Buddy
disable_ext_nokill "inoeonmfapjbbkmdafoankkfajkcphgd" # Read and Write for Google Chrome
disable_ext_nokill "enfolipbjmnmleonhhebhalojdpcpdoo" # Screenshot reader
disable_ext_nokill "joflmkccibkooplaeoinecjbmdebglab" # Securly
disable_ext_nokill "iheobagjkfklnlikgihanlhcddjoihkg" # Securly again
disable_ext_nokill "adkcpkpghahmbopkjchobieckeoaoeem" # LightSpeed
disable_ext_nokill "jcdhmojfecjfmbdpchihbeilohgnbdci" # Cisco Umbrella
disable_ext_nokill "jdogphakondfdmcanpapfahkdomaicfa" # ContentKeeper Authenticator
disable_ext_nokill "aceopacgaepdcelohobicpffbbejnfac" # Hapara
disable_ext_nokill "kmffehbidlalibfeklaefnckpidbodff" # iBoss
disable_ext_nokill "jaoebcikabjppaclpgbodmmnfjihdngk" # LightSpeed Classroom
disable_ext_nokill "ghlpmldmjjhmdgmneoaibbegkjjbonbk" # Blocksi
disable_ext_nokill "ddfbkhpmcdbciejenfcolaaiebnjcbfc" # Linewize
disable_ext_nokill "jfbecfmiegcjddenjhlbhlikcbfmnafd" # Securly Classroom
disable_ext_nokill "jjpmjccpemllnmgiaojaocgnakpmfgjg" # Impero
disable_ext_nokill "feepmdlmhplaojabeoecaobfmibooaid" # OrbitNote
disable_ext_nokill "dmhpekdihnngbkinliefnclgmgkpjeoo" # GoGuardian License
disable_ext_nokill "modkadcjnbamppdpdkfoackjnhnfiogi" # MyMPS Chrome SSO
ext_purge
echo "Done."
}
set_passwd() {
echo "Enter a new password to use for mush. This will be required to perform any future administrative actions, so make sure you write it down somewhere!"
read -r -p " > " newpassword
doas "touch /mnt/stateful_partition/murkmod/mush_password"
doas "echo '$newpassword'> /mnt/stateful_partition/murkmod/mush_password"
}
remove_passwd() {
echo "Removing password from mush..."
doas "rm -f /mnt/stateful_partition/murkmod/mush_password"
}
prompt_passwd() {
echo "Enter your password:"
read -r -p " > " password
stored_password=$(cat /mnt/stateful_partition/murkmod/mush_password)
if [ "$password" == "$stored_password" ]; then
main
return
else
echo "Incorrect password."
read -r -p "Press enter to continue." throwaway
fi
}
disable_dev_boot_usb() {
echo "Disabling dev_boot_usb"
sed -i 's/\(dev_boot_usb=\).*/\10/' /usr/bin/crossystem
}
enable_dev_boot_usb() {
echo "Enabling dev_boot_usb"
sed -i 's/\(dev_boot_usb=\).*/\11/' /usr/bin/crossystem
}
do_updates() {
doas "bash <(curl -SLk https://raw.githubusercontent.com/rainestorme/murkmod/main/murkmod.sh)"
exit
}
show_plugins() {
plugins_dir="/mnt/stateful_partition/murkmod/plugins"
plugin_files=()
while IFS= read -r -d '' file; do
plugin_files+=("$file")
done < <(find "$plugins_dir" -type f -name "*.sh" -print0)
plugin_info=()
for file in "${plugin_files[@]}"; do
plugin_script=$file
PLUGIN_NAME=$(grep -o 'PLUGIN_NAME=".*"' "$plugin_script" | cut -d= -f2-)
PLUGIN_FUNCTION=$(grep -o 'PLUGIN_FUNCTION=".*"' "$plugin_script" | cut -d= -f2-)
PLUGIN_DESCRIPTION=$(grep -o 'PLUGIN_DESCRIPTION=".*"' "$plugin_script" | cut -d= -f2-)
PLUGIN_AUTHOR=$(grep -o 'PLUGIN_AUTHOR=".*"' "$plugin_script" | cut -d= -f2-)
PLUGIN_VERSION=$(grep -o 'PLUGIN_VERSION=".*"' "$plugin_script" | cut -d= -f2-)
# remove quotes from around each PLUGIN_* variable
PLUGIN_NAME=${PLUGIN_NAME:1:-1}
PLUGIN_FUNCTION=${PLUGIN_FUNCTION:1:-1}
PLUGIN_DESCRIPTION=${PLUGIN_DESCRIPTION:1:-1}
PLUGIN_AUTHOR=${PLUGIN_AUTHOR:1:-1}
if grep -q "menu_plugin" "$plugin_script"; then
plugin_info+=("$PLUGIN_FUNCTION (provided by $PLUGIN_NAME)")
fi
done
# Print menu options
for i in "${!plugin_info[@]}"; do
printf "%s. %s\n" "$((i+1))" "${plugin_info[$i]}"
done
# Prompt user for selection
read -p "> Select a plugin (or q to quit): " selection
if [ "$selection" = "q" ]; then
return 0
fi
# Validate user's selection
if ! [[ "$selection" =~ ^[1-9][0-9]*$ ]]; then
echo "Invalid selection. Please enter a number between 0 and ${#plugin_info[@]}"
return 1
fi
if ((selection < 1 || selection > ${#plugin_info[@]})); then
echo "Invalid selection. Please enter a number between 0 and ${#plugin_info[@]}"
return 1
fi
# Get plugin function name and corresponding file
selected_plugin=${plugin_info[$((selection-1))]}
selected_file=${plugin_files[$((selection-1))]}
# Execute the plugin
bash <(cat $selected_file) # weird syntax due to noexec mount
return 0
}
install_plugins() {
clear
echo "Fetching plugin information..."
json=$(curl -s "https://api.github.com/repos/rainestorme/murkmod/contents/plugins")
file_contents=()
download_urls=()
for entry in $(echo "$json" | jq -c '.[]'); do
# Check if the entry is a file (type equals "file")
if [[ $(echo "$entry" | jq -r '.type') == "file" ]]; then
# Get the download URL for the file
download_url=$(echo "$entry" | jq -r '.download_url')
# Fetch the content of the file and append it to the array
file_contents+=("$(curl -s "$download_url")")
download_urls+=("$download_url")
fi
done
plugin_info=()
for content in "${file_contents[@]}"; do
# Create a temporary file to hold the content
tmp_file=$(mktemp)
echo "$content" > "$tmp_file"
# Extract information from the file
PLUGIN_NAME=$(grep -o 'PLUGIN_NAME=.*' "$tmp_file" | cut -d= -f2-)
PLUGIN_FUNCTION=$(grep -o 'PLUGIN_FUNCTION=.*' "$tmp_file" | cut -d= -f2-)
PLUGIN_DESCRIPTION=$(grep -o 'PLUGIN_DESCRIPTION=.*' "$tmp_file" | cut -d= -f2-)
PLUGIN_AUTHOR=$(grep -o 'PLUGIN_AUTHOR=.*' "$tmp_file" | cut -d= -f2-)
PLUGIN_VERSION=$(grep -o 'PLUGIN_VERSION=.*' "$tmp_file" | cut -d= -f2-)
PLUGIN_NAME=${PLUGIN_NAME:1:-1}
PLUGIN_FUNCTION=${PLUGIN_FUNCTION:1:-1}
PLUGIN_DESCRIPTION=${PLUGIN_DESCRIPTION:1:-1}
PLUGIN_AUTHOR=${PLUGIN_AUTHOR:1:-1}
# Add information to the plugin_info array
plugin_info+=(" $PLUGIN_NAME (version $PLUGIN_VERSION by $PLUGIN_AUTHOR) \n $PLUGIN_DESCRIPTION")
# Remove the temporary file
rm "$tmp_file"
done
clear
echo "Available plugins (press q to exit):"
selected_option=0
while true; do
for i in "${!plugin_info[@]}"; do
if [ $i -eq $selected_option ]; then
printf " -> "
else
printf " "
fi
printf "${plugin_info[$i]}"
# see if the plugin is already installed - get the filename of the plugin from its download url
filename=$(echo "${download_urls[$i]}" | rev | cut -d/ -f1 | rev)
if [ -f "/mnt/stateful_partition/murkmod/plugins/$filename" ]; then
echo " (installed)"
else
echo
fi
done
# Read a single character from the user
read -s -n 1 key
# Check the pressed key and update the selected option
case "$key" in
"q") break ;; # Exit the loop if the user presses 'q'
"A") ((selected_option--)) ;; # Arrow key up
"B") ((selected_option++)) ;; # Arrow key down
"") clear
echo "Using URL: ${download_urls[$selected_option]}"
echo "Installing plugin..."
doas "pushd /mnt/stateful_partition/murkmod/plugins && curl ${download_urls[$selected_option]} -O && popd" > /dev/null
echo "Done!"
;;
esac
# Ensure the selected option stays within bounds
((selected_option = selected_option < 0 ? 0 : selected_option))
((selected_option = selected_option >= ${#plugin_info[@]} ? ${#plugin_info[@]} - 1 : selected_option))
# Clear the screen for the next iteration
clear
echo "Available plugins (press q to exit):"
done
}
uninstall_plugins() {
clear
plugins_dir="/mnt/stateful_partition/murkmod/plugins"
plugin_files=()
while IFS= read -r -d '' file; do
plugin_files+=("$file")
done < <(find "$plugins_dir" -type f -name "*.sh" -print0)
plugin_info=()
for file in "${plugin_files[@]}"; do
plugin_script=$file
PLUGIN_NAME=$(grep -o 'PLUGIN_NAME=.*' "$plugin_script" | cut -d= -f2-)
PLUGIN_FUNCTION=$(grep -o 'PLUGIN_FUNCTION=.*' "$plugin_script" | cut -d= -f2-)
PLUGIN_DESCRIPTION=$(grep -o 'PLUGIN_DESCRIPTION=.*' "$plugin_script" | cut -d= -f2-)
PLUGIN_AUTHOR=$(grep -o 'PLUGIN_AUTHOR=.*' "$plugin_script" | cut -d= -f2-)
PLUGIN_VERSION=$(grep -o 'PLUGIN_VERSION=.*' "$plugin_script" | cut -d= -f2-)
PLUGIN_NAME=${PLUGIN_NAME:1:-1}
PLUGIN_FUNCTION=${PLUGIN_FUNCTION:1:-1}
PLUGIN_DESCRIPTION=${PLUGIN_DESCRIPTION:1:-1}
PLUGIN_AUTHOR=${PLUGIN_AUTHOR:1:-1}
plugin_info+=("$PLUGIN_NAME (version $PLUGIN_VERSION by $PLUGIN_AUTHOR)")
done
if [ ${#plugin_info[@]} -eq 0 ]; then
echo "No plugins installed."
read -r -p "Press enter to continue." throwaway
return
fi
while true; do
echo "Installed plugins:"
for i in "${!plugin_info[@]}"; do
echo "$(($i+1)). ${plugin_info[$i]}"
done
echo "0. Exit back to mush"
read -r -p "Enter a number to uninstall a plugin, or 0 to exit: " choice
if [ "$choice" -eq 0 ]; then
clear
return
fi
index=$(($choice-1))
if [ "$index" -lt 0 ] || [ "$index" -ge ${#plugin_info[@]} ]; then
echo "Invalid choice."
continue
fi
plugin_file="${plugin_files[$index]}"
PLUGIN_NAME=$(grep -o 'PLUGIN_NAME=".*"' "$plugin_file" | cut -d= -f2-)
PLUGIN_FUNCTION=$(grep -o 'PLUGIN_FUNCTION=".*"' "$plugin_file" | cut -d= -f2-)
PLUGIN_DESCRIPTION=$(grep -o 'PLUGIN_DESCRIPTION=".*"' "$plugin_file" | cut -d= -f2-)
PLUGIN_AUTHOR=$(grep -o 'PLUGIN_AUTHOR=".*"' "$plugin_file" | cut -d= -f2-)
PLUGIN_VERSION=$(grep -o 'PLUGIN_VERSION=".*"' "$plugin_file" | cut -d= -f2-)
# remove quotes
PLUGIN_NAME=${PLUGIN_NAME:1:-1}
PLUGIN_FUNCTION=${PLUGIN_FUNCTION:1:-1}
PLUGIN_DESCRIPTION=${PLUGIN_DESCRIPTION:1:-1}
PLUGIN_AUTHOR=${PLUGIN_AUTHOR:1:-1}
plugin_name="$PLUGIN_NAME (version $PLUGIN_VERSION by $PLUGIN_AUTHOR)"
read -r -p "Are you sure you want to uninstall $plugin_name? [y/n] " confirm
if [ "$confirm" == "y" ]; then
doas rm "$plugin_file"
echo "$plugin_name uninstalled."
unset plugin_info[$index]
plugin_info=("${plugin_info[@]}")
fi
done
}
powerwash() {
echo "Are you sure you wanna powerwash? This will remove all user accounts and data, but won't remove fakemurk."
sleep 2
echo "(Press enter to continue, ctrl-c to cancel)"
swallow_stdin
read -r
doas rm -f /stateful_unfucked
doas reboot
exit
}
revert() {
echo "This option will re-enroll your chromebook and restore it to its exact state before fakemurk was run. This is useful if you need to quickly go back to normal."
echo "This is *permanent*. You will not be able to fakemurk again unless you re-run everything from the beginning."
echo "Are you sure - 100% sure - that you want to continue? (press enter to continue, ctrl-c to cancel)"
swallow_stdin
read -r
printf "Setting kernel priority in 3 (this is your last chance to cancel)..."
sleep 1
printf "2..."
sleep 1
echo "1..."
sleep 1
echo "Setting kernel priority"
DST=$(get_largest_cros_blockdev)
if doas "((\$(cgpt show -n \"$DST\" -i 2 -P) > \$(cgpt show -n \"$DST\" -i 4 -P)))"; then
doas cgpt add "$DST" -i 2 -P 0
doas cgpt add "$DST" -i 4 -P 1
else
doas cgpt add "$DST" -i 4 -P 0
doas cgpt add "$DST" -i 2 -P 1
fi
echo "Setting vpd..."
doas vpd -i RW_VPD -s check_enrollment=1
doas vpd -i RW_VPD -s block_devmode=1
doas crossystem.old block_devmode=1
echo "Setting stateful unfuck flag..."
rm -f /stateful_unfucked
echo "Done. Press enter to reboot"
swallow_stdin
read -r
echo "Bye!"
sleep 2
doas reboot
sleep 1000
echo "Your chromebook should have rebooted by now. If your chromebook doesn't reboot in the next couple of seconds, press Esc+Refresh to do it manually."
}
harddisableext() { # calling it "hard disable" because it only reenables when you press
read -r -p "Enter extension ID > " extid
echo "$extid" | grep -qE '^[a-z]{32}$' && chmod 000 "/home/chronos/user/Extensions/$extid" && kill -9 $(pgrep -f "\-\-extension\-process") || "Invalid extension id."
}
hardenableext() {
read -r -p "Enter extension ID > " extid
echo "$extid" | grep -qE '^[a-z]{32}$' && chmod 777 "/home/chronos/user/Extensions/$extid" && kill -9 $(pgrep -f "\-\-extension\-process") || "Invalid extension id."
}
softdisableext() {
echo "Extensions will stay disabled until you press Ctrl+c or close this tab"
while true; do
kill -9 $(pgrep -f "\-\-extension\-process") 2>/dev/null
sleep 0.5
done
}
# https://chromium.googlesource.com/chromiumos/docs/+/master/lsb-release.md
lsbval() {
local key="$1"
local lsbfile="${2:-/etc/lsb-release}"
if ! echo "${key}" | grep -Eq '^[a-zA-Z0-9_]+$'; then
return 1
fi
sed -E -n -e \
"/^[[:space:]]*${key}[[:space:]]*=/{
s:^[^=]+=[[:space:]]*::
s:[[:space:]]+$::
p
}" "${lsbfile}"
}
install_crouton() {
# check if crouuton is already installed. if so, prompt the user to delete their old chroot
if [ -f /mnt/stateful_partition/crouton_installed ] ; then
read -p "Crouton is already installed. Would you like to delete your old chroot and create a new one? (y/N) " yn
case $yn in
[yY] ) doas "rm -rf /mnt/stateful_partition/crouton/chroots && rm -f /mnt/stateful_partition/crouton_installed";;
[nN] ) return;;
* ) return;;
esac
fi
echo "Installing Crouton..."
# if this is before v107, then we don't want to use the silence branch - audio is still supported
local local_version=$(lsbval GOOGLE_RELEASE)
if (( ${local_version%%\.*} <= 107 )); then
doas "bash <(curl -SLk https://goo.gl/fd3zc) -r bullseye -t xfce"
else
# theoretically we could copy or link the includes for cras, but im not entirely sure how to do that
# CROUTON_BRANCH=longliveaudiotools supports audio at the versions we're looking at, but it's experimental and tends to be broken
# ig we can prompt the user?
echo "Your version of ChromeOS is too recent to support the current main branch of Crouton. You can either install Crouton without audio support, or install the experimental audio branch. Which would you like to do?"
echo "1. Install without audio support"
echo "2. Install with experimental audio support (may be extremely broken)"
read -r -p "> (1-2): " choice
if [ "$choice" == "1" ]; then
doas "CROUTON_BRANCH=silence bash <(curl -SLk https://goo.gl/fd3zc) -r bullseye -t xfce"
elif [ "$choice" == "2" ]; then
doas "CROUTON_BRANCH=longliveaudiotools bash <(curl -SLk https://goo.gl/fd3zc) -r bullseye -t xfce"
else
echo "Invalid option, defaulting to silence branch"
doas "CROUTON_BRANCH=silence bash <(curl -SLk https://goo.gl/fd3zc) -r bullseye -t xfce"
fi
fi
doas "bash <(echo 'touch /mnt/stateful_partition/crouton_installed')" # idfk about the syntax but it seems to work so im not complaining
}
run_crouton() {
if [ -f /mnt/stateful_partition/crouton_installed ] ; then
echo "Use Crtl+Shift+Alt+Forward and Ctrl+Shift+Alt+Back to toggle between desktops"
doas "startxfce4"
else
echo "Install Crouton first!"
read -p "Press enter to continue."
fi
}
get_booted_kernnum() {
if doas "((\$(cgpt show -n \"$dst\" -i 2 -P) > \$(cgpt show -n \"$dst\" -i 4 -P)))"; then
echo -n 2
else
echo -n 4
fi
}
opposite_num() {
if [ "$1" == "2" ]; then
echo -n 4
elif [ "$1" == "4" ]; then
echo -n 2
elif [ "$1" == "3" ]; then
echo -n 5
elif [ "$1" == "5" ]; then
echo -n 3
else
return 1
fi
}
attempt_chromeos_update(){
read -p "Do you want to use the default ChromeOS bootsplash? [y/N] " use_orig_bootsplash
case "$use_orig_bootsplash" in
[yY][eE][sS]|[yY])
USE_ORIG_SPLASH="1"
;;
*)
USE_ORIG_SPLASH="0"
;;
esac
local builds=$(curl https://chromiumdash.appspot.com/cros/fetch_serving_builds?deviceCategory=Chrome%20OS)
local release_board=$(lsbval CHROMEOS_RELEASE_BOARD)
local board=${release_board%%-*}
local hwid=$(jq "(.builds.$board[] | keys)[0]" <<<"$builds")
local hwid=${hwid:1:-1}
local latest_milestone=$(jq "(.builds.$board[].$hwid.pushRecoveries | keys) | .[length - 1]" <<<"$builds")
local remote_version=$(jq ".builds.$board[].$hwid[$latest_milestone].version" <<<"$builds")
local remote_version=${remote_version:1:-1}
local local_version=$(lsbval GOOGLE_RELEASE)
if (( ${remote_version%%\.*} > ${local_version%%\.*} )); then
echo "Updating to ${remote_version}. THIS MAY DELETE ALL USER DATA! Press enter to confirm, Ctrl+C to cancel."
read -r
echo "Dumping emergency revert backup to stateful (this might take a while)..."
echo "Finding correct partitions..."
local dst=$(get_largest_cros_blockdev)
local tgt_kern=$(opposite_num $(get_booted_kernnum))
local tgt_root=$(( $tgt_kern + 1 ))
local kerndev=${dst}p${tgt_kern}
local rootdev=${dst}p${tgt_root}
echo "Dumping kernel..."
doas dd if=$kerndev of=/mnt/stateful_partition/murkmod/kern_backup.img bs=4M status=progress
echo "Dumping rootfs..."
doas dd if=$rootdev of=/mnt/stateful_partition/murkmod/root_backup.img bs=4M status=progress
echo "Creating restore flag..."
doas touch /mnt/stateful_partition/restore-emergency-backup
doas chmod 777 /mnt/stateful_partition/restore-emergency-backup
echo "Backups complete, actually updating now..."
# read choice
local reco_dl=$(jq ".builds.$board[].$hwid.pushRecoveries[$latest_milestone]" <<< "$builds")
local tmpdir=/mnt/stateful_partition/update_tmp/
doas mkdir $tmpdir
echo "Downloading ${remote_version} from ${reco_dl}..."
curl "${reco_dl:1:-1}" | doas "dd of=$tmpdir/image.zip status=progress"
echo "Unzipping update binary..."
cat $tmpdir/image.zip | gunzip | doas "dd of=$tmpdir/image.bin status=progress"
doas rm -f $tmpdir/image.zip
echo "Invoking image patcher..."
if [ "$USE_ORIG_SPLASH" == 0 ]; then
doas image_patcher.sh "$tmpdir/image.bin"
else
doas image_patcher.sh "$tmpdir/image.bin" cros
fi
local loop=$(doas losetup -f | tr -d '\r' | tail -1)
doas losetup -P "$loop" "$tmpdir/image.bin"
echo "Performing update..."
printf "Overwriting partitions in 3 (this is your last chance to cancel)..."
sleep 1
printf "2..."
sleep 1
echo "1..."
sleep 1
echo "Installing kernel patch to ${kerndev}..."
doas dd if="${loop}p4" of="$kerndev" status=progress
echo "Installing root patch to ${rootdev}..."
doas dd if="${loop}p3" of="$rootdev" status=progress
echo "Setting kernel priority..."
doas cgpt add "$dst" -i 4 -P 0
doas cgpt add "$dst" -i 2 -P 0
doas cgpt add "$dst" -i "$tgt_kern" -P 1
echo "Setting crossystem and vpd block_devmode..."
doas crossystem.old block_devmode=0
doas vpd -i RW_VPD -s block_devmode=0
echo "Cleaning up..."
doas rm -Rf $tmpdir
read -p "Done! Press enter to continue."
else
echo "Update not required."
read -p "Press enter to continue."
fi
}
attempt_backup_update(){
local builds=$(curl https://chromiumdash.appspot.com/cros/fetch_serving_builds?deviceCategory=Chrome%20OS)
local release_board=$(lsbval CHROMEOS_RELEASE_BOARD)
local board=${release_board%%-*}
local hwid=$(jq "(.builds.$board[] | keys)[0]" <<<"$builds")
local hwid=${hwid:1:-1}
local latest_milestone=$(jq "(.builds.$board[].$hwid.pushRecoveries | keys) | .[length - 1]" <<<"$builds")
local remote_version=$(jq ".builds.$board[].$hwid[$latest_milestone].version" <<<"$builds")
local remote_version=${remote_version:1:-1}
read -p "Do you want to make a backup of your backup, just in case? (Y/n) " yn
case $yn in
[yY] ) do_backup=true ;;
[nN] ) do_backup=false ;;
* ) do_backup=true ;;
esac
echo "Updating to ${remote_version}. THIS CAN POSSIBLY DAMAGE YOUR EMERGENCY BACKUP! Press enter to confirm, Ctrl+C to cancel."
read -r
echo "Finding correct partitions..."
local dst=$(get_largest_cros_blockdev)
local tgt_kern=$(opposite_num $(get_booted_kernnum))
local tgt_root=$(( $tgt_kern + 1 ))
local kerndev=${dst}p${tgt_kern}
local rootdev=${dst}p${tgt_root}
if [ "$do_backup" = true ] ; then
echo "Dumping emergency revert backup to stateful (this might take a while)..."
echo "Dumping kernel..."
doas dd if=$kerndev of=/mnt/stateful_partition/murkmod/kern_backup.img bs=4M status=progress
echo "Dumping rootfs..."
doas dd if=$rootdev of=/mnt/stateful_partition/murkmod/root_backup.img bs=4M status=progress
echo "Backups complete, actually updating now..."
fi
# read choice
local reco_dl=$(jq ".builds.$board[].$hwid.pushRecoveries[$latest_milestone]" <<< "$builds")
local tmpdir=/mnt/stateful_partition/update_tmp/
doas mkdir $tmpdir
echo "Downloading ${remote_version} from ${reco_dl}..."
curl "${reco_dl:1:-1}" | doas "dd of=$tmpdir/image.zip status=progress"
echo "Unzipping update binary..."
cat $tmpdir/image.zip | gunzip | doas "dd of=$tmpdir/image.bin status=progress"
doas rm -f $tmpdir/image.zip
echo "Creating loop device..."
local loop=$(doas losetup -f | tr -d '\r')
doas losetup -P "$loop" "$tmpdir/image.bin"
printf "Overwriting backup in 3 (this is your last chance to cancel)..."
sleep 1
printf "2..."
sleep 1
echo "1..."
sleep 1
echo "Performing update..."
echo "Installing kernel patch to ${kerndev}..."
doas dd if="${loop}p4" of="$kerndev" status=progress
echo "Installing root patch to ${rootdev}..."
doas dd if="${loop}p3" of="$rootdev" status=progress
echo "Setting crossystem and vpd block_devmode..." # idrk why, but it can't hurt to be safe
doas crossystem.old block_devmode=0
doas vpd -i RW_VPD -s block_devmode=0
echo "Cleaning up..."
doas rm -Rf $tmpdir
read -p "Done! Press enter to continue."
}
attempt_restore_backup_backup() {
echo "Looking for backup files..."
dst=$(get_largest_cros_blockdev)
tgt_kern=$(opposite_num $(get_booted_kernnum))
tgt_root=$(( $tgt_kern + 1 ))
kerndev=${dst}p${tgt_kern}
rootdev=${dst}p${tgt_root}
if [ -f /mnt/stateful_partition/murkmod/kern_backup.img ] && [ -f /mnt/stateful_partition/murkmod/root_backup.img ]; then
echo "Backup files found!"
echo "Restoring kernel..."
dd if=/mnt/stateful_partition/murkmod/kern_backup.img of=$kerndev bs=4M status=progress
echo "Restoring rootfs..."
dd if=/mnt/stateful_partition/murkmod/root_backup.img of=$rootdev bs=4M status=progress
echo "Removing backup files..."
rm /mnt/stateful_partition/murkmod/kern_backup.img
rm /mnt/stateful_partition/murkmod/root_backup.img
echo "Restored successfully!"
read -p "Press enter to continue."
else
echo "Missing backup image, aborting!"
read -p "Press enter to continue."
fi
}
attempt_install_chromebrew() {
doas 'sudo -i -u chronos curl -Ls git.io/vddgY | bash' # kinda works now with cros_debug
read -p 'Press enter to exit'
}