mirror of
https://github.com/armbian/build
synced 2025-09-24 19:47:06 +07:00
armbian-firstlogin: fix shellcheck issues (#4494)
Fix all shellcheck issues, as well as some formatting/indentation.
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
# warranty of any kind, whether express or implied.
|
# warranty of any kind, whether express or implied.
|
||||||
|
|
||||||
# read distribution status
|
# read distribution status
|
||||||
|
# shellcheck source=/dev/null
|
||||||
[[ -f /etc/lsb-release ]] && . /etc/lsb-release
|
[[ -f /etc/lsb-release ]] && . /etc/lsb-release
|
||||||
[[ -f /etc/os-release ]] && . /etc/os-release
|
[[ -f /etc/os-release ]] && . /etc/os-release
|
||||||
[[ -z "$DISTRIB_CODENAME" ]] && DISTRIB_CODENAME="${VERSION_CODENAME}"
|
[[ -z "$DISTRIB_CODENAME" ]] && DISTRIB_CODENAME="${VERSION_CODENAME}"
|
||||||
@@ -72,7 +73,7 @@ read_password()
|
|||||||
set_shell()
|
set_shell()
|
||||||
{
|
{
|
||||||
|
|
||||||
optionsAudits=($(grep "zsh\|/bash" /etc/shells | sed 's/\/bin\///g' | sed 's/\/usr//g' | uniq))
|
readarray -t optionsAudits <<<"$(grep "zsh\|/bash" /etc/shells | sed 's/\/bin\///g' | sed 's/\/usr//g' | uniq)"
|
||||||
USER_SHELL="bash"
|
USER_SHELL="bash"
|
||||||
|
|
||||||
if [[ "${#optionsAudits[@]}" -gt 1 ]]; then
|
if [[ "${#optionsAudits[@]}" -gt 1 ]]; then
|
||||||
@@ -82,9 +83,9 @@ set_shell()
|
|||||||
echo -e "\nChoose default system command shell:\n"
|
echo -e "\nChoose default system command shell:\n"
|
||||||
for o in "${optionsAudits[@]}"; do
|
for o in "${optionsAudits[@]}"; do
|
||||||
echo "$i) $o"
|
echo "$i) $o"
|
||||||
let i++
|
(( i++ )) || true
|
||||||
done
|
done
|
||||||
read -n1 -s reply
|
read -r -n1 -s reply
|
||||||
case $reply in
|
case $reply in
|
||||||
"1"|"${optionsAudits[0]}") USER_SHELL="${optionsAudits[0]}"; break;;
|
"1"|"${optionsAudits[0]}") USER_SHELL="${optionsAudits[0]}"; break;;
|
||||||
"2"|"${optionsAudits[1]}") USER_SHELL="${optionsAudits[1]}"; break;;
|
"2"|"${optionsAudits[1]}") USER_SHELL="${optionsAudits[1]}"; break;;
|
||||||
@@ -92,9 +93,9 @@ set_shell()
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
SHELL_PATH=$(grep /$USER_SHELL$ /etc/shells | tail -1)
|
SHELL_PATH=$(grep "/$USER_SHELL$" /etc/shells | tail -1)
|
||||||
|
|
||||||
chsh -s $(grep -iF "/$USER_SHELL" /etc/shells | tail -1)
|
chsh -s "$(grep -iF "/$USER_SHELL" /etc/shells | tail -1)"
|
||||||
echo -e "\nShell: \x1B[92m${USER_SHELL^^}\x1B[0m"
|
echo -e "\nShell: \x1B[92m${USER_SHELL^^}\x1B[0m"
|
||||||
|
|
||||||
# change shell for future users
|
# change shell for future users
|
||||||
@@ -107,7 +108,7 @@ set_timezone_and_locales()
|
|||||||
{
|
{
|
||||||
|
|
||||||
# Grab this machine's public IP address
|
# Grab this machine's public IP address
|
||||||
PUBLIC_IP=`curl --max-time 5 -s https://ipinfo.io/ip`
|
PUBLIC_IP=$(curl --max-time 5 -s https://ipinfo.io/ip)
|
||||||
|
|
||||||
# Check if we have wireless adaptor
|
# Check if we have wireless adaptor
|
||||||
WIFI_DEVICE=$(LC_ALL=C nmcli dev status | grep " wifi " 2>/dev/null)
|
WIFI_DEVICE=$(LC_ALL=C nmcli dev status | grep " wifi " 2>/dev/null)
|
||||||
@@ -128,21 +129,20 @@ set_timezone_and_locales()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Grab IP once again if not found
|
# Grab IP once again if not found
|
||||||
[[ -z "$PUBLIC_IP" && -n "$WIFI_DEVICE" ]] && PUBLIC_IP=`curl --max-time 5 -s https://ipinfo.io/ip`
|
[[ -z "$PUBLIC_IP" && -n "$WIFI_DEVICE" ]] && PUBLIC_IP=$(curl --max-time 5 -s https://ipinfo.io/ip)
|
||||||
|
|
||||||
# Call the geolocation API and capture the output
|
# Call the geolocation API and capture the output
|
||||||
RES=$(
|
RES=$(
|
||||||
curl --max-time 5 -s http://ipwhois.app/json/${PUBLIC_IP} | \
|
curl --max-time 5 -s "http://ipwhois.app/json/${PUBLIC_IP}" | \
|
||||||
jq '.timezone, .country, .country_code' | \
|
jq '.timezone, .country, .country_code' | \
|
||||||
while read -r TIMEZONE; do
|
while read -r TIMEZONE; do
|
||||||
read -r COUNTRY
|
read -r COUNTRY
|
||||||
echo "${TIMEZONE},${COUNTRY},${COUNTRYCODE}" | tr --delete \"
|
echo "${TIMEZONE},${COUNTRY},${COUNTRYCODE}" | tr --delete '"\n'
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
|
|
||||||
TZDATA=$(echo ${RES} | cut -d"," -f1)
|
TZDATA=$(echo "${RES}" | cut -d"," -f1)
|
||||||
STATE=$(echo ${RES} | cut -d"," -f2)
|
CCODE=$(echo "${RES}" | cut -d"," -f3 | xargs)
|
||||||
CCODE=$(echo ${RES} | cut -d"," -f3 | xargs)
|
|
||||||
echo -e "Detected timezone: \x1B[92m$TZDATA\x1B[0m"
|
echo -e "Detected timezone: \x1B[92m$TZDATA\x1B[0m"
|
||||||
echo ""
|
echo ""
|
||||||
unset response
|
unset response
|
||||||
@@ -161,7 +161,7 @@ set_timezone_and_locales()
|
|||||||
[[ -z "$LOCALES" ]] && LOCALES=$(grep territory /usr/share/i18n/locales/* | grep _"$CCODE" | cut -d ":" -f 1 | cut -d "/" -f 6 | \
|
[[ -z "$LOCALES" ]] && LOCALES=$(grep territory /usr/share/i18n/locales/* | grep _"$CCODE" | cut -d ":" -f 1 | cut -d "/" -f 6 | \
|
||||||
xargs -I{} grep {} /usr/share/i18n/SUPPORTED | cut -d " " -f 1)
|
xargs -I{} grep {} /usr/share/i18n/SUPPORTED | cut -d " " -f 1)
|
||||||
|
|
||||||
options=(`echo ${LOCALES}`);
|
readarray -t options <<<"${LOCALES}"
|
||||||
|
|
||||||
# when having more locales, prompt for choosing one
|
# when having more locales, prompt for choosing one
|
||||||
if [[ "${#options[@]}" -gt 1 ]]; then
|
if [[ "${#options[@]}" -gt 1 ]]; then
|
||||||
@@ -171,7 +171,7 @@ set_timezone_and_locales()
|
|||||||
PS3='Please enter your choice:'
|
PS3='Please enter your choice:'
|
||||||
select opt in "${options[@]}"
|
select opt in "${options[@]}"
|
||||||
do
|
do
|
||||||
if [[ " ${options[@]} " =~ " ${opt} " ]]; then
|
if [[ " ${options[*]} " == *" ${opt} "* ]]; then
|
||||||
LOCALES=${opt}
|
LOCALES=${opt}
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
@@ -195,12 +195,16 @@ set_timezone_and_locales()
|
|||||||
locale-gen "${LOCALES}" > /dev/null 2>&1
|
locale-gen "${LOCALES}" > /dev/null 2>&1
|
||||||
|
|
||||||
# setting detected locales only for user
|
# setting detected locales only for user
|
||||||
echo "export LC_ALL=$LOCALES" >> /home/"$RealUserName"/.bashrc
|
{
|
||||||
echo "export LANG=$LOCALES" >> /home/"$RealUserName"/.bashrc
|
echo "export LC_ALL=$LOCALES"
|
||||||
echo "export LANGUAGE=$LOCALES" >> /home/"$RealUserName"/.bashrc
|
echo "export LANG=$LOCALES"
|
||||||
echo "export LC_ALL=$LOCALES" >> /home/"$RealUserName"/.xsessionrc
|
echo "export LANGUAGE=$LOCALES"
|
||||||
echo "export LANG=$LOCALES" >> /home/"$RealUserName"/.xsessionrc
|
} >> /home/"$RealUserName"/.bashrc
|
||||||
echo "export LANGUAGE=$LOCALES" >> /home/"$RealUserName"/.xsessionrc
|
{
|
||||||
|
echo "export LC_ALL=$LOCALES"
|
||||||
|
echo "export LANG=$LOCALES"
|
||||||
|
echo "export LANGUAGE=$LOCALES"
|
||||||
|
} >> /home/"$RealUserName"/.xsessionrc
|
||||||
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -235,12 +239,12 @@ add_profile_sync_settings()
|
|||||||
|
|
||||||
add_user()
|
add_user()
|
||||||
{
|
{
|
||||||
read -t 0 temp
|
read -r -t 0 _
|
||||||
REPEATS=3
|
REPEATS=3
|
||||||
while [ -f "/root/.not_logged_in_yet" ]; do
|
while [ -f "/root/.not_logged_in_yet" ]; do
|
||||||
echo -e "\nPlease provide a username (eg. your first name): \c"
|
echo -e "\nPlease provide a username (eg. your first name): \c"
|
||||||
read -e username
|
read -r -e username
|
||||||
if ! grep '^[a-zA-Z]*$' <<< $username > /dev/null ; then
|
if ! grep '^[a-zA-Z]*$' <<< "$username" > /dev/null ; then
|
||||||
echo -e "\n\x1B[91mError\x1B[0m: illegal characters in username"
|
echo -e "\n\x1B[91mError\x1B[0m: illegal characters in username"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@@ -265,7 +269,7 @@ add_user()
|
|||||||
echo -e "\n\e[0;31mWarning:\x1B[0m Weak password, $okay \b!"
|
echo -e "\n\e[0;31mWarning:\x1B[0m Weak password, $okay \b!"
|
||||||
fi
|
fi
|
||||||
echo -e ""
|
echo -e ""
|
||||||
read -e -p "Please provide your real name: " -i "${RealUserName^}" RealName
|
read -r -e -p "Please provide your real name: " -i "${RealUserName^}" RealName
|
||||||
|
|
||||||
adduser --quiet --disabled-password --home /home/"$RealUserName" --gecos "$RealName" "$RealUserName"
|
adduser --quiet --disabled-password --home /home/"$RealUserName" --gecos "$RealName" "$RealUserName"
|
||||||
(echo "$first_input";echo "$second_input";) | passwd "$RealUserName" >/dev/null 2>&1
|
(echo "$first_input";echo "$second_input";) | passwd "$RealUserName" >/dev/null 2>&1
|
||||||
@@ -283,8 +287,7 @@ add_user()
|
|||||||
rm -f /root/.not_logged_in_yet
|
rm -f /root/.not_logged_in_yet
|
||||||
chmod +x /etc/update-motd.d/*
|
chmod +x /etc/update-motd.d/*
|
||||||
# set up profile sync daemon on desktop systems
|
# set up profile sync daemon on desktop systems
|
||||||
command -v psd >/dev/null 2>&1
|
if command -v psd >/dev/null 2>&1; then
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
echo -e "${RealUserName} ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper" >> /etc/sudoers
|
echo -e "${RealUserName} ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper" >> /etc/sudoers
|
||||||
touch /home/"${RealUserName}"/.activate_psd
|
touch /home/"${RealUserName}"/.activate_psd
|
||||||
chown "$RealUserName":"$RealUserName" /home/"${RealUserName}"/.activate_psd
|
chown "$RealUserName":"$RealUserName" /home/"${RealUserName}"/.activate_psd
|
||||||
@@ -314,7 +317,7 @@ if [[ -f /root/.not_logged_in_yet && -n $(tty) ]]; then
|
|||||||
systemctl is-system-running --wait >/dev/null
|
systemctl is-system-running --wait >/dev/null
|
||||||
|
|
||||||
# enable hiDPI support
|
# enable hiDPI support
|
||||||
if [[ "$(cat /sys/class/graphics/fb0/virtual_size 2>/dev/null | cut -d, -f1)" -gt 1920 ]]; then
|
if [[ "$(cut -d, -f1 < /sys/class/graphics/fb0/virtual_size 2> /dev/null)" -gt 1920 ]]; then
|
||||||
# lightdm
|
# lightdm
|
||||||
[[ -f /etc/lightdm/slick-greeter.conf ]] && echo "enable-hidpi = on" >> /etc/lightdm/slick-greeter.conf
|
[[ -f /etc/lightdm/slick-greeter.conf ]] && echo "enable-hidpi = on" >> /etc/lightdm/slick-greeter.conf
|
||||||
# xfce
|
# xfce
|
||||||
@@ -403,6 +406,7 @@ if [[ -f /root/.not_logged_in_yet && -n $(tty) ]]; then
|
|||||||
printf "\nYou selected \e[0;91mZSH\x1B[0m as your default shell. If you want to use it right away, please logout and login! \n\n"
|
printf "\nYou selected \e[0;91mZSH\x1B[0m as your default shell. If you want to use it right away, please logout and login! \n\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
declare ConfigureDisplay
|
||||||
# check whether desktop environment has to be considered
|
# check whether desktop environment has to be considered
|
||||||
if [ -n "$desktop_lightdm" ] && [ -n "$RealName" ] ; then
|
if [ -n "$desktop_lightdm" ] && [ -n "$RealName" ] ; then
|
||||||
|
|
||||||
@@ -456,7 +460,7 @@ if [[ -f /root/.not_logged_in_yet && -n $(tty) ]]; then
|
|||||||
systemctl start armbian-disable-autologin.timer
|
systemctl start armbian-disable-autologin.timer
|
||||||
fi
|
fi
|
||||||
# logout if logged at console
|
# logout if logged at console
|
||||||
[[ -n $(who -la | grep root | grep tty1) ]] && exit 1
|
who -la | grep root | grep -q tty1 && exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
elif [ -n "$desktop_gdm3" ] && [ -n "$RealName" ] ; then
|
elif [ -n "$desktop_gdm3" ] && [ -n "$RealName" ] ; then
|
||||||
@@ -488,7 +492,7 @@ if [[ -f /root/.not_logged_in_yet && -n $(tty) ]]; then
|
|||||||
(sleep 20; sed -i "s/AutomaticLoginEnable.*/AutomaticLoginEnable = false/" /etc/gdm3/custom.conf) &
|
(sleep 20; sed -i "s/AutomaticLoginEnable.*/AutomaticLoginEnable = false/" /etc/gdm3/custom.conf) &
|
||||||
fi
|
fi
|
||||||
# logout if logged at console
|
# logout if logged at console
|
||||||
[[ -n $(who -la | grep root | grep tty1) ]] && exit 1
|
who -la | grep root | grep -q tty1 && exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user