-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall.sh
executable file
·69 lines (58 loc) · 1.79 KB
/
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
64
65
66
67
68
69
#!/bin/sh
##############################################################
# canhaz install script
# Works from github or locally
##############################################################
ME="canhaz"
##############################################################
# Remote mode
# Pull from git, then run local install and cleanup
##############################################################
if [[ ! -f "$0" ]]; then
GITHUB_URL="git@github.com:briancavalier/${ME}.git"
# GITHUB_URL="git@github.com:unscriptable/cssx.git"
# Make a reasonable tmp dir
TMP_DIR="/tmp/${ME}-install.$$"
mkdir -p "$TMP_DIR"
git clone "$GITHUB_URL" "$TMP_DIR"
# Go to tmp dir and run this install.sh script again
# in local mode
pushd $TMP_DIR >> /dev/null
./install.sh
popd >> /dev/null
# Cleanup and exit
rm -rf "$TMP_DIR"
exit 0
fi
##############################################################
# Local mode
# Actually do the install
##############################################################
DEST="${HOME}/.${ME}"
echo "Installing in $DEST"
mkdir -p "$DEST"
LOG="$DEST/install.log"
echo "---------------------------------------" >> "$LOG"
echo "Installing ${ME}" >> "$LOG"
echo `date` >> "$LOG"
# Use rsync to install. This should allow install.sh to
# work as an updater also.
rsync -avp ./* "$DEST/" >> "$LOG"
chmod -R a+x ${DEST}/bin/*
# If we're sudo'ed, chmod files back to original user
if [[ "$SUDO_USER" != "" ]]
then
chown -R "$SUDO_USER" "$DEST"
fi
# Create symlink
EXE_DIR="/usr/local/bin"
mkdir -p "$EXE_DIR"
EXE="$EXE_DIR/$ME"
if [[ -e "$EXE" ]]
then
echo "warning: $EXE already exists. I'm not gonna overwrite it, so if it's a symlink from a previous install, it will still work." | tee -a "$LOG"
exit 1
else
ln -s $DEST/bin/generate "$EXE"
echo "Linked $EXE -> $DEST/bin/generate" | tee -a "$LOG"
fi