Where is the config file store for the xfce4-plugin "notification area" alias "systray" - linux

I am on Qubes OS. That means fedora-25 as dom0. I would like to change the configs for "notification area" alias "systray" plugin of xfce. How can I do it. I would like to delete/add one item.
The Gui only gives me the option to hide with ugly arrow on the side or to "clear all known applications". However, regarding the last option I am afraid to lose the notification area as it is and never get it back.
I looked with the "find" command for "xfce4" and "xfce4-plugins" and so on. All the files I could find, e.g. in ~/.config/xfce4, could not help me. I can nowhere find a config file for the plugin.
Thanks in advance :)

Known applications is stored as an array in xfconf, in the xfce4-panel channel and under the property /plugins/plugin-[id]/known-items, where the plugin id is dynamic and depends on the order plugins were added to panel.
You could hack your way messing with ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml but I strongly advise you not to, instead use xfconf-query to read and set values.
I'm going to write down some snippets below so you can use them to craft a script that suits your needs:
# Find the plugin id, can be empty if systray is not present
xfconf-query -c xfce4-panel -p /plugins -l -v | grep systray | grep -Po "plugin-\\d+" | head -n1
# Get array of current known apps
xfconf-query -c xfce4-panel -p /plugins/$PLUGIN_ID/known-items | tail -n +3
# Set array of known apps
xfconf-query -c xfce4-panel -p /plugins/$PLUGIN_ID/known-items -t string -s value1 -t string -s value2 ...

Related

Running a Script to change a wp-config file DB Name

I teach students how to fix wordpress sites and I would like to write a script that looks at what information they have in their wp-config.php and add a single letter or number to the database name.
For example the line is such
define('DB_NAME', 'cpanelUser_NameofDB');
I would like to add a number or a line to the end of NameofDB
I can use this to isolate the cpanelUser_NameofDB
grep -i 'DB_NAME' wp-config.php | cut -d"'" -f4
but I'm not sure how to add information, nor if this is the correct script I should run to get there. I would also like it to not matter what the name of the database is since it will be ran on multiple sites. I'm sure I could use regex but I'm not too versed in that and would not know where to start. Help please!
You can use WP CLI on the server:
Go to the website root:
cd /var/www/mysite.com/htdocs
...and list all the wp-config values:
wp config list
...or set the value you need to change:
sudo wp config set DB_NAME put_my_custom_db_name_here --allow-root
See more WP CONFIG features here:
https://developer.wordpress.org/cli/commands/config/
You can use sed for this purpose to fix this line:
#!/bin/bash
id=34
sed -i "s/^.*DB_NAME.*$/define('DB_NAME', 'cpanelUser_NameofDB${id}');/" wp-config.php
flag -i means that we do change in file directly.
Alternatively you can make template file and generate new file while sed works on stdin and stdout
#!/bin/bash
id=34
cat wp-config.php-template| sed "s/^.*DB_NAME.*$/define('DB_NAME', 'cpanelUser_NameofDB${id}');/" > wp-config.php.$id

How does one create a wrapper around a program?

