#!/usr/bin/env bash
# This script installs the Hartman Lab Server Manual to each user's desktop
# Copyright 2021-2025 Bryan C. Roessler
# Licensed under the Apache License, Version 2.0
p="${BASH_SOURCE[0]%/*}"; [[ -r $p/script-functions ]] && . "$p"/script-functions || exit 1

manual_url="https://github.com/UAB-Hartman-Lab/server"
remove=("manual.pdf" "manual.odt" "Notes.pdf" "Notes.odt" \
    "README.html" "Link to Manual.desktop" "manual-images" \
    "manual.html" "Manual.desktop" "manual.desktop")

is_root

for desktop in /home/*/Desktop; do
  [[ -d $desktop ]] || continue
  echo "Removing old manuals from $desktop"
  for f in "${remove[@]}"; do
    [[ -z $f ]] && continue
    if [[ -e $desktop/$f || -L $desktop/$f ]]; then
      echo "Removing $desktop/$f"
      rm -f -- "${desktop:?}/$f"
    fi
  done
  echo "Installing manual to $desktop/manual.desktop"
  cat <<-EOF > "$desktop/manual.desktop"
		[Desktop Entry]
		Encoding=UTF-8
		Name=Hartman Lab Server Manual
		Type=Link
		URL=$manual_url
		Icon=help-browser
	EOF
  chmod 644 "$desktop/manual.desktop"
done
