CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/scripts/desktop.sh
Views: 3960
1
#!/bin/bash
2
#
3
# Copyright (c) 2013-2021 Igor Pecovnik, igor.pecovnik@gma**.com
4
#
5
# This file is licensed under the terms of the GNU General Public
6
# License version 2. This program is licensed "as is" without any
7
# warranty of any kind, whether express or implied.
8
9
# Functions:
10
11
# create_desktop_package
12
# install_ppa_prerequisites
13
# add_apt_sources
14
# add_desktop_package_sources
15
# desktop_postinstall
16
17
18
19
20
create_desktop_package ()
21
{
22
23
echo "Showing PACKAGE_LIST_DESKTOP before postprocessing" >> "${DEST}"/${LOG_SUBPATH}/output.log
24
# Use quotes to show leading and trailing spaces
25
echo "\"$PACKAGE_LIST_DESKTOP\"" >> "${DEST}"/${LOG_SUBPATH}/output.log
26
27
# Remove leading and trailing spaces with some bash monstruosity
28
# https://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-a-bash-variable#12973694
29
DEBIAN_RECOMMENDS="${PACKAGE_LIST_DESKTOP#"${PACKAGE_LIST_DESKTOP%%[![:space:]]*}"}"
30
DEBIAN_RECOMMENDS="${DEBIAN_RECOMMENDS%"${DEBIAN_RECOMMENDS##*[![:space:]]}"}"
31
# Replace whitespace characters by commas
32
DEBIAN_RECOMMENDS=${DEBIAN_RECOMMENDS// /,};
33
# Remove others 'spacing characters' (like tabs)
34
DEBIAN_RECOMMENDS=${DEBIAN_RECOMMENDS//[[:space:]]/}
35
36
echo "DEBIAN_RECOMMENDS : ${DEBIAN_RECOMMENDS}" >> "${DEST}"/${LOG_SUBPATH}/output.log
37
38
# Replace whitespace characters by commas
39
PACKAGE_LIST_PREDEPENDS=${PACKAGE_LIST_PREDEPENDS// /,};
40
# Remove others 'spacing characters' (like tabs)
41
PACKAGE_LIST_PREDEPENDS=${PACKAGE_LIST_PREDEPENDS//[[:space:]]/}
42
43
local destination tmp_dir
44
tmp_dir=$(mktemp -d)
45
destination=${tmp_dir}/${BOARD}/${CHOSEN_DESKTOP}_${REVISION}_all
46
rm -rf "${destination}"
47
mkdir -p "${destination}"/DEBIAN
48
49
echo "${PACKAGE_LIST_PREDEPENDS}" >> "${DEST}"/${LOG_SUBPATH}/output.log
50
51
# set up control file
52
cat <<-EOF > "${destination}"/DEBIAN/control
53
Package: ${CHOSEN_DESKTOP}
54
Version: $REVISION
55
Architecture: all
56
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
57
Installed-Size: 1
58
Section: xorg
59
Priority: optional
60
Recommends: ${DEBIAN_RECOMMENDS//[:space:]+/,}, orangepi-bsp-desktop
61
Provides: ${CHOSEN_DESKTOP}, orangepi-${RELEASE}-desktop
62
Pre-Depends: ${PACKAGE_LIST_PREDEPENDS//[:space:]+/,}
63
Description: Orange Pi desktop for ${DISTRIBUTION} ${RELEASE}
64
EOF
65
66
# Recreating the DEBIAN/postinst file
67
echo "#!/bin/sh -e" > "${destination}/DEBIAN/postinst"
68
69
local aggregated_content=""
70
aggregate_all_desktop "debian/postinst" $'\n'
71
72
echo "${aggregated_content}" >> "${destination}/DEBIAN/postinst"
73
echo "exit 0" >> "${destination}/DEBIAN/postinst"
74
75
chmod 755 "${destination}"/DEBIAN/postinst
76
77
#display_alert "Showing ${destination}/DEBIAN/postinst"
78
cat "${destination}/DEBIAN/postinst" >> "${DEST}"/${LOG_SUBPATH}/install.log
79
80
# OrangePi create_desktop_package scripts
81
82
unset aggregated_content
83
84
mkdir -p "${destination}"/etc/orangepi
85
86
local aggregated_content=""
87
aggregate_all_desktop "orangepi/create_desktop_package.sh" $'\n'
88
eval "${aggregated_content}"
89
[[ $? -ne 0 ]] && display_alert "create_desktop_package.sh exec error" "" "wrn"
90
91
display_alert "Building desktop package" "${CHOSEN_DESKTOP}_${REVISION}_all" "info"
92
93
mkdir -p "${DEB_STORAGE}/${RELEASE}"
94
cd "${destination}"; cd ..
95
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${destination}" "${DEB_STORAGE}/${RELEASE}/${CHOSEN_DESKTOP}_${REVISION}_all.deb" >/dev/null
96
97
# cleanup
98
rm -rf "${tmp_dir}"
99
100
unset aggregated_content
101
102
}
103
104
105
106
107
create_bsp_desktop_package ()
108
{
109
110
display_alert "Creating board support package for desktop" "${package_name}" "info"
111
112
local package_name="${BSP_DESKTOP_PACKAGE_FULLNAME}"
113
114
local destination tmp_dir
115
tmp_dir=$(mktemp -d)
116
destination=${tmp_dir}/${BOARD}/${BSP_DESKTOP_PACKAGE_FULLNAME}
117
rm -rf "${destination}"
118
mkdir -p "${destination}"/DEBIAN
119
120
copy_all_packages_files_for "bsp-desktop"
121
122
# set up control file
123
cat <<-EOF > "${destination}"/DEBIAN/control
124
Package: orangepi-bsp-desktop-${BOARD}
125
Version: $REVISION
126
Architecture: $ARCH
127
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
128
Installed-Size: 1
129
Section: xorg
130
Priority: optional
131
Provides: orangepi-bsp-desktop, orangepi-bsp-desktop-${BOARD}
132
Depends: ${BSP_CLI_PACKAGE_NAME}
133
Description: Orange Pi Board Specific Packages for desktop users using $ARCH ${BOARD} machines
134
EOF
135
136
# Recreating the DEBIAN/postinst file
137
echo "#!/bin/sh -e" > "${destination}/DEBIAN/postinst"
138
139
local aggregated_content=""
140
aggregate_all_desktop "debian/orangepi-bsp-desktop/postinst" $'\n'
141
142
echo "${aggregated_content}" >> "${destination}/DEBIAN/postinst"
143
echo "exit 0" >> "${destination}/DEBIAN/postinst"
144
145
chmod 755 "${destination}"/DEBIAN/postinst
146
147
# Orange Pi create_desktop_package scripts
148
149
unset aggregated_content
150
151
mkdir -p "${destination}"/etc/orangepi
152
153
local aggregated_content=""
154
aggregate_all_desktop "debian/orangepi-bsp-desktop/prepare.sh" $'\n'
155
eval "${aggregated_content}"
156
[[ $? -ne 0 ]] && display_alert "prepare.sh exec error" "" "wrn"
157
158
mkdir -p "${DEB_STORAGE}/${RELEASE}"
159
cd "${destination}"; cd ..
160
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${destination}" "${DEB_STORAGE}/${RELEASE}/${package_name}.deb" >/dev/null
161
162
# cleanup
163
rm -rf "${tmp_dir}"
164
165
unset aggregated_content
166
167
}
168
169
170
171
172
install_ppa_prerequisites() {
173
174
# Myy : So... The whole idea is that, a good bunch of external sources
175
# are PPA.
176
# Adding PPA without add-apt-repository is poorly conveninent since
177
# you need to reconstruct the URL by hand, and find the GPG key yourself.
178
# add-apt-repository does that automatically, and in a way that allows you
179
# to remove it cleanly through the same tool.
180
181
# Myy : TODO Try to find a way to install this package only when
182
# we encounter a PPA.
183
run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get install -yqq software-properties-common"
184
185
}
186
187
188
189
190
add_apt_sources() {
191
192
local potential_paths=""
193
local sub_dirs_to_check=". "
194
if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then
195
sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}"
196
fi
197
get_all_potential_paths "${DEBOOTSTRAP_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}" "sources/apt"
198
get_all_potential_paths "${CLI_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}" "sources/apt"
199
get_all_potential_paths "${DESKTOP_ENVIRONMENTS_SEARCH_RELATIVE_DIRS}" "." "sources/apt"
200
get_all_potential_paths "${DESKTOP_APPGROUPS_SEARCH_RELATIVE_DIRS}" "${DESKTOP_APPGROUPS_SELECTED}" "sources/apt"
201
202
display_alert "Adding additional apt sources"
203
204
for apt_sources_dirpath in ${potential_paths}; do
205
if [[ -d "${apt_sources_dirpath}" ]]; then
206
for apt_source_filepath in "${apt_sources_dirpath}/"*.source; do
207
apt_source_filepath=$(echo $apt_source_filepath | sed -re 's/(^.*[^/])\.[^./]*$/\1/')
208
local new_apt_source="$(cat "${apt_source_filepath}.source")"
209
local apt_source_gpg_filepath="${apt_source_filepath}.gpg"
210
211
# extract filenames
212
local apt_source_gpg_filename="$(basename ${apt_source_gpg_filepath})"
213
local apt_source_filename="$(basename ${apt_source_filepath}).list"
214
215
display_alert "Adding APT Source ${new_apt_source}"
216
217
if [[ "${new_apt_source}" == ppa* ]] ; then
218
# ppa with software-common-properties
219
run_on_sdcard "add-apt-repository -y -n \"${new_apt_source}\""
220
# add list with apt-add
221
# -y -> Assumes yes to all queries
222
# -n -> Do not update package cache after adding
223
if [[ -f "${apt_source_gpg_filepath}" ]]; then
224
display_alert "Adding GPG Key ${apt_source_gpg_filepath}"
225
cp "${apt_source_gpg_filepath}" "${SDCARD}/tmp/${apt_source_gpg_filename}"
226
run_on_sdcard "apt-key add \"/tmp/${apt_source_gpg_filename}\""
227
echo "APT Key returned : $?"
228
fi
229
else
230
# installation without software-common-properties, sources.list + key.gpg
231
echo "${new_apt_source}" > "${SDCARD}/etc/apt/sources.list.d/${apt_source_filename}"
232
if [[ -f "${apt_source_gpg_filepath}" ]]; then
233
display_alert "Adding GPG Key ${apt_source_gpg_filepath}"
234
# local apt_source_gpg_filename="$(basename ${apt_source_gpg_filepath})"
235
mkdir -p "${SDCARD}"/usr/share/keyrings/
236
cp "${apt_source_gpg_filepath}" "${SDCARD}"/usr/share/keyrings/
237
fi
238
239
fi
240
241
done
242
fi
243
done
244
245
}
246
247
248
249
250
add_desktop_package_sources() {
251
252
# Myy : I see Snap and Flatpak coming up in the next releases
253
# so... let's prepare for that
254
255
add_apt_sources
256
257
ls -l "${SDCARD}/usr/share/keyrings" >> "${DEST}"/${LOG_SUBPATH}/install.log
258
ls -l "${SDCARD}/etc/apt/sources.list.d" >> "${DEST}"/${LOG_SUBPATH}/install.log
259
cat "${SDCARD}/etc/apt/sources.list" >> "${DEST}"/${LOG_SUBPATH}/install.log
260
261
}
262
263
264
265
266
desktop_postinstall ()
267
{
268
269
# disable display manager for the first run
270
#run_on_sdcard "systemctl --no-reload disable lightdm.service >/dev/null 2>&1"
271
#run_on_sdcard "systemctl --no-reload disable gdm3.service >/dev/null 2>&1"
272
273
# update packages index
274
run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get update >/dev/null 2>&1"
275
276
# install per board packages
277
if [[ -n ${PACKAGE_LIST_DESKTOP_BOARD} ]]; then
278
run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get -yqq --no-install-recommends install $PACKAGE_LIST_DESKTOP_BOARD"
279
fi
280
281
# install per family packages
282
if [[ -n ${PACKAGE_LIST_DESKTOP_FAMILY} ]]; then
283
run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get -yqq --no-install-recommends install $PACKAGE_LIST_DESKTOP_FAMILY"
284
fi
285
286
# Compile Turbo Frame buffer for sunxi
287
if [[ $LINUXFAMILY == sun8i && $BRANCH == legacy ]]; then
288
sed 's/name="use_compositing" type="bool" value="true"/name="use_compositing" type="bool" value="false"/' -i "${SDCARD}"/etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml
289
290
# enable memory reservations
291
echo "disp_mem_reserves=on" >> "${SDCARD}"/boot/orangepiEnv.txt
292
echo "extraargs=cma=96M" >> "${SDCARD}"/boot/orangepiEnv.txt
293
fi
294
295
if [[ -d ${SDCARD}/etc/lightdm ]]; then
296
mkdir -p ${SDCARD}/etc/lightdm/lightdm.conf.d
297
cat <<-EOF > ${SDCARD}/etc/lightdm/lightdm.conf.d/22-orangepi-autologin.conf
298
[Seat:*]
299
autologin-user=$OPI_USERNAME
300
autologin-user-timeout=0
301
user-session=xfce
302
EOF
303
fi
304
305
#mkdir -p /etc/gdm3
306
#cat <<-EOF > /etc/gdm3/custom.conf
307
#[daemon]
308
#AutomaticLoginEnable = true
309
#AutomaticLogin = $RealUserName
310
#EOF
311
}
312
313