murkmod.sh 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #!/bin/bash
  2. CURRENT_MAJOR=6
  3. CURRENT_MINOR=1
  4. CURRENT_VERSION=2
  5. if [[ -z "${MURKMOD_BRANCH}" ]]; then
  6. BRANCH="main"
  7. else
  8. BRANCH="${MURKMOD_BRANCH}"
  9. fi
  10. get_asset() {
  11. curl -s -f "https://api.github.com/repos/rainestorme/murkmod/contents/$1?ref=$BRANCH" | jq -r ".content" | base64 -d
  12. }
  13. get_asset_fakemurk() {
  14. curl -s -f "https://api.github.com/repos/MercuryWorkshop/fakemurk/contents/$1" | jq -r ".content" | base64 -d
  15. }
  16. get_built_asset_fakemurk() {
  17. curl -SLk "https://github.com/MercuryWorkshop/fakemurk/releases/latest/download/1"
  18. }
  19. install() {
  20. TMP=$(mktemp)
  21. get_asset "$1" >"$TMP"
  22. if [ "$?" == "1" ] || ! grep -q '[^[:space:]]' "$TMP"; then
  23. echo "Failed to install $1 to $2"
  24. rm -f "$TMP"
  25. exit
  26. fi
  27. # Don't mv, that would break permissions
  28. cat "$TMP" >"$2"
  29. rm -f "$TMP"
  30. }
  31. install_fakemurk() {
  32. TMP=$(mktemp)
  33. get_asset_fakemurk "$1" >"$TMP"
  34. if [ "$?" == "1" ] || ! grep -q '[^[:space:]]' "$TMP"; then
  35. echo "Failed to install $1 to $2"
  36. rm -f "$TMP"
  37. exit
  38. fi
  39. # Don't mv, that would break permissions
  40. cat "$TMP" >"$2"
  41. rm -f "$TMP"
  42. }
  43. install_built_fakemurk() {
  44. TMP=$(mktemp)
  45. get_built_asset_fakemurk "$1" >"$TMP"
  46. if [ "$?" == "1" ] || ! grep -q '[^[:space:]]' "$TMP"; then
  47. echo "failed to install $1 to $2"
  48. rm -f "$TMP"
  49. return 1
  50. fi
  51. cat "$TMP" >"$2"
  52. rm -f "$TMP"
  53. }
  54. if [ "$BRANCH" != "main" ]; then
  55. echo "Using branch $BRANCH - Keep in mind any alternate branches can be unstable and are not reccomended!"
  56. if [ "$0" != "/usr/local/tmp/murkmod.sh" ]; then
  57. echo "Fetching installer on alternate branch..."
  58. mkdir -p /usr/local/tmp
  59. install "murkmod.sh" /usr/local/tmp/murkmod.sh
  60. chmod 755 /usr/local/tmp/murkmod.sh
  61. clear
  62. echo "Handing over to alternate branch..."
  63. MURKMOD_BRANCH=$BRANCH /usr/local/tmp/murkmod.sh
  64. exit 0
  65. else
  66. echo "Running installer from branch $BRANCH!"
  67. fi
  68. fi
  69. show_logo() {
  70. echo -e " __ .___\n _____ __ _________| | __ _____ ____ __| _/\n / \| | \_ __ \ |/ // \ / _ \ / __ | \n| Y Y \ | /| | \/ <| Y Y ( <_> ) /_/ | \n|__|_| /____/ |__| |__|_ \__|_| /\____/\____ | \n \/ \/ \/ \/\n"
  71. echo " The fakemurk plugin manager - v$CURRENT_MAJOR.$CURRENT_MINOR.$CURRENT_VERSION"
  72. }
  73. lsbval() {
  74. local key="$1"
  75. local lsbfile="${2:-/etc/lsb-release}"
  76. if ! echo "${key}" | grep -Eq '^[a-zA-Z0-9_]+$'; then
  77. return 1
  78. fi
  79. sed -E -n -e \
  80. "/^[[:space:]]*${key}[[:space:]]*=/{
  81. s:^[^=]+=[[:space:]]*::
  82. s:[[:space:]]+$::
  83. p
  84. }" "${lsbfile}"
  85. }
  86. install_patched_files() {
  87. install "daemon.sh" /sbin/murkmod-daemon.sh
  88. local milestone=$(lsbval CHROMEOS_RELEASE_CHROME_MILESTONE $ROOT/etc/lsb-release)
  89. if [ "$milestone" -gt "116" ]; then
  90. echo "Detected v116 or higher, using new chromeos_startup"
  91. install "chromeos_startup.sh" /sbin/chromeos_startup
  92. touch /new-startup
  93. chmod 755 /sbin/chromeos_startup
  94. else
  95. install "chromeos_startup.sh" /sbin/chromeos_startup.sh
  96. chmod 755 /sbin/chromeos_startup.sh
  97. fi
  98. install "mush.sh" /usr/bin/crosh
  99. install "pre-startup.conf" /etc/init/pre-startup.conf
  100. install "cr50-update.conf" /etc/init/cr50-update.conf
  101. install "ssd_util.sh" /usr/share/vboot/bin/ssd_util.sh
  102. install "image_patcher.sh" /sbin/image_patcher.sh
  103. if [ "$milestone" -gt "78" ]; then
  104. echo "Detected v78 or higher, patching chromeos-boot-alert to prevent blocking devmode virtually"
  105. install "chromeos-boot-alert" /sbin/chromeos-boot-alert
  106. chmod 755 /sbin/chromeos-boot-alert
  107. fi
  108. chmod 777 /sbin/murkmod-daemon.sh /usr/bin/crosh /usr/share/vboot/bin/ssd_util.sh /sbin/image_patcher.sh
  109. }
  110. create_stateful_files() {
  111. # This is only here for backwards compatibility
  112. touch /mnt/stateful_partition/murkmod_version
  113. echo "$CURRENT_MAJOR $CURRENT_MINOR $CURRENT_VERSION" > /mnt/stateful_partition/murkmod_version
  114. mkdir -p /mnt/stateful_partition/murkmod/plugins
  115. touch /mnt/stateful_partition/murkmod/settings
  116. if [ ! -f /mnt/stateful_partition/murkmod/settings ]; then
  117. echo "# ----- murkmod settings -----" > /mnt/stateful_partition/murkmod/settings
  118. echo "" >> /mnt/stateful_partition/murkmod/settings
  119. echo "# this file is unused for now, but this might change" >> /mnt/stateful_partition/murkmod/settings
  120. fi
  121. }
  122. check_for_emergencyshell() {
  123. if test -d "/home/chronos/user/Downloads/fix-mush"; then
  124. echo "Running from emergency shell, reverting..."
  125. rm -Rf /home/chronos/user/Downloads/fix-mush
  126. fi
  127. }
  128. do_policy_patch() {
  129. url1="https://raw.githubusercontent.com/rainestorme/murkmod/main/pollen.json"
  130. url2="https://raw.githubusercontent.com/MercuryWorkshop/fakemurk/main/pollen.json"
  131. response1=$(curl -s "$url1")
  132. response2=$(curl -s "$url2")
  133. if [ "$response1" = "$response2" ]; then
  134. install "pollen.json" /etc/opt/chrome/policies/managed/policy.json
  135. else
  136. read -r -p "Use murkmod reccomended pollen config? [Y/n] " choice
  137. case "$choice" in
  138. n | N) install_fakemurk "pollen.json" /etc/opt/chrome/policies/managed/policy.json ;;
  139. *) install "pollen.json" /etc/opt/chrome/policies/managed/policy.json ;;
  140. esac
  141. fi
  142. }
  143. set_chronos_password() {
  144. echo -en "murkmod\nmurkmod\n" | passwd chronos > /dev/null
  145. }
  146. set_sudo_perms() {
  147. if ! cat /etc/sudoers | grep chronos; then
  148. echo "Sudo permissions are not already set, setting..."
  149. echo "chronos ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
  150. else
  151. echo "Looks like sudo permissions are already set correctly."
  152. fi
  153. }
  154. set_cros_debug() {
  155. sed -i "s/\(cros_debug=\).*/\11/" /usr/bin/crossystem
  156. }
  157. check_legacy_daemon() {
  158. if [ -f /sbin/fakemurk-daemon.sh ]; then
  159. echo "Found legacy fakemurk daemon, removing..."
  160. kill -9 $(pgrep fakemurk)
  161. rm -f /sbin/fakemurk-daemon.sh
  162. mkdir -p /var/murkmod
  163. echo "Restarting daemon..."
  164. /sbin/murkmod-daemon.sh >/var/murkmod/daemon-log 2>&1 &
  165. fi
  166. }
  167. murkmod() {
  168. show_logo
  169. if [ "$1" != "--dryrun" ]; then
  170. if [ ! -f /sbin/fakemurk-daemon.sh ]; then
  171. if [ ! -f /sbin/murkmod-daemon.sh ]; then
  172. echo "Either your system has a broken fakemurk/murkmod installation or your system doesn't have a fakemurk or murkmod installation at all. (Re)install fakemurk/murkmod, then re-run this script."
  173. exit
  174. fi
  175. fi
  176. echo "Checking for emergency shell..."
  177. check_for_emergencyshell
  178. echo "Installing patched files..."
  179. install_patched_files
  180. echo "Checking for legacy fakemurk daemon..."
  181. check_legacy_daemon
  182. echo "Creating stateful partition files..."
  183. create_stateful_files
  184. read -r -p "Would you like to update pollen config? This will overwrite your pollen edits. [Y/n] " choice
  185. case "$choice" in
  186. n | N) echo "Skipping patching policy..." ;;
  187. *) echo "Patching policy..."
  188. do_policy_patch ;;
  189. esac
  190. echo "Setting chronos user password..."
  191. set_chronos_password
  192. echo "Checking sudo perms..."
  193. set_sudo_perms
  194. echo "Setting crossystem cros_debug..."
  195. set_cros_debug
  196. fi
  197. read -n 1 -s -r -p "Done. If cros_debug was enabled for the first time, a reboot may be required. Press any key to exit."
  198. exit
  199. }
  200. if [ "$0" = "$BASH_SOURCE" ]; then
  201. if [ "$EUID" -ne 0 ]; then
  202. echo "Please run this as root from mush. Use option 1 (root shell) instead of any other method of getting to a shell."
  203. exit
  204. fi
  205. murkmod
  206. fi