Skip to content

Commit

Permalink
Add support for desktop install [WIP]
Browse files Browse the repository at this point in the history
Needs #3
  • Loading branch information
igorpecovnik committed Dec 4, 2022
1 parent cb3f236 commit 4cc6ffe
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
78 changes: 78 additions & 0 deletions functions/desktop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash
#
# Copyright (c) Authors: http://www.armbian.com/authors, [email protected]
#
# 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

}
2 changes: 2 additions & 0 deletions share/menu/help/help
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo "test"
63 changes: 63 additions & 0 deletions test/desktop_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
#
# Copyright (c) Authors: http://www.armbian.com/authors, [email protected]
#
# 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

0 comments on commit 4cc6ffe

Please sign in to comment.