-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_user_config.sh
executable file
·58 lines (49 loc) · 2.33 KB
/
new_user_config.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Script to configure a new user
# Adds custom aliases file, add change user script, etc
working_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cd $working_dir
source scripts/colors.sh
# Make sure we have installed
if [ -d "$ALIASES_DIR" ]; then
cd $ALIASES_DIR
else
text_red
echo "Please run the install script first!"
text_reset
exit -1
fi
# Get this user name
read -p "Enter your desired username. Should be unique! " username
username=$(echo $username | sed 's/ //g')
text_green
echo "Setting username:" $username
text_reset
# Create a unique file for this user's personal aliases
touch scripts/users/$username.sh
echo '#!/bin/bash' >> scripts/users/$username.sh
echo '' >> scripts/users/$username.sh
echo '# ADD YOUR PERSONAL ALIASES HERE' >> scripts/users/$username.sh
echo '' >> scripts/users/$username.sh
echo '# An alias for changing the git user on this computer' >> scripts/users/$username.sh
# Give the the git switching alias automatically
read -p "Enter your Github username: " git_user
read -p "Enter the email affiliated with your Github account: " git_email
echo "alias git_$username='git config --global user.name $git_user ; git config --global user.email $git_email'" >> scripts/users/$username.sh
# Add an entry to change_user script for this user
echo "" >> scripts/change_user.sh
echo "function source_future_$username {" >> scripts/change_user.sh
echo " echo '#!/bin/bash' > \$ALIASES_DIR/.adam_aliases/current_user #empties current user file" >> scripts/change_user.sh
echo " echo 'source \$ALIASES_DIR/scripts/users/$username.sh' >> \$ALIASES_DIR/.adam_aliases/current_user #set to you" >> scripts/change_user.sh
echo " source \$ALIASES_DIR/scripts/users/$username.sh #and source the new file now" >> scripts/change_user.sh
echo " git_$username #set new git user" >> scripts/change_user.sh
echo " DIR=\"\$ALIASES_DIR/.adam_aliases/$username\"" >> scripts/change_user.sh
echo " if [ ! -d \"\$DIR\" ]; then" >> scripts/change_user.sh
echo " mkdir \"\$DIR\"" >> scripts/change_user.sh
echo " fi" >> scripts/change_user.sh
echo "}" >> scripts/change_user.sh
echo "alias source_$username='source_future_$username ; source ~/.bashrc'" >> scripts/change_user.sh
# Add a folder for their temporary files
if [[ ! -d $ALIASES_DIR/.adam_aliases/$username ]]; then
mkdir $ALIASES_DIR/.adam_aliases/$username
fi