-
Notifications
You must be signed in to change notification settings - Fork 4
/
ubuntu-change-gdm-background
executable file
·77 lines (66 loc) · 2.52 KB
/
ubuntu-change-gdm-background
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
# Autor: Thiago Silva
# Contact: [email protected]
# URL: https://github.com/thiggy01/ubuntu-change-gdm-background
# ============================================================= #
# Add the restore option in order to restore gdm original theme.
if [ "$1" = "--restore" ]; then
cat /usr/share/gnome-shell/theme/gdm3.css~ > /usr/share/gnome-shell/theme/\
gdm3.css
echo "Login background sucessfully restored to its original theme."
echo "Restart Gnome to apply change."
exit 0
fi
# Get the image selected by user from yad based GUI.
usrInput=`yad --file --center --width=900 --height=450 --title "Select An \
Image File" --add-preview --file-filter "Image Files | *.jpg *.png" 2> /dev/null`
# Verify if yad is installed
if [ "$?" -eq 127 ]; then
echo "yad package is not installed."
echo "It is needed for graphical interface."
echo "Exiting."
exit 1
fi
# Check if there is a user input.
[ -z "$usrInput" ] && exit 1
# Test if argument is an image file.
if [[ $(file --mime-type -b "$usrInput") == image/*g ]]; then
# Get the full path of submited image.
imgPath=$(realpath "$usrInput")
imgName=$(basename "$usrInput")
# Save pictures to /usr/share/gdm-backgrounds.
[ ! -d /usr/share/gdm/saved-pictures ] && mkdir /usr/share/gdm/saved-pictures
cp "$imgPath" /usr/share/gdm/saved-pictures
bgImgPath=/usr/share/gdm/saved-pictures/"$imgName"
# Ubuntu GDM login background configuration file path.
cssPath=/usr/share/gnome-shell/theme/gdm3.css
# Test if there is a backup of the original gdm css file and create a backup,
# if there isn't one.
[ ! -f "$cssPath"~ ] && cp "$cssPath" "$cssPath"~
# Change the login background image to the one you submited.
ex $cssPath << EOF
/#lockDialogGroup
:normal jf:ld}a url(file://$bgImgPath);obackground-size: cover; }
:wq
EOF
# Test if login screen background was changed.
if grep -wq "$bgImgPath" "$cssPath"; then
yad --title "Sucessful Message" --center \
--width=300 --height=100 --borders=20 \
--text="Login image sucessfully changed." \
--button=gtk-ok
yad --title "Restart Question" --center \
--width=300 --height=100 --borders=20 \
--text="Restart gdm to apply change?" \
--button=gtk-yes:1 --button=gtk-no:2
ret=$?
if [ $ret == 1 ]; then
service gdm restart
elif [ $ret == 2 ]; then
yad --title "Warning Message" --center \
--width=300 --height=100 --borders=20 \
--text="Change won't be applied until restart." \
--button=gtk-ok
fi
fi
fi