Commit 5beffbd8 authored by Igor Pecovnik's avatar Igor Pecovnik
Browse files

Moving user creation to a separate function and started with network manager...

Moving user creation to a separate function and started with network manager static / dynamic editor which not working properly yet.
parent c3bb1fda
...@@ -199,7 +199,11 @@ function jobs () ...@@ -199,7 +199,11 @@ function jobs ()
echo -e "DHCP=ipv4" >>$filename echo -e "DHCP=ipv4" >>$filename
fi fi
else else
create_if_config "$DEFAULT_ADAPTER" "$DEFAULT_ADAPTER" "dynamic" > /etc/network/interfaces if [[ -n $(LC_ALL=C nmcli device status | grep $DEFAULT_ADAPTER | grep connected) ]]; then
nmcli connection delete uuid $(LC_ALL=C nmcli -f UUID,DEVICE connection show | grep $DEFAULT_ADAPTER | awk '{print $1}')
else
create_if_config "$DEFAULT_ADAPTER" "$DEFAULT_ADAPTER" "dynamic" > /etc/network/interfaces
fi
fi fi
fi fi
...@@ -209,7 +213,11 @@ function jobs () ...@@ -209,7 +213,11 @@ function jobs ()
if [[ -n $SYSTEMDNET ]]; then if [[ -n $SYSTEMDNET ]]; then
systemd_ip_editor "${DEFAULT_ADAPTER}" systemd_ip_editor "${DEFAULT_ADAPTER}"
else else
ip_editor "$DEFAULT_ADAPTER" "$DEFAULT_ADAPTER" "/etc/network/interfaces" if [[ -n $(LC_ALL=C nmcli device status | grep $DEFAULT_ADAPTER | grep connected) ]]; then
nm_ip_editor "$DEFAULT_ADAPTER"
else
ip_editor "$DEFAULT_ADAPTER" "$DEFAULT_ADAPTER" "/etc/network/interfaces"
fi
fi fi
fi fi
;; ;;
...@@ -711,9 +719,7 @@ function jobs () ...@@ -711,9 +719,7 @@ function jobs ()
&& echo "/usr/sbin/nodm" > /etc/X11/default-display-manager && \ && echo "/usr/sbin/nodm" > /etc/X11/default-display-manager && \
sed -i "s/^NODM_ENABLED=.*/NODM_ENABLED=true/" /etc/default/nodm && service nodm start sed -i "s/^NODM_ENABLED=.*/NODM_ENABLED=true/" /etc/default/nodm && service nodm start
else else
debconf-apt-progress -- apt-get update configure_desktop
debconf-apt-progress -- apt-get -y install armbian-desktop-${DISTROID}
configure-desktop
fi fi
fi fi
;; ;;
......
...@@ -245,6 +245,34 @@ function description ...@@ -245,6 +245,34 @@ function description
} }
#-----------------------------------------------------------------------------------------------------------------------------------------#
# edit ip address witing network manager
#
function nm_ip_editor ()
{
exec 3>&1
dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1
\n " 12 38 0 \
"Address:" 1 1 "$address" 1 15 15 0 \
"Netmask:" 2 1 "$netmask" 2 15 15 0 \
"Gateway:" 3 1 "$gateway" 3 15 15 0 \
2>&1 1>&3 | {
read -r address;read -r netmask;read -r gateway
if [[ $? = 0 ]]; then
localuuid=$(LC_ALL=C nmcli -f UUID,DEVICE connection show | grep $1 | awk '{print $1}')
nmcli con mod $localuuid ipv4.method manual ipv4.addresses "$address/$netmask $gateway" ipv4.dns "8.8.8.8,$gateway"
nmcli c down $localuuid
sleep 2
nmcli c up $localuuid
fi
}
exit
}
#-----------------------------------------------------------------------------------------------------------------------------------------#
# edit ip address
#
function systemd_ip_editor () function systemd_ip_editor ()
{ {
local filename="/etc/systemd/network/10-$1.network" local filename="/etc/systemd/network/10-$1.network"
...@@ -494,11 +522,10 @@ function get_h3modes () ...@@ -494,11 +522,10 @@ function get_h3modes ()
fi fi
} }
function add_choose_user ()
#-----------------------------------------------------------------------------------------------------------------------------------------# #-----------------------------------------------------------------------------------------------------------------------------------------#
# configure armbian desktop # create or pick unprivileged user
# #
function configure-desktop ()
{ {
IFS=$'\r\n' IFS=$'\r\n'
GLOBIGNORE='*' GLOBIGNORE='*'
...@@ -511,41 +538,63 @@ function configure-desktop () ...@@ -511,41 +538,63 @@ function configure-desktop ()
done done
LIST_LENGHT=$((${#LIST[@]}/2)); LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 1 ]; then if [ "$LIST_LENGHT" -eq 0 ]; then
DESKTOP_USER=${USERS[0]} dialog --backtitle "$BACKTITLE" --title " Notice " --msgbox "\nWe didn't find any unprivileged user with sudo rights which is required to run this service.\
\n\nPress enter to create one!" 10 48
read -t 0 temp
echo -e "\nPlease provide a username (eg. your forename) or leave blank for canceling user creation: \c"
read -e username
CHOSEN_USER="$(echo "$username" | tr '[:upper:]' '[:lower:]' | tr -d -c '[:alnum:]')"
[ -z "$CHOSEN_USER" ] && return
echo "Trying to add user $CHOSEN_USER"
adduser $CHOSEN_USER || return
elif [ "$LIST_LENGHT" -eq 1 ]; then
CHOSEN_USER=${USERS[0]}
else else
exec 3>&1 exec 3>&1
DESKTOP_USER=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \ CHOSEN_USER=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
--title "Select interface" --clear --menu "" $((6+${LIST_LENGHT})) 40 15 "${LIST[@]}" 2>&1 1>&3) --title "Select unprivileged user" --clear --menu "" $((6+${LIST_LENGHT})) 40 15 "${LIST[@]}" 2>&1 1>&3)
exec 3>&- exec 3>&-
fi fi
}
# install nodm
debconf-apt-progress -- apt-get -y -qq install nodm
# add user to groups #-----------------------------------------------------------------------------------------------------------------------------------------#
for additionalgroup in sudo netdev audio video dialout plugdev bluetooth systemd-journal ssh; do # configure armbian desktop
usermod -aG ${additionalgroup} ${DESKTOP_USER} 2>/dev/null #
done function configure_desktop ()
{
add_choose_user
if [ -n "$CHOSEN_USER" ]; then
# install desktop and nodm
debconf-apt-progress -- apt-get update
debconf-apt-progress -- apt-get -y install armbian-desktop-${DISTROID}
DEBIAN_FRONTEND=noninteractive debconf-apt-progress -- apt-get -y -qq install nodm
# add user to groups
for additionalgroup in sudo netdev audio video dialout plugdev bluetooth systemd-journal ssh; do
usermod -aG ${additionalgroup} ${CHOSEN_USER} 2>/dev/null
done
# fix for gksu in Xenial # fix for gksu in Xenial
touch /home/${DESKTOP_USER}/.Xauthority touch /home/${CHOSEN_USER}/.Xauthority
cp -R /etc/skel/. /home/${DESKTOP_USER} cp -R /etc/skel/. /home/${CHOSEN_USER}
# set up profile sync daemon on desktop systems # set up profile sync daemon on desktop systems
which psd >/dev/null 2>&1 which psd >/dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "${DESKTOP_USER} ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper" >> /etc/sudoers echo "${CHOSEN_USER} ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper" >> /etc/sudoers
touch /home/${DESKTOP_USER}/.activate_psd touch /home/${CHOSEN_USER}/.activate_psd
fi fi
sed -i "s/NODM_USER=\(.*\)/NODM_USER=${DESKTOP_USER}/" /etc/default/nodm sed -i "s/NODM_USER=\(.*\)/NODM_USER=${CHOSEN_USER}/" /etc/default/nodm
sed -i "s/NODM_ENABLED=\(.*\)/NODM_ENABLED=true/g" /etc/default/nodm sed -i "s/NODM_ENABLED=\(.*\)/NODM_ENABLED=true/g" /etc/default/nodm
chown -R ${DESKTOP_USER}:${DESKTOP_USER} /home/${DESKTOP_USER}/. chown -R ${CHOSEN_USER}:${CHOSEN_USER} /home/${CHOSEN_USER}/.
sleep 3 sleep 3
service nodm stop service nodm stop
sleep 1 sleep 1
service nodm start service nodm start
fi
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment