Run script as root because access to files in /etc
Build a list of files to edit
When list is complete call a script as normal user to compare/edit pair of files in the list ( normal_user files )
I start a script from .desktop file as root user
[Desktop Entry]
Comment[en_US]=cmp diff with first install
Comment=cmp diff with first install
Exec=/backup_sys/000_COMMON/Bin/file_file_compare_diff_with_first_install d
GenericName[en_US]=cmp diff with first install
GenericName=cmp diff with first install
Icon=yast-geo-cluster
MimeType=
Name[en_US]=cmp diff with first install
Name=cmp diff with first install
Path=
StartupNotify=true
Terminal=true
TerminalOptions=\s--noclose
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=true
X-KDE-Username=root
At then end of the script, when the job is finished I call another script for a standard user
#
# we are root
#
CUR_USER="some_user"
chmod -v 777 /tmp/files_find_new_config_after_install*
chown -v $CUR_USER:users /tmp/files_find_new_config_after_install*
chown -v $CUR_USER:users /backup_sys/000_COMMON/Bin/file_file_compare_diff_with_first_install_edit_diff
export $(dbus-launch)
su -c "/backup_sys/000_COMMON/Bin/file_file_compare_diff_with_first_install_edit_diff \"$OUTPUT_FILE_EDIT_LIST_DIFFER\" DIFFER " -m $CUR_USER
su -c "/backup_sys/000_COMMON/Bin/file_file_compare_diff_with_first_install_edit_diff \"$OUTPUT_FILE_EDIT_LIST_EQUAL\" EQUAL " -m $CUR_USER
exit
here the sub script called by root ( su -c "… )
if $# -gt 0 ]] ; then
INPUT_FILE="$1"
SESSION_NAME="$2"
echo "INPUT_FILE : $INPUT_FILE"
echo "SESSION_NAME : $SESSION_NAME"
echo "DISPLAY : $DISPLAY"
set -x
OIFS="$IFS"
IFS=$'
'
while IFS='' read -r line || -n "$line" ]]; do
SOURCE_FILE="$line"
echo "FILE : $SOURCE_FILE"
DISPLAY=:0 kate --start $SESSION_NAME $SOURCE_FILE &
done < "$INPUT_FILE"
IFS="$OIFS"
set +x
else
exit 255
fi
here the following errors
..................
..................
..................
++ DISPLAY=:0
++ kate --start EQUAL ' /home/some_user/.config/kcookiejarrc '
++ DISPLAY=:0
++ kate --start EQUAL ' /home/some_user/.config/kaccessrc '
++ DISPLAY=:0
++ kate --start EQUAL ' /home/some_user/.kde4/share/config/kcminputrc '
..................
..................
..................
No protocol specified
QXcbConnection: Could not connect to display :0
No protocol specified
QXcbConnection: Could not connect to display :0
No protocol specified
QXcbConnection: Could not connect to display :0
..................
..................
..................
Recommend do not invoke any graphical apps, is there any good reason to invoke Kate (usually there isn’t).
Also,
I don’t seem to see what you’re testing or diffing, but are you sure simply running diff wouldn’t do what you want more simply?
(I’m referring to the common utility “diff”)
It might be good to state the actual point of this. For diffing changed files it seems overly complicated. Also, if you really, really need graphical representation, why not use a diff app like kompare that shows changes side by side?
Regarding the user switch: You know that root can edit files of other users without changing the file owner, right? Or the other way around: run as user and get file lists with sudo. Which would be preferred anyway.
For graphical connection: given that there actually is an xserver running, you probably need to fiddle with XAUTHORITY on the active display. Another option would be fake remote ssh connections like ‘ssh -Y some_user@localhost kate’ which should open kate on the current desktop.
Run script as root because access to files in /etc
Build a list of files to edit
When list is complete call a script as normal user to compare/edit pair of files in the list ( normal_user files )
And my very simple question was how to start kate from script.
> It might be good to state the actual point of this. For diffing changed files it seems overly complicated. Also, if you really, really need graphical representation, why not use a diff app like kompare that shows changes side by side?
You cannot edit within kompare
> Regarding the user switch: You know that root can edit files of other users without changing the file owner, right? Or the other way around: run as user and get file lists with sudo. Which would be preferred anyway.
I know all that. My problem is not building the list one way or another.
>For graphical connection: given that there actually is an xserver running, you probably need to fiddle with XAUTHORITY on the active display. Another option would be fake remote ssh connections like ‘ssh -Y some_user@localhost kate’ which should open kate on the current desktop.
This is exactly what I don’t want to do.
Up to leap 42.2 it was possible to start kate from script.
Now it seems we are going back to code on a punched card.
>For graphical connection: given that there actually is an xserver running, you probably need to fiddle with XAUTHORITY on the active display.
Use diff to compare files, then your logic can perhaps invoke sed(or awk) to replace test strings in the content.
Or, skip the step to diff the files,
Just run your string replacement against all files, and if the specified string to replace isn’t in the file, then you’ve only lost the time to inspect the file contents line by line and nothing will be changed. In fact, if your individual files are very small, then this approach might even be faster than diffing files in the first place.
There is always a big penalty if you switch between graphical and non-graphical apps so you need to carefully determine your reason for invoking a graphical app… and even in those cases there can be an ncurses based utility to display your info in graphical text form.