diff --git a/functions/desktop.sh b/functions/desktop.sh new file mode 100644 index 00000000..251b3535 --- /dev/null +++ b/functions/desktop.sh @@ -0,0 +1,110 @@ +#!/bin/bash +# +# Copyright (c) Authors: http://www.armbian.com/authors, info@armbian.com +# +# This file is licensed under the terms of the GNU General Public +# License version 2. This program is licensed "as is" without any +# warranty of any kind, whether express or implied. +# +# CPU related functions. See https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt for more info. +# + +# @description Return list of available desktops +# +# @example +# desktop::get_variants +# echo $? +# #Output +# 0 +# +# @exitcode 0 If successful. +# +# @stdout Space delimited string of virtual desktop packages. +desktop::get_variants(){ + printf '%s\n' "$(apt list 2>/dev/null | grep armbian | grep desktop | grep -v bsp | cut -d" " -f1 | cut -d"/" -f1)" +} + +# @description Display sessions per desktops +# +# @arg $1 string desktop [xfce,cinnamon,budgie,...] +# +desktop::get_session(){ + + # Check number of arguments + [[ $# -lt 1 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 2 + case $1 in + gnome) + printf '%s\n' "ubuntu wayland" + ;; + kde-plasma) + printf '%s\n' "plasmawayland" + ;; + budgie) + printf '%s\n' "budgie-desktop" + ;; + *) + printf '%s\n' "$1" + ;; + esac +} + +# @description Install desktop environment +# +# @arg $1 string desktop [xfce,cinnamon,budgie,...] +# @arg $2 string username +# @arg $3 string session (xfce,wayland,budgie-desktop) +# @arg $4 dryrun + +desktop::set_de(){ + + declare -a sessions=( $(string::split "$(desktop::get_session $1)" "") ) + printf "\nAll sessions for xfce\n" + printf "%s\n" "${sessions[@]}" | collection::each "print_func" + + + # Check number of arguments + [[ $# -lt 3 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 2 + + # Read arguments and get os codename + local de="armbian-$(os::detect_linux_codename)-desktop-$1" + local username=$2 + + # Return desktops as array + declare -a desktops=( $(string::split "$(desktop::get_variants)" " ") ) + + # Validate parameter + array::contains "$de" ${desktops[@]} + [[ $? != 0 ]] && printf "%s: Invalid desktop\n" "${FUNCNAME[0]}" && return 3 + + # Install desktop + COMMAND="apt-get install -y --reinstall -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --install-recommends $de lightdm lightdm-gtk-greeter" + [[ $4 == dryrun ]] && echo $COMMAND || eval $COMMAND + + # in case previous install was interrupted + [[ $? -eq 130 ]] && dpkg --configure -a + + # clean apt cache + apt-get -y clean + + # add user to groups + for additionalgroup in sudo netdev audio video dialout plugdev input bluetooth systemd-journal ssh; do + usermod -aG ${additionalgroup} ${username} 2>/dev/null + done + + # set up profile sync daemon on desktop systems + which psd >/dev/null 2>&1 + if [[ $? -eq 0 && -z $(grep overlay-helper /etc/sudoers) ]]; then + echo "${username} ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper" >> /etc/sudoers + touch /home/${username}/.activate_psd + fi + + # configure login manager + mkdir -p /etc/lightdm/lightdm.conf.d + echo "[Seat:*]" > /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf + echo "autologin-user=${username}" >> /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf + echo "autologin-user-timeout=0" >> /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf + echo "user-session=xfce" >> /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf + ln -s /lib/systemd/system/lightdm.service /etc/systemd/system/display-manager.service >/dev/null 2>&1 + service lightdm start >/dev/null 2>&1 + +} diff --git a/test/desktop_test.sh b/test/desktop_test.sh new file mode 100755 index 00000000..c79aff65 --- /dev/null +++ b/test/desktop_test.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# +# Copyright (c) Authors: http://www.armbian.com/authors, info@armbian.com +# +# This file is licensed under the terms of the GNU General Public +# License version 2. This program is licensed "as is" without any +# warranty of any kind, whether express or implied. +# +# CPU related tests. +# + +cur_dir=$(pwd) +# Source bash-utility and cpu functions (this will word under sudo) +source "$cur_dir/../functions/bash-utility-master/src/string.sh" +source "$cur_dir/../functions/bash-utility-master/src/collection.sh" +source "$cur_dir/../functions/bash-utility-master/src/array.sh" +source "$cur_dir/../functions/bash-utility-master/src/check.sh" +source "$cur_dir/../functions/bash-utility-master/src/os.sh" +source "$cur_dir/../functions/desktop.sh" + +# @description Print value from collection. +# +# @example +# collection::each "print_func" +# #Output +# Value in collection +print_func(){ + printf "%s\n" "$1" + return 0 + } + +# @description Check function exit code and exit script if != 0. +# +# @example +# check_return +# #Output +# Nothing +check_return(){ + if [ "$?" -ne 0 ]; then + exit 1 + fi + } + +# Get desktops +declare -a desktops=( $(string::split "$(desktop::get_variants)" " ") ) +check_return +printf "\nAll desktops\n" +# Print all values in collection +printf "%s\n" "${desktops[@]}" | collection::each "print_func" + +# Are we running as sudo? +[[ "$EUID" != 0 ]] && printf "Must call desktop::set_de as sudo\n" && exit 1 + +# +# desktop, user, session +# + +desktop::set_de "gnome" "guest" "xfce" "dryrun" \ No newline at end of file