2023-10-22 21:47:45 +00:00
|
|
|
#!/usr/bin/env bash
|
2023-10-22 18:33:11 +00:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
add_to_steam() {
|
|
|
|
encodedUrl="steam://addnonsteamgame/$(python3 -c "import urllib.parse;print(urllib.parse.quote(\"$1\", safe=''))")"
|
|
|
|
touch /tmp/addnonsteamgamefile
|
|
|
|
steam "$encodedUrl"
|
|
|
|
}
|
|
|
|
|
|
|
|
show_error() {
|
|
|
|
if [ "$show_dialog" = "1" ]; then
|
|
|
|
zenity --title Error --error --text "$1"
|
|
|
|
else
|
|
|
|
echo "$1" >&2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $(id -u) = "0" ]; then
|
|
|
|
show_error "This script cannot be run as root"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$XDG_SESSION_TYPE" = "tty" ] && ! pgrep -x steam >/dev/null 2>&1; then
|
|
|
|
show_error "Cannot run this script from a tty if Steam is not running"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "-ui" ]; then
|
|
|
|
show_dialog=1
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
|
|
|
file=$(realpath "$1")
|
|
|
|
if [ ! -e "$file" ]
|
|
|
|
then
|
|
|
|
echo "Usage: steamos-add-to-steam [-ui] <path>"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-10-23 00:04:54 +00:00
|
|
|
mime=$(xdg-mime query filetype "$file")
|
2023-10-22 18:33:11 +00:00
|
|
|
case "$mime" in
|
|
|
|
"application/x-desktop"|"application/x-ms-dos-executable")
|
|
|
|
add_to_steam "$file"
|
|
|
|
;;
|
|
|
|
"application/x-executable"|"application/vnd.appimage"|"application/x-shellscript")
|
|
|
|
if [ -x "$file" ]; then
|
|
|
|
add_to_steam "$file"
|
|
|
|
else
|
|
|
|
show_error "Unable to add non-Steam game. Is the file executable?"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
show_error "Unsupported file type"
|
|
|
|
;;
|
|
|
|
esac
|