make auto-choice in terminal - terminal

I would like to know if there is a way to make a choice in terminal using command line.
For example: when I type sudo update-alternatives --config glx
I get the response:
There are 4 choices for the alternative glx (providing /usr/lib/glx).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/nvidia 100 auto mode
1 /usr/lib/fglrx 99 manual mode
2 /usr/lib/fglrx/igpu 90 manual mode
* 3 /usr/lib/mesa-diverted 5 manual mode
4 /usr/lib/nvidia 100 manual mode
Press enter to keep the current choice[*], or type selection number:
I would like to make a command where I can execute a lot of stuff in the same line without having to type this choice. Something like
sudo service lightdm stop && update-alternatives --config glx && ??? && service lightdm start
I'm glad if someone could help me with this.

Related

I'm using Dakboard kiosk on Raspberry Pi and is there way to code a GPIO button as "F5" keyboard input for refresh?

I made a wall calendar by using old monitor and Raspberry Pi and Dakboard like a kiosk. Sometimes I need to refresh the web page and I use my keyboard F5 button to do that, but I was wondering is there a way to use push button in GPIO to work as a F5 button for refresh my web page?
I used this code to make it autorun:
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
#xset s off
#xset -dpms
#xest s noblank
#chromium-browser --noerrdialogs --incognito --kiosk http://dakboard.com
I've been working on quite some options and got a working script now. I'm sure this can be improved, it's tested on a Raspberry Pi Zero W, which handles my keys very slow, and a Raspberry Pi Model 3B+, which handles it fine. I started by creating my own page which handles key-inputs with Javascript.
For your question:
Install xdotools.
Create an exectuable python3-script (and install python3 ofcourse). My script handles three buttons from ports 17, 27 and 22.
#!/bin/bash
import subprocess
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
print("\n\nscript started\n")
while (True):
if GPIO.input(17) > 0:
print("rode knop ingedrukt")
subprocess.call(["/usr/bin/xdotool", "key", "Right"])
time.sleep(0.3)
if GPIO.input(27) > 0:
print("gele knop ingedrukt")
subprocess.call(["/usr/bin/xdotool", "key", "0xff0d"])
time.sleep(0.3)
if GPIO.input(22) > 0:
print("groene knop ingedrukt")
subprocess.call(["/usr/bin/xdotool", "key", "Left"])
time.sleep(0.3)
If you want F5 you can use xdotool key F5, in python that's subprocess.call(["/usr/bin/xdotool", "key", "F5"]). I tried removing the print-lines, but then it stopped working. That's probably a timing thing so you should test to add sleep before interacting.
Change your autostart script of xserver. Add the python-script sudo python3 GpioPython.py, change your display export DISPLAY=:0 and don't forget the ampersand & after the chromium-browser line!
xset s off
xset s noblank
xset -dpms
setxkbmap -option terminate:ctrl_alt_bksp
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' ~/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' ~/.config/chromium/Default/Preferences
export DISPLAY=:0
chromium-browser --disable-infobars --kiosk 'http:.......' &
sudo python3 GpioPython.py
Let me know if the instructions are complete!

Problems with Raspian autostart via /etc/init.d

