1
+ #! /bin/bash
2
+ # ######################################
3
+ # Automate the install process for .cmdw
4
+ # wrapper for all users on a given system.
5
+ #
6
+ # Install:
7
+ # source <(curl -s https://raw.githubusercontent.com/0xZDH/cmdw/master/install-all.sh)
8
+ # ######################################
9
+
10
+ # Validate the current terminal is Bash or Zsh.
11
+ # Assume this is the terminal all users will use.
12
+ [ -n " $BASH_VERSION " -o -n " $ZSH_VERSION " ] || return 0
13
+
14
+ # Download cmdw.sh to our home directory. Force the file
15
+ # to be overwritten when it exists to allow for updates
16
+ # to be installed.
17
+ curl -s -o " $HOME /.cmdw" \
18
+ -q " https://raw.githubusercontent.com/0xZDH/cmdw/master/cmdw.sh"
19
+
20
+ # Identify current shell type
21
+ [ -n " $ZSH_VERSION " ] && \
22
+ shell_file=" .zshrc" || \
23
+ shell_file=" .bashrc"
24
+
25
+ # Identify, bsaed on system, where the user's home directories
26
+ # are located
27
+ if [[ " $( uname) " == " Darwin" ]]; then
28
+ # OS X
29
+ home_dir=" /Users"
30
+ else
31
+ # Linux
32
+ home_dir=" /home"
33
+ fi
34
+
35
+ # Loop over all users on the system and set up cmdw for
36
+ # each user's profile
37
+ for user in $( ls " $home_dir " ) ; do
38
+ # Ignore the 'Shared' dir on OS X systems
39
+ if [[ " $user " == " Shared" ]]; then
40
+ continue
41
+ fi
42
+
43
+ # Define the user's home dir
44
+ user_dir=" $home_dir /$user "
45
+
46
+ # Copy the .cmdw script to each user's home dir
47
+ if [ " $HOME " != " $user_dir " ]; then
48
+ cp " $HOME /.cmdw" " $user_dir /"
49
+ fi
50
+
51
+ # Add .cmdw to each user's shell profile
52
+ [ ! " $( grep ' source $HOME/.cmdw' " $user_dir /$shell_file " ) " ] && \
53
+ echo ' [ -f $HOME/.cmdw ] && source $HOME/.cmdw' >> " $user_dir /$shell_file "
54
+
55
+ # Clean up
56
+ unset user_dir
57
+ done
58
+
59
+ # Reload our shell profile
60
+ source " $HOME /$shell_file "
61
+
62
+ # Clean up
63
+ unset shell_file
64
+ unset home_dir
0 commit comments