-
Notifications
You must be signed in to change notification settings - Fork 1
/
shifter.sh
182 lines (143 loc) · 6.74 KB
/
shifter.sh
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#! /bin/bash
clear
echo " ______________________________________________ "
echo " /| | "
echo " / | ___ /\ | "
echo " | | | / \ | "
echo " | | |___ __ _ _ __ __ /_ _\ | "
echo " | | | |_| | |_ | |_ |__) || | "
echo " | | ___| | | | | | |__ | \ || | "
echo " | |______________________________________________| "
echo " | / / "
echo " |/______________________________________________/ "
echo ""
echo ""
currdir=`pwd`/shifter.sh
currdir="${currdir//\//\\/}"
echo $currdir
option=$1
if [ " $option " = ' -b ' ] || [ " $option " = ' --change-boot-background ' ] ; then
echo "Changing boot background"
imagepath=$2
folderpath=$2
change=$4
shifter_path="\/usr\/share\/shifter\/image.jpg"
if [ -z " $imagepath " ] ; then
echo $imagepath
echo "No image path specified "
exit 2
fi
if [ ' $change ' = ' true ' ] ; then
images=`ls $folderpath`
cp shifterboot.conf /etc/init/shifterboot.conf
sed -i "5s/.*/exec $currdir -b $folderpath -c true/" /etc/init/shifterboot.conf #change the directory at shifterboot.conf file to the working dir
#editing grub.cfg
currentimage=`ls -p | grep -v / | shuf -n 1`
mkdir -p /usr/share/shifter/
magick convert $currentimage -depth 8 -colorspace RGB /usr/share/shifter/image.png
line=`grep -n -r "background_image" "/boot/grub/grub.cfg"`
lineno=${line%:*} #take out the line number from string
lineno=$lineno's' #add s to the line number
linetext=${line##*:} # read the text in the line
firsttxt=${linetext% /*} #read the chars before the image path
lasttxt=${linetext##*;}
sed -i "$lineno/.*/$firsttxt $shifter_path;$lasttxt/" /boot/grub/grub.cfg #write everything back to the grub.cfg file.
elif [ ' $change ' = ' false ' ] ; then
rm -f /etc/init/shifterboot.conf
mkdir -p /usr/share/shifter/
magick convert $imagepath -depth 8 -colorspace RGB /usr/share/shifter/image.png
rm -f /etc/init/shifterboot.conf
if [ ! -f " /boot/grub/grubcopy.cfg " ] ; then
cp /boot/grub/grub.cfg /boot/grub/grubcopy.cfg
fi
line=`grep -n -r "background_image" "/boot/grub/grub.cfg"`
lineno=${line%:*} #take out the line number from string
lineno=$lineno's'
linetext=${line##*:} # read the text in the line
firsttxt=${linetext% /*} #read the chars before the image path
lasttxt=${linetext##*;}
sed -i "$lineno/.*/$firsttxt $shifter_path;$lasttxt/" /boot/grub/grub.cfg #write everything back to the grub.cfg file.
echo "Boot background has been changed. Cheers!! "
fi
mkdir -p /usr/share/shifter/
magick convert $imagepath -depth 8 -colorspace RGB /usr/share/shifter/image.png
rm -f /etc/init/shifterboot.conf
if [ ! -f " /boot/grub/grubcopy.cfg " ] ; then
cp /boot/grub/grub.cfg /boot/grub/grubcopy.cfg
fi
line=`grep -n -r "background_image" "/boot/grub/grub.cfg"`
lineno=${line%:*} #take out the line number from string
lineno=$lineno's'
linetext=${line##*:} # read the text in the line
firsttxt=${linetext% /*} #read the chars before the image path
lasttxt=${linetext##*;}
sed -i "$lineno/.*/$firsttxt $shifter_path;$lasttxt/" /boot/grub/grub.cfg #write everything back to the grub.cfg file.
echo "Boot background has been changed. Cheers!! "
#..........................................................................................................................................
elif [[ " $option " = ' -d ' ]] || [[ " $option " = ' --change-desktop-background ' ]] ; then
echo "Changing desktop background."
folderpath=$2
imagepath=$2
ol=$3
change=0
change=`expr $4 + 0`
if [ -z " $imagepath " ] ; then
echo $imagepath
echo "No image path specified "
fi
if [ " $change " -gt " 0 " ] ; then
cp shifterback.conf /etc/init/shifterback.conf
images=`ls $folderpath`
folderpath="${folderpath//\//\\/}"
sed -i "5s/.*/exec $currdir -d $folderpath -c $change/" /etc/init/shifterback.conf #change the directory at shifterboot.conf file to the working dir
while true ;
do
for image in $images ; do
gsettings set org.gnome.desktop.background picture-uri file://$imagepath/$image
sleep $change
done
done
fi
gsettings set org.gnome.desktop.background picture-uri file://$imagepath
echo "Desktop background has been changed"
#...........................................................................................................................................
elif [[ " $option " = ' -r ' ]] || [[ " $option " = ' --reset ' ]] ; then
update-grub
#............................................................................................................................................
elif [[ " $option " = ' -i ' ]] || [[ " $option " = ' --install ' ]] ; then
if [ ! -f " /usr/share/shifter/ " ] ; then
echo "Installing packages - build-essential, checkinstall, libx11-dev, libxext-dev, zlib1g-dev, libpng12-dev, libjpeg-dev, libfreetype6-dev, libxml2-dev "
sudo apt-get install build-essential checkinstall libx11-dev libxext-dev zlib1g-dev libpng12-dev libjpeg-dev libfreetype6-dev libxml2-dev
echo "Setting up ImageMagick..."
echo "It might take a while.... Go have a cup of tea, or... coffee or... anything..... "
tar xvzf ImageMagick.tar.gz
cd ImageMagick-7.0.7-19
./configure
make
sudo make install
sudo ldconfig /usr/local/lib
/usr/local/bin/convert logo: logo.gif
make check
echo "Completed Installation."
#else echo "Install build-essential, checkinstall, libx11-dev, libxext-dev, zlib1g-dev, libpng12-dev, libjpeg-dev, libfreetype6-dev, libxml2-dev and ImageMagick-7.0.7-19 manually"
fi
elif [[ " $option " = ' -h ' ]] || [[ " $option " = ' --help ' ]] ; then
echo "Usage - bash ./shifter.sh [option] [imagepath/folderpath] [suboption] "
echo "Options- "
echo " -b --change-boot-backround - To change the boot background "
echo " -d --change-desktop-background - To change desktop background "
echo " -r --reset - To reset grub configurations "
echo " -i --install - To install ImageMagic and other prerequisites"
echo ""
echo "Suboptions- "
echo ""
echo " with -b[option] /path/to/image/folder/ -c 4[value > 0] - To change the desktop background in n seconds "
echo " Example- bash ./shifter.sh -b /absolute/path/to/images/folder/ -c 20 -Changes background in every 20 seconds"
echo ""
echo " with -d[option] /path/to/image/folder/ -c true - To change the boot background everytime you boot"
echo " with -d[option] /path/to/image/folder/ -c false - To keep the boot background static."
echo " Example- bash ./shifter.sh -d /absolute/path/to/images/folder/ -c true "
else
echo "Usage - bash ./shifter.sh [option] [imagepath] "
echo "refer bash ./shifter.sh -h for more options"
fi