Last active
July 3, 2023 07:34
-
-
Save spencerwooo/b6a22e8ddea9c046cf695afd5227bc4e to your computer and use it in GitHub Desktop.
GPU server maintainence scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# -*- coding: utf-8 -*- | |
# See: https://docs.anaconda.com/anaconda/install/multi-user/ | |
echo "[➤] Multi-user installation for Anaconda >>>" | |
# Check for root access | |
if [ "$EUID" -ne 0 ] | |
then echo "[✘] Please run as root, exiting >>>" | |
exit | |
fi | |
# Create new group called gpuuser | |
if ! [ $(getent group gpuuser) ]; then | |
groupadd gpuuser | |
echo "[➤] Created new group 'gpuuser' >>>" | |
fi | |
anaconda_path=/usr/local/anaconda3 | |
if [ -d $anaconda_path ]; then | |
# Change ownership | |
chgrp -R gpuuser $anaconda_path | |
echo "[➤] Changed ownership for path" $anaconda_path "to group 'gpuuser' >>>" | |
# Change permissions to read and execute | |
chmod 755 -R /usr/local/anaconda3 | |
echo "[➤] Changed permissions for path" $anaconda_path "to 755 >>>" | |
# Append Anaconda and cuda PATH to /etc/profile | |
echo "export PATH=/usr/local/anaconda3/bin:$PATH" >> /etc/profile | |
echo "export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH" >> /etc/profile | |
echo "export CUDA_HOME=/usr/local/cuda" >> /etc/profile | |
echo "export PATH=/usr/local/cuda/bin:$PATH" >> /etc/profile | |
echo "[➤] Added Anaconda and CUDA PATH to '/etc/profile' >>>" | |
echo "[✔] Done!" | |
else | |
echo "[✘] Path" $anaconda_path "not found! Please check Anaconda installation path >>>" | |
echo "[✘] Aborting ..." | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# -*- coding: utf-8 -*- | |
# Check for root access | |
if [ "$EUID" -ne 0 ]; then | |
echo "[✘] Please run as root, exiting >>>" | |
exit | |
fi | |
if ! [ $(getent group gpuuser) ]; then | |
# Create new group called gpuuser | |
groupadd gpuuser | |
echo "[➤] No group gpuuser detected so I created one for you >>>" | |
fi | |
USER_FILE=users.txt | |
if ! test -f $USER_FILE; then | |
echo "[✘] Username file 'users.txt' not found, exiting >>>" | |
exit | |
fi | |
for i in $( cat users.txt ); do | |
if id -u $i >/dev/null 2>&1; then | |
echo "[-] User" $i "already exists, skipping >>>" | |
else | |
# Create a user and adding into default group gpuuser | |
useradd -g gpuuser -s /bin/bash -d /home/$i -m $i | |
# Set the password | |
echo $i:$i | chpasswd | |
echo "[➤] Created user with name" $i "and added into group gpuuser >>>" | |
fi | |
done | |
echo "[✔] Done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# -*- coding: utf-8 -*- | |
if [ $# -ne 1 ]; then | |
echo "[➤] Usage: $0 username" | |
exit -1 | |
fi | |
# Check for root access | |
if [ "$EUID" -ne 0 ]; then | |
echo "[✘] Please run as root, exiting >>>" | |
exit | |
fi | |
if ! [ $(getent group gpuuser) ]; then | |
# Create new group called gpuuser | |
groupadd gpuuser | |
echo "[➤] No group gpuuser detected so I created one for you >>>" | |
fi | |
# Create a user and adding into default group gpuuser | |
useradd -g gpuuser -s /bin/bash -d /home/$1 -m $1 | |
# Set the password | |
echo $1:$1 | chpasswd | |
echo "[✔] Done! Created user with name" $1 "and added into group gpuuser >>>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if the file path is provided as a command line argument | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 <file>" | |
exit 1 | |
fi | |
file="$1" | |
# Check if the file exists and is readable | |
if [ ! -f "$file" ] || [ ! -r "$file" ]; then | |
echo "File '$file' does not exist or is not readable." | |
exit 1 | |
fi | |
# Read the file line by line and delete each user | |
while IFS= read -r username; do | |
echo "Deleting user: $username" | |
userdel -r "$username" | |
done < "$file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# -*- coding: utf-8 -*- | |
# See: https://docs.anaconda.com/anaconda/install/multi-user/ | |
# Mambaforge from: https://github.com/conda-forge/miniforge#mambaforge | |
echo "[➤] Multi-user installation for Mambaforge >>>" | |
# Check for root access | |
if [ "$EUID" -ne 0 ] | |
then echo "[✘] Please run as root, exiting >>>" | |
exit | |
fi | |
# Create new group called gpuuser | |
if ! [ $(getent group gpuuser) ]; then | |
groupadd gpuuser | |
echo "[➤] Created new group 'gpuuser' >>>" | |
fi | |
mambaforge_path=/opt/mambaforge | |
if [ -d $mambaforge_path ]; then | |
# Change ownership | |
chgrp -R gpuuser $mambaforge_path | |
echo "[➤] Changed ownership for path" $mambaforge_path "to group 'gpuuser' >>>" | |
# Change permissions to read and execute | |
chmod 755 -R $mambaforge_path | |
echo "[➤] Changed permissions for path" $mambaforge_path "to 755 >>>" | |
# Append Mambaforge | |
echo "export PATH=$mambaforge_path/bin:$PATH" >> /etc/profile | |
echo "[➤] Added Mambaforge bin PATH to '/etc/profile' >>>" | |
echo "[✔] Done!" | |
else | |
echo "[✘] Path" $mambaforge_path "not found! Please check Mambaforge installation path >>>" | |
echo "[✘] Aborting ..." | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
spencer | |
tenkey | |
etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment