murkmod.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #!/bin/bash
  2. CURRENT_MAJOR=0
  3. CURRENT_MINOR=3
  4. CURRENT_VERSION=2
  5. get_asset() {
  6. curl -s -f "https://api.github.com/repos/rainestorme/murkmod/contents/$1" | jq -r ".content" | base64 -d
  7. }
  8. get_asset_fakemurk() {
  9. curl -s -f "https://api.github.com/repos/MercuryWorkshop/fakemurk/contents/$1" | jq -r ".content" | base64 -d
  10. }
  11. get_built_asset_fakemurk() {
  12. curl -SLk "https://github.com/MercuryWorkshop/fakemurk/releases/latest/download/$1"
  13. }
  14. install() {
  15. TMP=$(mktemp)
  16. get_asset "$1" >"$TMP"
  17. if [ "$?" == "1" ] || ! grep -q '[^[:space:]]' "$TMP"; then
  18. echo "Failed to install $1 to $2"
  19. rm -f "$TMP"
  20. exit
  21. fi
  22. # Don't mv, that would break permissions
  23. cat "$TMP" >"$2"
  24. rm -f "$TMP"
  25. }
  26. install_fakemurk() {
  27. TMP=$(mktemp)
  28. get_asset_fakemurk "$1" >"$TMP"
  29. if [ "$?" == "1" ] || ! grep -q '[^[:space:]]' "$TMP"; then
  30. echo "Failed to install $1 to $2"
  31. rm -f "$TMP"
  32. exit
  33. fi
  34. # Don't mv, that would break permissions
  35. cat "$TMP" >"$2"
  36. rm -f "$TMP"
  37. }
  38. install_built_fakemurk() {
  39. TMP=$(mktemp)
  40. get_built_asset_fakemurk "$1" >"$TMP"
  41. if [ "$?" == "1" ] || ! grep -q '[^[:space:]]' "$TMP"; then
  42. echo "failed to install $1 to $2"
  43. rm -f "$TMP"
  44. return 1
  45. fi
  46. cat "$TMP" >"$2"
  47. rm -f "$TMP"
  48. }
  49. show_logo() {
  50. echo -e " __ .___\n _____ __ _________| | __ _____ ____ __| _/\n / \| | \_ __ \ |/ // \ / _ \ / __ | \n| Y Y \ | /| | \/ <| Y Y ( <_> ) /_/ | \n|__|_| /____/ |__| |__|_ \__|_| /\____/\____ | \n \/ \/ \/ \/\n"
  51. echo " The fakemurk plugin manager - v$CURRENT_MAJOR.$CURRENT_MINOR.$CURRENT_VERSION"
  52. }
  53. install_patched_files() {
  54. install "fakemurk-daemon.sh" /sbin/fakemurk-daemon.sh
  55. install "chromeos_startup.sh" /sbin/chromeos_startup.sh
  56. install "mush.sh" /usr/bin/crosh
  57. install "pre-startup.conf" /etc/init/pre-startup.conf
  58. install "cr50-update.conf" /etc/init/cr50-update.conf
  59. install "ssd_util.sh" /usr/share/vboot/bin/ssd_util.sh
  60. install_built_fakemurk "image_patcher.sh" /sbin/image_patcher.sh
  61. chmod 777 /sbin/fakemurk-daemon.sh /sbin/chromeos_startup.sh /usr/bin/crosh /usr/share/vboot/bin/ssd_util.sh /sbin/image_patcher.sh
  62. }
  63. create_stateful_files() {
  64. # This is only here for backwards compatibility
  65. touch /mnt/stateful_partition/murkmod_version
  66. echo "$CURRENT_MAJOR $CURRENT_MINOR $CURRENT_VERSION" > /mnt/stateful_partition/murkmod_version
  67. mkdir -p /mnt/stateful_partition/murkmod/plugins
  68. touch /mnt/stateful_partition/murkmod/settings
  69. if [ ! -f /mnt/stateful_partition/murkmod/settings ]; then
  70. echo "# ----- murkmod settings -----" > /mnt/stateful_partition/murkmod/settings
  71. echo "" >> /mnt/stateful_partition/murkmod/settings
  72. echo "# Whether or not to show experimental features" >> /mnt/stateful_partition/murkmod/settings
  73. echo "show_experimental=false" >> /mnt/stateful_partition/murkmod/settings
  74. fi
  75. }
  76. check_for_emergencyshell() {
  77. if test -d "/home/chronos/user/Downloads/fix-mush"; then
  78. echo "Running from emergency shell, reverting..."
  79. rm -Rf /home/chronos/user/Downloads/fix-mush
  80. fi
  81. }
  82. do_policy_patch() {
  83. url1="https://raw.githubusercontent.com/rainestorme/murkmod/main/pollen.json"
  84. url2="https://raw.githubusercontent.com/MercuryWorkshop/fakemurk/main/pollen.json"
  85. response1=$(curl -s "$url1")
  86. response2=$(curl -s "$url2")
  87. if [ "$response1" = "$response2" ]; then
  88. install "pollen.json" /etc/opt/chrome/policies/managed/policy.json
  89. else
  90. read -r -p "Use murkmod reccomended pollen config? [Y/n] " choice
  91. case "$choice" in
  92. n | N) install_fakemurk "pollen.json" /etc/opt/chrome/policies/managed/policy.json ;;
  93. *) install "pollen.json" /etc/opt/chrome/policies/managed/policy.json ;;
  94. esac
  95. fi
  96. }
  97. set_chronos_password() {
  98. echo -en "murkmod\nmurkmod\n" | passwd chronos
  99. }
  100. set_sudo_perms() {
  101. if ! cat /etc/sudoers | grep chronos; then
  102. echo "Sudo permissions are not already set, setting..."
  103. echo "chronos ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
  104. else
  105. echo "Looks like sudo permissions are already set correctly."
  106. fi
  107. }
  108. murkmod() {
  109. show_logo
  110. if [ ! -f /sbin/fakemurk-daemon.sh ]; then
  111. echo "Either your system has a broken fakemurk installation or your system doesn't have a fakemurk installation at all. (Re)install fakemurk, then re-run this script."
  112. exit
  113. fi
  114. echo "Checking for emergency shell..."
  115. check_for_emergencyshell
  116. echo "Installing patched files..."
  117. install_patched_files
  118. echo "Creating stateful partition files..."
  119. create_stateful_files
  120. echo "Patching policy..."
  121. do_policy_patch
  122. echo "Setting chronos user password..."
  123. set_chronos_password
  124. echo "Checking sudo perms..."
  125. set_sudo_perms
  126. read -n 1 -s -r -p "Done. Press any key to exit."
  127. exit
  128. }
  129. if [ "$0" = "$BASH_SOURCE" ]; then
  130. if [ "$EUID" -ne 0 ]; then
  131. echo "Please run this as root from mush. Use option 1 (root shell) instead of any other method of getting to a shell."
  132. exit
  133. fi
  134. murkmod
  135. fi