You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.6 KiB
Bash
74 lines
2.6 KiB
Bash
#!/bin/bash
|
|
|
|
die() {
|
|
echo "$1" >&2
|
|
exit 1
|
|
}
|
|
|
|
container_name="$1"
|
|
[ -z "container_name" ] && die "Please provide name of container"
|
|
container_root=/var/lib/machines/$container_name
|
|
|
|
app_name="$2"
|
|
[ -z "$app_name" ] && die "Please provide name of app"
|
|
|
|
is_user_app=false
|
|
desktop_file=$container_root/usr/share/applications/$app_name.desktop
|
|
desktop_file_content=$(sudo cat $desktop_file 2>/dev/null)
|
|
if ! [ $? == 0 ]; then
|
|
is_user_app=true
|
|
desktop_file=$container_root/home/user/.local/share/applications/$app_name.desktop
|
|
desktop_file_content=$(sudo cat $desktop_file 2>/dev/null)
|
|
fi
|
|
[ $? == 0 ] || die "App $app_name not found in container $container_name"
|
|
|
|
icon_name=$(echo "$desktop_file_content" | grep "Icon=" | head -1 | cut -d'=' -f 2)
|
|
[ -z "$icon_name" ] && die "No icon defined for app $app_name"
|
|
|
|
if $is_user_app; then
|
|
icon_root=$container_root/home/user/.local/share/icons/hicolor
|
|
else
|
|
icon_root=$container_root/usr/share/icons/hicolor
|
|
fi
|
|
|
|
icon_pixmap=false
|
|
if [ "${icon_name:0:1}" = "/" ]; then
|
|
icons=("$container_root$icon_name")
|
|
icon_name=$(basename "$icon_name")
|
|
icon_ext="${icon_name##*.}"
|
|
icon_name="$app_name" # If the icon path is absolute, we always use the app name as icon name (to prevent conflicts)
|
|
icon_absolute_path=true
|
|
else
|
|
icons=($(sudo find $icon_root -name "$icon_name.*"))
|
|
icon_absolute_path=false
|
|
|
|
if [ ${#icons[@]} == 0 ]; then
|
|
# Pixmap icons (but really, apps should stop putting icons in pixmaps)
|
|
icon_root=$container_root/usr/share/pixmaps
|
|
icons=($(sudo find $icon_root -name "$icon_name.*"))
|
|
icon_pixmap=true
|
|
fi
|
|
fi
|
|
[ ${#icons[@]} == 0 ] && die "Cannot find any icon for app $app_name"
|
|
|
|
for icon in ${icons[@]}; do
|
|
if $icon_absolute_path; then
|
|
icon_target=$HOME/.local/share/icons/hicolor/256x256/apps/$icon_name.$icon_ext # See comment before; this is to avoid name conflicts
|
|
elif $icon_pixmap; then
|
|
icon_target=${icon//$icon_root/$HOME/.local/share/icons/hicolor/256x256/apps} # Use 256x256 by default when unspecified
|
|
else
|
|
icon_target=${icon//$icon_root/$HOME/.local/share/icons/hicolor}
|
|
fi
|
|
icon_target_dir=$(dirname "$icon_target")
|
|
echo "Copying $icon to $icon_target in $icon_target_dir"
|
|
mkdir -p "$icon_target_dir"
|
|
sudo cat "$icon" > "$icon_target"
|
|
done
|
|
|
|
mkdir -p $HOME/.local/share/applications
|
|
echo "$desktop_file_content" | grep -v "^TryExec=.*\$" \
|
|
| sed -r "s@^Icon=.*\$@Icon=${icon_name}@g" \
|
|
| sed -r "s@^Exec=(.*)\$@Exec=env CONTAINER_NAME=$container_name $HOME/.local/bin/run_app_container \\1@g" \
|
|
> $HOME/.local/share/applications/$app_name.desktop
|
|
echo "Created $HOME/.local/share/applications/$app_name.desktop"
|