37 lines
1.3 KiB
Bash
Executable file
37 lines
1.3 KiB
Bash
Executable file
#!/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"
|
|
|
|
desktop_file=$container_root/usr/share/applications/$app_name.desktop
|
|
desktop_file_content=$(sudo cat $desktop_file 2>/dev/null)
|
|
[ $? == 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"
|
|
|
|
icon_root=$container_root/usr/share/icons/hicolor
|
|
icons=($(sudo find $icon_root -name "$icon_name.*"))
|
|
[ ${#icons[@]} == 0 ] && die "Cannot find any icon for app $app_name"
|
|
|
|
for icon in ${icons[@]}; do
|
|
icon_target=${icon//$icon_root/$HOME/.local/share/icons/hicolor}
|
|
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" | 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"
|