How can I specify a display? - x11

When I run some programs over SSH, such as firefox &, I get an error
Error: no display specified
I would like to open many displays, still showing the stdout of each program.
Initial Question: How can I specify the display to get a many-displayed program?
Pablo Santa Cruz gives me the following code as a solution.
I do not understand it.
$ export DISPLAY=yourmachine.yourdomain.com:0.0
$ firefox &
What are yourmachine and yourdomain.com in the command?

The way that X works is the same as the way any network program works. You have a server of some description (in this case, the X display server) which runs on a specific machine, and you have X clients (like firefox) that try to connect to that server to get their information displayed.
Often (on "home" machines), the client and server run on the same box and there's only one server, but X is powerful enough that this doesn't need to happen. It was built with the server/client separation built in from the start.
This allows you to do such wondrous things such as log on to your box (in text mode) halfway around the planet, tell it that the display server is the box you're currently on and, voila, the windows suddenly start appearing locally.
In order for a client to interact with a user, it needs to know how to find the server. There are a number of ways to do this. Many clients allow the -display or --displayoption to specify it:
xeyes -display paxbox1.paxco.com:0.0
Many will use the DISPLAY environment variable if a display isn't specifically given. You can set this variable like any other:
DISPLAY=paxbox1.paxco.com:0.0; export DISPLAY # in .profile
export DISPLAY=paxbox1.paxco.com:0.0 # in your shell
DISPLAY=paxbox1.paxco.com:0.0 firefox & # for that command (shell permitting)
The first part of the DISPLAY variable is just the address of the display server machine. It follows the same rule as any other IP address; it can be a resolvable DNS name (including localhost) or a specific IP address (such as 192.168.10.55).
The second part is X-specific. It gives the X "display" (X server) number and screen number to use. The first (display number) generally refers to a group of devices containing one or more screens but with a single keyboard and mouse (i.e., one input stream). The screen number generally gives the specific screen within that group.
An example would be:
+----------------------------------------+
|paxbox1.paxco.com| |
+-----------------+ |
| |
| +----------+----+ +----------+----+ |
| |Display :0| | |Display :1| | |
| +----------+ | +----------+ | |
| | | | | |
| | +-----------+ | | | |
| | |Screen :0.0| | | | |
| | +-----------+ | | | |
| | +-----------+ | | | |
| | |Screen :0.1| | | | |
| | +-----------+ | | | |
| | +-----------+ | | +-----------+ | |
| | |Screen :0.2| | | |Screen :1.0| | |
| | +-----------+ | | +-----------+ | |
| | +-----------+ | | +-----------+ | |
| | |Screen :0.3| | | |Screen :1.1| | |
| | +-----------+ | | +-----------+ | |
| | +-----------+ | | +-----------+ | |
| | | Keyboard | | | | Keyboard | | |
| | +-----------+ | | +-----------+ | |
| | +-----------+ | | +-----------+ | |
| | | Mouse | | | | Mouse | | |
| | +-----------+ | | +-----------+ | |
| +---------------+ +---------------+ |
| |
+----------------------------------------+
Here you have a single machine (paxbox1.paxco.com) with two display servers. The first has four screens and the second has two. The possibilities are then:
DISPLAY=paxbox1.paxco.com:0.0
DISPLAY=paxbox1.paxco.com:0.1
DISPLAY=paxbox1.paxco.com:0.2
DISPLAY=paxbox1.paxco.com:0.3
DISPLAY=paxbox1.paxco.com:1.0
DISPLAY=paxbox1.paxco.com:1.1
depending on where you want your actual windows to appear and which input devices you want to use.

$ export DISPLAY=yourmachine.yourdomain.com:0.0
$ firefox &

When you are connecting to another machine over SSH, you can enable X-Forwarding in SSH, so that X windows are forwarded encrypted through the SSH tunnel back to your machine. You can enable X forwarding by appending -X to the ssh command line or setting ForwardX11 yes in your SSH config file.
To check if the X-Forwarding was set up successfully (the server might not allow it), just try if echo $DISPLAY outputs something like localhost:10.0.

login to your server via
ssh -X root#yourIP
edit /etc/ssh/sshd_config file, and add this line to it.
X11UseLocalhost no
Restart sshd. for CentOS (check your distribution)
/sbin/service sshd restart
check your DISPLAY
echo $DISPLAY
you should see this
yourIP:10.0
Enjoy
firefox
for more info

Try
export DISPLAY=localhost:0.0

