wallpaper.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. # menu_plugin
  3. PLUGIN_NAME="Wallpaper Manager"
  4. PLUGIN_FUNCTION="Manage wallpaper"
  5. PLUGIN_DESCRIPTION="Allows you to manage policy-set wallpapers through Pollen automagically"
  6. PLUGIN_AUTHOR="rainestorme"
  7. PLUGIN_VERSION=1
  8. doas() {
  9. ssh -t -p 1337 -i /rootkey -oStrictHostKeyChecking=no root@127.0.0.1 "$@"
  10. }
  11. # Prompt the user to choose a file from /home/chronos/user/Downloads/
  12. echo "Choose a jpg or png from your Downloads folder"
  13. PS3="Enter the number of the file you want to choose: "
  14. options=($(ls -1 /home/chronos/user/Downloads | grep -E '\.(jpg|png)$'))
  15. select opt in "${options[@]}"
  16. do
  17. if [[ -n "$opt" ]]; then
  18. image_path="/home/chronos/user/Downloads/$opt"
  19. break
  20. fi
  21. done
  22. # Fetch the SHA256 hash of the image file
  23. hash=$(sha256sum "$image_path" | cut -d ' ' -f 1)
  24. # Construct the new JSON object with the updated values
  25. new_json="{\"hash\": \"$hash\", \"url\": \"file://$image_path\"}"
  26. # Update the "WallpaperImage" key in the JSON file with the new values
  27. json_file="/etc/opt/chrome/policies/managed/policy.json"
  28. if grep -q "\"WallpaperImage\":" "$json_file"; then
  29. # "WallpaperImage" key already exists in the JSON file, update its value
  30. sed -i "s/\(\"WallpaperImage\":{\).*\(:{.*\)\(}\)/\1$new_json\3/" "$json_file"
  31. else
  32. # "WallpaperImage" key does not exist in the JSON file, add it to the end
  33. sed -i "s/\(}\)$/,\n \"WallpaperImage\": $new_json\n\1/" "$json_file"
  34. fi
  35. echo "Set wallpaper successfully."