-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.sh
executable file
·163 lines (148 loc) · 5.6 KB
/
install.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
#! /bin/bash
set -e
# This script installs the GRUB2 theme in /boot/grub/themes/, /boot/grub2/themes/ or /grub/themes/
# depending on the distribution.
#
# Copyright (C) 2013 Safiyat Reza
#
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details at <http://www.gnu.org/licenses/>.
# Set variables
Theme_Name="GReza" # The theme will be installed in a dir with this name. Avoid spaces.
Theme_Definition_File="theme.txt" # Filename of theme definition file.
Theme_Resolution="any" # The resolution the theme was designed to show best at, 640x480, 1024x768 etc,
# or "any" for any resolution (resolution independent).
Inst_Dir=$(dirname $0)
Grub_Dist_Dirs="/grub /boot/grub /boot/grub2" # Directories must be in this order.
let Grub_Min_Version=198 # Do not change this.
Grub_File="/etc/default/grub"
Grub_Dir=
mkConfig_File=
# Check that the script is being run as root.
if [[ $(id -u) != 0 ]]; then
echo "Please run this script with root privileges."
exit 0
fi
# Get GRUB's installation directory.
for i in $Grub_Dist_Dirs; do
if [[ -d $i ]]; then
Grub_Dir=$i
fi
done
# Exit this script if we could not locate GRUB's installation directory.
if [[ -z $Grub_Dir ]]; then
echo "Could not locate GRUB's installation directory."
exit 0
fi
# Exit the script if GRUB's version is < 1.98
if [[ -f $(which grub2-install) ]]; then
Grub_Version_Long=$(grub2-install --version)
elif [[ -f $(which grub-install) ]]; then
Grub_Version_Long=$(grub-install --version)
else
echo 'Could not locate grub-install or grub2-install in your path.'
exit 0
fi
Grub_Version=$(echo $Grub_Version_Long | sed 's,[[:alpha:][:punct:][:blank:]],,g')
if (( ${Grub_Version:0:3} < Grub_Min_Version )); then
echo "GRUB must be at least version ${Grub_Min_Version:0:1}.${Grub_Min_Version:1:2}."
echo "The installed version is ${Grub_Version:0:1}.${Grub_Version:1:2}."
exit 0
fi
# Check that /etc/default/grub exists.
if [[ ! -f $Grub_File ]]; then
echo "Could not find $Grub_File"
exit 0
fi
# Check that GRUB's mkconfig script file exists.
mkConfig_File=$(which ${Grub_Dir##*/}-mkconfig) || \
(echo "GRUB's mkconfig script file was not found in your path." && exit 0)
# Ask for desired resolution if set to "any"
if [[ $Theme_Resolution = "any" ]]; then
echo ""
echo "Enter desired resolution in the form of 1024x768, 800x600, 1600x1200, etc."
echo "Also, only choose a resolution that is supported by your VESA BIOS Extensions"
echo "which can be found by installing the hwinfo package, and running hwinfo --framebuffer,"
echo "or by running vbeinfo at grub's command line. The outputs may vary."
echo ""
echo -n "Enter desired resolution: "
read Theme_Resolution
fi
# Create theme directory. If directory already exists, ask the user if they would like
# to overwrite the contents with the new theme or create a new theme directory.
Theme_Dir=$Grub_Dir/themes/$Theme_Name
while [[ -d $Theme_Dir ]]; do
echo "Directory $Theme_Dir already exists!"
echo -n "Would you like to overwrite it's contents or create a new directory? [(o)verwrite (c)reate] "
read Response
case $Response in
c|create)
echo -n "Please enter a new name for the theme's directory: "
read Response
Theme_Dir=$Grub_Dir/themes/$Response;;
o|overwrite)
echo -n "This will delete all files in $Theme_Dir. Are you sure? [(y)es (n)o] "
read Response
case $Response in
y|yes)
rm -r $Theme_Dir;;
*)
exit 0;;
esac;;
*)
exit 0;;
esac
done
mkdir -p $Theme_Dir
# Copy the theme's files to the theme's directory.
for i in $Inst_Dir/*; do
cp -r $i $Theme_Dir/$(basename $i)
done
# Check whether an icons directory exists. If icons are not included in this theme,
# check if one exists in ..../themes/icons. If it exists, ask the user if they would like to use it.
if [[ ! -d $Theme_Dir/icons && -d $Grub_Dir/themes/icons ]]; then
echo "An icons directory was not included in this theme."
echo "However, one was found in $Grub_Dir/themes/icons containing these files:"
echo $(ls $Grub_Dir/themes/icons)
echo -n "Would you like to use these icons? [(y)es (n)o] "
read Response
case $Response in
y|yes)
ln -s $Grub_Dir/themes/icons $Theme_Dir/;;
*)
echo "This theme will not show any icons.";;
esac
elif [[ ! $Theme_Dir/icons && ! -d $Grub_Dir/themes/icons ]]; then
echo "Could not find an icons directory. This theme will not show any icons."
fi
# Change GRUB's resolution to match that of the theme.
if [[ $Theme_Resolution != "any" ]]; then
i=$(sed -n 's,^#\?GRUB_GFXMODE=,&,p' $Grub_File)
if [[ -z $i ]]; then
echo -e "\nGRUB_GFXMODE=$Theme_Resolution" >>$Grub_File
else
sed "s,^#\?GRUB_GFXMODE=.*,GRUB_GFXMODE=$Theme_Resolution," <$Grub_File >$Grub_File.~
mv $Grub_File.~ $Grub_File
fi
fi
# Ask the user if they would like to set the theme as their new theme.
echo -n "Would you like to set this as your new theme? [(y)es (n)o] "
read Response
if [[ $Response = yes || $Response = y ]]; then
i=$(sed -n 's,^#\?GRUB_THEME=,&,p' $Grub_File)
if [[ -z $i ]]; then
echo -e "\nGRUB_THEME=$Theme_Dir/$Theme_Definition_File" >>$Grub_File
else
sed "s,^#\?GRUB_THEME=.*,GRUB_THEME=$Theme_Dir/$Theme_Definition_File," <$Grub_File >$Grub_File.~
mv $Grub_File.~ $Grub_File
fi
$($mkConfig_File -o $Grub_Dir/grub.cfg) # Generate new grub.cfg
fi
exit 0