Standardize function import

This commit is contained in:
2024-06-30 15:30:50 -04:00
parent ccf91fe0f5
commit a5cde22362
16 changed files with 49 additions and 105 deletions

View File

@@ -6,7 +6,7 @@
parent="${BASH_SOURCE[0]}"
parent=${parent%/*}
[[ -f "$parent"/script-functions ]] && . "$parent"/script-functions || exit 1
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
is_root

View File

@@ -5,7 +5,7 @@
parent="${BASH_SOURCE[0]}"
parent=${parent%/*}
[[ -f "$parent"/script-functions ]] && . "$parent"/script-functions || exit 1
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
is_root

View File

@@ -5,7 +5,7 @@
parent="${BASH_SOURCE[0]}"
parent=${parent%/*}
[[ -f "$parent"/script-functions ]] && . "$parent"/script-functions || exit 1
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
is_root

View File

@@ -5,7 +5,7 @@
parent="${BASH_SOURCE[0]}"
parent=${parent%/*}
[[ -f "$parent"/script-functions ]] && . "$parent"/script-functions || exit 1
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
is_root

View File

@@ -2,7 +2,7 @@
# Generic btrfsmaintenance install script
# Copyright 2021 Bryan C. Roessler
[[ -f functions ]] && . functions || exit 1
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
is_root

View File

@@ -5,7 +5,7 @@
parent="${BASH_SOURCE[0]}"
parent=${parent%/*}
[[ -f "$parent"/script-functions ]] && . "$parent"/script-functions || exit 1
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
is_root

View File

@@ -5,7 +5,7 @@
parent="${BASH_SOURCE[0]}"
parent=${parent%/*}
[[ -f "$parent"/script-functions ]] && . "$parent"/script-functions || exit 1
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
is_root

View File

@@ -5,7 +5,7 @@
parent="${BASH_SOURCE[0]}"
parent=${parent%/*}
[[ -f "$parent"/script-functions ]] && . "$parent"/script-functions || exit 1
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
is_root

View File

@@ -1,44 +0,0 @@
#!/usr/bin/env bash
# Update the R binaries and RStudio-R4 application menu entry
# $1: R version number, ex. '4.1.2'
# $2: RStudio version number, ex. '2021.09.1-372'
# Copyright 2021 Bryan C. Roessler
parent="${BASH_SOURCE[0]}"
parent=${parent%/*}
[[ -f "$parent"/script-functions ]] && . "$parent"/script-functions || exit 1
is_root
if [[ $# -eq 2 ]]; then
re='^[0-9].[0-9].[0-9]$'
if [[ ! $1 =~ $re ]]; then
echo "Bad R version number"
exit 1
fi
re='^[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9]-[0-9]+$'
if [[ ! $2 =~ $re ]]; then
echo "Bad RStudio version number"
exit 1
fi
else
echo "You must provide exactly two arguments!"
echo "\$1: R version, ex. '4.1.2'"
echo "\$2: RStudio version, ex. '2021.09.1-372'"
exit 1
fi
ask_ok "Update R to version $1 and RStudio to version $2?" || exit
if sudo dnf install -y "https://cdn.rstudio.com/r/centos-7/pkgs/R-${1}-1-1.x86_64.rpm" \
"https://download2.rstudio.org/server/centos7/x86_64/rstudio-server-rhel-${2}-x86_64.rpm" \
"https://download1.rstudio.org/desktop/centos7/x86_64/rstudio-${2}-x86_64.rpm" &&
desktop_file="/usr/share/applications/rstudio-R4.desktop" &&
[[ -f "$desktop_file" ]] && sed -i "s|/opt/R/.*/bin/R|/opt/R/$1/bin/R|" "$desktop_file"; then
echo "Successfully updated R and RStudio"
exit 0
else
echo "R and RStudio update failed!"
exit 1
fi

View File

@@ -5,20 +5,20 @@
parent="${BASH_SOURCE[0]}"
parent=${parent%/*}
[[ -f "$parent"/script-functions ]] && . "$parent"/script-functions || exit 1
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
is_root
echo "This script supports two optional arguments, a username and password"
if [[ $# -eq 0 ]]; then
prompt username
prompt user
prompt password
elif [[ $# -eq 1 ]]; then
username="$1"
user="$1"
prompt password
elif [[ $# -eq 2 ]]; then
username="$1"
user="$1"
password="$2"
elif [[ $# -gt 2 ]]; then
echo "Too many arguments provided"
@@ -27,45 +27,45 @@ fi
useradd_cmd=(useradd -m -U)
if id -u "$username" &>/dev/null; then
ask_ok "User $username exists. Run script-user-remove first?" || exit $?
"$parent"/script-user-remove "$username" || exit $?
if id -u "$user" &>/dev/null; then
ask_ok "User $user exists. Run script-user-remove first?" || exit $?
"$parent"/script-user-remove "$user" || exit $?
fi
ask_ok "Create user $username with password $password?" || exit $?
ask_ok "Create user $user with password $password?" || exit $?
restore="no"
if [[ -d /mnt/array/home-retired/$username ]]; then
ask_ok "Restore user $username's files from /mnt/array/home-retired/$user?" && restore="yes"
if [[ -d /mnt/array/home-retired/$user ]]; then
ask_ok "Restore user $user's files from /mnt/array/home-retired/$user?" && restore="yes"
fi
samba="no"
ask_ok "Enable shared file access for user $username?" && group_str="smbgrp," && samba="yes"
ask_ok "Enable shared file access for user $user?" && group_str="smbgrp," && samba="yes"
ask_ok "Make $username an admin?" && \
ask_ok "Make $user an admin?" && \
group_str+="wheel"
useradd_cmd+=("-G" "$group_str")
useradd_cmd+=("$username")
useradd_cmd+=("$user")
if [[ "$restore" == "yes" ]]; then
if rsync -av --progress=info2 /mnt/array/home-retired/"$username" /home/"$username"; then
ask_ok "User $username's files successfully restored, remove backup at /mnt/array/home-retired/$username?" && \
rm -rf /mnt/array/home-retired/"$username"
if rsync -av --progress=info2 /mnt/array/home-retired/"$user" /home/"$user"; then
ask_ok "User $user's files successfully restored, remove backup at /mnt/array/home-retired/$user?" && \
rm -rf /mnt/array/home-retired/"$user"
fi
fi
# echo "Running: ${useradd_cmd[*]}"
"${useradd_cmd[@]}"
echo "$username":"$password" | chpasswd
echo "$user":"$password" | chpasswd
if [[ "$samba" == "yes" ]]; then
(echo "$password"; echo "$password") | smbpasswd -a -s "$username"
(echo "$password"; echo "$password") | smbpasswd -a -s "$user"
fi
ask_ok "Prompt user to reset password on next login?" &&
sudo passwd --expire "$username"
sudo passwd --expire "$user"
# TODO check if centos 9 does by default
# Add subuids & subgids for container namespace
@@ -75,12 +75,12 @@ sudo passwd --expire "$username"
# last_gid=$(tail -1 /etc/subgid | cut -d':' -f2)
# start_uid=$(( last_uid + id_offset ))
# start_gid=$(( last_gid + id_offset ))
# echo "$username:$start_uid:$id_num" >> /etc/subuid
# echo "$username:$start_gid:$id_num" >> /etc/subgid
# echo "$user:$start_uid:$id_num" >> /etc/subuid
# echo "$user:$start_gid:$id_num" >> /etc/subgid
# Copy manual to user desktop
mkdir -p /home/"$username"/Desktop/
ln -fs "$parent"/README.html /home/"$username"/Desktop/
chown "$username":"$username" -R /home/"$username"/Desktop
mkdir -p /home/"$user"/Desktop/
ln -fs "$parent"/README.html /home/"$user"/Desktop/
chown "$user":"$user" -R /home/"$user"/Desktop
exit $?

View File

@@ -1,18 +0,0 @@
#!/usr/bin/env bash
# This script will register a new remote user for the lab workstation
# Copyright 2021 Bryan C. Roessler
[[ $# -eq 0 ]] && remote_host="hartmanlab.genetics.uab.edu"
[[ $# -eq 1 ]] && remote_host="$1"
[[ $# -gt 1 ]] && echo "Only one argument permitted" && exit 1
#remote_host="hartmanlab.genetics.uab.edu"
# generate local key if not available
if [[ -x $(command -v ssh-copy-id) ]]; then
ask_ok "Copy public key to $remote_host?"
ssh-copy-id "$remote_host"
fi

View File

@@ -7,7 +7,7 @@ parent=${parent%/*}
unset user
[[ -f $parent/functions ]] && . "$parent"/functions || exit 1
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
is_root

View File

@@ -7,25 +7,27 @@ unset user password
parent="${BASH_SOURCE[0]}"
parent=${parent%/*}
[[ -f "$parent"/script-functions ]] && . "$parent"/script-functions || exit 1
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
is_root
echo "This script supports two optional arguments, a username and password"
if [[ $# -eq 0 ]]; then
prompt username
prompt user
prompt password
elif [[ $# -eq 1 ]]; then
username="$1"
user="$1"
prompt password
elif [[ $# -eq 2 ]]; then
username="$1"
user="$1"
password="$2"
elif [[ $# -gt 2 ]]; then
echo "Too many arguments provided"
exit 1
fi
if ! id -u "$username" &>/dev/null; then
if ! id -u "$user" &>/dev/null; then
echo "User $user does not exist"
exit 1
fi

View File

@@ -5,13 +5,17 @@
parent="${BASH_SOURCE[0]}"
parent=${parent%/*}
[[ -f "$parent"/script-functions ]] && . "$parent"/script-functions || exit 1
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
is_root
[[ $# -lt 1 ]] && echo "No username provided!" && exit 1
[[ $# -ge 1 ]] && user="$1"
echo "This script supports one optional argument, a username"
if [[ $# -eq 1 ]]; then
user="$1"
else
prompt user
fi
# Clean local user cache
rm -rf /home/"$user"/.x2go/C-"$user"-*

View File

@@ -5,7 +5,7 @@
parent="${BASH_SOURCE[0]}"
parent=${parent%/*}
[[ -f "$parent"/script-functions ]] && . "$parent"/script-functions || exit 1
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
is_root

View File

@@ -3,7 +3,7 @@
# Place in /usr/share/smartmontools/smartd_warning.d/ or use "DEVICESCAN -m @smartd-notify-all" in /etc/smartd.conf
# Copyright 2021 Bryan C. Roessler
[[ -f functions ]] && . functions || exit 1
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
is_root