(Sorry for bad English, I'm German)
I'm trying (without success) to make my own program start automatically after booting (on a raspberry with raspian).
This is my script: (Note: You have to run this program with root privileges) (Note#2: There must be an empty file called "/home/testLog.txt" with write privileges for every user):
rm /etc/init.d/RMStart
echo "
#! /bin/sh
### BEGIN INIT INFO
# Provides: bla1
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: bla2
# Description: bla3
### END INIT INFO
#Switch case for the first parameter
case \"\$1\" in
start)
echo \"Start\" >> /home/testLog.txt
echo runlevel >> /home/testLog.txt
;;
stop)
echo \"Stop\" >> /home/testLog.txt
echo runlevel >> /home/testLog.txt
;;
restart)
echo \"Restart\" >> /home/testLog.txt
echo runlevel >> /home/testLog.txt
;;
*)
echo \"something else\" >> /home/testLog.txt
;;
esac
exit 0
" >> /etc/init.d/RMStart
chmod +x /etc/init.d/RMStart
update-rc.d RMStart remove #Remove older versions of this program ... in theory
update-rc.d RMStart defaults #Install new version of this program ... in theory
I've rebooted the raspberry, but the file /home/testLog.txt is still empty.
However, if I run the command: "/etc/init.d/RMStart" or "/etc/init.d/RMStart start" there is a new entry in /home/testLog.txt.
I would be thankful if anyone knows why the file /home/testLog.txt is still empty and how I could fix that.
Update:
I've tried a new installation script:
#RMS install script
chmod +x botComp.sh
rm /home/pi/RMS
pkill RMS
./botComp.sh
cp RMS /home/pi
chmod +x /home/pi/RMS
rm /etc/init.d/startRMS
sudo echo "#!/bin/sh
### BEGIN INIT INFO
# Provides: fqew
# Required-Start:
# Required-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 6
# Short-Description: sfwef
# Description: gfewf
### END INIT INFO
# Actions
case \"\$1\" in
start)
# START
su pi sh -c \" /home/pi/RMS \"
;;
stop)
# STOP
;;
restart)
# RESTART
;;
esac
exit 0 " >> /etc/init.d/startRMS
chmod +x /etc/init.d/startRMS
update-rc.d startRMS remove
update-rc.d startRMS defaults
The only difference I can see is the name of the script (/etc/init.d/startRMS instead of /etc/init.d/RMStart).
The script works, RMS is running.
It's not really a problem, but the script outputs:
insserv: script RMStart: service F already provided!
insserv: script RMStart: service F already provided!
I've added the line system("runlevel >> /home/pi/runlevelLog.txt"); In the program (RMS) but the content of /home/pi/runlevelLog.txt is: "unknown".
Does RMS start at runlevel 3? How I can I verify this? (I think runlevel 3 is ideal, because RMS needs Network Connection.) Thank you for your help.
is /etc/init.d/RMStart definitely being executed on reboot? use ls -lu to check the last time the file was accessed, wait a minute before rebooting, and repeat the command once you're back up. If the access time hasn't moved on then your script isn't being run which would explain the empty file as your script looks Ok.
You should also double check that update-rc.d has created symbolic links to your script in the appropriate run level directives e.g. does /etc/rc2.d/RMStart exist?
Another sanity check would be running your script using the symbolic links in the above directory rather than from /etc/init.d e.g. does /etc/rc2.d/RMStart
generate output in /home/testLog.txt?
Let me know what you find and we'll take it from there.
EDIT: attempting to replicate..
Well I managed to find my PI; the good news is that neither of us are going mad because it worked perfectly first time as we both believed it should.
I took a copy of your file, and I wrote a quick script (x) to check the exit codes from update-rc.d just to make 100% sure it wasn't complaining about anything.
Hopefully you can follow what I did in the screen shot above - I replicated the steps you followed almost exactly with a bit of extra checking along the way. The script certainly works as designed when called directly.
I then rebooted immediately and checked testLog.txt as soon soon as the system was up. You can see two entries in the file which is expected behaviour as init would have run /etc/rc6.d/K01RMStart as the system went down for reboot, and /etc/rc5.d/S01RMStart as it came up again.
Unfortunately this doesn't help you much.....
The only significant differnce between our tests was that I ran everything as root rather than using sudo. This shouldn't make a difference but the next logical thing for you to try is probably copying my test exactly and seeing if it works for you?
Not that this should be at all significant but I'm running Raspbian 8 (kernel 4.1.13+).
EDIT2: awesome... great stuff. I'd still like to know what the problem was but the main thing in that it's working.
System V based distributions will usually start in either level 3 or level 5, the difference being that level 5 will start the GUI whereas level 3 will start in text mode, their default runlevel is controlled by a line in /etc/inittab.
Debian(Raspian) distros are a bit different - (https://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit). They make no distinction between run levels 2-5 and leave it up the user to configure them to suit their requirements by adding services using the mechanism that's been causing us pain for the last 24 hours. They always start in level 5 unless a "init=" kernel boot parameter has been set, which you can do either at boot time or with a tool like bum or raspi-config.
The command runlevel will tell you the current level on raspian.
You can change the runlevel on the fly with telinit new_runlevel if you need to, but whatever you do, don't set the default runlevel to 0 :-)

Send keystroke to Dockerfile, Ubuntu

I'm creating Dockerfile script and it has a command line that executes a program and requires user input 1 from keyboard as selected option to go to further steps.
Xdotool, man yes or expect cannot help in this situation.
Update source-code:
First off, download and extract RevoMath library, navigate to RevoMath folder then execute the install script.
...
RUN wget -q https://mran.microsoft.com/install/mro/3.2.4/RevoMath-3.2.4.tar.gz
RUN tar -xzf RevoMath-3.2.4.tar.gz
RUN cd RevoMath/
RUN ./RevoMath.sh
...
Install script has some select options as follow:
echo "1. Install MKL"
echo "2. Uninstall MKL"
echo "3. Exit utility"
We need to enter 1 from keyboard to install. How can we do it via Docker command?
Any help would be appreciated!
If I correctly understand you, you would like to add echo 1 | before ./RevoMath.sh in your Dockerfile:
...
RUN cd RevoMath/ && echo 1 | ./RevoMath.sh
...
BTW: In your example this lines will not work as you expected:
RUN cd RevoMath/
RUN ./RevoMath.sh
Because each RUN is an independent execution.
You should use && if you want to execute RevoMath.sh script from specific folder (see my example in the beginning)
I suggest to use redirect from standard input.
For example install.sh required some input(s) from user at execution time.
Suppose you need to enter 1 as a response to first interaction(questions) and
then you have another response as y for further interaction then it's good to use redirect from stdin.
$#>install.sh <EOF
$#>1
$#>y
$#>EOF
This way whenever script is waiting for inputs it will answer as 1 for the first question and y for the second question.

How to remove rebol script security level prompts

I'd like to remove the prompt when using load/library
1) From the Crimson Editor
I tried to load the script using -s secure allow arguments with no effect
2) within the script secure [ library allow ]
gives me another prompt "script requests permission to lower security level"
How can I manage Rebol security prompt free ?
I'd prefer a script level (more general) solution.
Have you tried starting your script this way?
REBOL --secure none script.r
That should work.
See http://www.rebol.com/r3/docs/functions/secure.html
You have to give -s as a start parameter to Rebol.
>> usage
The command line usage is:
REBOL <options> <script> <arguments>
All fields are optional. Supported options are:
--cgi (-c) Check for CGI input
--do expr Evaluate expression
--link url Connect to Link
--help (-?) Display this usage information
--nowindow (-w) Do not open a window
--noinstall (-i) Do not install (Link, View)
--quiet (-q) Don't print banners
--reinstall (+i) Force an install (Link, View)
--script file Explicitly specify script
--secure level Set security: allow ask throw quit
--trace (-t) Enable trace mode
--uninstall (-u) Uninstall REBOL (Link, View)
--version tuple Minimum version of script, when URL (View)
--noviewtop (-v) Do not start viewtop (view desktop)
Special command line options:
+q Force not quiet (Link, View)
-s No security
+s Full security
-- args Provide args without a script
Examples:
REBOL script.r
REBOL -s script.r
REBOL script.r 10:30 test#domain.dom
REBOL --do "verbose: true" script.r
REBOL -cswq
REBOL --cgi --secure throw --script cgi.r "debug: true"
REBOL --version 1.2.3 http://www.rebol.net/test.r ; view only
Although usage shows the same in R3, I guess security is not or not fully functional in Rebol3. Also some of the most recent versions of Rebol2 have a slightly different behavior regarding -i or --noinstall.

How to execute commands requiring root privileges inside a script?

I have to change the frequency of CPU (through slide privileges) . I have written the command to change frequencies inside a script .However , when I run the script, I get the following error message
#!/bin/bash
slide
for i in 0 1 2 3
do
echo 1600000 > /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_setspeed
done
when I run the script , it gives following error
./change_freq.sh: line 4: /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed: Permission denied
Any suggestions ?
I don't know how slide works, but a possibly similar action using sudo that produces the same kind of error would be:
sudo echo foo > /path/to/file
The way to solve that is:
echo foo | sudo tee /path/to/file > /dev/null
I would be curious to know if any of the following provide further information on the origin of slide:
type -a slide
man slide
slide -v
slide --version
slide -h
slide -?

Resources