[LIVE] Execute Bash script from Main Menu
#1
Is it possible to execute a set bash script from the main menu in xbmc?

For example I go into the skin options, add a button on the main menu and direct it to a bash script?

What I know you can only choose to direct it to an addon as of Dharma. Do I need to make a small addon that launches that bash script or something then?
Reply
#2
Don't think you can do bash directly - but you should be able to write a 2 liner in python that imports "os" and allows you to directly call a bash script from there. Then create a button in the skin you are using and map it to the apropriate xbmc builtin function to call a python script.

Of course, instead of bash you can use python directly as well for whatever you want to do.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#3
Well it isn't a 100 liner script, just these two lines:

sudo grub-reboot 2
sudo shutdown -r now

So I guess I will have to dig in and make an addon to xbmc which executes those 2 lines.
Reply
#4
Write the script and add it as a favorite. Did that with my AppleTV Crystalbuntu install. While it's not an element of the main screen, i.e. you still have to go to Favorites to select it, it's certainly doable.
Reply
#5
I solved it by writing it as an addon, so now I can have it on my home page Smile
Reply
#6
hi can you show me example how you did it?
Reply
#7
Here is the addon I made:
http://www.multiupload.com/X8OPY9O5GN

Just unzip it and open the file default.py and you will find my code.
Replace YOURPASSWORD with the sudo password and replace OSNMBR with the number to the OS you want to start.

Or follow these steps that I posted on another forum:

Code:
1. Edit the file /etc/default/grub to have GRUB_DEFAULT=saved (if it is not already like that).

2. Regenerate the file /boot/grub/grub.cfg:

sudo grub-mkconfig -o /boot/grub/grub.cfg


3. Run this command to get the numbers of the installed OSes in grub:

sudo cat /boot/grub/grub.cfg | grep menuentry | awk -F\" '{print N++,$(NF-1)}'

4. Replace OSNMBR with the number to the OS you want to switch to.

5. Replace YOURPASSWORD with the sudo password.

6. Save and rezip the script.osswitcher folder.

7. Install the addon into XBMC Live, or XBMC on ubuntu.

8. Don't forget to set your default boot OS in grub to XBMC so you just have to select reboot in the other OS to make it boot back into XBMC.

9. Optional: Go to System > Skin and add a shortcut to the Program submenu on the homepage (don't know yet how to get it directly on the homepage).

10. Optional: Set GRUB_TIMEOUT=5 or lower for even faster switching.

I wrote this for my HTPC that dual boots Windows 7 with XBMC Live. I don't have a physical keyboard nor mouse attached to it. Just the remote that came with and my iPhone. So therefore I am unable to choose which OS to boot when it starts.

If someone is willing to add a UI to this addon to minimize the manual config you are free to do that, but please post back here so everyone can have a share of the cookie Wink
Reply
#8
Hi Cyb3rH4Xter, Id like to try out your addon but I cant connect to the link provided, any chance you could email me the files for this addon? Ive PM'd you my email. Ive been holding for eden to customize xbmc a bit and rebooting to windows once for games/emulators from the home screen is one of the things on my todo list.
Reply
#9
This is exacltly what im looking for !

I can currently reboot my box into another OS using an SSH terminal from another machine but this would be so much smarter.

Is there any chance this could be re-uploaded please?

Pretty please with a cherry on top?

Big Grin
Reply
#10
The script is quite simple actually, here is mine:

Code:
#cat /home/xbmc/reboot.py
import os
os.system('sh /home/xbmc/.scripts/reboot-to-windows-once.sh')

And the script to reboot to windows once:

Code:
#cat /home/xbmc/.scripts/reboot-to-windows-once.sh

#not necessary although helpful
sudo grub-set-default 0

sudo grub-reboot 5

sudo reboot

0 is the listing of linux in the GRUB boot menu and 5 being windows.
Reply
#11
After re-reading this thread I realised that making a addon would be much easier than trying to integrate the script into confluence... It won't be as pretty but I think it will be more future proof and its going to be a sub menu item under programs which isn't so bad.

This is my first addon for xbmc and I have copied the addon framework from the xbmc-backup addon but I'm sure that it doesn't use any code specific to the xbmc-backup addon.

The addon requires setting up before installation and this will allow you to tailor the addon to your needs, I use it to reboot from linux to windows for games and emulators so I have the addon named 'games' with a game pad as a icon. Open the zip file, change what is needed and re-zip then install.

First off you need to configure grub. Im basing this off my set up where 0 is the grub linux entry which is usually boot from and 5 is the listing number of the windows partition that I reboot to. This is on Ubuntu 12.04 x64.

Code:
sudo nano /etc/default/grub

The first uncommented option should be GRUB_DEFAULT=, make sure that line is:

Code:
GRUB_DEFAULT=saved

Now update grub:

Code:
sudo update-grub

Next you need to add the commands needed to reboot the pc to /etc/sudoers so they can run without having to enter the root password:

Code:
sudo visudo

The end of the file should look like this. NOTE you need replace <your username> with the username xbmc uses:

Code:
#includedir /etc/sudoers.d

<your username>    ALL=(ALL) NOPASSWD: /sbin/reboot, /usr/sbin/grub-set-default, /usr/sbin/grub-reboot

To change the icon and name of the plugin replace the icon.png file and edit the addon.xml (name=) within the zip file. Edit default.py to change the command settings need to reboot to the OS of your choice. Make sure these commands run from the command line with no password.

The link to the addon.


Reply
#12
while i'm sure the add-on cuts it, i would like to point out that you can use the system.exec or system.execwait builtins to launch your scripts as well.
Reply
#13
Would they be used in the default.py within the addon folder?
Reply
#14
hi community,

I want to create a little script addon. basically when this addon is opened I would like it to either

i) log out and auto log back into Kodi, (No password required)
or
ii) stop and auto restart current skin

Can anyone help?

Thank you

simontfs
Reply

Logout Mark Read Team Forum Stats Members Help
[LIVE] Execute Bash script from Main Menu0