I want to learn to create a wrapper around a program in linux. How does one do this? A tutorial reference web-page/link or example will do. To clarify what I want to learn, I will explain with an example.
I use vim for editing text files. And use rcs as my simple revision control system. rcs allows you to check-in and checkout-files. I would like to create a warpper program named vir which when I type in the shell as:
$ vir temp.txt
will load the file temp.txt into rcs with ci -u temp.txt and then allows me to edit the file using vim.
When I get out and go back in, It will need to check out the file first, using ci -u temp.txt and allow me to edit the file as one normally does with vim, and then when I save and exit, it should check-in the file using co -u temp.txt and as part of that I should be able to add a version control comment.
Basically, all I want to be doing on the command line is:
$ vir temp.txt
as one would with vim. And the wrapper should take care of the version control for me.
Take a look at rcsvers.vim, a vim plugin for automatically saving versions in RCS; you could modify that. There are also other RCS plugins for vim at vim.org
I have a wrapper to enhance the ping command (using zsh) it could, maybe help you:
# ping command wrapper - Last Change: out 27 2019 18:47
# source: https://www.cyberciti.biz/tips/unix-linux-bash-shell-script-wrapper-examples.html
ping(){
# Name: ping() wrapper
# Arg: (url|domain|ip)
# Purpose: Send ping request to domain by removing urls, protocol, username:pass using system /usr/bin/ping
local array=( $# ) # get all args in an array
local host=${array[-1]} # get the last arg
local args=${array[1,-2]} # get all args before last arg in $#
#local _ping="/usr/bin/ping"
local _ping="/bin/ping"
local c=$(_getdomainnameonly "$host")
[ "$host" != "$c" ] && echo "Sending ICMP ECHO_REQUEST to \"$c\"..."
# pass args and host
# $_ping $args $c
# default args for ping
$_ping -n -c 2 -i 1 -W1 $c
}
_getdomainnameonly(){
# Name: _getdomainnameonly
# Arg: Url/domain/ip
# Returns: Only domain name
# Purpose: Get domain name and remove protocol part, username:password and other parts from url
# get url
local h="$1"
# upper to lowercase
local f="${h:l}"
# remove protocol part of hostname
f="${f#http://}"
f="${f#https://}"
f="${f#ftp://}"
f="${f#scp://}"
f="${f#scp://}"
f="${f#sftp://}"
# Remove username and/or username:password part of hostname
f="${f#*:*#}"
f="${f#*#}"
# remove all /foo/xyz.html*
f=${f%%/*}
# show domain name only
echo "$f"
}
What it hides the local ping using a function called "ping", so if your script has precedence on your path it will find at first the function ping. Then inside the script I define an internal variable called ping that points out to the real ping command:
local _ping="/bin/ping"
You can also notice that the args are stored in one array.

Is there a simple alternative to "who am i" and "logname"?

I noticed that RHEL 8 and Fedora 30 don't update the utmp file properly.
As a result, commands such as 'who am i', 'last', 'w' etc print incorrect results (who am i actually doesn't print anything)
After a bit of googling, I found 'logname' which worked in this case but I read that gnome is dropping support for utmp altogether so it's a matter of time until this stops working too.
I wrote the following script which finds the login name of the user (even if he is using sudo the moment he runs the command) but it's way too complicated so I'm looking for alternatives.
LOGIN_UID=$(cat /proc/self/loginuid)
LOGIN_NAME=$(awk -v val=LOGIN_UID -F ":" '$3==val{print $1}' /etc/passwd)
Is there a simple alternative which is not based on proper updating of /var/run/utmp ?
Edit 1: Solutions that don't work $HOME, $USER and id return incorrect values when used in a script that has been run with the sudo command. who am i and logname depend on utmp which isn't always updated by the terminal.
Working solution: After a bit of searching, a simpler way than the aforementioned was found in https://unix.stackexchange.com/users/5685/frederik-deweerdt 's comment to his own answer
Link to answer which contains the commment: https://unix.stackexchange.com/a/74312
Answer 1
stat -c "%U" $(tty)
Second answer found at https://stackoverflow.com/a/51765389/10630167
Answer 2
`pstree -lu -s $$ | grep --max-count=1 -o '([^)]*)' | head -n 1 | sed 's/[()]//g'`
Your question is not well-defined because if X and Y are not working, what are the chances that Z will work? This depends entirely on the precise failure mode you are attempting to handle, and there is nothing in your question to reveal the specific circumstances in which you need this.
With that out of the way, perhaps look at the POSIX id command, which has explicit options to print the real (login) or effective (after any setuid command) user id with -r or -u, respectively. Of course, the precise means by which it obtains this information are not specified, and will remain implementation-dependent, and thus might or might not work on your platform under your specific circumstances.
As an aside, here is a refactoring of your code to avoid polluting the variable name space with two separate variables.
LOGIN_NAME=$(awk 'NR==FNR { val=$0; next }
$3==val{print $1}' /proc/self/loginuid FS=":" /etc/passwd)

Could not locate a Bowtie index corresponding to basename

I am new to Bowtie. I am trying to use Bowtie for end to end local alignment. I've got this error message:
Could not locate a Bowtie index corresponding to basename "/bowtie2-index/hg19"
In my installation and in the bowtie2-index/hg19 folder there are six bt2 files. I am using the following command:
/opt/bowtie2/bowtie2-align-s --wrapper basic-0 -p 64 -x /mnt/miczfs/tide/bowtie2-index/hg19 -S /mnt/miczfs/tide/Data/chr2chr3/chr2chr3.sam -1 /mnt/miczfs/tide/Data/chr2chr3/chr2chr3.f1.fastq -2 /mnt/miczfs/tide/Data/chr2chr3/chr2chr3.f2.fastq
This is a perennial question, I guess the documentation isn't explicit enough here. By using -x /mnt/miczfs/tide/bowtie2-index/hg19, you're telling bowtie2 that you have files like /mnt/miczfs/tide/bowtie2-index/hg19.1.bt2 that it should use. You don't specify a folder, you specify a "basename". You probably meant -x /mnt/miczfs/tide/bowtie2-index/hg19/hg19 or something like that.

Need help coloring/replacing arbitrary strings using Bash and sed

I'm using a bash script based on the technique used here: Get color output in bash to color the output of my builds and other scripts to make things easier to read. One of the steps in my build executes a "git pull" and the git server spits out a "welcome" string like this amidst a bunch of other output:
** WARNING: THIS IS A PRIVATE NETWORK. UNAUTHORIZED ACCESS IS PROHIBITED. **
Use of this system constitutes your consent to interception, monitoring,
and recording for official purposes of information related to such use,
including criminal investigations.
I'd like to color this specific message yellow or possibly delete it from the output while leaving the rest of the output alone. I've tried to replace a simple string like this:
WelcomeMessage="WARNING"
pathpat=".*"
ccred=$(echo -e "\033[0;31m")
ccyellow=$(echo -e "\033[0;33m")
ccend=$(echo -e "\033[0m")
git pull 2>&1 | sed -r -e "/$WelcomeMessage/ s%$pathpat%$ccyellow&$ccend%g"
The first line of the welcome string is colored yellow as expected but the rest of the lines are not. I'd really like to color the exact welcome string and only that string but for many reasons, this doesn't work:
WelcomeMessage="** WARNING: THIS IS A PRIVATE NETWORK. UNAUTHORIZED ACCESS IS PROHIBITED. **
Use of this system constitutes your consent to interception, monitoring,
and recording for official purposes of information related to such use,
including criminal investigations."
pathpat=".*"
ccred=$(echo -e "\033[0;31m")
ccyellow=$(echo -e "\033[0;33m")
ccend=$(echo -e "\033[0m")
git pull 2>&1 | sed -r -e "/$WelcomeMessage/ s%$pathpat%$ccyellow&$ccend%g"
This fails with the error: sed: -e expression #1, char 78: unterminated address regex
I've looked at a couple other questions and I was able to get the asterisks escaped (by preceding them with backslashes) but I'm baffled by the periods and multiple lines. I'd like to continue using sed to solve this problem since it integrates nicely with the colorizing solution.
Any help is appreciated. Thanks!
The following will colorize in yellow every line from the first instance of ** to the first instance of a period . that's not on the same line. This will match the entire warning message as written.
NORMAL=$(tput sgr0)
YELLOW=$(tput setaf 3)
git pull 2>&1 | sed "/\*\*/,/\./s/.*/$YELLOW&$NORMAL/"
Note: If you want to delete the message you can use this:
git pull 2>&1 | sed '/\*\*/,/\./d'

Resources