Skip to content

Instantly share code, notes, and snippets.

@dzogrim
Last active September 26, 2024 16:39
Show Gist options
  • Save dzogrim/350344c09190d9ea4d53427005758469 to your computer and use it in GitHub Desktop.
Save dzogrim/350344c09190d9ea4d53427005758469 to your computer and use it in GitHub Desktop.
Use a full configuration template for new user creation by cloning directory
#!/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