-
Notifications
You must be signed in to change notification settings - Fork 68
/
install.sh
executable file
·159 lines (126 loc) · 4.15 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
#! /usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
GRUB_THEME='fallout-grub-theme'
INSTALLER_LANG='English'
# Check dependencies
INSTALLER_DEPENDENCIES=(
'mktemp'
'sed'
'sort'
'sudo'
'tar'
'tee'
'tr'
'wget'
)
for i in "${INSTALLER_DEPENDENCIES[@]}"; do
command -v $i > /dev/null 2>&1 || {
echo >&2 "'$i' command is required, but not available. Aborting.";
exit 1;
}
done
# Change to temporary directory
cd $(mktemp -d)
# Pre-authorise sudo
sudo echo
# Select language, optional
declare -A INSTALLER_LANGS=(
[Chinese_simplified]=zh_CN
[Chinese_traditional]=zh_TW
[English]=EN
[French]=FR
[German]=DE
[Hungarian]=HU
[Italian]=IT
[Korean]=KO
[Latvian]=LV
[Norwegian]=NO
[Polish]=PL
[Portuguese]=PT
[Russian]=RU
[Rusyn]=RUE
[Spanish]=ES
[Turkish]=TR
[Ukrainian]=UA
)
if [[ ${1:-} == "--lang" && -v 2 && -v INSTALLER_LANGS[$2] ]]; then
INSTALLER_LANG=$2
else
INSTALLER_LANG_NAMES=($(echo ${!INSTALLER_LANGS[*]} | tr ' ' '\n' | sort -n))
PS3='Please select language #: '
select l in "${INSTALLER_LANG_NAMES[@]}"; do
if [[ -v INSTALLER_LANGS[$l] ]]; then
INSTALLER_LANG=$l
break
else
echo 'No such language, try again'
fi
done < /dev/tty
fi
echo 'Fetching and unpacking theme'
wget -O - https://github.com/shvchk/${GRUB_THEME}/archive/master.tar.gz | tar -xzf - --strip-components=1
if [[ "$INSTALLER_LANG" != "English" ]]; then
echo "Changing language to ${INSTALLER_LANG}"
sed -i -r -e '/^\s+# EN$/{n;s/^(\s*)/\1# /}' \
-e '/^\s+# '"${INSTALLER_LANGS[$INSTALLER_LANG]}"'$/{n;s/^(\s*)#\s*/\1/}' theme.txt
fi
# Detect distro and set GRUB location and update method
GRUB_DIR='grub'
UPDATE_GRUB=''
BOOT_MODE='legacy'
if [[ -d /boot/efi && -d /sys/firmware/efi ]]; then
BOOT_MODE='UEFI'
fi
echo "Boot mode: ${BOOT_MODE}"
if [[ -e /etc/os-release ]]; then
ID=""
ID_LIKE=""
source /etc/os-release
if [[ "$ID" =~ (debian|ubuntu|solus|void) || \
"$ID_LIKE" =~ (debian|ubuntu|void) ]]; then
UPDATE_GRUB='update-grub'
elif [[ "$ID" =~ (arch|gentoo|artix) || \
"$ID_LIKE" =~ (^arch|gentoo|^artix) ]]; then
UPDATE_GRUB="grub-mkconfig -o /boot/${GRUB_DIR}/grub.cfg"
elif [[ "$ID" =~ (centos|fedora|opensuse) || \
"$ID_LIKE" =~ (fedora|rhel|suse) ]]; then
GRUB_DIR='grub2'
UPDATE_GRUB="grub2-mkconfig -o /boot/${GRUB_DIR}/grub.cfg"
# BLS etries have 'kernel' class, copy corresponding icon
if [[ -d /boot/loader/entries && -e icons/${ID}.png ]]; then
cp icons/${ID}.png icons/kernel.png
fi
fi
fi
echo 'Creating GRUB themes directory'
sudo mkdir -p /boot/${GRUB_DIR}/themes/${GRUB_THEME}
echo 'Copying theme to GRUB themes directory'
sudo cp -r * /boot/${GRUB_DIR}/themes/${GRUB_THEME}
echo 'Removing other themes from GRUB config'
sudo sed -i '/^GRUB_THEME=/d' /etc/default/grub
echo 'Making sure GRUB uses graphical output'
sudo sed -i 's/^\(GRUB_TERMINAL\w*=.*\)/#\1/' /etc/default/grub
echo 'Removing empty lines at the end of GRUB config' # optional
sudo sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' /etc/default/grub
echo 'Adding new line to GRUB config just in case' # optional
echo | sudo tee -a /etc/default/grub
echo 'Adding theme to GRUB config'
echo "GRUB_THEME=/boot/${GRUB_DIR}/themes/${GRUB_THEME}/theme.txt" | sudo tee -a /etc/default/grub
echo 'Removing theme installation files'
rm -rf "$PWD"
cd
echo 'Updating GRUB'
if [[ $UPDATE_GRUB ]]; then
eval sudo "$UPDATE_GRUB"
else
cat << ' EOF'
--------------------------------------------------------------------------------
Cannot detect your distro, you will need to run `grub-mkconfig` (as root) manually.
Common ways:
- Debian, Ubuntu, Solus and derivatives: `update-grub` or `grub-mkconfig -o /boot/grub/grub.cfg`
- RHEL, CentOS, Fedora, SUSE and derivatives: `grub2-mkconfig -o /boot/grub2/grub.cfg`
- Arch, Artix, Gentoo and derivatives: `grub-mkconfig -o /boot/grub/grub.cfg`
--------------------------------------------------------------------------------
EOF
fi