From 1c4ea96f5313cc5af3d94710e43be03902de6bfc Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Mon, 18 Oct 2021 00:46:11 -0400 Subject: [PATCH] Rename option now working. --- .includes/chuser.sh | 11 +-- .includes/functions.sh | 10 +++ .includes/gaming.sh | 5 -- .includes/ui.sh | 2 +- configure-stormux.sh | 180 +++++------------------------------------ 5 files changed, 35 insertions(+), 173 deletions(-) create mode 100755 .includes/functions.sh mode change 100644 => 100755 .includes/gaming.sh diff --git a/.includes/chuser.sh b/.includes/chuser.sh index 7e94e2e..cf486b2 100755 --- a/.includes/chuser.sh +++ b/.includes/chuser.sh @@ -36,12 +36,12 @@ exit 1 fi - local oldUser="$USER" + oldUser="$USER" - local groups="$(groups "$oldUser")" + groups="$(groups "$oldUser")" groups="${groups// /,}" - local newUser="$1" + newUser="$1" if ! [[ "$newUser" =~ ^[a-z][-a-z0-9]*$ ]]; then msgbox "Username $newUser failed validation. It cannot contain spaces or some punctuation." exit 1 @@ -59,8 +59,3 @@ EOF # Files in cron.d must be 644 to work. sudo chmod 644 /etc/cron.d/0chuser - # Reboot the computer so the script can run - local answer="$(yesno "Would you like to reboot now so the username can be changed? If no, you will need to reboot manually for the changes to be applied.")" - if [[ "$answer" == "Yes" ]]; then - sudo reboot - fi diff --git a/.includes/functions.sh b/.includes/functions.sh new file mode 100755 index 0000000..a65c0d7 --- /dev/null +++ b/.includes/functions.sh @@ -0,0 +1,10 @@ +install_package() { + # If for some reason we have to change AUR helpers, this function should make it easy to update everything all at once. + yay --needed --noconfirm -S "$@" +} + +restart() { +if dialog --clear --backtitle "Stormux" --yesno "Would you like to reboot now to apply changes?" 10 80 ; then + sudo reboot + fi +} diff --git a/.includes/gaming.sh b/.includes/gaming.sh old mode 100644 new mode 100755 index bec3556..ddae762 --- a/.includes/gaming.sh +++ b/.includes/gaming.sh @@ -1,11 +1,6 @@ #!/bin/bash -install_package() { - # If for some reason we have to change AUR helpers, this function should make it easy to update everything all at once. - yay --needed --noconfirm -S "$@" -} - # URL from where wine is downloaded, must be i686 wineURL="https://32.arlm.tyzoid.com/i686/community/wine-5.14-1.0-i686.pkg.tar.zst" diff --git a/.includes/ui.sh b/.includes/ui.sh index 96cdf03..34e5494 100755 --- a/.includes/ui.sh +++ b/.includes/ui.sh @@ -83,7 +83,7 @@ menulist() { dialog --backtitle "Stormux" \ --clear \ --no-tags \ - --menu "Please select an option" 0 0 0 ${menuList[@]} --stdout + --menu "Please select an option" 0 0 0 "${menuList[@]}" --stdout return $? } diff --git a/configure-stormux.sh b/configure-stormux.sh index 55d0c20..7f03d13 100755 --- a/configure-stormux.sh +++ b/configure-stormux.sh @@ -21,167 +21,29 @@ # #--code-- -# UI code starts here. - -# Settings to improve accessibility of dialog. -export DIALOGOPTS='--insecure --no-lines --visit-items' - -inputbox() { - # Returns: text entered by the user - # Args 1, Instructions for box. - # args: 2 initial text (optional) - dialog --backtitle "Stormux" \ - --clear \ - --inputbox "$1" 0 0 "$2" --stdout -} - -passwordbox() { - # Returns: text entered by the user - # Args 1, Instructions for box. - # args: 2 initial text (optional) - dialog --backtitle "Stormux" \ - --clear \ - --passwordbox "$1" 0 0 "$2" --stdout -} - -msgbox() { -# Returns: None -# Shows the provided message on the screen with an ok button. -dialog --clear --msgbox "$*" 10 72 -} - -infobox() { - # Returns: None - # Shows the provided message on the screen with no buttons. - local timeout=3 - dialog --infobox "$*" 0 0 - read -n1 -t $timeout continue - # Clear any keypresses from the buffer - read -t 0.01 continue -} - -yesno() { - # Returns: Yes or No - # Args: Question to user. - # Called in if $(yesno) == "Yes" - # Or variable=$(yesno) - dialog --clear --backtitle "Stormux" --yesno "$*" 10 80 --stdout - if [[ $? -eq 0 ]]; then - echo "Yes" - else - echo "No" - fi -} - -menulist() { - # Args: List of items for menu. - # returns: selected tag - local menuList - for i in "${@}" ; do - menuList+=("$i" "$i") - done - dialog --backtitle "Stormux" \ - --clear \ - --no-tags \ - --menu "Please select an option" 0 0 0 ${menuList[@]} --stdout - return $? -} - -show_doc() { - # Displays file in w3m using pager mode - # Args: path to file. - # Returns: none. - fold -sw $cols "$1" | w3m -o keymap_file=~/.w3m/pager -} - - -# System modification functions begin here. - -change_user() { - # The user can not be logged in when the name change occurs. - # Write a file to /etc/cron.d/chuser - # The file will run at boot, change the username, and delete itself. - # Args: new username. - - if [[ $# -ne 1 ]]; then - msgbox "Missing required argument, username." - exit 1 - fi - - if [[ "$(whoami)" == "root" ]]; then - msgbox "Please run this script as the user you would like to rename, not as root." - exit 1 - fi - - local oldUser="$USER" - - local groups="$(groups "$oldUser")" - groups="${groups// /,}" - - local newUser="$1" - if ! [[ "$newUser" =~ ^[a-z][-a-z0-9]*$ ]]; then - msgbox "Username $newUser failed validation. It cannot contain spaces or some punctuation." - exit 1 - fi - -# Heredocument left-aligned -cat << EOF | sudo tee /etc/cron.d/0chuser &> /dev/null -SHELL=/bin/bash -PATH=/sbin:/bin:/usr/sbin:/usr/bin -@reboot root usermod -a -G $groups -m -d /home/$newUser -l $newUser $oldUser && sed -i -e "s#NODM_USER=.*#NODM_USER='$newUser'#" -e "s#NODM_XSESSION=.*#NODM_XSESSION='/home/$newUser/.xinitrc'#" /etc/nodm.conf; rm -f /etc/cron.d/0chuser;reboot - -EOF -# Heredocument end. - - # Files in cron.d must be 644 to work. - sudo chmod 644 /etc/cron.d/0chuser && echo "Setting file permissions on /etc/cron.d/0chuser to 644" | log - - # Reboot the computer so the script can run - local answer="$(yesno "Would you like to reboot now so the username can be changed? If no, you will need to reboot manually for the changes to be applied.")" - if [[ "$answer" == "Yes" ]]; then - sudo reboot - fi -} - - -set_timezone() { -# Attempt to autodetect the timezone. -local timezone="$(curl -s --connect-timeout 5 ipinfo.io | grep -E '\s*"timezone":' | cut -d '"' -f4)" | dialog --progressbox "Attempting to detect your timezone..." 0 0 -if [[ -n "$timezone" ]]; then - local answer="$(yesno "The timezone for your current location is ${timezone}. Would you like to use this timezone?")" -fi -if [[ "$answer" == "No" ]]; then -# Get the list of timezones -mapfile -t regions < <(timedatectl --no-pager list-timezones | cut -d '/' -f1 | sort -u) -region=$(menulist ${regions[@]}) -mapfile -t cities < <(timedatectl --no-pager list-timezones | grep "$region" | cut -d '/' -f2 | sort -u) -city=$(menulist ${cities[@]}) - -timezone="${region}/${city}" -fi -# Set the timezone -sudo timedatectl set-timezone ${timezone} -# Make sure we are syncing with the internet -sudo timedatectl set-ntp true -} - - -unmute_soundcard() { - # Try to unmute the soundcard. - if amixer get Master | grep -q '\[off\]' ; then - amixer sset Master unmute - fi - # Check system volume, try to make sure it is unmuted and at a reasonable level. - soundcardVolume=$(amixer get Master | grep '\[on\]' | cut -d '[' -f2 | cut -d '%' -f1 | head -1) - if [[ $soundcardVolume -le 25 ]]; then - amixer sset Master 50% |& log - fi -} - -# System modification functions end here. +# Include functions common to all operations +source .includes/functions.sh +# Include the dialog based UI +source .includes/ui.sh # Make sure basic xdg directory structure is in place: -xdg-user-dirs-update +if [[ ! -d ~/Desktop ]]; then + xdg-user-dirs-update +fi + +while [[ "$choice" != "Exit" ]]; do + case "$choice" in + "Change username") + ./.includes/chuser.sh $(inputbox "Please enter the new username, letters, dashes, and underscores only.") + restart + ;; + esac + choice="$(menulist \ + "Change username" \ + "Set up gaming" \ + "Exit" \ + )" +done exit 0