swetoast / steamlink-launcher

Steamlink launcher for OSMC
GNU General Public License v2.0
155 stars 19 forks source link

Install Steam Link if needed, before launching it #11

Closed slouken closed 4 years ago

swetoast commented 4 years ago
"""Steamlink Launcher for OSMC"""
import os
import xbmc
import xbmcgui
import xbmcaddon

__plugin__ = "steamlink"
__author__ = "toast"
__url__ = "https://github.com/swetoast/steamlink-launcher/"
__git_url__ = "https://github.com/swetoast/steamlink-launcher/"
__credits__ = "toast"
__version__ = "0.0.6"

dialog = xbmcgui.Dialog()
addon = xbmcaddon.Addon(id='plugin.program.steamlink')

def main():
    """Main operations of this plugin."""
    if os.path.isfile("/tmp/steamlink-launcher.sh"):
        output = os.popen("sh /tmp/steamlink-launcher.sh").read()
    else:
        create_files()
        output = os.popen("sh /tmp/steamlink-launcher.sh").read()
    dialog.ok("Starting Steamlink", output)
    #print output
def create_files():
    """Creates bash files to be used for this plugin."""
    with open('/tmp/steamlink-launcher.sh', 'w') as outfile:
              outfile.write('#!/bin/sh\n'
                            'install_steam () {\n'
                              'mkdir /storage\n'
                              'chown $USER /storage\n'
                              'wget "$(wget -q -O - http://media.steampowered.com/steamlink/rpi/public_build.txt)" -O /storage/steamlink.tar.gz\n'
                              'tar -zxf steamlink.tar.gz\n'
                              'rm steamlink.tar.gz\n'
                                  'chown $USER /storage/steamlink\n'
                                  'chmod +x $USER /storage/steamlink\n'
                                  'usermod -a -G input,plugdev $USER\n'
                              '}\n'
                              'start_steamlink () {\n'
                                  'sh /tmp/steamlink-watchdog.sh\n'
                                  'openvt -c 7 -s -f clear\n'
                                  'openvt -c 7 -f -s steamlink > /dev/null 2> &1\n'
                                  'systemctl stop mediacenter\n'
                              '}\n'
                              'if [ ! -f "/storage/steamlink" ]; then install_steamlink; else start_steamlink; fi\n')
              outfile.close()
    with open('/tmp/steamlink-watchdog.sh', 'w') as outfile:
              outfile.write('#!/bin/sh\n'
                                'if [ "$(pgrep hyperion | wc -l)" -eq 1 ]\n'
                                'then sudo service hyperion restart; fi\n'
                                   'while true\n'
                                   'do STEAMCHECK="$(pgrep steamlink)"\n'
                                   'if [ ! "$STEAMCHECK" ]\n'
                                   'then openvt -c 7 -s -f clear\n'
                                   'systemctl restart mediacenter; fi\n'
                                   'done')
              outfile.close()
        main()
swetoast commented 4 years ago

maybe something like this couldnt stop thinking about it so i reviewed your stuff and came up with this dont know if its working or not it needs testing

swetoast commented 4 years ago

that one need linting have an update but at work

slouken commented 4 years ago

That won't work, shutting down the mediacenter will kill steamlink-launcher.sh. Also, I clobber the install scripts on purpose - upgrades to the package won't take effect if you don't. Any particular reason you don't want to take the PR as-is?

swetoast commented 4 years ago

kinda wanna include *elec system also so im making it as universal as possible and your script gave me that idea

So here is what i have in mind again inspired by your initial work

swetoast commented 4 years ago

decided to merge and rebase of your commit seems like a straight forward deal. tnx again @slouken

slouken commented 4 years ago

You're welcome!

swetoast commented 4 years ago

got some plans coming up for the launcher so im gonna dedicate this weekend for some coding,

i wanna include libreelec systems since they are using this launcher for the minimal distro wanna make it a bit easier so they dont have change alot of system files on install

slouken commented 4 years ago

sounds good