Last active
September 26, 2024 16:39
-
-
Save dzogrim/350344c09190d9ea4d53427005758469 to your computer and use it in GitHub Desktop.
Use a full configuration template for new user creation by cloning directory
This file contains hidden or 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 | |
# Ensure that the script receives two arguments: first name and last name | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 <prenom> <nom>" | |
exit 1 | |
fi | |
PRENOM=$1 | |
NOM=$2 | |
# Check if the source directory exists | |
if [ ! -d "perso/paul-dupont" ]; then | |
echo "Error: The directory 'perso/paul-dupont' does not exist." | |
exit 1 | |
fi | |
# Check if the destination directory already exists | |
if [ -d "perso/$PRENOM-$NOM" ]; then | |
echo "Error: The directory 'perso/$PRENOM-$NOM' already exists." | |
exit 1 | |
fi | |
# Perform the copy | |
cp -pr perso/paul-dupont perso/$PRENOM-$NOM | |
if [ $? -ne 0 ]; then | |
echo "Error: Failed to copy the directory." | |
exit 1 | |
fi | |
# Change to the new directory | |
cd perso/$PRENOM-$NOM || exit 1 | |
# Perform sed substitutions with proper variable expansion | |
sed -i -e "s|paul-dupont|$PRENOM-$NOM|g" ./homeManager/gnome.nix | |
sed -i -e "s|paul-dupont|$PRENOM-$NOM|g" ./default.nix | |
sed -i -e "s|paul.dupont|$PRENOM.$NOM|g" ./homeManager/git.nix | |
sed -i -e "s|paul.dupont|$PRENOM.$NOM|g" ./default.nix | |
sed -i -e "s|dupont-workstation|$NOM-laptop|g" ./default.nix | |
# Check for remaining occurrences of 'paul' and 'dupont' | |
echo "Info: You must not see anything about paul or dupont now:" | |
grep -ri paul . | |
grep -ri dupont . | |
echo "Script completed successfully. You might want to run the custom installer now ..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment