Related
So I am trying to make a tool to use with the LG Ally for root and recovery, kind of like Unrevoked. All commands necessary can be done via ADB, all resources including adb can be placed in a resource folder.
I am having very frustrating issues as the Ally doesn't have Root on auto via adb, and adb root doesnt work properly. So I started using a batch file and fan into problems where when I issue adb shell su the script gets "stuck" in the shell and wont accept any input until the su shell terminates. If I adb shell su then close the window, the su permissions are NOT preserved.
I have moved on to visual basic, so I have a little more control, but I cannot for the life of me find out how to successfully pass commands to the shell the best I can do is open new shells for each command which is no good.
I know Im missing something and I know its something simple I just cant for the life of me figure it out
ok so I made a media player which is written in c# and it passes commands to adb...I can show you how to talk to shell via c# if you want.
Ok s how are you writing to shell one by one? Are you using a stream writer to a process?
At this point the commands are issued one by one.
I just installed vb 2k8, I think my problems lye in the deprecation of vb6 commands
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Shell("C:\android-sdk-windows\tools\adb.exe shell su")
SendKeys.Send("ls")
SendKeys.Send("{ENTER}")
End Sub
End Class
Im trying to keep it simple for now. This code will open up 2 cmd windows for some reason. and it doesnt pass the SendKeys.Send keys, I just end up with 2 cmd windows sitting at the #.
If I Shell("CMD.EXE") and try running adb commands with sendkeys, the keys sent will be jarbled, it moves around my keys (I would imagine because / is an escape char?)
I havent mucked about with vb in a few years so sorry for my noobism, Im good at bash scripting but this is very counter-intuitive
ok that is a bad way of doing it...no offense
Anyway, here's the proper way of sending shell commands one by one and getting back output...
objProcess = New System.Diagnostics.Process()
objProcess.StartInfo.FileName = ProcessPath
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
objProcess.Start()
and you set processpath to be "cmd"
and you say objprocess.standardinput.writeline("whatever command you want")
and you say objprocess.standardoutput.readline() to return a string which you can display in a messagebox by saying "msgbox(string)"
-Hope this helps
None taken, my VB is weak like the ukraine, Im just trying to make a copy of my tool for windows, since most people use it. Thatsnks for the tips Im on the right track now, I think.
It is however giving me some trouble with objProcess.StandardInput.WriteLine...
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objProcess = New System.Diagnostics.Process()
objProcess.StartInfo.FileName = "cmd"
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
objProcess.Start()
objProcess.StandardInput.WriteLine("echo TEST")
End Sub
End Class
its still super simple in testing mode. This when ran gives me the error "StandardIn has not been redirected." Thanks for the help im currently researching to see if I can figure it out. If you have any more ideals let me know
Got it, thanks
heres is the working code for a test I did
Code:
Public Class Form1
Private WithEvents objProcess As Process
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
objProcess = New Process
objProcess.StartInfo.FileName = "cmd"
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
objProcess.StartInfo.RedirectStandardInput = True
objProcess.StartInfo.UseShellExecute = False
objProcess.StartInfo.RedirectStandardOutput = True
objProcess.Start()
objProcess.StandardInput.WriteLine("C:\android-sdk-windows\tools\adb.exe kill-server")
objProcess.StandardInput.WriteLine("C:\android-sdk-windows\tools\adb.exe start-server")
objProcess.StandardInput.WriteLine("C:\android-sdk-windows\tools\adb.exe shell su")
objProcess.StandardInput.WriteLine("C:\android-sdk-windows\tools\adb.exe shell mkdir /sdcard/TEST")
End Sub
End Class
If it's useful, I have a technique to start an app, then to call the app again from the command line.
If the app is still running, it will process the command line. If it's not running, it simply launches a new instance and then processes the command line.
Let me know if you can use it.
Cheers
You Guys should look at the AndroidLib.dll it has adb/fastboot and device libraries already so you can just package 1 exe in your distro without the need to include or reference Adb and fastboot directly. Here is an example of a Form Button to reboot in to the bootloader.
Code:
private void button1_Click(object sender, EventArgs e)
{
AdbCommand adbrebootCmd = Adb.FormAdbCommand(device, "reboot bootloader");
Adb.ExecuteAdbCommand(adbrebootCmd);
android.Dispose();
}
The library also allows you to send AdbShell commands with Root access.
Really useful.
Basically I have been working on a Boot animation changer for the Nexus 7 and the program so far is coded in a C# form for windows.
I have coded everything fine up till now. And I'm a little stuck.
I need to run a ADB command to push a file from my Program files x86 to the nexus 7 and write over the original Boot file.
But is there a simple and easy solution for writing this code? Or do I need to make a console application which does this process when started?
Thanks.
( I can push files manually via ADB, but the point is to make the tool " one click " If you get my drift. )
QuantumCipher said:
Basically I have been working on a Boot animation changer for the Nexus 7 and the program so far is coded in a C# form for windows.
I have coded everything fine up till now. And I'm a little stuck.
I need to run a ADB command to push a file from my Program files x86 to the nexus 7 and write over the original Boot file.
But is there a simple and easy solution for writing this code? Or do I need to make a console application which does this process when started?
Thanks.
( I can push files manually via ADB, but the point is to make the tool " one click " If you get my drift. )
Click to expand...
Click to collapse
Simply execute adb via shell command?
cakebomb said:
Simply execute adb via shell command?
Click to expand...
Click to collapse
Oh so I can actually run the command from the C# application instead of the console? Just write the argument?
QuantumCipher said:
Oh so I can actually run the command from the C# application instead of the console? Just write the argument?
Click to expand...
Click to collapse
I don't know, how to do it in C#, I just know VB.
But you should be able to run adb (shell) with process.start or something and then just type the commands behind adb (shell), like if you want to run 'cmd.exe shutdown -s'.
And if not let your program create and run a batch file, which starts adb and copys the files to the phone, this is definitely possible.
Sent from my GT-I9100 using xda app-developers app
QuantumCipher said:
Oh so I can actually run the command from the C# application instead of the console? Just write the argument?
Click to expand...
Click to collapse
not 100% sure but should be something like
this is just an example and may be wrong, better check out exact arguments or google
using System;
using System.Diagnostics;
namespace adb.test
{
class ProcessStart
{
static void Main(string[] args)
{
Process adb = new Process();
adb.StartInfo.FileName = "adb.exe";
adb.StartInfo.Arguments = "shell";
adb.Start();
}
}
}
hopefully this will help you.
ADB VB Express 2008 - WM-Explorer
Hi,
this function is maked by my for WM-Explorer (WM8850 tablets - nanospic.ro ) in VB Express 2008
Dim CurrentPath As String = Environment.CurrentDirectory & "\"
Public Function ADB_Send_Cmd(ByVal cmd As String, ByVal timeout As Integer) As String
Dim dos_out As String = "dos_out.pms"
Dim bat_file As String = "getcmd.bat"
Dim sir As String
sir = "adb.exe " & cmd & " > " & dos_out
System.IO.File.WriteAllText(CurrentPath & bat_file, sir)
Shell(CurrentPath & bat_file, AppWinStyle.Hide, True, timeout)
Application.DoEvents()
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("adb")
For Each p As Process In pProcess
p.Kill()
p.WaitForExit()
Next
Application.DoEvents()
Dim sr As StreamReader = File.OpenText(CurrentPath & dos_out)
Dim out As String = sr.ReadToEnd
sr.Close()
System.IO.File.Delete(CurrentPath & bat_file)
System.IO.File.Delete(CurrentPath & dos_out)
ADB_Send_Cmd = out
End Function
and how to use this function :
cmd = "devices"
rezultat = ADB_Send_Cmd(cmd, 20000)
'rezultat' may be :
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
xxxxxxxxx
cakebomb said:
I don't know, how to do it in C#, I just know VB.
But you should be able to run adb (shell) with process.start or something and then just type the commands behind adb (shell), like if you want to run 'cmd.exe shutdown -s'.
And if not let your program create and run a batch file, which starts adb and copys the files to the phone, this is definitely possible.
Sent from my GT-I9100 using xda app-developers app
Click to expand...
Click to collapse
Xadder said:
not 100% sure but should be something like
this is just an example and may be wrong, better check out exact arguments or google
using System;
using System.Diagnostics;
namespace adb.test
{
class ProcessStart
{
static void Main(string[] args)
{
Process adb = new Process();
adb.StartInfo.FileName = "adb.exe";
adb.StartInfo.Arguments = "shell";
adb.Start();
}
}
}
hopefully this will help you.
Click to expand...
Click to collapse
diabetu said:
Hi,
this function is maked by my for WM-Explorer (WM8850 tablets - nanospic.ro ) in VB Express 2008
Dim CurrentPath As String = Environment.CurrentDirectory & "\"
Public Function ADB_Send_Cmd(ByVal cmd As String, ByVal timeout As Integer) As String
Dim dos_out As String = "dos_out.pms"
Dim bat_file As String = "getcmd.bat"
Dim sir As String
sir = "adb.exe " & cmd & " > " & dos_out
System.IO.File.WriteAllText(CurrentPath & bat_file, sir)
Shell(CurrentPath & bat_file, AppWinStyle.Hide, True, timeout)
Application.DoEvents()
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("adb")
For Each p As Process In pProcess
p.Kill()
p.WaitForExit()
Next
Application.DoEvents()
Dim sr As StreamReader = File.OpenText(CurrentPath & dos_out)
Dim out As String = sr.ReadToEnd
sr.Close()
System.IO.File.Delete(CurrentPath & bat_file)
System.IO.File.Delete(CurrentPath & dos_out)
ADB_Send_Cmd = out
End Function
and how to use this function :
cmd = "devices"
rezultat = ADB_Send_Cmd(cmd, 20000)
'rezultat' may be :
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
xxxxxxxxx
Click to expand...
Click to collapse
Thanks for the effort guys I found a way round it all and learnt a few new things about the android system ways and file permissions Ill be posting the app on here today or tomorrow may add a few more features to make it more worth while for users.
(Y)
QuantumCipher said:
Thanks for the effort guys I found a way round it all and learnt a few new things about the android system ways and file permissions Ill be posting the app on here today or tomorrow may add a few more features to make it more worth while for users.
(Y)
Click to expand...
Click to collapse
I am attempting a similar feat and I was wondering what your work around is?
My batch file terminates issues cmd commands at the shell prompt.
I am merely using a "Unlock" and "Lock" Form button to issue several commands to ADB Shell to Change the HTC One Max Flag for Locked Bootloader status. I would like to hard code the shell commands to execute with form button press but I have yet to find a way. Below are 2 sequenced events i need to occur on button press. I am using Visual Studio 2013
Mark Boot loader as Locked Code is:
Code:
adb shell
su
(if needed to get a # prompt)
echo -ne '\x00\x00\x00\x00' | dd of=/dev/block/mmcblk0p3 bs=1 seek=33796
exit
exit
adb reboot bootloader
(This is for the user to verify the Bootloader flag has changed)
Mark Boot loader as Unlocked Code is:
Code:
adb shell
su
(if needed to get a # prompt)
echo -ne "HTCU" | dd of=/dev/block/mmcblk0p3 bs=1 seek=33796
exit
exit
adb reboot bootloader
Thanks for your help
DeadPhoenix said:
I am attempting a similar feat and I was wondering what your work around is?
My batch file terminates issues cmd commands at the shell prompt.
I am merely using a "Unlock" and "Lock" Form button to issue several commands to ADB Shell to Change the HTC One Max Flag for Locked Bootloader status. I would like to hard code the shell commands to execute with form button press but I have yet to find a way. Below are 2 sequenced events i need to occur on button press. I am using Visual Studio 2013
Mark Boot loader as Locked Code is:
Code:
adb shell
su
(if needed to get a # prompt)
echo -ne '\x00\x00\x00\x00' | dd of=/dev/block/mmcblk0p3 bs=1 seek=33796
exit
exit
adb reboot bootloader
(This is for the user to verify the Bootloader flag has changed)
Mark Boot loader as Unlocked Code is:
Code:
adb shell
su
(if needed to get a # prompt)
echo -ne "HTCU" | dd of=/dev/block/mmcblk0p3 bs=1 seek=33796
exit
exit
adb reboot bootloader
Thanks for your help
Click to expand...
Click to collapse
does this help?
http://forum.xda-developers.com/showthread.php?t=2042227
QuantumCipher said:
does this help?
http://forum.xda-developers.com/showthread.php?t=2042227
Click to expand...
Click to collapse
I was looking at more of something like this.
http://www.regawmod.com/software/wi...html/986559a3-c009-64d7-e1b0-c3cad2bf4fd4.htm
The reason your linked thread won't work is because once you enter the ADB Shell environment your are no longer issuing commands via the cmd.exe process. There for any command sent from that process are not interpreted by the console as valid as you are in ADB Shell. At least that is my understanding. The Namespace in my link seems to have what I need but I am having a hard time breaking down what I need as I am so new to C# programming.
DeadPhoenix said:
I was looking at more of something like this.
http://www.regawmod.com/software/wi...html/986559a3-c009-64d7-e1b0-c3cad2bf4fd4.htm
Click to expand...
Click to collapse
OKay ive just refrenced that in my new tool ..Ill look in a few hours buddy going ski center now
DeadPhoenix said:
I was looking at more of something like this.
http://www.regawmod.com/software/wi...html/986559a3-c009-64d7-e1b0-c3cad2bf4fd4.htm
The reason your linked thread won't work is because once you enter the ADB Shell environment your are no longer issuing commands via the cmd.exe process. There for any command sent from that process are not interpreted by the console as valid as you are in ADB Shell. At least that is my understanding. The Namespace in my link seems to have what I need but I am having a hard time breaking down what I need as I am so new to C# programming.
Click to expand...
Click to collapse
Right I had a quick look and I think I know what you mean.. Theres a few ways I can think of ..
1. Is Make a thread process and covert your commands like adb reboot to Cmd process like my tutorial.
And for the shell as you said there is AndroidLIB.DLL You need to set the adb shell up from that so you can execute that longer command.
http://www.regawmod.com/software/wi...html/986559a3-c009-64d7-e1b0-c3cad2bf4fd4.htm
Something like this :
But obviously change this code to use adbshellcommand
Code:
AdbCommand adbCmd = Adb.FormAdbCommand(device, true, "input", "keyevent", (int)KeyEventCode.HOME);
If you get stuck Ill right the code out later as I was thinking about adding shell to my console app.
QuantumCipher said:
Right I had a quick look and I think I know what you mean.. Theres a few ways I can think of ..
1. Is Make a thread process and covert your commands like adb reboot to Cmd process like my tutorial.
And for the shell as you said there is AndroidLIB.DLL You need to set the adb shell up from that so you can execute that longer command.
http://www.regawmod.com/software/wi...html/986559a3-c009-64d7-e1b0-c3cad2bf4fd4.htm
Something like this :
But obviously change this code to use adbshellcommand
Code:
AdbCommand adbCmd = Adb.FormAdbCommand(device, true, "input", "keyevent", (int)KeyEventCode.HOME);
If you get stuck Ill right the code out later as I was thinking about adding shell to my console app.
Click to expand...
Click to collapse
Here is my code for the button I am using
Code:
private void lockboot_Click(object sender, EventArgs e)
{
string serial;
android = AndroidController.Instance;
android.UpdateDeviceList();
serial = android.ConnectedDevices[0];
device = android.GetConnectedDevice(serial);
AdbCommand adbCmd = Adb.FormAdbShellCommand(device, true, "echo", "-ne '\x00\x00\x00\x00' | dd of=/dev/block/mmcblk0p3 bs=1 seek=33796");
Adb.ExecuteAdbCommand(adbCmd);
lbllocked.Visible = true;
lblunlock.Visible = false;
textboxcolor.BackColor = Color.Red;
}
It Compiles with no issues however the command is not executing properly. The Bootloader show be flagged unlocked when I boot in to Bootloader. It is however remaining unchanged.
DeadPhoenix said:
Here is my code for the button I am using
Code:
private void lockboot_Click(object sender, EventArgs e)
{
string serial;
android = AndroidController.Instance;
android.UpdateDeviceList();
serial = android.ConnectedDevices[0];
device = android.GetConnectedDevice(serial);
AdbCommand adbCmd = Adb.FormAdbShellCommand(device, true, "echo", "-ne '\x00\x00\x00\x00' | dd of=/dev/block/mmcblk0p3 bs=1 seek=33796");
Adb.ExecuteAdbCommand(adbCmd);
lbllocked.Visible = true;
lblunlock.Visible = false;
textboxcolor.BackColor = Color.Red;
}
It Compiles with no issues however the command is not executing properly. The Bootloader show be flagged unlocked when I boot in to Bootloader. It is however remaining unchanged.
Click to expand...
Click to collapse
Any Suggestions?
Hi XDA developers community!
I think this question was not asked before, because it's too specific.
So here is the problem:
From the Terminal Emulator I am trying to start Poot like so:
Code:
am start -a android.intent.action.MAIN -n org.giantpune.Poot.Poot/android.intent.action.MAIN
and get this error message:
Code:
Error type 3
Error: Activity class {org.giantpune.Poot.Poot/android.intent.action.MAIN} does not exist.
I inspected the AndroidManifest.xml and looked for useful intent commands, but had no luck and even converted the .apk with dex2jar.
As I don't have any experience with Java, the sole purpose of decompiling it in the first place was an interesting intent entry on line 136 in the QtActivity.java file.
It is either located in org/kde/necessitas/origo/ as QtActivity.class, when converted with dex2jar.
Or in Poot-debug(W100)/smali/org/kde/necessitas/origo/ as QtActivity.smali, when decompiled with apktool.
What I am trying to achieve is not only starting the app from the console, but to make it run the action of the "Press here to poot" button.
The device is rooted, should that matter at all.
How can I achieve this and do I even need intent commands or not?
I hope you can help.
Bump
Can anybody help?
As nobody has answered, here is the information I was able to gather meanwhile:
According to a post (can't post link due to restriction) on Android Enthusiasts I need to enter a classname like this:
Code:
am start -a android.intent.action.MAIN -n <package_name>/<full_class_name>
But as there is no class name specified in the AndroidManifest.xml (Link located in first post above), I am not sure how this problem can be solved.
I entered different variations of the command:
Code:
am start -a android.intent.action.MAIN org.giantpune.Poot
Code:
am start org.giantpune.Poot/android.intent.action.MAIN
Code:
am start -a android.intent.action.LAUNCHER org.giantpune.Poot
Code:
am start org.giantpune.Poot/android.intent.action.LAUCHER
None of them worked.
Can someone answer this?
Hello,
sorry about my poor english.
Searching for a step by step how to to build a QML App for Ubuntu Touch.
- How to run system commands like " ls -la > test.txt "
- How to translate the Buttons, Texts etc.
- How to create a button to exit the App
- How to include a Icon for the App
I have installed a Ubuntu 14.04.2 (amd64) and Ubuntu SDK 1.126
can create a Simple QML App and install it on my Ubuntu Phone.
But no Icon, an did not sucess to run system commands.
Thanks for help.
ds2k5 said:
I have installed a Ubuntu 14.04.2 (amd64) and Ubuntu SDK 1.126.
Click to expand...
Click to collapse
First of all, please update your Ubuntu SDK installation to the latest version (1.194) from the PPA from the installation page.
ds2k5 said:
- How to run system commands like " ls -la > test.txt "
Click to expand...
Click to collapse
This is possible if you add a C++ backend to your application but you'll have to ship every binary you want to execute in your click package or you'll have to run your app unconfined to achieve this. The latter will result in your app not being included in the official Ubuntu Store. There's an unofficial one for unconfined applications though.
ds2k5 said:
- How to translate the Buttons, Texts etc.
Click to expand...
Click to collapse
Simply wrap strings in i18n.tr() calls and use gettext to create pot and po files.
Example:
Code:
Button {
text: i18n.tr("Translatable string")
}
ds2k5 said:
- How to create a button to exit the App
Click to expand...
Click to collapse
I don't know whether this is possible from QML but you will for sure be able to do this from a C++ backend.
ds2k5 said:
- How to include a Icon for the App
Click to expand...
Click to collapse
Set the icon path in your desktop file to your custom one which you place in the app directory.
Check out the Qt.quit() function call for closing your app.
Sent from my awesome Ubuntu Touch device using the Forum Browser app
Hey everyone,
I am looking for a way to activate sleep mode of my chromebook manually in order to save battery without having to log out or power off all the time (it's connected to an external display, so closing the lid doesn't trigger it).
So far I found out that calling "powerd_dbus_suspend" from the shell does the trick, but as you can imagine, using the shell and actually typing the command every time is not really a solution.
Is there a way to create a chrome os app that executes this program call, so I can put it in my shelf and just click it to activate sleep?
I'm not really good at .json, maybe there's a way? Or any other suggestions?
Thanks alot!
Markus
I would like to know it too. Anyone?
Sneets said:
Hey everyone,
I am looking for a way to activate sleep mode of my chromebook manually in order to save battery without having to log out or power off all the time (it's connected to an external display, so closing the lid doesn't trigger it).
So far I found out that calling "powerd_dbus_suspend" from the shell does the trick, but as you can imagine, using the shell and actually typing the command every time is not really a solution.
Is there a way to create a chrome os app that executes this program call, so I can put it in my shelf and just click it to activate sleep?
I'm not really good at .json, maybe there's a way? Or any other suggestions?
Thanks alot!
Markus
Click to expand...
Click to collapse
Run a tiny web server like lighttpd in the shell on a weird port, restrict to localhost. Set up index.php to run system (whatever);
Then bookmark the 127.0.0.1: xxxx URL
Which system call invokes power_dbus_suspend?
Thanks Parrotgeek1. Working off your excellent suggestion I installed a lightweight local server on ChromeOS (Web Server for Chrome with the 200 OK! icon) and built a small framework app that is served from local storage. I'm all set up to call chrome.app.??? from my JavaScript. Which API provides the power_dbus_suspend capability? I looked through the Power and System APIs and I don't see anything. - Thanks!
Sneets said:
Hey everyone,
I am looking for a way to activate sleep mode of my chromebook manually in order to save battery without having to log out or power off all the time (it's connected to an external display, so closing the lid doesn't trigger it).
So far I found out that calling "powerd_dbus_suspend" from the shell does the trick, but as you can imagine, using the shell and actually typing the command every time is not really a solution.
Is there a way to create a chrome os app that executes this program call, so I can put it in my shelf and just click it to activate sleep?
I'm not really good at .json, maybe there's a way? Or any other suggestions?
Thanks alot!
Markus
Click to expand...
Click to collapse
Have you tried this simple extension? Keep Awake
https://chrome.google.com/webstore/...lb?utm_source=chrome-app-launcher-info-dialog
What I do is have the shell tab pinned, and press [up arrow] for the command then hit [enter]. Probably not ideal if you use the shell a lot as you have to step through recently used commands.
Re: Pkt_Lnt's post
Thanks Pkt_Lnt. That app only deals with disabling the normal sleep behavior, not causing it, and in particular not causing it when an external monitor is connected. I'm looking for something like Sneets has requested, to invoke a powerd_dbus_suspend command that will force the system to sleep (and turn off an external monitor). Per Parrotgeek1's comment, I've got a little app now sitting on the shelf that is all set to call some system command to invoke powerd_dbus_suspend, only I'm looking for what command to call, from JavaScript.
I managed to find a way to do something similar with the Secure Shell app. During the process of figuring it out, I also found that I was able to create a homescreen shortcut on my Android tablet which when tapped sends a shell command to the Chromebook.
This method might be overkill somewhat, but, anyway, what I did was as follows:
Installed Secure Shell extension; setup sshd on the Chromebook (by making a symlink in /etc/init/ pointing to /usr/share/chromeos-ssh-config/init/openssh-server-conf); rebooted; added public key from ConnectBot (Android app) to ~/.ssh/authorized_keys in order to test connection; setup Android homescreen shortcut to send shell command; created profile in Secure Shell app on Chromebook to connect to [email protected]/my local IP address; generated keys on Chromebook (in ~/.ssh); added generated public key to ~/.ssh/authorized_keys; imported newly-generated private/public key pair within Secure Shell app (one by one); created bookmark link to [email protected] profile in shelf, and, finally, added required command to profile in Secure Shell.
It works well! It looks like any command can be added to the 'Arguments' field in Secure Shell, with the syntax:
Code:
-- thecommand
Although I guess commands that need sudo would require a connection to [email protected], instead of chronos. (-t argument lets you use sudo, but then sending a line break/ENTER seems to be needed)
The window opened with the click does hang around - I haven't figured out if it's possible to avoid this - but it does at least seem to persistently remember the size and position to which it's set.
I posted up some further details at http://nolirium.blogspot.com/shell-command-shelf-shortcut-chromeos.html
Impressive! But a bit more than I'm looking to do
@Nolirum - I read your blogspot doc and your procedure's pretty impressive. Frankly it's a little beyond me and beyond what I'm looking for. If you ever run across a way to invoke powerd_dbus_suspend a little more directly please post here as well. You clearly have a strong grasp of the issues!
Nolirum said:
I managed to find a way to do something similar with the Secure Shell app. During the process of figuring it out, I also found that I was able to create a homescreen shortcut on my Android tablet which when tapped sends a shell command to the Chromebook.
This method might be overkill somewhat, but, anyway, what I did was as follows:
Installed Secure Shell extension; setup sshd on the Chromebook (by making a symlink in /etc/init/ pointing to /usr/share/chromeos-ssh-config/init/openssh-server-conf); rebooted; added public key from ConnectBot (Android app) to ~/.ssh/authorized_keys in order to test connection; setup Android homescreen shortcut to send shell command; created profile in Secure Shell app on Chromebook to connect to [email protected]/my local IP address; generated keys on Chromebook (in ~/.ssh); added generated public key to ~/.ssh/authorized_keys; imported newly-generated private/public key pair within Secure Shell app (one by one); created bookmark link to [email protected] profile in shelf, and, finally, added required command to profile in Secure Shell.
It works well! It looks like any command can be added to the 'Arguments' field in Secure Shell, with the syntax:
Code:
-- thecommand
Although I guess commands that need sudo would require a connection to [email protected], instead of chronos. (-t argument lets you use sudo, but then sending a line break/ENTER seems to be needed)
The window opened with the click does hang around - I haven't figured out if it's possible to avoid this - but it does at least seem to persistently remember the size and position to which it's set.
Click to expand...
Click to collapse
This really is impressive! Thanks for the extremely detailed explanation.
I was able to follow along completely and get the SSH argument "powerd_dbus_suspend" working.
However, I got to thinking. I was wondering if this could be extended to use an alias stored in ~/.bashrc?
After doing some research of my own and using various parameters and arguments, I was unsuccessful.
The goal is to have a linux app (through crouton) be run using xiwi with just a single bookmark by utilizing an alias.
Any thoughts?
UPDATE:
Of course just a few moments later I figured this out! Rather than dealing with an alias stored in ~/.bashrc and ensuring ssh had access, typing the entire alias command as an argument worked. Now I can run Steam directly from a shelf bookmark. All it took was replacing "powerd_dbus_suspend" with "-- sudo enter-chroot xiwi steam" in the argument.
Thanks again!
DandyRandyMarsh said:
This really is impressive! Thanks for the extremely detailed explanation.
I was able to follow along completely and get the SSH argument "powerd_dbus_suspend" working.
Click to expand...
Click to collapse
No problem! I think it's perhaps overly detailed if anything. Might be easier to follow if I cut it down a bit.
DandyRandyMarsh said:
Now I can run Steam directly from a shelf bookmark. All it took was replacing "powerd_dbus_suspend" with "-- sudo enter-chroot xiwi steam" in the argument.
Click to expand...
Click to collapse
Nice!
Adding crouton single app shortcuts is a cool idea which I hadn't considered. Does it work OK for you with sudo in the command, even straight after booting up? ...You didn't have to setup sudoing without a password via sudoers.d or anything?
Inspired by your post I added xiwi to my chroot to try it out. I seem to remember experiencing quite unbearable lag and slowness when running a full desktop via xiwi in the past, but with single apps there doesn't seem to be any noticeable performance hit (this is on an armv7 Asus Flip, with the chroot on a slooow USB drive).
In order to not have to enter my sudo password, in the argument I put:
Code:
-t -- echo mypassword | sudo -S sh /media/removable/3/bin/enter-chroot xiwi firefox
Maybe I'm missing something? Is there a better way, perhaps?
Anyway, since I have rootfs verification switched off, I also tried saving a similar command to a file in /usr/bin, and putting the filename in the argument instead. This works, too, and I suppose could potentially be useful e.g. in the case of needing to run a more convoluted sequence of commands with a shortcut.
Nolirum said:
Adding crouton single app shortcuts is a cool idea which I hadn't considered. Does it work OK for you with sudo in the command, even straight after booting up? ...You didn't have to setup sudoing without a password via sudoers.d or anything?
Click to expand...
Click to collapse
I'm not entirely familiar with exactly how my process worked, but I do not have any sudo password required within shell.
Here's the list of steps I followed allowing me to use sudo commands in the SSH Arguments box.
As a side note, this is the crouton installation I am running on an ASUS c302.
sudo sh ~/Downloads/crouton -r trusty -t unity,touch,xiwi,extension
Setup Bookmarks that Run Shell Commands
1. Installed Secure Shell extension
2. Open crosh with Ctrl+Atl+T
3. Enter Command: shell
4. Enter Command: sudo su -
5. Enter Command: sudo /usr/share/vboot/bin/make_dev_ssd.sh --force --remove_rootfs_verification
6. Enter Command: reboot
7. Let Chrome OS reboot
8. Open crosh with Ctrl+Atl+T
9. Enter Command: shell
10. Enter Command: sudo su -
11. Enter Command: mount –o remount rw /
12. Close current crosh window
13. Open a new crosh with Ctrl+Atl+T
14. Enter Command: shell
15. Enter Command: sudo ln -s /usr/share/chromeos-ssh-config/init/openssh-server.conf /etc/init/openssh-server.conf
16. Enter Command: sudo initctl reload-configuration
17. Enter Command: sudo initctl start openssh-server
18. Enter Command: cd ~/.ssh/
19. Enter Command: ssh-keygen
“Enter file in which…” *LEAVE BLANK*
“Enter passphrase” *LEAVE BLANK*
“Enter same passphrase” * LEAVE BLANK*20. Enter Command: cat /home/chronos/user/.ssh/id_rsa.pub >> /home/chronos/user/.ssh/authorized_keys
21. Enter Command: cp -a /home/chronos/user/.ssh/id_rsa* /home/chronos/user/Downloads
22. Close current crosh terminal and open Secure Shell extension
23. Select [New Connection]
24. Click Import… and select “id_rsa”
25. Click Import… again and select “id_rsa.pub”
26. Enter chronos as the username and localhost as the hostname
27. Enter a shorthand name replacing the text in the top cell “[email protected]”
28. Click Enter. If prompted, enter “yes” to continue connecting
29. Bookmark the page that is open which should end in, "#profile-id:_ _ _ _"
DONE. Now time to add some commands to automate.
Open Secure Shell and select the connection created. In the arguments box, start with two dashes -- and follow it your desired shell command.
Examples:
-- sudo startunity
-- sudo startgnome
-- sudo enter-chroot xiwi steam
-- sudo enter-chroot xiwi wine microWord
Next Steps... Getting Custom Shelf Icons
Now here I am running into some issues. Rather than have all these icons be the same, I was hoping to customize them.
Followed a strategy found on reddit, Change Shelf Icon for Website, but this only works if the site already had an "apple-touch-icon" set. Also, tried to inject the entire code myself which I couldn't get to work. Unfortunately, I think that since this bookmark is created from a Secure Shell, there are some issues.
I have already tried adding in code for this into the site, but it is having no effect. If someone could make this work then we're really looking good here.
DandyRandyMarsh said:
I'm not entirely familiar with exactly how my process worked, but I do not have any sudo password required within shell.
Click to expand...
Click to collapse
Oh, I see what you mean. You are saying that you can sudo in the shell generally, without being prompted for a password, right?
Was that the default setup on your CB (after switching to Dev mode)? Or did you have to configure it manually for passwordless sudoing...
DandyRandyMarsh said:
Here's the list of steps I followed allowing me to use sudo commands in the SSH Arguments box.
Click to expand...
Click to collapse
Nice work summarizing the steps. :highfive: It's probably easier to follow, listed out like that. One slight addendum, perhaps - at step 29, it might be good to clarify the "add to shelf" procedure. Especially because of the following...
DandyRandyMarsh said:
Next Steps... Getting Custom Shelf Icon
Now here I am running into some issues. Rather than have all these icons be the same, I was hoping to customize them.
Click to expand...
Click to collapse
Happily it turns out that, when you add shortcuts to the shelf on Chrome OS like this, a minimal app is created for each one, with its own manifest.json, and icon.pngs. Our shell shortcuts were getting created with blank pngs by default (the black box with P in the center).
So, all we need to do, is get some icons, find the right folder for our shelf shortcut apps, then copy our new icons into them!
For instance, here's how I made a nice shiny icon for my single app shelf shortcut to Firefox.
Prepared icons:
Created a temporary folder in ~/Downloads to store downloaded icons.
Prepared a set of icons in ~/Downloads/firefox. (I downloaded mine from findicons.com).
Six sizes are required - from 32px to 256. To avoid any manifest editing, saved them as *size*.png
e.g. 32.png; 48.png; 64.png; 96.png; 128.png; 256.png
Located folder to copy icons to:
It is easiest to do this directly after clicking "add to shelf"
EITHER:
To change dir into the most recently modified extension icon subfolder automatically, the following one-liner worked for me*.
Code:
shell
cd ~/Extensions/&&cd $(ls -v1td */ | head -1)/*/icons&&ls
A list of blank icons (*.png) should be visible. If so, the new icons can simply be copied over these, e.g..
Code:
sudo cp ~/Downloads/firefox/* .
*YMMV with this particular one-liner - sometimes there's an extra 'temp' folder in ~/Extensions, which stops it working as expected. If you get an error after running the command, simply use the slightly more manual method to locate the folder, as detailed below.
OR:
(slightly more manual method).
Code:
shell
ls -ltr ~/Extensions
Checked the date/times - the most recently added folder is at the bottom. Then,
Code:
cd themostrecentlyaddedfolder
(or, the folder modified at the date/time that the shortcut was "added to shelf"). Then,
Code:
cd */icons
ls
sudo cp ~/Downloads/firefox/* .
I then repeated the above with a new SSH argument and a set of Ubuntu icons, for a custom startxfce4 shortcut, too.
Then just did sudo restart ui, and enjoyed the shiny new shelf icons!
I am hopeful that these changes will get picked up by CrOS's sync, thus getting backed-up and restored automatically. At this point I am not sure if that will be the case, but I don't see why it wouldn't.
Another way?
Another way to approach this, since you're modifying system stuff anyway, might be to edit crosh at /usr/bin/crosh. It's a regular ol' dash/bash shell program, and you can create a shortcut to it on the shelf by opening crosh (ctrl-alt-T), then right click the top right of the browser and select More Tools --> Add to shelf...
Clicking the newly-created link (which looks like an "N") will launch /usr/bin/crosh in a tab. Changing the default behavior of /usr/bin/crosh could accomplish your goal to do whatever you want. With some experimenting, you might even be able to pass arguments to make it do different things depending on how it's opened (via ALT-CTRL-T vs from the shelf-- dunno if it can read the url used to call crosh), but at the very least you could do something like have it run whatever you want it to run if a second modifier key is held down (or if it isn't...), otherwise return to normal operation. A menu w/1 sec timeout could do this as well, ie--
Doing [THE THING YOU WANT] in 2 seconds (press SPACE for crosh)... /
Note there's no proof-of-concept here. Just throwing it out as an idea that I'm pretty sure would work... Someone might even create a neat extension that allows crosh to use scripts/plugins to execute different system operations beyond the stock ones that are built-in via single-clicks... If it worked, it might be a little simplier than via the SSH extension and you wouldn't have to run any extra daemons.
ft
This is probably harder, but a third way, which probably is the "right" way is to see how the crosh extension works and learn about opening the hterm.Terminal instance chrome.terminalprivate object directly, sending it output, and closing it in the same way crosh does it. There's a file in the crosh extension at js/crosh.js that shows the basics of how it's done:
var terminal = new hterm.Terminal(profileName);
And then you can do stuff with it. You could then create an extension that could handle multiple shelf-icons (say by appending ?COMMAND=ls to the URL to do different shell commands(. The security implications for this would probably be huge obviously.
Update: More on embedding hterm is here.
Nolirum said:
I managed to find a way to do something similar with the Secure Shell app. During the process of figuring it out, I also found that I was able to create a homescreen shortcut on my Android tablet which when tapped sends a shell command to the Chromebook.
I posted up some further details at http://nolirium.blogspot.com/shell-command-shelf-shortcut-chromeos.html
Click to expand...
Click to collapse
Nice post - Some good food for thought, changing up the contents of crosh etc directly is an interesting idea.
fattire said:
Another way to approach this, since you're modifying system stuff anyway, might be to edit crosh at /usr/bin/crosh. It's a regular ol' dash/bash shell program, and you can create a shortcut to it on the shelf by opening crosh (ctrl-alt-T), then right click the top right of the browser and select More Tools --> Add to shelf...
Click to expand...
Click to collapse
Interesting! ....Aaaaand, now I've broken crosh. lol. Lucky I had my SSH shortcut setup... (actually, we can still get into the VTs with CtrlAltF2 etc anyway).
Some good potential for experimentation with this, definitely.
fattire said:
This is probably harder, but a third way, which probably is the "right" way is to see how the crosh extension works and learn about opening the hterm.Terminal instance chrome.terminalprivate object directly, sending it output, and closing it in the same way crosh does it. There's a file in the crosh extension at js/crosh.js that shows the basics of how it's done:
Click to expand...
Click to collapse
Again, very interesting. Now you come to mention it, an approach such as this does seem like it might be do-able without too much messing around (maybe)...
Any possible method we can get e.g. an extension to 'talk' to the shell is worth looking into I think; as you say, if we can cut out the middleman (ssh) and maybe do it more elegantly, that might be pretty useful indeed.