Please do NOT try to set $DISPLAY manually when connecting over SSH.
If you connect via SSH -X and $DISPLAY stays empty, this usually means that no encrypted channel could be established.
Most likely you are missing the package xauth or xorg-x11-xauth. Try to install it on the remote machine using:
sudo apt-get install xauth
or
sudo apt-get install xorg-x11-xauth
After that end and restart your SSH connection. Don't forget to use SSH -X so that X Window output is forwarded to your local machine.
Now try echo $DISPLAYagain to see if $DISPLAY has been set automatically by the SSH demon. It should show you a line with an IP address and a port.

I ran into a similar issue, so maybe this answer will help someone.
The reason for the Error: no display specified error is that Firefox is being launched, but there is no X server (GUI) running on the remote host. You can use X11 forwarding to run Firefox on the remote host, but display it on your local host. On Mac OS X, you will need to download XQuartz in order to use X11 forwarding. Without it, you won't have a $DISPLAY variable set, so if you try and echo $DISPLAY, it will be blank.

Try installing the xorg-x11-xauth package.

I faced similar problem today. So, here's a simple solution:
While doing SSH to the machine, just add Ctrl - Y.
ssh user#ip_address -Y
After login, type firefox &.
And you are good to go.

Even i faced the same in CentOS 6.8.
yum reinstall xorg*
End your current session and open another session in tool like mobiXterm. Make sure session has X11 forwarding enabled in the tool.

I through vnc to understand the X11 more.
To specify the display to get a many-displayed program,
export DISPLAY=IP:DisplayNum.ScreenNum
For example,
vncserver :2
vncserver -list
echo '$DISPLAY'=$DISPLAY
export DISPLAY=:2 # export DISPLAY=IP:DisplayNum or export DISPLAY=:DisplayNum for localhost; So that can vnc connect and see the vnc desktop :2 if $DISPLAY is not :2.
echo '$DISPLAY'=$DISPLAY

I'm using xming server before typing firefox use the following command
export DISPLAY=0:0

Related

Getting latest version of Android from sdkmanager automatically

I was trying to make a bash script to automatically install flutter and android sdk without Android Studio.
I managed to get the latest version of build-tools using the following sequence
btversion=`sdkmanager --list | tac | sed "/build-tools/q" | tac | sed -n 1p`
btversion=${btversion% *}
btversion=${btversion:2}
I am trying to do something similar to install platforms;android-%version%, except doing something like this lead me to a dead end:
sdkmanager --list | tac | sed "/platforms;android-[0-9]+/g"
The [0-9]+ filter is necessary as packages such as platforms;android-TiramisuPrivacySandbox show up in the list.
I would like to know what would be a better filter. For reference, this is how the output of sdkmanager --list sort of looks like
platforms;android-27 | 3 | Android SDK Platform 27
platforms;android-28 | 6 | Android SDK Platform 28
platforms;android-29 | 5 | Android SDK Platform 29
platforms;android-30 | 3 | Android SDK Platform 30
platforms;android-31 | 1 | Android SDK Platform 31
platforms;android-32 | 1 | Android SDK Platform 32
platforms;android-33 | 2 | Android SDK Platform 33
It would be like
sdkmanager --list | egrep -i 'platforms;android-[0-9]{2}' | tac | head -n 1 | sed 's/\(platforms;android-[0-9]\+\).*/\1/'
or
sdkmanager --list | egrep -i 'platforms;android-[0-9]{2}' | sed 's/\(platforms;android-[0-9]\+\).*/\1/' | tail -1

Firebase app distribution via Fastlane "the server responded with status 403"

