script-deploy-manual 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env bash
  2. # This script installs the Hartman Lab Server Manual to each user's desktop
  3. # Usage: script-deploy-manual USERNAME|--all
  4. # Copyright 2021-2025 Bryan C. Roessler
  5. # Licensed under the Apache License, Version 2.0
  6. script-deploy-manual() {
  7. local user_arg="$1"
  8. local manual_url="https://docs.google.com/document/d/1K_KwAlv8Zljmy-enwmhT6gMTFutlAFglixvpLGBx0VY"
  9. local remove=("manual.pdf" "manual.odt" "Notes.pdf" "Notes.odt" \
  10. "README.html" "Link to Manual.desktop" "manual-images" \
  11. "manual.html" "Manual.desktop" "manual.desktop")
  12. local users=()
  13. if [[ -z "$user_arg" || "$user_arg" == "--help" ]]; then
  14. cat <<-EOF
  15. Usage: script-deploy-manual USERNAME|--all
  16. USERNAME: Specify a single user's name.
  17. --all: Deploy the manual to all users with a Desktop directory.
  18. EOF
  19. return 1
  20. fi
  21. if [[ "$user_arg" == "--all" ]]; then
  22. for d in /home/*; do [[ -d $d ]] && users+=("${d##*/}"); done
  23. else
  24. users+=("$user_arg")
  25. fi
  26. for user in "${users[@]}"; do
  27. desktop="/home/$user/Desktop"
  28. [[ -d $desktop ]] || continue
  29. echo "Scanning $desktop for old manuals"
  30. for f in "${remove[@]}"; do
  31. if [[ -e $desktop/$f || -L $desktop/$f ]]; then
  32. echo "Removing $desktop/$f"
  33. rm -f "${desktop:?}/$f"
  34. fi
  35. done
  36. echo "Installing manual to $desktop/manual.desktop"
  37. cat <<-EOF > "$desktop/manual.desktop"
  38. [Desktop Entry]
  39. Encoding=UTF-8
  40. Name=Hartman Lab Server Manual
  41. Type=Link
  42. URL=$manual_url
  43. Icon=text-html
  44. EOF
  45. done
  46. }
  47. # Allow script to be safely sourced
  48. if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
  49. script-deploy-manual "$@"
  50. exit
  51. fi