Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/next/scripts/desktop.sh
Views: 3960
#!/bin/bash1#2# Copyright (c) 2013-2021 Igor Pecovnik, igor.pecovnik@gma**.com3#4# This file is licensed under the terms of the GNU General Public5# License version 2. This program is licensed "as is" without any6# warranty of any kind, whether express or implied.78# Functions:910# create_desktop_package11# install_ppa_prerequisites12# add_apt_sources13# add_desktop_package_sources14# desktop_postinstall1516171819create_desktop_package ()20{2122echo "Showing PACKAGE_LIST_DESKTOP before postprocessing" >> "${DEST}"/${LOG_SUBPATH}/output.log23# Use quotes to show leading and trailing spaces24echo "\"$PACKAGE_LIST_DESKTOP\"" >> "${DEST}"/${LOG_SUBPATH}/output.log2526# Remove leading and trailing spaces with some bash monstruosity27# https://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-a-bash-variable#1297369428DEBIAN_RECOMMENDS="${PACKAGE_LIST_DESKTOP#"${PACKAGE_LIST_DESKTOP%%[![:space:]]*}"}"29DEBIAN_RECOMMENDS="${DEBIAN_RECOMMENDS%"${DEBIAN_RECOMMENDS##*[![:space:]]}"}"30# Replace whitespace characters by commas31DEBIAN_RECOMMENDS=${DEBIAN_RECOMMENDS// /,};32# Remove others 'spacing characters' (like tabs)33DEBIAN_RECOMMENDS=${DEBIAN_RECOMMENDS//[[:space:]]/}3435echo "DEBIAN_RECOMMENDS : ${DEBIAN_RECOMMENDS}" >> "${DEST}"/${LOG_SUBPATH}/output.log3637# Replace whitespace characters by commas38PACKAGE_LIST_PREDEPENDS=${PACKAGE_LIST_PREDEPENDS// /,};39# Remove others 'spacing characters' (like tabs)40PACKAGE_LIST_PREDEPENDS=${PACKAGE_LIST_PREDEPENDS//[[:space:]]/}4142local destination tmp_dir43tmp_dir=$(mktemp -d)44destination=${tmp_dir}/${BOARD}/${CHOSEN_DESKTOP}_${REVISION}_all45rm -rf "${destination}"46mkdir -p "${destination}"/DEBIAN4748echo "${PACKAGE_LIST_PREDEPENDS}" >> "${DEST}"/${LOG_SUBPATH}/output.log4950# set up control file51cat <<-EOF > "${destination}"/DEBIAN/control52Package: ${CHOSEN_DESKTOP}53Version: $REVISION54Architecture: all55Maintainer: $MAINTAINER <$MAINTAINERMAIL>56Installed-Size: 157Section: xorg58Priority: optional59Recommends: ${DEBIAN_RECOMMENDS//[:space:]+/,}, orangepi-bsp-desktop60Provides: ${CHOSEN_DESKTOP}, orangepi-${RELEASE}-desktop61Pre-Depends: ${PACKAGE_LIST_PREDEPENDS//[:space:]+/,}62Description: Orange Pi desktop for ${DISTRIBUTION} ${RELEASE}63EOF6465# Recreating the DEBIAN/postinst file66echo "#!/bin/sh -e" > "${destination}/DEBIAN/postinst"6768local aggregated_content=""69aggregate_all_desktop "debian/postinst" $'\n'7071echo "${aggregated_content}" >> "${destination}/DEBIAN/postinst"72echo "exit 0" >> "${destination}/DEBIAN/postinst"7374chmod 755 "${destination}"/DEBIAN/postinst7576#display_alert "Showing ${destination}/DEBIAN/postinst"77cat "${destination}/DEBIAN/postinst" >> "${DEST}"/${LOG_SUBPATH}/install.log7879# OrangePi create_desktop_package scripts8081unset aggregated_content8283mkdir -p "${destination}"/etc/orangepi8485local aggregated_content=""86aggregate_all_desktop "orangepi/create_desktop_package.sh" $'\n'87eval "${aggregated_content}"88[[ $? -ne 0 ]] && display_alert "create_desktop_package.sh exec error" "" "wrn"8990display_alert "Building desktop package" "${CHOSEN_DESKTOP}_${REVISION}_all" "info"9192mkdir -p "${DEB_STORAGE}/${RELEASE}"93cd "${destination}"; cd ..94fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${destination}" "${DEB_STORAGE}/${RELEASE}/${CHOSEN_DESKTOP}_${REVISION}_all.deb" >/dev/null9596# cleanup97rm -rf "${tmp_dir}"9899unset aggregated_content100101}102103104105106create_bsp_desktop_package ()107{108109display_alert "Creating board support package for desktop" "${package_name}" "info"110111local package_name="${BSP_DESKTOP_PACKAGE_FULLNAME}"112113local destination tmp_dir114tmp_dir=$(mktemp -d)115destination=${tmp_dir}/${BOARD}/${BSP_DESKTOP_PACKAGE_FULLNAME}116rm -rf "${destination}"117mkdir -p "${destination}"/DEBIAN118119copy_all_packages_files_for "bsp-desktop"120121# set up control file122cat <<-EOF > "${destination}"/DEBIAN/control123Package: orangepi-bsp-desktop-${BOARD}124Version: $REVISION125Architecture: $ARCH126Maintainer: $MAINTAINER <$MAINTAINERMAIL>127Installed-Size: 1128Section: xorg129Priority: optional130Provides: orangepi-bsp-desktop, orangepi-bsp-desktop-${BOARD}131Depends: ${BSP_CLI_PACKAGE_NAME}132Description: Orange Pi Board Specific Packages for desktop users using $ARCH ${BOARD} machines133EOF134135# Recreating the DEBIAN/postinst file136echo "#!/bin/sh -e" > "${destination}/DEBIAN/postinst"137138local aggregated_content=""139aggregate_all_desktop "debian/orangepi-bsp-desktop/postinst" $'\n'140141echo "${aggregated_content}" >> "${destination}/DEBIAN/postinst"142echo "exit 0" >> "${destination}/DEBIAN/postinst"143144chmod 755 "${destination}"/DEBIAN/postinst145146# Orange Pi create_desktop_package scripts147148unset aggregated_content149150mkdir -p "${destination}"/etc/orangepi151152local aggregated_content=""153aggregate_all_desktop "debian/orangepi-bsp-desktop/prepare.sh" $'\n'154eval "${aggregated_content}"155[[ $? -ne 0 ]] && display_alert "prepare.sh exec error" "" "wrn"156157mkdir -p "${DEB_STORAGE}/${RELEASE}"158cd "${destination}"; cd ..159fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${destination}" "${DEB_STORAGE}/${RELEASE}/${package_name}.deb" >/dev/null160161# cleanup162rm -rf "${tmp_dir}"163164unset aggregated_content165166}167168169170171install_ppa_prerequisites() {172173# Myy : So... The whole idea is that, a good bunch of external sources174# are PPA.175# Adding PPA without add-apt-repository is poorly conveninent since176# you need to reconstruct the URL by hand, and find the GPG key yourself.177# add-apt-repository does that automatically, and in a way that allows you178# to remove it cleanly through the same tool.179180# Myy : TODO Try to find a way to install this package only when181# we encounter a PPA.182run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get install -yqq software-properties-common"183184}185186187188189add_apt_sources() {190191local potential_paths=""192local sub_dirs_to_check=". "193if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then194sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}"195fi196get_all_potential_paths "${DEBOOTSTRAP_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}" "sources/apt"197get_all_potential_paths "${CLI_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}" "sources/apt"198get_all_potential_paths "${DESKTOP_ENVIRONMENTS_SEARCH_RELATIVE_DIRS}" "." "sources/apt"199get_all_potential_paths "${DESKTOP_APPGROUPS_SEARCH_RELATIVE_DIRS}" "${DESKTOP_APPGROUPS_SELECTED}" "sources/apt"200201display_alert "Adding additional apt sources"202203for apt_sources_dirpath in ${potential_paths}; do204if [[ -d "${apt_sources_dirpath}" ]]; then205for apt_source_filepath in "${apt_sources_dirpath}/"*.source; do206apt_source_filepath=$(echo $apt_source_filepath | sed -re 's/(^.*[^/])\.[^./]*$/\1/')207local new_apt_source="$(cat "${apt_source_filepath}.source")"208local apt_source_gpg_filepath="${apt_source_filepath}.gpg"209210# extract filenames211local apt_source_gpg_filename="$(basename ${apt_source_gpg_filepath})"212local apt_source_filename="$(basename ${apt_source_filepath}).list"213214display_alert "Adding APT Source ${new_apt_source}"215216if [[ "${new_apt_source}" == ppa* ]] ; then217# ppa with software-common-properties218run_on_sdcard "add-apt-repository -y -n \"${new_apt_source}\""219# add list with apt-add220# -y -> Assumes yes to all queries221# -n -> Do not update package cache after adding222if [[ -f "${apt_source_gpg_filepath}" ]]; then223display_alert "Adding GPG Key ${apt_source_gpg_filepath}"224cp "${apt_source_gpg_filepath}" "${SDCARD}/tmp/${apt_source_gpg_filename}"225run_on_sdcard "apt-key add \"/tmp/${apt_source_gpg_filename}\""226echo "APT Key returned : $?"227fi228else229# installation without software-common-properties, sources.list + key.gpg230echo "${new_apt_source}" > "${SDCARD}/etc/apt/sources.list.d/${apt_source_filename}"231if [[ -f "${apt_source_gpg_filepath}" ]]; then232display_alert "Adding GPG Key ${apt_source_gpg_filepath}"233# local apt_source_gpg_filename="$(basename ${apt_source_gpg_filepath})"234mkdir -p "${SDCARD}"/usr/share/keyrings/235cp "${apt_source_gpg_filepath}" "${SDCARD}"/usr/share/keyrings/236fi237238fi239240done241fi242done243244}245246247248249add_desktop_package_sources() {250251# Myy : I see Snap and Flatpak coming up in the next releases252# so... let's prepare for that253254add_apt_sources255256ls -l "${SDCARD}/usr/share/keyrings" >> "${DEST}"/${LOG_SUBPATH}/install.log257ls -l "${SDCARD}/etc/apt/sources.list.d" >> "${DEST}"/${LOG_SUBPATH}/install.log258cat "${SDCARD}/etc/apt/sources.list" >> "${DEST}"/${LOG_SUBPATH}/install.log259260}261262263264265desktop_postinstall ()266{267268# disable display manager for the first run269#run_on_sdcard "systemctl --no-reload disable lightdm.service >/dev/null 2>&1"270#run_on_sdcard "systemctl --no-reload disable gdm3.service >/dev/null 2>&1"271272# update packages index273run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get update >/dev/null 2>&1"274275# install per board packages276if [[ -n ${PACKAGE_LIST_DESKTOP_BOARD} ]]; then277run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get -yqq --no-install-recommends install $PACKAGE_LIST_DESKTOP_BOARD"278fi279280# install per family packages281if [[ -n ${PACKAGE_LIST_DESKTOP_FAMILY} ]]; then282run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get -yqq --no-install-recommends install $PACKAGE_LIST_DESKTOP_FAMILY"283fi284285# Compile Turbo Frame buffer for sunxi286if [[ $LINUXFAMILY == sun8i && $BRANCH == legacy ]]; then287sed '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.xml288289# enable memory reservations290echo "disp_mem_reserves=on" >> "${SDCARD}"/boot/orangepiEnv.txt291echo "extraargs=cma=96M" >> "${SDCARD}"/boot/orangepiEnv.txt292fi293294if [[ -d ${SDCARD}/etc/lightdm ]]; then295mkdir -p ${SDCARD}/etc/lightdm/lightdm.conf.d296cat <<-EOF > ${SDCARD}/etc/lightdm/lightdm.conf.d/22-orangepi-autologin.conf297[Seat:*]298autologin-user=$OPI_USERNAME299autologin-user-timeout=0300user-session=xfce301EOF302fi303304#mkdir -p /etc/gdm3305#cat <<-EOF > /etc/gdm3/custom.conf306#[daemon]307#AutomaticLoginEnable = true308#AutomaticLogin = $RealUserName309#EOF310}311312313