From 4cc6ffe410a1ec2b05d34f21e3ac5a21fecd563f Mon Sep 17 00:00:00 2001 From: Igor Date: Sun, 4 Dec 2022 16:57:04 +0100 Subject: [PATCH] Add support for desktop install [WIP] Needs https://github.com/armbian/configng/pull/3 --- functions/desktop.sh | 78 ++++++++++++++++++++++++++++++++++++++++++++ share/menu/help/help | 2 ++ test/desktop_test.sh | 63 +++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 functions/desktop.sh create mode 100755 share/menu/help/help create mode 100755 test/desktop_test.sh diff --git a/functions/desktop.sh b/functions/desktop.sh new file mode 100644 index 000000000..a12cc7221 --- /dev/null +++ b/functions/desktop.sh @@ -0,0 +1,78 @@ +#!/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 Install desktop environment +# +# @arg $1 string desktop [xfce,cinnamon,budgie,...] +# @arg $2 string username + +desktop::set_de(){ + + # Check number of arguments + [[ $# -lt 1 ]] && 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 + apt-get install --reinstall -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" --install-recommends $de lightdm lightdm-gtk-greeter + + # in case previous install was interrupted + [[ $? -eq 130 ]] && dpkg --configure -a + + # clean apt cache + apt 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/share/menu/help/help b/share/menu/help/help new file mode 100755 index 000000000..a3225bf29 --- /dev/null +++ b/share/menu/help/help @@ -0,0 +1,2 @@ +#!/bin/bash +echo "test" diff --git a/test/desktop_test.sh b/test/desktop_test.sh new file mode 100755 index 000000000..a7de7a5a9 --- /dev/null +++ b/test/desktop_test.sh @@ -0,0 +1,63 @@ +#!/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 -i variants=$(desktop::get_variants) +#check_return +#printf 'Desktop variants = %d\n' "$variants" +#os::detect_linux_version +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 +# Before +printf "\nBefore\n" +#cat /etc/default/cpufrequtils +desktop::set_de "xfce" +# After +printf "\nAfter\n" +#cat /etc/default/cpufrequtils