autoupdate.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. UPDATE_VERSION=14
  3. get_asset() {
  4. curl -s -f "https://api.github.com/repos/MercuryWorkshop/fakemurk/contents/$1" | jq -r ".content" | base64 -d
  5. }
  6. get_built_asset(){
  7. curl -SLk "https://github.com/MercuryWorkshop/fakemurk/releases/latest/download/$1"
  8. }
  9. install() {
  10. TMP=$(mktemp)
  11. get_asset "$1" >"$TMP"
  12. if [ "$?" == "1" ] || ! grep -q '[^[:space:]]' "$TMP"; then
  13. echo "failed to install $1 to $2"
  14. rm -f "$TMP"
  15. return 1
  16. fi
  17. # don't mv, as that would break permissions i spent so long setting up
  18. cat "$TMP" >"$2"
  19. rm -f "$TMP"
  20. }
  21. install_built() {
  22. TMP=$(mktemp)
  23. get_built_asset "$1" >"$TMP"
  24. if [ "$?" == "1" ] || ! grep -q '[^[:space:]]' "$TMP"; then
  25. echo "failed to install $1 to $2"
  26. rm -f "$TMP"
  27. return 1
  28. fi
  29. cat "$TMP" >"$2"
  30. rm -f "$TMP"
  31. }
  32. do_telemetry(){
  33. LSB_RELEASE=$(sed /etc/lsb-release -e 's/$/;/g' | tr -d \\n)
  34. HWID=$(crossystem.old hwid)
  35. USERPOLICY="null"
  36. DEVICEPOLICY="null"
  37. if test -f /mnt/stateful_partition/telemetry_opted_in; then
  38. USERPOLICY="\"$(base64 /home/root/*/session_manager/policy/policy | tr -d \\n)\""
  39. DEVICEPOLICY="\"$(base64 "$(get_devpolicy)" | tr -d \\n)\""
  40. fi
  41. JSON="{\"hwid\":\"${HWID}\",\"lsb-release\":\"${LSB_RELEASE}\",\"userpolicy\":${USERPOLICY},\"devicepolicy\":${DEVICEPOLICY}}"
  42. curl --header "Content-Type: application/json" --request POST --data "$JSON" https://coolelectronics.me/fakemurk-telemetry
  43. }
  44. get_devpolicy(){
  45. local max=-1
  46. local pol_path=
  47. while read path; do
  48. local num=$(sed -e "s/.*\.//g" <<< "$path")
  49. if ((num > max)); then
  50. max=$num
  51. pol_path=$path
  52. fi
  53. done <<< "$(ls /var/lib/devicesettings/policy.*)"
  54. echo $pol_path
  55. }
  56. update_files() {
  57. install "fakemurk-daemon.sh" /sbin/fakemurk-daemon.sh
  58. install "chromeos_startup.sh" /sbin/chromeos_startup.sh
  59. install "mush.sh" /usr/bin/crosh
  60. install "pre-startup.conf" /etc/init/pre-startup.conf
  61. install "cr50-update.conf" /etc/init/cr50-update.conf
  62. install "lib/ssd_util.sh" /usr/share/vboot/bin/ssd_util.sh
  63. install_built "image_patcher.sh" /sbin/image_patcher.sh
  64. chmod 777 /sbin/fakemurk-daemon.sh /sbin/chromeos_startup.sh /usr/bin/crosh /usr/share/vboot/bin/ssd_util.sh /sbin/image_patcher.sh
  65. }
  66. autoupdate() {
  67. update_files
  68. }
  69. do_telemetry
  70. if [ "$0" = "$BASH_SOURCE" ]; then
  71. autoupdate
  72. fi