Skip to content

Commit

Permalink
Merge pull request #133 from nmfs-opensci/dev
Browse files Browse the repository at this point in the history
improved icon and start
  • Loading branch information
eeholmes authored Nov 1, 2024
2 parents a7befa4 + f5ee1fd commit 7173170
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 38 deletions.
11 changes: 8 additions & 3 deletions appendix
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,22 @@ ONBUILD USER ${NB_USER}
# ${REPO_DIR} is owned by ${NB_USER}
ONBUILD COPY --chown=${NB_USER}:${NB_USER} . ${REPO_DIR}/childimage

# The Desktop and apt.txt installs need to be root
ONBUILD USER root

# Copy Desktop files into ${REPO_DIR}/Desktop if they exist. start will copy to Application dir and Desktop
# Will not fail if Desktop dir exists but is empty
ONBUILD RUN echo "Checking for 'Desktop directory'..." \
; cd "${REPO_DIR}/childimage/" \
; if test -d Desktop ; then \
mkdir -p "${REPO_DIR}/Desktop" && \
[ "$(ls -A Desktop 2>/dev/null)" ] && cp -r Desktop/* "${REPO_DIR}/Desktop/"; \
fi
cp -r Desktop/* "${REPO_DIR}/Desktop/" 2>/dev/null && \
chmod +x "${REPO_DIR}/desktop.sh" ; \
fi \
; "${REPO_DIR}/desktop.sh"

# Install apt packages specified in a apt.txt file if it exists.
# blank lines and comments are supported in apt.txt
ONBUILD USER root
ONBUILD RUN echo "Checking for 'apt.txt'..." \
; cd "${REPO_DIR}/childimage/" \
; if test -f "apt.txt" ; then \
Expand All @@ -77,6 +81,7 @@ ONBUILD RUN echo "Checking for 'apt.txt'..." \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
; fi

ONBUILD USER ${NB_USER}

# Add the conda environment
Expand Down
70 changes: 70 additions & 0 deletions desktop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash
# The default for XDG and xfce4 is for Desktop files to be in ~/Desktop but this leads to a variety of problems
# First we are altering the user directiory which seems rude, second orphan desktop files might be in ~/Desktop so who knows
# what the user Desktop experience with be, here the Desktop dir is set to /usr/share/Desktop so is part of the image.
# users that really want to customize Desktop can change ~/.config/user-dirs.dirs. Though py-rocket-base might not respect that.
set -e

# Copy in the Desktop files
APPLICATIONS_DIR=/usr/share/applications/packages
DESKTOP_DIR=/usr/share/Desktop
mkdir -p "${APPLICATIONS_DIR}"
mkdir -p "${DESKTOP_DIR}"
chown :staff /usr/share/Desktop
chmod 775 /usr/share/Desktop
# set the Desktop dir default for XDG
echo 'XDG_DESKTOP_DIR="${DESKTOP_DIR}"' > /etc/xdg/user-dirs.defaults

# The for loops will fail if they return null (no files). Set shell option nullglob
shopt -s nullglob

for desktop_file_path in ${REPO_DIR}/Desktop/*.desktop; do
cp "${desktop_file_path}" "${APPLICATIONS_DIR}/."

# Symlink application to desktop and set execute permission so xfce (desktop) doesn't complain
desktop_file_name="$(basename ${desktop_file_path})"
# Set execute permissions on the copied .desktop file
chmod +x "${APPLICATIONS_DIR}/${desktop_file_name}"
ln -sf "${APPLICATIONS_DIR}/${desktop_file_name}" "${DESKTOP_DIR}/${desktop_file_name}"
done
update-desktop-database "${APPLICATIONS_DIR}"

# Add MIME Type data from XML files to the MIME database.
MIME_DIR="/usr/share/mime"
MIME_PACKAGES_DIR="${MIME_DIR}/packages"
mkdir -p "${MIME_PACKAGES_DIR}"
for mime_file_path in ${REPO_DIR}/Desktop/*.xml; do
cp "${mime_file_path}" "${MIME_PACKAGES_DIR}/."
done
update-mime-database "${MIME_DIR}"

# Add icons
ICON_DIR="/usr/share/icons/hicolor"
ICON_SIZES=("16x16" "22x22" "24x24" "32x32" "48x48")

# Copy PNG icons only to existing size directories
for icon_file_path in "${REPO_DIR}"/Desktop/*.png; do
for size in "${ICON_SIZES[@]}"; do
target_dir="${ICON_DIR}/${size}/apps"
if [ -d "${target_dir}" ]; then
cp "${icon_file_path}" "${target_dir}/$(basename "${icon_file_path}")" || echo "Failed to copy ${icon_file_path} to ${target_dir}"
else
echo "Directory ${target_dir} does not exist. Skipping."
fi
done
done

# Copy SVG icons only to the existing scalable directory, if it exists
target_dir="${ICON_DIR}/scalable/apps"
for icon_file_path in "${REPO_DIR}"/Desktop/*.svg; do
if [ -d "${target_dir}" ]; then
cp "${icon_file_path}" "${target_dir}/$(basename "${icon_file_path}")" || echo "Failed to copy ${icon_file_path} to ${target_dir}"
else
echo "Directory ${target_dir} does not exist. Skipping SVG."
fi
done
# Update the icon cache for hicolor
gtk-update-icon-cache "${ICON_DIR}"
# Print a success message
echo "Icons have been copied to existing hicolor directories, and the icon cache has been updated."

35 changes: 0 additions & 35 deletions start
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,6 @@ set -euo pipefail
source ${REPO_DIR}/env.txt
# End - Set any environment variables here

# The for loops will fail if they return null (no files). Set shell option nullglob
shopt -s nullglob

# Add any .desktop files to the application database and desktop. This is done
# at startup-time because it's expected that a remote filesystem will be
# mounted at $HOME, which would overwrite the data if it was created at
# build-time.
APPLICATIONS_DIR="${HOME}/.local/share/applications"
DESKTOP_DIR="${HOME}/Desktop"
# Remove DESKTOP_DIR if it exists to avoid leftover files
if [ -d "${DESKTOP_DIR}" ]; then
rm -rf "${DESKTOP_DIR}"
fi
mkdir -p "${APPLICATIONS_DIR}"
mkdir -p "${DESKTOP_DIR}"
for desktop_file_path in ${REPO_DIR}/Desktop/*.desktop; do
cp "${desktop_file_path}" "${APPLICATIONS_DIR}/."

# Symlink application to desktop and set execute permission so xfce (desktop) doesn't complain
desktop_file_name="$(basename ${desktop_file_path})"
# Set execute permissions on the copied .desktop file
chmod +x "${APPLICATIONS_DIR}/${desktop_file_name}"
ln -sf "${APPLICATIONS_DIR}/${desktop_file_name}" "${DESKTOP_DIR}/${desktop_file_name}"
done
update-desktop-database "${APPLICATIONS_DIR}"

# Add MIME Type data from XML files to the MIME database.
MIME_DIR="${HOME}/.local/share/mime"
MIME_PACKAGES_DIR="${MIME_DIR}/packages"
mkdir -p "${MIME_PACKAGES_DIR}"
for mime_file_path in ${REPO_DIR}/Desktop/*.xml; do
cp "${mime_file_path}" "${MIME_PACKAGES_DIR}/."
done
update-mime-database "${MIME_DIR}"

# Run child start in a subshell to contain its environment
[ -f ${REPO_DIR}/childimage/start ] && ( source ${REPO_DIR}/childimage/start )

Expand Down

0 comments on commit 7173170

Please sign in to comment.