Skip to content

chgreeterbg.sh Boo Boo #9

@odoncaoa

Description

@odoncaoa

Greeting Sergiy,

Was in the process of tracking down an easy way to change the lubuntu v17.10 login background, and stumbled into your github.com/SergKolo/sergrep project via chgreeterbg.sh. I was finding alot of information regarding 'official' ways to complete such a task, but wanted to see what zenity would do. I've never directly used it before. Thus, I downloaded chgreeterbg.sh, and renamed it to ch_greeter-bkgnd.sh. However, upon invocation as my regular user, you can see that the script presently does not really work for such a scenario. You too can see there is an execution problem in such situations:

~/HD-GDU3/tmp/Ux/Prog 2018-05-04 14:05
odoncaoa@waterford[65]$ ./ch_greeter-bkgnd.sh
++ id -u
+ '[' 1000 -eq 0 ']'
+ '[' -eq 0 ']'
./ch_greeter-bkgnd.sh: line 76: [: -eq: unary operator expected
++ readlink -e ./ch_greeter-bkgnd.sh
++ readlink -q -e
readlink: missing operand
Try 'readlink --help' for more information.
+ sudo /media/odoncaoa/HD-GDU3/Tmp/Ux/Prog/ch_greeter-bkgnd.sh ''
[sudo] password for odoncaoa: 
+ set +x

From the script's appearance, it would appear to have been generated as the product of an IDE, but enough said. I would simply try to raise your awareness to the inherent issue within; as such a problem exists for every other programming language, as well. I would simply make the statement that such problems can infect, or break code anywhere that a clever test is not first created, and thus executed before a programmer can relay upon similar variable resources. While system global resources can be expected to exist within a Ux programming environment, usually, they will not actually be present unless first called upon, and initialized within a sript/program at it's beginning! I made an update which does just that for chgreeterbg.sh; and, you can see for yourself. Thanks for chgreeterbg.sh, though!

Douglas Randall
odoncaoa

#!/bin/bash

Author: Serg Kolo

Date: Nov 17, 2015

Script Description: changes background of

the unity greeter, throught creating/modifying

appropriate glib schema override file

Copyright Sergiy Kolodyazhnyy 2015

Permission to use, copy, modify, and distribute this software is hereby granted

without fee, provided that the copyright notice above and this permission statement

appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL

THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER

DEALINGS IN THE SOFTWARE.

set -x
print_usage()
{
printf "\n!!! %s\n%s\n" "Usage:" "sudo script.sh /path/to/image"
exit 1
}

create_override_file()
{

ensure image is readable

chmod +r "$image_file"

Ensure file exists with required information

{ printf "%s\n" "[com.canonical.unity-greeter]" ;
printf "%s\n" "draw-user-backgrounds=false" ;
printf "%s\n" "background='$2'" ;
} > "$1"

glib-compile-schemas "$3"
}

main()
{
ARGC=$#
ARGV="$@"

local image_file="$(readlink -e "$ARGV" 2>/dev/null )" 
local schemas_dir="/usr/share/glib-2.0/schemas/"
local override_file="$schemas_dir/99_unity_greeter_background.gschema.override" 

if [ -z $ARGV ];then 
    image_file="$(zenity --file-selection --filename='/home' )"
fi

if [ -z "$image_file" ] || ! [ -f "$image_file"  ] ;then
    exit 1
fi

create_override_file "$override_file" "$image_file" "$schemas_dir"

text="Done. Preview changes with 'dm-tool switch-to-greeter' command"
if [ $? -eq 0  ] && [ -z "$ARGV"   ];then
    zenity --info --text="$text"
else
    printf "\n%s\n" "$text"
fi

}

ARGC=0

ARGC=0

check if we're root, else quit

if [ $( id -u ) -eq 0 ]; then
main "$@"
else
# calling script without arguments spawns GUI dialog
if [ $ARGC -eq 0 ]; then
zenity --password |
sudo -S "$(readlink -e $0)" -p ""
|| exit 1
else
sudo "$(readlink -e $0)" "$(readlink -q -e "$@" )"
fi
fi
set +x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions