Skip to content

Commit 726353b

Browse files
committed
Add install script for all users
1 parent 12d7faf commit 726353b

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ stop Wed 07 Oct 2020 05:00:00 AM UTC
2323

2424
Install one-liner: `source <(curl -s https://raw.githubusercontent.com/0xZDH/cmdw/master/install.sh)`
2525

26+
### All Users
27+
28+
The `install-all.sh` script will install and setup cmdw for all users on the system.
29+
30+
One-liner: `source <(curl -s https://raw.githubusercontent.com/0xZDH/cmdw/master/install-all.sh)`
31+
2632
## History Size:
2733
If required, the user can modify the size of the maintained history file by setting CMDWSIZE as an environment variable (Default: 10,000):
2834
* `export CMDWSIZE=1000`

install-all.sh

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)