murkmod.sh 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. #!/bin/bash
  2. CURRENT_MAJOR=6
  3. CURRENT_MINOR=1
  4. CURRENT_VERSION=1
  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. else
  94. install "chromeos_startup.sh" /sbin/chromeos_startup.sh
  95. fi
  96. install "mush.sh" /usr/bin/crosh
  97. install "pre-startup.conf" /etc/init/pre-startup.conf
  98. install "cr50-update.conf" /etc/init/cr50-update.conf
  99. install "ssd_util.sh" /usr/share/vboot/bin/ssd_util.sh
  100. install "image_patcher.sh" /sbin/image_patcher.sh
  101. chmod 777 /sbin/murkmod-daemon.sh /sbin/chromeos_startup.sh /sbin/chromeos_startup /usr/bin/crosh /usr/share/vboot/bin/ssd_util.sh /sbin/image_patcher.sh
  102. }
  103. create_stateful_files() {
  104. # This is only here for backwards compatibility
  105. touch /mnt/stateful_partition/murkmod_version
  106. echo "$CURRENT_MAJOR $CURRENT_MINOR $CURRENT_VERSION" > /mnt/stateful_partition/murkmod_version
  107. mkdir -p /mnt/stateful_partition/murkmod/plugins
  108. touch /mnt/stateful_partition/murkmod/settings
  109. if [ ! -f /mnt/stateful_partition/murkmod/settings ]; then
  110. echo "# ----- murkmod settings -----" > /mnt/stateful_partition/murkmod/settings
  111. echo "" >> /mnt/stateful_partition/murkmod/settings
  112. echo "# this file is unused for now, but this might change" >> /mnt/stateful_partition/murkmod/settings
  113. fi
  114. }
  115. check_for_emergencyshell() {
  116. if test -d "/home/chronos/user/Downloads/fix-mush"; then
  117. echo "Running from emergency shell, reverting..."
  118. rm -Rf /home/chronos/user/Downloads/fix-mush
  119. fi
  120. }
  121. do_policy_patch() {
  122. url1="https://raw.githubusercontent.com/rainestorme/murkmod/main/pollen.json"
  123. url2="https://raw.githubusercontent.com/MercuryWorkshop/fakemurk/main/pollen.json"
  124. response1=$(curl -s "$url1")
  125. response2=$(curl -s "$url2")
  126. if [ "$response1" = "$response2" ]; then
  127. install "pollen.json" /etc/opt/chrome/policies/managed/policy.json
  128. else
  129. read -r -p "Use murkmod reccomended pollen config? [Y/n] " choice
  130. case "$choice" in
  131. n | N) install_fakemurk "pollen.json" /etc/opt/chrome/policies/managed/policy.json ;;
  132. *) install "pollen.json" /etc/opt/chrome/policies/managed/policy.json ;;
  133. esac
  134. fi
  135. }
  136. set_chronos_password() {
  137. echo -en "murkmod\nmurkmod\n" | passwd chronos > /dev/null
  138. }
  139. set_sudo_perms() {
  140. if ! cat /etc/sudoers | grep chronos; then
  141. echo "Sudo permissions are not already set, setting..."
  142. echo "chronos ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
  143. else
  144. echo "Looks like sudo permissions are already set correctly."
  145. fi
  146. }
  147. set_cros_debug() {
  148. sed -i "s/\(cros_debug=\).*/\11/" /usr/bin/crossystem
  149. }
  150. check_legacy_daemon() {
  151. if [ -f /sbin/fakemurk-daemon.sh ]; then
  152. echo "Found legacy fakemurk daemon, removing..."
  153. kill -9 $(pgrep fakemurk)
  154. rm -f /sbin/fakemurk-daemon.sh
  155. mkdir -p /var/murkmod
  156. echo "Restarting daemon..."
  157. /sbin/murkmod-daemon.sh >/var/murkmod/daemon-log 2>&1 &
  158. fi
  159. }
  160. murkmod() {
  161. show_logo
  162. if [ "$1" != "--dryrun" ]; then
  163. if [ ! -f /sbin/fakemurk-daemon.sh ]; then
  164. if [ ! -f /sbin/murkmod-daemon.sh ]; then
  165. 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."
  166. exit
  167. fi
  168. fi
  169. echo "Checking for emergency shell..."
  170. check_for_emergencyshell
  171. echo "Installing patched files..."
  172. install_patched_files
  173. echo "Checking for legacy fakemurk daemon..."
  174. check_legacy_daemon
  175. echo "Creating stateful partition files..."
  176. create_stateful_files
  177. echo "Patching policy..."
  178. do_policy_patch
  179. echo "Setting chronos user password..."
  180. set_chronos_password
  181. echo "Checking sudo perms..."
  182. set_sudo_perms
  183. echo "Setting crossystem cros_debug..."
  184. set_cros_debug
  185. fi
  186. 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."
  187. exit
  188. }
  189. if [ "$0" = "$BASH_SOURCE" ]; then
  190. if [ "$EUID" -ne 0 ]; then
  191. echo "Please run this as root from mush. Use option 1 (root shell) instead of any other method of getting to a shell."
  192. exit
  193. fi
  194. murkmod
  195. fi