I setup Firebase app distribution feature in Fastlane Fastfile to distribute beta version of my iOS app. It was working fine but It suddenly started showing errors.
This is how my lane looks like.
lane :distribute_beta do |options|
sync_code_signing_adhoc()
update_build_number_of_all_frameworks()
build_ios_app_adhoc()
firebase_app_distribution(
app: "<app ID here>",
testers: "<tester emials here>",
release_notes: options[:release_note],
firebase_cli_path: "/usr/local/bin/firebase"
)
end
When I run this lane it shows error
the server responded with status 403
on Step: firebase_app_distribution
Log also says authentication to google succeeded.
Authenticating with GOOGLE_APPLICATION_CREDENTIALS environment variable: /<path to cred>/<cred_file_name>.json
🔐 Authenticated successfully.
Following is entire error around "Step: firebase_app_distribution "
[17:11:04]: ---------------------------------------
[17:11:04]: --- Step: firebase_app_distribution ---
[17:11:04]: ---------------------------------------
[17:11:04]: Authenticating with GOOGLE_APPLICATION_CREDENTIALS environment variable: /<path to cred>/<cred_file_name>.json
[17:11:04]: 🔐 Authenticated successfully.
+------------------------------------+---------------------------------------------+
| Lane Context |
+------------------------------------+---------------------------------------------+
| DEFAULT_PLATFORM | ios |
| PLATFORM_NAME | ios |
| LANE_NAME | ios distribute_beta |
| SIGH_PROFILE_TYPE | ad-hoc |
| MATCH_PROVISIONING_PROFILE_MAPPING | {"<my bndle ID>"=>"match AdHoc |
| | <my bundle ID>"} |
| BUILD_NUMBER | 107 |
| IPA_OUTPUT_PATH | /Users/my_user_name/Repository/App/App|
| | y/App.ipa |
| XCODEBUILD_ARCHIVE | /Users/my_user_name/Library/Developer/Xcode/A|
| | rchives/2021-01-08/App 2021-01-08 |
| | 17.09.08.xcarchive |
| DSYM_OUTPUT_PATH | /Users/my_user_name/Repository/App/App |
| | y/App.app.dSYM.zip |
+------------------------------------+---------------------------------------------+
[17:11:06]: the server responded with status 403
+------+-----------------------------+-------------+
| fastlane summary |
+------+-----------------------------+-------------+
| Step | Action | Time (in s) |
+------+-----------------------------+-------------+
| 1 | default_platform | 0 |
| 2 | Switch to ios | 0 |
| | sync_code_signing_adhoc | |
| | lane | |
| 3 | sync_code_signing | 18 |
| 4 | Switch to ios | 0 |
| | update_build_number_of_all | |
| | _frameworks lane | |
| 5 | increment_build_number | 1 |
| 6 | commit_version_bump | 0 |
| 7 | Switch to ios | 0 |
| | build_ios_app_adhoc lane | |
| 8 | build_ios_app | 126 |
| 💥 | firebase_app_distribution | 1 |
+------+-----------------------------+-------------+
[17:11:06]: fastlane finished with errors
How can I fix this?
Usually, when you get that specific message it means that the Firebase Refresh Token is no longer valid.
So, when you submit the app, at some point, you have to specify the Firebase Refresh Token:
...
firebase_app_distrubution(
...
firebase_cli_token: "<YourFirebaseRefreshToken>"
)
...
You can get this token from here. If your script started to fail out of nowhere, that probably means that whoever generated this (or any other authentication token) got removed from the Firebase project.
If you're getting a 403 that definitely means that either someone got removed from your Firebase project or that someone removed/regenerated a token on the Firebase console.
Simply run the following command on console:
curl -sL https://firebase.tools | bash
then, authenticate on the browser
Then run
firebase login:ci
After success you will get printed your new cli token, like this:
Waiting for authentication...
✔ Success! Use this token to login on a CI server:
1//here_will_be_your_new_token
Example: firebase deploy --token "$FIREBASE_TOKEN"
As for me, it was because the service account that I am using does not have Firebase App Distribution Admin role. https://firebase.google.com/docs/app-distribution/authenticate-service-account?platform=ios
I simply had to edit my existing service, to do that, go to firebase console > project settings > Service accounts > then click on the service accounts as shown in the image below
It will take you to GCP IAM and Admin where you can find and edit the role of your service account.
For me, I had to add the particular account I was using for App Distribution login to the Project settings for my app.
Check that your firebase account have distribution permission for project.
Project settings -> Users and permissions -> Member should be with "Editor" role

How to use local jdk in SDKMAN! script

My script changes to a jdk installed with sdkman but not to a local one. How can I change into my local oracle 8 v261 jdk in a script with sdkman?
The script
#!/bin/bash
. /usr/local/sdkman/bin/sdkman-init.sh
sdk ls java
for i in {"8_261-oracle", "9.0.4-open"}
do
sdk u java $i
done
gives as output
[...]
| | 9.0.4 | open | installed | 9.0.4-open
| >>> | 8.0.265 | open | installed | 8.0.265-open
| | 8.0.232 | open | local only | 8.0.232-open
[...]
Unclassified | | 8_261 | none | local only | 8_261-oracle
================================================================================
Use the Identifier for installation:
$ sdk install java 11.0.3.hs-adpt
================================================================================
Stop! java 8_261-oracle, is not installed.
Using java version 9.0.4-open in this shell.
I was inspired by How to use SDKMAN! to install packages from within scripts.
You could parse the output of sdkman to retrieve the list of installed sdks as follows:
#!/bin/bash
sdks=`sdk list java | grep installed | awk -F"|" '{print $6}'`
for sdk in ${sdks[#]}; do
sdk use java $sdk
### YOUR CODE HERE
done
I have omitted the . /usr/local/sdkman/bin/sdkman-init.sh part because I suggest to set it up in bashrc/zshrc as suggested in sdkman doc.
An example from my ~/.zshrc:
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="$YOUR_PATH/.sdkman"
[[ -s "$YOUR_PATH/.sdkman/bin/sdkman-init.sh" ]] && source "$YOUR_PATH/.sdkman/bin/sdkman-init.sh"

Bash autorun bash script on USB connect fails to get USB info

I wrote a script to get all the USB info. So far when I run the script with the USB already connected everything works fine.
USB_NAME=$(blkid | grep -oP '(?<=LABEL=").+?(?=")' | tail -1)
USB_DEVICE=$(blkid -o device | tail -1)
USB_TYPE=$(blkid | grep -oP '(?<=TYPE=").+?(?=")' | tail -1)
However, when I try to let the autorun script kick by inserting the USB with the 10.usb-rules:
KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="usb", RUN+="/home/user/test.sh"
It runs the script and everything and i see the output from my script, but the output of my USB_NAME, USB_DEVICE and USB_TYPE all come out blank.
Is it trying to grab the info too quick or something?
Issue fixed by adding sudo in front of each statement.
USB_NAME=$(sudo blkid | grep -oP '(?<=LABEL=").+?(?=")' | tail -1) 2>&1
USB_DEVICE=$(sudo blkid -o device | tail -1) 2>&1
USB_DEVICE_NAME=$(sudo blkid -o device | cut -d'/' -f3 | tail -1) 2>&1
USB_TYPE=$(sudo blkid | grep -oP '(?<=TYPE=").+?(?=")' | tail -1) 2>&1

tree command on osx bash

I'm following a screen cast on a ruby gem called pry. At 8:10, the .tree command is used, which I believe is a Unix command.
It does not appear to be working on my system:
[24] pry(main)> .tree
\Error: there was a problem executing system command: tree
and I have traced the issue to here, in which pry references a shell command:
Pry::CommandSet.new do
command(/\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".<shell command>") do |cmd|
if cmd =~ /^cd\s+(.+)/i
dest = $1
begin
Dir.chdir File.expand_path(dest)
rescue Errno::ENOENT
output.puts "No such directory: #{dest}"
end
else
if !system(cmd)
output.puts "Error: there was a problem executing system command: #{cmd}"
end
end
end
from the context of bash I tried using the command tree with no luck:
projects/sms(apps2)$ tree
-bash: tree: command not found
~/projects/sms(apps2)$ .tree
-bash: .tree: command not found
This looks incredibly useful, how can I get this command?
Using homebrew:
brew install tree
Using macports:
sudo port install tree
Using the source:
Follow these directions. (Caveat; you should use the flags/etc. that make sense.)
<rant>All systems should come with tree; I use it a lot. And we can post directory structures as text, not pics.</rant>
For a simple approach you can also add the following alias to your ~/.bashrc or ~/.zshrc file:
alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
This results in the following:
$ tree
.
|____.git
| |____config
| |____objects
| | |____pack
| | |____info
| |____HEAD
| |____info
| | |____exclude
| |____description
| |____hooks
| | |____commit-msg.sample
| | |____pre-rebase.sample
| | |____pre-commit.sample
| | |____applypatch-msg.sample
| | |____pre-receive.sample
| | |____prepare-commit-msg.sample
| | |____post-update.sample
| | |____pre-applypatch.sample
| | |____pre-push.sample
| | |____update.sample
| |____refs
| | |____heads
| | |____tags
Found this solution here:
http://osxdaily.com/2016/09/09/view-folder-tree-terminal-mac-os-tree-equivalent/
Use brew install tree command on the terminal if you're using Homebrew on your Mac.
Not exactly the same, but gives you a list of all directories and files in those directories using:
find .
You can also specify list directories only
find -type d
or if you want to see files only
find -type f
you can also specify depth
find -type d -maxdepth 2
Add this to your shell startup file(~/.bashrc or ~/.zshrc):
tree() {
find $1 -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
}
After restarting your shell, you can use the tree command like so:
% tree Downloads
Downloads
|____ideaIU-2020.1.3-no-jbr.tar.gz
|____Firicico.ttf

Resources