forked from wimpysworld/desktopify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesktopify
executable file
·262 lines (234 loc) · 7.83 KB
/
desktopify
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/usr/bin/env bash
# Display help usage
function usage () {
echo
echo "Usage"
echo " $0 --de <desktop environment>"
echo
echo "Available desktop environments are"
echo " lubuntu"
echo " kubuntu"
echo " ubuntu"
echo " ubuntu-budgie"
echo " ubuntu-kylin"
echo " ubuntu-mate"
echo " ubuntu-studio"
echo " xubuntu"
echo
echo "You can also pass the optional --oem optional which will run a setup"
echo "wizard on the next boot."
}
function apply_tweaks() {
if [ "${DESKTOP_ENVIRONMENT}" == "ubuntu-mate" ]; then
cat <<EOM > /usr/share/glib-2.0/schemas/50_ubuntu-mate-raspi-tweaks.gschema.override
[org.mate.interface]
enable-animations=false
[org.mate.Marco.general]
compositing-manager=false
[org.mate.session.required-components]
windowmanager='marco-no-composite'
EOM
glib-compile-schemas /usr/share/glib-2.0/schemas/
fi
}
function configure_network() {
message 0 "Will now configure network"
# Disable cloud-init from managing the network
echo "network: {config: disabled}" > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
# Instruct netplan to hand all network management to NetworkManager
cat <<EOM > /etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
EOM
# Disable Wifi Powersaving to improve Pi WiFi performance
if [ -e /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf ]; then
sed -i 's/wifi.powersave = 3/wifi.powersave = 2/' /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
fi
}
function enable_oem() {
if [ "${ENABLE_OEM}" -eq 1 ] && [ "${DESKTOP_ENVIRONMENT}" != "lubuntu" ]; then
apt -y install whois
local DATE=""
DATE=$(date +%m%H%M%S)
local PASSWD=""
PASSWD=$(mkpasswd -m sha-512 oem "${DATE}")
addgroup --gid 29999 oem
adduser --gecos "OEM Configuration (temporary user)" --add_extra_groups --disabled-password --gid 29999 --uid 29999 oem
usermod -a -G sudo -p "${PASSWD}" oem
if [ "${DESKTOP_ENVIRONMENT}" == "kubuntu" ]; then
apt-get -y install --no-install-recommends oem-config-kde ubiquity-frontend-kde ubiquity-ubuntu-artwork
else
apt-get -y install --no-install-recommends oem-config-gtk ubiquity-frontend-gtk ubiquity-ubuntu-artwork
fi
if [ "${DESKTOP_ENVIRONMENT}" == "ubuntu" ]; then
apt-get -y install --no-install-recommends oem-config-slideshow-ubuntu
elif [ "${DESKTOP_ENVIRONMENT}" == "ubuntu-budgie" ]; then
apt-get -y install --no-install-recommends oem-config-slideshow-ubuntu-budgie
# Force the slideshow to use Ubuntu Budgie artwork.
sed -i 's/oem-config-slideshow-ubuntu/oem-config-slideshow-ubuntu-budgie/' /usr/lib/ubiquity/plugins/ubi-usersetup.py
sed -i 's/oem-config-slideshow-ubuntu/oem-config-slideshow-ubuntu-budgie/' /usr/sbin/oem-config-remove-gtk
sed -i 's/ubiquity-slideshow-ubuntu/ubiquity-slideshow-ubuntu-budgie/' /usr/sbin/oem-config-remove-gtk
elif [ "${DESKTOP_ENVIRONMENT}" == "ubuntu-mate" ]; then
apt-get -y install --no-install-recommends oem-config-slideshow-ubuntu-mate
# Force the slideshow to use Ubuntu MATE artwork.
sed -i 's/oem-config-slideshow-ubuntu/oem-config-slideshow-ubuntu-mate/' /usr/lib/ubiquity/plugins/ubi-usersetup.py
sed -i 's/oem-config-slideshow-ubuntu/oem-config-slideshow-ubuntu-mate/' /usr/sbin/oem-config-remove-gtk
sed -i 's/ubiquity-slideshow-ubuntu/ubiquity-slideshow-ubuntu-mate/' /usr/sbin/oem-config-remove-gtk
fi
mkdir -p /var/log/installer
touch /var/log/installer/debug
cp -a /usr/lib/oem-config/oem-config.service /lib/systemd/system
cp -a /usr/lib/oem-config/oem-config.target /lib/systemd/system
systemctl enable oem-config.service
systemctl enable oem-config.target
systemctl set-default oem-config.target
fi
}
function message() {
# $1 = type , $2 = message
# Message types
# 0 - info
# 1 - warning
# 2 - error
local RED="\e[31m"
local GREEN="\e[32m"
local YELLOW="\e[33m"
local RESET="\e[0m"
local MESSAGE_TYPE=""
local MESSAGE=""
MESSAGE_TYPE=$1
MESSAGE=$2
if [[ ${MESSAGE_TYPE} -eq 0 ]]; then
echo -e " [${GREEN}+${RESET}] INFO: ${MESSAGE}"
elif [[ ${MESSAGE_TYPE} -eq 1 ]]; then
echo -e " [${YELLOW}*${RESET}] WARNING: ${MESSAGE}"
elif [[ ${MESSAGE_TYPE} -eq 2 ]]; then
echo -e " [${RED}!${RESET}] ERROR: ${MESSAGE}"
fi
}
CLASSIC_SNAPS=()
CONFINED_SNAPS=()
DESKTOP_ENVIRONMENT=""
ENABLE_OEM=0
FORCE=0
# Take command line arguments
while [ $# -gt 0 ]; do
case "${1}" in
-de|--de)
DESKTOP_ENVIRONMENT="${2}"
shift
shift;;
-force|--force)
FORCE=1
shift
shift;;
-h|--h|-help|--help)
usage
exit 0;;
-oem|--oem)
ENABLE_OEM=1
shift;;
*)
message 2 "\"${1}\" is not a supported parameter."
echo "${DESKTOP_ENVIRONMENT}"
usage
exit 1;;
esac
done
# Set variables based on chosen desktop environment
case "${DESKTOP_ENVIRONMENT}" in
ubuntu)
message 0 "Specified ubuntu desktop"
DESKTOP_PACKAGES="ubuntu-desktop"
CONFINED_SNAPS=(gnome-3-34-1804 gtk-common-themes snap-store)
shift;;
ubuntu-mate)
message 0 "Specified Ubuntu MATE desktop"
DESKTOP_PACKAGES="ubuntu-mate-desktop"
CLASSIC_SNAPS=(ubuntu-mate-welcome software-boutique)
shift;;
ubuntu-budgie)
message 0 "Specified Ubuntu Budgie desktop"
DESKTOP_PACKAGES="ubuntu-budgie-desktop"
CLASSIC_SNAPS=(ubuntu-budgie-welcome)
shift;;
ubuntu-kylin)
message 0 "Specified Ubunty Kylin desktop"
DESKTOP_PACKAGES="ubuntukylin-desktop"
shift;;
ubuntu-studio)
message 0 "Specified Ubuntu Studio desktop"
DESKTOP_PACKAGES="ubuntustudio-desktop"
shift;;
kubuntu)
message 0 "Specified Kubuntu desktop"
DESKTOP_PACKAGES="kubuntu-desktop"
shift;;
lubuntu)
message 0 "Specified Lubuntu desktop"
DESKTOP_PACKAGES="lubuntu-desktop"
shift;;
xubuntu)
message 0 "Specified Xubuntu desktop"
DESKTOP_PACKAGES="xubuntu-desktop"
shift;;
*)
if [ -z "${DESKTOP_ENVIRONMENT}" ]; then
message 2 "Please specifiy a desktop environment"
else
message 2 "${DESKTOP_ENVIRONMENT} is not a valid desktop environment"
fi
usage
exit 1;;
esac
# Check if the user running the script is root
if [ "$(id -u)" -ne 0 ]; then
message 2 "You need to be root."
exit 1
fi
HOST_ARCH=$(uname -m)
if [ "${HOST_ARCH}" != "armv7l" ] && [ "${HOST_ARCH}" != "aarch64" ]; then
message 2 "This script is only intended to run on ARM devices."
exit 1
fi
# Check if we're running on a Raspberry Pi
PI_MODEL=$(grep ^Model /proc/cpuinfo | cut -d':' -f2- | sed 's/ R/R/')
if [[ "${PI_MODEL}" == *"Raspberry Pi"* ]]; then
message 0 "Configuring your ${PI_MODEL}"
else
message 2 "This is not a Raspberry Pi. Quitting!"
exit 1
fi
# Check if we're running Ubuntu
IS_UBUNTU=$(lsb_release -is)
if [ "${IS_UBUNTU}" != "Ubuntu" ]; then
message 2 "This script is only intended to run on Ubuntu."
exit 1
fi
# Check if we're running 20.04
CODENAME=$(lsb_release -cs)
if [ "${CODENAME}" != "focal" ]; then
message 2 " This script is only intended to run on Ubuntu 20.04."
exit 1
fi
# Do the installation
HARDWARE_PACKAGES="pi-bluetooth libgpiod-dev python3-libgpiod python3-gpiozero"
message 0 "Will now install ${DESKTOP_PACKAGES} and ${HARDWARE_PACKAGES}"
#Check if system already has a desktop installed
#if [ "$(apt list --installed "${DESKTOP_PACKAGES}" 2>/dev/null)" ] && [ "${FORCE}" -eq 0 ]; then
# echo "[*] WARNING: ${DESKTOP_PACKAGES} already installed. To force install use -force or --force flags."
#else
apt install -y "${DESKTOP_PACKAGES}^"
#fi
for CLASSIC_SNAP in "${CLASSIC_SNAPS[@]}"; do
snap install "${CLASSIC_SNAP}" --classic
done
for CONFINED_SNAP in "${CONFINED_SNAPS[@]}"; do
snap install "${CONFINED_SNAP}"
done
apt install -y ${HARDWARE_PACKAGES}
configure_network
apply_tweaks
enable_oem