Skip to content

Commit

Permalink
Merge pull request #21 from mahdichi/v24.11
Browse files Browse the repository at this point in the history
fix user creating bugs
  • Loading branch information
mahdichi authored Dec 8, 2024
2 parents 3fd01ea + a6235d9 commit 9737f4f
Show file tree
Hide file tree
Showing 2 changed files with 250 additions and 63 deletions.
68 changes: 7 additions & 61 deletions userpatches/customize-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,11 @@ fxBloxCustomScript()
# read all variable from config file
source /tmp/overlay/config

#fix blutooth frimware loading error
# echo "fix blutooth"
# ln -s /lib/firmware/rtl8852bu_config /lib/firmware/rtl_bt/rtl8852bu_config.bin
# ln -s /lib/firmware/rtl8852bu_fw /lib/firmware/rtl_bt/rtl8852bu_fw.bin

fxBloxCustomScriptService;

InstallpythonPackages;

InstallDocker;
#InstallDockerOffline;

InstallFulaOTA;

Expand All @@ -76,40 +70,9 @@ fxBloxCustomScriptService()
{
echo "install fxBlox Custom Script Service"

display_alert "$BOARD" "preset configs for rootfs" "info"

# Set PRESET_NET_CHANGE_DEFAULTS to 1 to apply any network related settings below
echo "PRESET_NET_CHANGE_DEFAULTS=0" > "${SDCARD}"/root/.not_logged_in_yet

# Country code to enable power ratings and channels for your country. eg: GB US DE | https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
echo "PRESET_NET_WIFI_COUNTRYCODE='GB'" >> /root/.not_logged_in_yet

# Preset user default shell, you can choose bash or zsh
echo "PRESET_USER_SHELL=bash" >> /root/.not_logged_in_yet

# Set PRESET_CONNECT_WIRELESS=y if you want to connect wifi manually at first login
echo "PRESET_CONNECT_WIRELESS=n" >> /root/.not_logged_in_yet

# Set SET_LANG_BASED_ON_LOCATION=n if you want to choose "Set user language based on your location?" with "n" at first login
echo "SET_LANG_BASED_ON_LOCATION=y" >> /root/.not_logged_in_yet

# Preset default locale
echo "PRESET_LOCALE=en_US.UTF-8" >> /root/.not_logged_in_yet

# Preset timezone
echo "PRESET_TIMEZONE=Etc/UTC" >> /root/.not_logged_in_yet

# Preset root password
echo "PRESET_ROOT_PASSWORD=${ARMBIAN_ROOT_PASSWORD}" >> /root/.not_logged_in_yet

# Preset username
echo "PRESET_USER_NAME=${ARMBIAN_USER_NAME}" >> /root/.not_logged_in_yet

# Preset user password
echo "PRESET_USER_PASSWORD=${ARMBIAN_USER_PASSWORD}" >> /root/.not_logged_in_yet

# Preset user default realname
echo "PRESET_DEFAULT_REALNAME=${ARMBIAN_USER_NAME}" >> /root/.not_logged_in_yet
# disable armbian autoconfig
rm /root/.not_logged_in_yet

mkdir -p /usr/bin/fula/
cp /tmp/overlay/config /usr/bin/fula/
Expand All @@ -124,19 +87,19 @@ fxBloxCustomScriptService()
cat > /etc/systemd/system/fxBlox_custom_script_service.service <<- EOF
[Unit]
Description=fxBlox custom script service
After=multi-user.target network.target
After=default.target
ConditionPathExists=/root/.fxBlox_custom_script_service
[Service]
Type=oneshot
Type=simple
User=root
Group=root
ExecStart=/bin/bash /usr/bin/fxBlox_custom_script_service.sh
RemainAfterExit=yes
TimeoutStartSec=infinity
[Install]
WantedBy=multi-user.target
WantedBy=default.target
EOF
systemctl --no-reload enable fxBlox_custom_script_service.service

Expand Down Expand Up @@ -165,7 +128,7 @@ InstallDocker()

#Add Docker's official GPG key:
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do apt-get remove $pkg; done
#apt-get update

# Add Docker's official GPG key:
apt-get update
apt-get install ca-certificates curl
Expand All @@ -189,31 +152,14 @@ InstallDocker()
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
} # InstallDocker

InstallDockerOffline()
{
echo "installing docker"
apt install /tmp/overlay/docker/*.deb

#Install Docker Compose 1.29.2
echo "Docker Compose"
cp /tmp/overlay/docker/docker-compose /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

} # InstallDockerOffline

InstallFulaOTA()
{
echo "Install Fula OTA"

mkdir -p /home/$ARMBIAN_USER_NAME
#chown -R $ARMBIAN_USER_NAME:$ARMBIAN_USER_NAME /home/$ARMBIAN_USER_NAME

git clone -b main https://github.com/functionland/fula-ota /home/$ARMBIAN_USER_NAME/fula-ota

#copy offline docker
#mkdir -p /usr/bin/fula/
#cp /tmp/overlay/offline_docker/* /usr/bin/fula/
git clone --depth=1 -b main https://github.com/functionland/fula-ota /home/$ARMBIAN_USER_NAME/fula-ota

cd /home/$ARMBIAN_USER_NAME/fula-ota/docker/fxsupport/linux
bash ./fula.sh install chroot
Expand Down
245 changes: 243 additions & 2 deletions userpatches/overlay/fxBlox_custom_script_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,253 @@ if [[ -f /root/.fxBlox_custom_script_service ]]; then
# read variable from config file
source /usr/bin/fula/config

usermod -aG docker "$RealUserName"
# disable autologin
# rm -f /etc/systemd/system/[email protected]/override.conf
# rm -f /etc/systemd/system/[email protected]/override.conf
# systemctl daemon-reload

declare desktop_dm="none"
declare -i desktop_is_sddm=0 desktop_is_lightdm=0 desktop_is_gdm3=0
if [[ -f /usr/bin/sddm ]]; then
desktop_dm="sddm"
desktop_is_sddm=1
fi
if [[ -f /usr/sbin/lightdm ]]; then
desktop_dm="lightdm"
desktop_is_lightdm=1
fi
if [[ -f /usr/sbin/gdm3 ]]; then
desktop_dm="gdm3"
desktop_is_gdm3=1
fi

echo -e "\nWaiting for system to finish booting ..."
systemctl is-system-running --wait > /dev/null

# enable hiDPI support
if [[ "$(cut -d, -f1 < /sys/class/graphics/fb0/virtual_size 2> /dev/null)" -gt 1920 ]]; then
# lightdm
[[ -f /etc/lightdm/slick-greeter.conf ]] && echo "enable-hidpi = on" >> /etc/lightdm/slick-greeter.conf
# xfce
[[ -f /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml ]] && sed -i 's|<property name="WindowScalingFactor" type="int" value=".*|<property name="WindowScalingFactor" type="int" value="2">|g' /etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml

# framebuffer console larger font
setfont /usr/share/consolefonts/Uni3-TerminusBold32x16.psf.gz
fi

#set shell
USER_SHELL="bash"

SHELL_PATH=$(grep "/$USER_SHELL$" /etc/shells | tail -1)
chsh -s "$(grep -iF "/$USER_SHELL" /etc/shells | tail -1)"

# change shell for future users
sed -i "s|^SHELL=.*|SHELL=${SHELL_PATH}|" /etc/default/useradd
sed -i "s|^DSHELL=.*|DSHELL=${SHELL_PATH}|" /etc/adduser.conf

# set root password
password=$ARMBIAN_ROOT_PASSWORD
(
echo "$password"
echo "$password"
) | passwd root > /dev/null 2>&1



# create user
RealUserName=$ARMBIAN_USER_NAME
RealName=$ARMBIAN_USER_NAME
password=$ARMBIAN_USER_PASSWORD

adduser --quiet --disabled-password --home /home/"$RealUserName" --gecos "$RealName" "$RealUserName"
(
echo "$password"
echo "$password"
) | passwd "$RealUserName" > /dev/null 2>&1

mkdir -p /home/$RealUserName/
chown -R "$RealUserName":"$RealUserName" /home/"$RealUserName"/

for additionalgroup in sudo netdev audio video disk tty users games dialout plugdev input bluetooth systemd-journal ssh render docker; do
usermod -aG "${additionalgroup}" "${RealUserName}" 2> /dev/null
done

# fix for gksu in Xenial
touch /home/"$RealUserName"/.Xauthority
chown "$RealUserName":"$RealUserName" /home/"$RealUserName"/.Xauthority
RealName="$(awk -F":" "/^${RealUserName}:/ {print \$5}" < /etc/passwd | cut -d',' -f1)"
[ -z "$RealName" ] && RealName="$RealUserName"
echo -e "\nDear \e[0;92m${RealName}\x1B[0m, your account \e[0;92m${RealUserName}\x1B[0m has been created and is sudo enabled."
echo -e "Please use this account for your daily work from now on.\n"
rm -f /root/.not_logged_in_yet
chmod +x /etc/update-motd.d/*
# set up profile sync daemon on desktop systems
if command -v psd > /dev/null 2>&1; 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

# re-enable passing locale environment via ssh
sed -e '/^#AcceptEnv LANG/ s/^#//' -i /etc/ssh/sshd_config
# restart sshd daemon
systemctl restart ssh.service


# rpardini: hacks per-dm, very much legacy stuff that works by a miracle
if [[ "${desktop_dm}" == "lightdm" ]] && [ -n "$RealName" ]; then

mkdir -p /etc/lightdm/lightdm.conf.d
cat <<- EOF > /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf
[Seat:*]
autologin-user=$RealUserName
autologin-user-timeout=0
user-session=xfce
EOF

# select gnome session (has to be first or it breaks budgie/cinnamon desktop autologin and user-session)
# @TODO: remove this, gnome should use gdm3, not lightdm
[[ -x $(command -v gnome-session) ]] && sed -i "s/user-session.*/user-session=ubuntu/" /etc/lightdm/lightdm.conf.d/11-armbian.conf
[[ -x $(command -v gnome-session) ]] && sed -i "s/user-session.*/user-session=ubuntu/" /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf

# select awesome session
[[ -x $(command -v awesome) ]] && sed -i "s/user-session.*/user-session=awesome/" /etc/lightdm/lightdm.conf.d/11-armbian.conf
[[ -x $(command -v awesome) ]] && sed -i "s/user-session.*/user-session=awesome/" /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf

# select budgie session
[[ -x $(command -v budgie-desktop) ]] && sed -i "s/user-session.*/user-session=budgie-desktop/" /etc/lightdm/lightdm.conf.d/11-armbian.conf
[[ -x $(command -v budgie-desktop) ]] && sed -i "s/user-session.*/user-session=budgie-desktop/" /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf

# select cinnamon session
[[ -x $(command -v cinnamon) ]] && sed -i "s/user-session.*/user-session=cinnamon/" /etc/lightdm/lightdm.conf.d/11-armbian.conf
[[ -x $(command -v cinnamon) ]] && sed -i "s/user-session.*/user-session=cinnamon/" /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf

# select deepin session
[[ -x $(command -v deepin-wm) ]] && sed -i "s/user-session.*/user-session=deepin/" /etc/lightdm/lightdm.conf.d/11-armbian.conf
[[ -x $(command -v deepin-wm) ]] && sed -i "s/user-session.*/user-session=deepin/" /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf

# select ice-wm session
[[ -x $(command -v icewm-session) ]] && sed -i "s/user-session.*/user-session=icewm-session/" /etc/lightdm/lightdm.conf.d/11-armbian.conf
[[ -x $(command -v icewm-session) ]] && sed -i "s/user-session.*/user-session=icewm-session/" /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf

# select i3 session
[[ -x $(command -v i3) ]] && sed -i "s/user-session.*/user-session=i3/" /etc/lightdm/lightdm.conf.d/11-armbian.conf
[[ -x $(command -v i3) ]] && sed -i "s/user-session.*/user-session=i3/" /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf

# select lxde session
[[ -x $(command -v startlxde) ]] && sed -i "s/user-session.*/user-session=LXDE/" /etc/lightdm/lightdm.conf.d/11-armbian.conf
[[ -x $(command -v startlxde) ]] && sed -i "s/user-session.*/user-session=LXDE/" /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf

# select lxqt session
[[ -x $(command -v startlxqt) ]] && sed -i "s/user-session.*/user-session=lxqt/" /etc/lightdm/lightdm.conf.d/11-armbian.conf
[[ -x $(command -v startlxqt) ]] && sed -i "s/user-session.*/user-session=lxqt/" /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf

# select mate session
[[ -x $(command -v mate-wm) ]] && sed -i "s/user-session.*/user-session=mate/" /etc/lightdm/lightdm.conf.d/11-armbian.conf
[[ -x $(command -v mate-wm) ]] && sed -i "s/user-session.*/user-session=mate/" /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf

# select sway wayland session
[[ -x $(command -v sway) ]] && sed -i "s/user-session.*/user-session=sway/" /etc/lightdm/lightdm.conf.d/11-armbian.conf
[[ -x $(command -v sway) ]] && sed -i "s/user-session.*/user-session=sway/" /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf

# select xmonad session
[[ -x $(command -v xmonad) ]] && sed -i "s/user-session.*/user-session=xmonad/" /etc/lightdm/lightdm.conf.d/11-armbian.conf
[[ -x $(command -v xmonad) ]] && sed -i "s/user-session.*/user-session=xmonad/" /etc/lightdm/lightdm.conf.d/22-armbian-autologin.conf

ln -sf /lib/systemd/system/lightdm.service /etc/systemd/system/display-manager.service

if [[ -f /var/run/resize2fs-reboot ]]; then
# Let the user reboot now otherwise start desktop environment
printf "\n\n\e[0;91mWarning: a reboot is needed to finish resizing the filesystem \x1B[0m \n"
printf "\e[0;91mPlease reboot the system now \x1B[0m \n\n"
else
echo -e "\n\e[1m\e[39mNow starting desktop environment...\x1B[0m\n"
sleep 1
service lightdm start 2> /dev/null
if [ -f /root/.desktop_autologin ]; then
rm /root/.desktop_autologin
else
systemctl -q enable armbian-disable-autologin.timer
systemctl start armbian-disable-autologin.timer
fi
# logout if logged at console
who -la | grep root | grep -q tty1 && exit 1
fi

elif [[ "${desktop_dm}" == "gdm3" ]] && [ -n "$RealName" ]; then
# 1st run goes without login
mkdir -p /etc/gdm3
cat <<- EOF > /etc/gdm3/custom.conf
[daemon]
AutomaticLoginEnable = true
AutomaticLogin = $RealUserName
EOF

ln -sf /lib/systemd/system/gdm3.service /etc/systemd/system/display-manager.service

if [[ -f /var/run/resize2fs-reboot ]]; then
# Let the user reboot now otherwise start desktop environment
printf "\n\n\e[0;91mWarning: a reboot is needed to finish resizing the filesystem \x1B[0m \n"
printf "\e[0;91mPlease reboot the system now \x1B[0m \n\n"
else
echo -e "\n\e[1m\e[39mNow starting desktop environment...\x1B[0m\n"
sleep 1
service gdm3 start 2> /dev/null
if [ -f /root/.desktop_autologin ]; then
rm /root/.desktop_autologin
else
(
sleep 20
sed -i "s/AutomaticLoginEnable.*/AutomaticLoginEnable = false/" /etc/gdm3/custom.conf
) &
fi
# logout if logged at console
who -la | grep root | grep -q tty1 && exit 1
fi
elif [[ "${desktop_dm}" == "sddm" ]] && [ -n "$RealName" ]; then

# create default sddm config
mkdir -p /etc/sddm.conf.d
cat <<- EOF > /etc/sddm.conf.d/armbian.conf
[Theme]
Current=breeze
[General]
InputMethod=none
EOF

# 1st run goes without login
cat <<- EOF > /etc/sddm.conf.d/autologin.conf
[Autologin]
User=$RealUserName
EOF
echo -e "\n\e[1m\e[39mNow starting desktop environment via ${desktop_dm}...\x1B[0m\n"
systemctl enable --now sddm 2> /dev/null

if [ -f /root/.desktop_autologin ]; then
rm /root/.desktop_autologin
else
systemctl -q enable armbian-disable-autologin.timer
fi
# logout if logged at console
who -la | grep root | grep -q tty1 && exit 1

else
# no display manager detected -> clear screen and show motd
clear
run-parts --lsbsysinit /etc/update-motd.d

# Display reboot recommendation if necessary
if [[ -f /var/run/resize2fs-reboot ]]; then
printf "\n\n\e[0;91mWarning: a reboot is needed to finish resizing the filesystem \x1B[0m \n"
printf "\e[0;91mPlease reboot the system now \x1B[0m \n\n"
fi
fi


rm -f /root/.fxBlox_custom_script_service
sync
sleep 1
systemctl --no-reload disable fxBlox_custom_script_service.service
rm -rf /etc/systemd/system/fxBlox_custom_script_service.service
#reboot
reboot
fi

0 comments on commit 9737f4f

Please sign in to comment.