Started work on splitting configure-stormux into modules.
This commit is contained in:
parent
0aecfda4ad
commit
1547290cd0
66
.includes/chuser.sh
Executable file
66
.includes/chuser.sh
Executable file
@ -0,0 +1,66 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Configure Stormux
|
||||||
|
# A script to configure the system for new users.
|
||||||
|
#
|
||||||
|
# Copyright 2020, Storm Dragon, <storm_dragon@linux-a11y.org>
|
||||||
|
#
|
||||||
|
# This is free software; you can redistribute it and/or modify it under the
|
||||||
|
# terms of the GNU General Public License as published by the Free
|
||||||
|
# Software Foundation; either version 3, or (at your option) any later
|
||||||
|
# version.
|
||||||
|
#
|
||||||
|
# This software is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this package; see the file COPYING. If not, write to the Free
|
||||||
|
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
# 02110-1301, USA.
|
||||||
|
#
|
||||||
|
#--code--
|
||||||
|
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# 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
|
95
.includes/ui.sh
Executable file
95
.includes/ui.sh
Executable file
@ -0,0 +1,95 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Configure Stormux
|
||||||
|
# A script to configure the system for new users.
|
||||||
|
#
|
||||||
|
# Copyright 2020, Storm Dragon, <storm_dragon@linux-a11y.org>
|
||||||
|
#
|
||||||
|
# This is free software; you can redistribute it and/or modify it under the
|
||||||
|
# terms of the GNU General Public License as published by the Free
|
||||||
|
# Software Foundation; either version 3, or (at your option) any later
|
||||||
|
# version.
|
||||||
|
#
|
||||||
|
# This software is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this package; see the file COPYING. If not, write to the Free
|
||||||
|
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
# 02110-1301, USA.
|
||||||
|
#
|
||||||
|
#--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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user