-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp-projectmanager-install.sh
executable file
·64 lines (53 loc) · 2.07 KB
/
p-projectmanager-install.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
59
60
61
62
63
#!/usr/bin/env bash
eval P_SOURCEFILE_LOCAL="$HOME/.p.sh";
eval P_SOURCEFILE_REMOTE="https://raw.githubusercontent.com/hhallman/p/master/p.sh";
eval P_PROJECTFILE_USER_LOCAL="$HOME/.pfile.sh";
eval P_PROJECTFILE_USER_REMOTE="https://raw.githubusercontent.com/hhallman/p/master/example-pfile.sh";
eval USER_BASHRC_NOPROFILE="$HOME/.bashrc"
eval USER_BASHRC_PROFILE="$HOME/.bash_profile"
function FAIL {
echo -e "\033[31m[FAIL]\033[0m $@";
exit 1;
}
function STEP {
echo -e "\033[34m[STEP]\033[0m $@";
}
function NOTE {
echo -e "\033[33m[NOTE]\033[0m $@";
}
function DONE {
echo -e "\033[32m[DONE]\033[0m $@";
}
STEP "Downloading files into $P_SOURCEFILE_LOCAL, $P_PROJECTFILE_USER_LOCAL";
curl -s -o "$P_SOURCEFILE_LOCAL" "$P_SOURCEFILE_REMOTE" ||
FAIL "Could not download $P_SOURCEFILE_REMOTE to $P_SOURCEFILE_LOCAL";
[ -f "$P_PROJECTFILE_USER_LOCAL" ] && {
NOTE "Local projectfile already exists, ($P_PROJECTFILE_USER_LOCAL) will not overwrite. Consider updating from: $P_PROJECTFILE_USER_REMOTE"
}
[ -f "$P_PROJECTFILE_USER_LOCAL" ] || {
curl -s -o "$P_PROJECTFILE_USER_LOCAL" "$P_PROJECTFILE_USER_REMOTE" ||
FAIL "Could not download $P_PROJECTFILE_USER_REMOTE to $P_PROJECTFILE_USER_LOCAL";
}
function install_to_script {
USER_BASHRC="$1";
STEP "Configuring bash profile: $USER_BASHRC";
[ -f $USER_BASHRC ] || { NOTE "Creating file: $USER_BASHRC"; }
cat >> $USER_BASHRC << EOF
#############
# Set up p-project manager. (info: https://github.com/hhallman/p )
[ -f $P_SOURCEFILE_LOCAL ] || {
echo "ERROR: p project-manager script is missing. Please check https://github.com/hhallman/p or clean script: $USER_BASHRC ";
}
[ -f $P_SOURCEFILE_LOCAL ] && {
. $P_SOURCEFILE_LOCAL;
}
# end-of-p
#############
EOF
}
#p project manager should be accessible in both login and nologin shells:
install_to_script "$USER_BASHRC_NOPROFILE";
install_to_script "$USER_BASHRC_PROFILE";
DONE "Done setting up p project-manager. Use 'p create' to create a project";
NOTE "To load p project-manager into the current shell, run the following command: (Automatic in new shells.)"
echo "source $P_SOURCEFILE_LOCAL"