Compare commits
3 commits
09be333ac6
...
4cca51744b
Author | SHA1 | Date | |
---|---|---|---|
4cca51744b | |||
02c8e3ad07 | |||
6e163d4afa |
5 changed files with 78 additions and 3 deletions
|
@ -1,2 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
TRACK_PACKAGE_ARCHLINUX="extra/any/shattered-pixel-dungeon"
|
||||
DESKTOP_FILE_PATH="/usr/share/applications/shattered-pixel-dungeon.desktop"
|
||||
|
|
|
@ -4,7 +4,7 @@ script_path="$(dirname "$(realpath "$0")")"
|
|||
. "$script_path/functions.sh"
|
||||
assert_prerequisites
|
||||
|
||||
image_name="$(path_to_image_name "$1")"
|
||||
image_name="$(relative_path_to_image_name "$1")"
|
||||
|
||||
# Load config if we have it
|
||||
[ -f "$script_path/$1/control" ] && . "$script_path/$1/control"
|
||||
|
|
72
create-shortcut.sh
Executable file
72
create-shortcut.sh
Executable file
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
script_path="$(dirname "$(realpath "$0")")"
|
||||
. "$script_path/functions.sh"
|
||||
assert_prerequisites
|
||||
|
||||
[ -z "$1" ] && die "Usage: create-shortcut.sh <app_name>"
|
||||
|
||||
image_name="$(relative_path_to_image_name "apps/$1")"
|
||||
assert_image_exists "$image_name"
|
||||
|
||||
[ -f "$script_path/apps/$1/control" ] || \
|
||||
die "App $1 does not have a control file that defines how to generate a shortcut"
|
||||
|
||||
. "$script_path/apps/$1/control"
|
||||
|
||||
[ -z "${DESKTOP_FILE_PATH+x}" ] && die "App $1 did not specify DESKTOP_FILE_PATH in its control file"
|
||||
|
||||
# Create a temporary working directory
|
||||
# Because we will have to extract files from the container image
|
||||
tmp_dir="$(mktemp -d -p /tmp)"
|
||||
pushd "$tmp_dir"
|
||||
|
||||
tmp_container_name="dobu-tmp-$(cat /dev/urandom | tr -dc '[:alpha:]' | fold -w 10 | head -n 1)"
|
||||
|
||||
# Let's set up cleanup tasks first
|
||||
cleanup() {
|
||||
popd || true
|
||||
rm -rf "$tmp_dir" || true
|
||||
podman rm -f -v "$tmp_container_name" || true
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
log "Creating temporary container $tmp_container_name from $image_name"
|
||||
|
||||
podman create --name "$tmp_container_name" "$image_name"
|
||||
|
||||
log "Extracting $DESKTOP_FILE_PATH from $tmp_container_name"
|
||||
podman cp "$tmp_container_name:$DESKTOP_FILE_PATH" ./$1.desktop
|
||||
|
||||
log "Extracting /usr/share/icons from $tmp_container_name"
|
||||
podman cp "$tmp_container_name:/usr/share/icons" ./icons
|
||||
|
||||
log "Destroying temporary container $tmp_container_name"
|
||||
podman rm -f -v "$tmp_container_name"
|
||||
|
||||
desktop_file_content="$(cat ./$1.desktop)"
|
||||
|
||||
icon_name="$(echo "$desktop_file_content" | grep "Icon=" | head -1 | cut -d'=' -f 2)"
|
||||
[ -z "$icon_name" ] && die "No icon defined for $1"
|
||||
|
||||
log "Searching for icon file for $1: $icon_name"
|
||||
|
||||
# Here we assume that $icon_name always refers to something in /usr/share/icons in the container
|
||||
# When building images, make sure they are always placed there
|
||||
icons=($(find ./icons -name "$icon_name.*"))
|
||||
[ "${#icons[@]}" -eq 0 ] && die "No icons found for $icon_name"
|
||||
for icon in "${icons[@]}"; do
|
||||
icon_target="${icon/.\/icons\/hicolor/$HOME/.local/share/icons/hicolor}"
|
||||
log "Copying $icon to $icon_target"
|
||||
mkdir -p "$(dirname "$icon_target")"
|
||||
cp "$icon" "$icon_target"
|
||||
done
|
||||
|
||||
desktop_target="$HOME/.local/share/applications/$1.desktop"
|
||||
log "Creating $desktop_target"
|
||||
echo "$desktop_file_content" | grep -v "^TryExec=.*\$i" \
|
||||
| sed -r "s@^Exec=(.*)\$@Exec=$script_path/dobu-run.sh $1@" > "$desktop_target"
|
||||
|
||||
log "Desktop shortcut for $1 has been generated"
|
||||
log "You may now need to refresh your desktop application list by re-logging in"
|
|
@ -6,7 +6,7 @@ assert_prerequisites
|
|||
|
||||
[ -z "$1" ] && die "Expecting 1 argument"
|
||||
|
||||
image_name="$(path_to_image_name "apps/$1")"
|
||||
image_name="$(relative_path_to_image_name "apps/$1")"
|
||||
# image_name is of the form dobu/xxxx, while for containers we want dobu-xxx
|
||||
container_name="${image_name/\//-}"
|
||||
home_path="$HOMEDIR_STORAGE/$1"
|
||||
|
@ -87,4 +87,6 @@ podman run --rm "${podman_security_args[@]}" --name "$container_name" \
|
|||
-e QT_SCALE_FACTOR="$QT_SCALE_FACTOR" \
|
||||
-e QT_SCREEN_SCALE_FACTORS="$QT_SCREEN_SCALE_FACTORS" \
|
||||
-e QT_AUTO_SCREEN_SCALE_FACTOR="$QT_AUTO_SCREEN_SCALE_FACTOR" \
|
||||
`# Use podman's init stub inside the container for better control` \
|
||||
--init \
|
||||
$extra_args "$image_name"
|
||||
|
|
|
@ -42,7 +42,7 @@ is_in_array() {
|
|||
return 1
|
||||
}
|
||||
|
||||
path_to_image_name() {
|
||||
relative_path_to_image_name() {
|
||||
local context_path="$script_path/$1"
|
||||
|
||||
[ -d "$context_path" ] || die "$context_path does not exist"
|
||||
|
|
Loading…
Add table
Reference in a new issue