From c67bb3127110d4f9ae6b2d96ce52bc6e432b3082 Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Fri, 2 Mar 2018 16:27:45 +0100 Subject: [PATCH] Desktop package building RFC #2 with proper post install scripting. Works but we need more testing before use. Disabled for now. --- lib/desktop-ng.sh | 204 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 174 insertions(+), 30 deletions(-) diff --git a/lib/desktop-ng.sh b/lib/desktop-ng.sh index ce9042b9af..711ff28475 100644 --- a/lib/desktop-ng.sh +++ b/lib/desktop-ng.sh @@ -9,59 +9,204 @@ install_desktop () { - display_alert "Installing desktop" "XFCE" "info" + display_alert "Creating desktop package" "XFCE" "info" # temporally. move to configuration.sh once this file gets in action - PACKAGE_LIST_DESKTOP="$PACKAGE_LIST_DESKTOP vibrancy-colors" + PACKAGE_LIST_DESKTOP="$PACKAGE_LIST_DESKTOP numix-icon-theme" # cleanup package list PACKAGE_LIST_DESKTOP=${PACKAGE_LIST_DESKTOP// /,}; PACKAGE_LIST_DESKTOP=${PACKAGE_LIST_DESKTOP//[[:space:]]/} - local destination=$SRC/.tmp/armbian-desktop_${REVISION}_${ARCH} + local destination=$SRC/.tmp/armbian-desktop-${RELEASE}_${REVISION}_all rm -rf $destination mkdir -p $destination/DEBIAN # set up control file cat <<-EOF > $destination/DEBIAN/control - Package: armbian-desktop + Package: armbian-desktop-${RELEASE} Version: $REVISION - Architecture: $ARCH + Architecture: all Maintainer: $MAINTAINER <$MAINTAINERMAIL> Installed-Size: 1 - Section: kernel + Section: xorg Priority: optional Depends: ${PACKAGE_LIST_DESKTOP//[:space:]+/,} - Provides: armbian-desktop + Provides: armbian-desktop-${RELEASE} Description: Armbian generic desktop EOF - # set up pre install script + # set up templates + cat <<-EOF > $destination/DEBIAN/templates + Template: armbian-desktop-stretch/desktop_username + Type: string + Description: Please provide or create a username under which a desktop should run. + + Template: armbian-desktop-stretch/desktop_password + Type: password + Description: Choose a password. + + Template: armbian-desktop-stretch/desktop_fullname + Type: string +Description: Your full name (eg. John Doe) + EOF + + # set up a config file + cat <<-EOF > $destination/DEBIAN/config + #!/bin/sh -e + + # Source debconf library. + . /usr/share/debconf/confmodule + db_version 2.0 + + # This conf script is capable of backing up + db_capb backup + + STATE=1 + while [ "\$STATE" != 0 -a "\$STATE" != 4 ]; do + case "\$STATE" in + 1) + # Ask for username + db_input high armbian-desktop-stretch/desktop_username || true + ;; + + 2) + # Ask for password + db_input high armbian-desktop-stretch/desktop_password || true + ;; + + 3) + # Ask for full name + db_input high armbian-desktop-stretch/desktop_fullname || true + ;; + esac + + if db_go; then + STATE=\$((\$STATE + 1)) + else + STATE=\$((\$STATE - 1)) + fi + done + EOF + chmod 755 $destination/DEBIAN/config + cat <<-EOF > $destination/DEBIAN/postinst - #!/bin/sh - source /etc/armbian-release - mv /etc/chromium-browser/armbian /etc/chromium-browser/default + #!/bin/sh -e + . /usr/share/debconf/confmodule + db_version 2.0 + + case "\$1" in + configure) + if db_get armbian-desktop-stretch/desktop_username; then + RealUserName="\$RET" + fi + + if db_get armbian-desktop-stretch/desktop_password; then + RealUserPass="\$RET" + fi + + if db_get armbian-desktop-stretch/desktop_fullname; then + RealUserFull="\$RET" + fi + + # check if exist + if [ -z "\$(getent passwd \${RealUserName})" ]; then + echo "Trying to add user \${RealUserName}" + adduser \${RealUserName} --gecos "\${RealUserFull}" --disabled-password + echo "\${RealUserName}:\${RealUserPass}" | sudo chpasswd + else + echo "Username \${RealUserName} exists." + fi + + # add user to groups + for additionalgroup in sudo netdev audio video dialout plugdev bluetooth systemd-journal ssh; do + usermod -aG \${additionalgroup} \${RealUserName} 2>/dev/null + done + + # fix for gksu in Xenial + touch /home/\${RealUserName}/.Xauthority + chown \${RealUserName}:\${RealUserName} /home/\${RealUserName}/.Xauthority + + # set up profile sync daemon on desktop systems + which psd >/dev/null 2>&1 + if [ \$? -eq 0 ]; then + echo "\${RealUserName} ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper" >> /etc/sudoers + touch /home/\${RealUserName}/.activate_psd + chown \${RealUserName}:\${RealUserName} /home/\${RealUserName}/.activate_psd + fi + + sed -i "s/NODM_USER=\(.*\)/NODM_USER=\${RealUserName}/" /etc/default/nodm + sed -i "s/NODM_ENABLED=\(.*\)/NODM_ENABLED=true/g" /etc/default/nodm + echo "Now (re)starting desktop environment...\n" + sleep 3 + service nodm stop + sleep 1 + service nodm start + ;; + esac + + db_stop + exit 0 + EOF + + + # set up pre install script + cat <<-EOF > $destination/DEBIAN/postinst.1 + #!/bin/bash # Disable Pulseaudio timer scheduling which does not work with sndhdmi driver if [ -f /etc/pulse/default.pa ]; then sed "s/load-module module-udev-detect$/& tsched=0/g" -i /etc/pulse/default.pa; fi + # Enable network manager - if [ -f /etc/NetworkManager/NetworkManager.conf ]]; then + if [[ -f /etc/NetworkManager/NetworkManager.conf ]]; then sed "s/managed=\(.*\)/managed=true/g" -i /etc/NetworkManager/NetworkManager.conf # Disable dns management withing NM sed "s/\[main\]/\[main\]\ndns=none/g" -i /etc/NetworkManager/NetworkManager.conf printf '[keyfile]\nunmanaged-devices=interface-name:p2p0\n' >> /etc/NetworkManager/NetworkManager.conf fi - # Compile Turbo Frame buffer for sunxi - if [ $LINUXFAMILY = sun4i ] || [ $LINUXFAMILY = sun7i ] || [ $LINUXFAMILY = sun8i ] && [ $BRANCH = next ]; - sed 's/name="use_compositing" type="bool" value="true"/name="use_compositing" type="bool" value="false"/' -i /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml - sed 's/name="use_compositing" type="bool" value="true"/name="use_compositing" type="bool" value="false"/' -i /root/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml - if [ -n "$SUDO_USER" ]; then - sed 's/name="use_compositing" type="bool" value="true"/name="use_compositing" type="bool" value="false"/' -i /${SUDO_USER}/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml; - fi - # enable memory reservations - if ! grep disp_mem_reserves /boot/armbianEnv.txt; echo "disp_mem_reserves=on" >> /boot/armbianEnv.txt; fi + + # adding or choosing a user + function add_user { + read -t 0 temp + echo -e "\nPlease provide a username (eg. your forename): \c" + read -e username + RealUserName="\$(echo "\$username" | tr '[:upper:]' '[:lower:]' | tr -d -c '[:alnum:]')" + if [ -z "\$(getent passwd \$RealUserName)" ]; then + echo "Trying to add user \$RealUserName" + adduser \$RealUserName + exitstatus=\$? + else + echo "Using existing user \$RealUserName" + exitstatus=0 + fi + } + + while [[ "\$exitstatus" != "0" ]]; do + add_user + done + + # add user to groups + for additionalgroup in sudo netdev audio video dialout plugdev bluetooth systemd-journal ssh; do + usermod -aG \${additionalgroup} \${RealUserName} 2>/dev/null + done + + # fix for gksu in Xenial + touch /home/\$RealUserName/.Xauthority + chown \$RealUserName:\$RealUserName /home/\$RealUserName/.Xauthority + + # set up profile sync daemon on desktop systems + which psd >/dev/null 2>&1 + if [ \$? -eq 0 ]; then + echo -e "\${RealUserName} ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper" >> /etc/sudoers + touch /home/\${RealUserName}/.activate_psd + chown \$RealUserName:\$RealUserName /home/\${RealUserName}/.activate_psd fi - # copy skel to sudo user - if [ -n "$SUDO_USER" ]; then cp -R /etc/skel /home/$SUDO_USER; fi - # TODO: change ownership/fix permissions + + sed -i "s/NODM_USER=\(.*\)/NODM_USER=\${RealUserName}/" /etc/default/nodm + sed -i "s/NODM_ENABLED=\(.*\)/NODM_ENABLED=true/g" /etc/default/nodm + echo -e "\n\e[1m\e[39mNow starting desktop environment...\x1B[0m\n" + sleep 3 + service nodm stop + sleep 1 + service nodm start exit 0 EOF chmod 755 $destination/DEBIAN/postinst @@ -71,13 +216,13 @@ install_desktop () cp $SRC/packages/blobs/desktop/desktop-splash/desktop-splash.service $destination/etc/systemd/system/desktop-splash.service # install optimized chromium configuration - mkdir -p $destination/etc/chromium-browser - cp $SRC/packages/blobs/desktop/chromium.conf $destination/etc/chromium-browser/armbian + mkdir -p $destination/etc/chromium-browser $destination/etc/chromium.d + cp $SRC/packages/blobs/desktop/chromium.conf $destination/etc/chromium-browser/default + cp $SRC/packages/blobs/desktop/chromium.conf $destination/etc/chromium.d/chromium.conf # install default desktop settings - mkdir -p $destination/etc/skel $destination/root + mkdir -p $destination/etc/skel cp -R $SRC/packages/blobs/desktop/skel/. $destination/etc/skel - cp -R $SRC/packages/blobs/desktop/skel/. $destination/root # install dedicated startup icons mkdir -p $destination/usr/share/pixmaps $destination/etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/ @@ -94,10 +239,9 @@ install_desktop () [[ -f $SDCARD/etc/default/nodm ]] && sed "s/NODM_ENABLED=\(.*\)/NODM_ENABLED=false/g" -i $SDCARD/etc/default/nodm [[ -d $SDCARD/etc/lightdm ]] && chroot $SDCARD /bin/bash -c "systemctl --no-reload disable lightdm.service >/dev/null 2>&1" - # create board DEB file display_alert "Building Armbian desktop package" "$CHOSEN_ROOTFS" "info" - fakeroot dpkg-deb -b $destination ${destination}.deb + fakeroot dpkg-deb -b $destination ${destination}.deb >/dev/null mkdir -p $DEST/debs/ mv ${destination}.deb $DEST/debs/ # cleanup