Running PyQt Webkit script with Xvfb from a shell script - shell

I am trying to run a Python script that involves PyQt Webkit on a headless server using xvfb. The following command works when I run it from the command line, but not from a bash script:
# !/bin/bash
xvfb-run -a -e /path/to/error.log python script.py
The error log shows the following in both instances:
[dix] Could not init font path element /var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType, removing from list!
which I read could be ignored. The script runs fine when the bash script is just:
# !/bin/bash
python script.py
aka without Xvfb. Is there something about the bash environment that would prevent the script from running with xvfb? I'm stumped!

I wouldn't ignore that error. It leads to incorrectly rendered fonts if you're attempting to perform screen captures. To get rid of the error (and hopefully your larger issue), you'll need to install the TrueType fonts as follows (Ubuntu syntax here):
sudo apt-get -y install x-ttcidfont-conf cabextract ttf-mscorefonts-installer
(you'll have to enable the multiverse repo to get ttf-mscorefonts-installer)
Accept the EULA terms for ttf-mscorefonts-installer.
Then:
sudo dpkg-reconfigure x-ttcidfont-conf
(choose the freetype fonts).
You should then have cleared the error which will hopefully both fix your issue and cause fonts to render correctly.

Related

Creating executable file with pip install command on MacOS

I'm both new here and with MacOS and coding.
I know in windows I can create bash file to have an executable command in cmd. I've researched and discovered I can use similar file with MacOS (shell files) but I'm struggling to understand how to make one. I've tried different route:
As first thing I've tried creating a file in txt editor with this code:
#!/bin/bash
pip3 install pgzero
echo Installing Pygame Zero
Using later 'chmod 700 Filename' in terminal. It did not worked
I then tried with Apple Scrip, with a code like:
tell application "Terminal"
activate
do script "pip3 install pgzero"
do script "echo Installing Pygame Zero"
end tell
and it kinda worked, but it wasn't an executable
Then I tried with another approach found on google:
echo '#!/bin/bash
pip3 install pgzero
echo Installing PyGame Zero'> ~/Desktop/PygameInstaller.command
chmod 740> ~/Desktop/PygameInstaller.command
and it still didn't worked D:
Can someone land a bit of help? I'm starting feeling lost q,q
Thank you in advance!
In terms of what you want in your shell script, your first attempt is probably close to what you want but the echo should precede the pip3 command. I guess if you change the verb from Installing to Installed, then you could leave it where it is.
$ cat <<EOF > ~/Desktop/PygameInstaller.command
#!/bin/bash
echo Installing Pygame Zero
pip3 install pgzero
EOF
$ chmod 700 ~/Desktop/PygameInstaller.command
The permissions you assign to the script and the script's location depend on who you want to grant execution. If it's only you, then your desktop and 700 should be fine.
Now, if you want to execute the script from a command line like what you would see if you opened an instance of Terminal.app, then you have options.
If you want to fully specify the command, then you would type this (showing prompt which you would not type):
$ ~/Desktop/PygameInstaller.command
If you want to specify only the name of the script, then you would type this after adding ~/Desktop to your PATH:
$ PATH="$HOME/Desktop:$PATH"
$ PygameInstaller.command
If you prefer to type only PygameInstaller, then don't put the code in a file named PygameInstaller.command. Instead, you put the code in a file called simply PygameInstaller.
If you need the script to be executable by everyone, then put it in /usr/local/bin because most people will either have that in their PATH or have no political problem doing so. But you'll have to use the sudo command to elevate your privileges to accomplish that task.
If, however, you want to have that script be treated like any other app that you can launch with a double-click, then you have significantly more work to do.

How do I get colorized output on my windows git-bash terminal?

How do I get colorized highlighting on the output?
e.g
npm start
npm test
etc.
System:
Windows 10
Git version 2.16.1.windows.4
Node 5.6.0
Uninstall Git Bash for Windows 10 and run the installer again:
Click next until you'll prompt to choose to Configure the terminal emulator to use with Git Bash, here you select Use Windows default console window (instead of the default option which use MinTTY as terminal emulator)
Click next and finish the installation
Test if it works correctly:
Open Git Bash (cmd will open up), try to use ls you'll see all folder colored in blue
Try some ANSI escape code by running echo -e "\033[44m\033[37m Test \033[0m" you'll se the text Test with a blue background as seen in the screenshot below
Windows 10 Console support 24-bit color and ANSI escape sequences
The terminal was a MinTTY, which does not support colors it seems. Fixed it by re-installing and ticking of Windows Terminal.
For me, it was choosing Windows default console window instead of MinTTY that made color output not working.
My solution:
Uninstall git bash; during installing, choose MinTTY (the default option).
After installation, head over to C:\Program Files\Git\etc, open your git bash
vim ~/.bashrc (for some reason using an editor doesn't work; I guess it's a privilege issue)
Under # Add colors to 'ls' change it to
alias ls='ls --color=auto'
Then restart and it should work.
My version: git version 2.24.1.windows.2
Use winpty
Windows Git Bash has some documented quirks: Winpty and Git Bash
$ winpty npm start
winpty: error: cannot start 'npm': Not found in PATH
Again another windows / git bash quirk, it doesn't attempt to resolve executables ending in .cmd so it needs a nudge.
$ winpty npm.cmd start
The same applies for yarn with:
winpty yarn.cmd start
While we are here and you are having trouble getting gyp to locate your Python2 install location to compile native extensions then try this:
env PYTHON=/c/Python27/ winpty yarn.cmd install
Git Bash overrides your PYTHON environment variable for only the duration of this command. You get winpty to run the pseudo-tty session to allow animation rendering and coloring.
Assuming your python 2 install location is C:\Python27

How can I determine where an error message printed during shell startup comes from?

After uninstall Docker on Ubuntu, each time I start a bash shell window, it emits the following hint:
The program 'docker' is currently not installed. You can install it by typing:
sudo apt install docker.io
I have searched in .bashrc, .profile, .bash_profile, but didn't found any lines related to docker.
So, how can I get rid of those tips?
Run PS4=':${BASH_SOURCE}:$LINENO+' bash -x -l -i to log every command in your startup scripts, including which config file or script they came from. Search through that, and you'll find the individual command that's creating this error.
(Note that very new versions of bash ignore inherited values of PS4 when running as root for security reasons. But you're not using root as your primary account... right?)

How to enable shell command completion for gcloud?

I'm trying to install the Google Cloud SDK on a Mac (following https://cloud.google.com/sdk/docs/quickstart-mac-os-x), using the install.sh script:
~/Downloads$ ./google-cloud-sdk/install.sh
In the logged output, I see the following instructions:
==> Source [/Users/kurtpeek/Downloads/google-cloud-sdk/completion.bash.inc] in your profile to enable shell command completion for gcloud.
==> Source [/Users/kurtpeek/Downloads/google-cloud-sdk/path.bash.inc] in your profile to add the Google Cloud SDK command line tools to your $PATH.
Indeed, I find that using the gsutil command still leads to a -bash: gsutil: command not found error, so I still probably have to perform this step.
It is not entirely clear to me, however, what is meant by these instructions. I'm on a Mac and my bash profile is ~/.bash_profile. What lines would I have to add in order to make the command line completion work?
Update
The first time I installed I did not use sudo. Reinstalling with sudo, I get an additional prompt whether to modify my bash profile, which upon accepting leads to the following lines added to my .bash_profile:
# The next line updates PATH for the Google Cloud SDK.
if [ -f '/Users/kurtpeek/Downloads/google-cloud-sdk/path.bash.inc' ]; then source '/Users/kurtpeek/Downloads/google-cloud-sdk/path.bash.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/Users/kurtpeek/Downloads/google-cloud-sdk/completion.bash.inc' ]; then source '/Users/kurtpeek/Downloads/google-cloud-sdk/completion.bash.inc'; fi
However, I still get gsutil: command not found errors.
The trick was to run the install.sh using sudo as described in the update. After that I needed to restart the terminal (as described in the instructions) for the changes to take effect.
For Mac Run below command to run the install.sh :
sudo chmod +x install.sh

Display command in bash not working anymore

I'm using a bash script with display command, after upgrading to Ubuntu 10.10 this bash script ends with error message:
display: command not found
Where could be the fault?
You haven't installed the anything that provides the 'display' command.
$ dpkg -S /usr/bin/display
imagemagick: /usr/bin/display
Installing "imagemagick" should allow you to use 'display' again.

Resources