-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·86 lines (75 loc) · 1.83 KB
/
install
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
usage_short(){ echo "usage: $(basename $0) [-hl]" ; }
usage() {
# eventually want to add [-u user] [-p path] and -s (system) options.
usage_short
echo -e "\t-h\tDisplay this help text"
echo -e "\t-l\tInstall via Symlinks to these files instead of copying"
echo -e "\t\t(Don't move this dir after, or you'll be sorry!)"
}
# should we do a backup? probably
perform_backup=yes
#set $PREFIX for install. This should match the PREFIX in bashrc.
PREFIX=$HOME/.local
# by default, we install by copying, so the user can delete this directory.
# installing by symlink is useful for development, and other purposes.
install="cp -a"
# the list of files to install. We have to prefix each with a '.' during install.
files=(
bash_profile
bashrc
bash.d
)
# list of directories to make. This sets up $PREFIX to work right.
dirs=(
bin
etc
include
lib
lib32
opt
sbin
share
src
)
# Adust install feature based on OS
case `uname -s` in
Linux|Darwin) install='cp -a' ;;
SunOS) install='cp -PR' ;;
esac
while getopts ":hl" option; do
case $option in
h) usage
exit 0
;;
l) install="ln -s"
;;
:) echo "$(basename $0): option -$option requires an argument"
usage_short
exit 1
;;
?) echo "$(basename $0): illegal option -- $option"
usage_short
exit 1
;;
esac
done
# First, backup any old bash configuration files so we don't lose them.
if [ $perform_backup ]; then
backup=$(mktemp -d ~/.bash_backup.XXXXXX)
for file in $HOME/.bash*; do
mv $file $backup >/dev/null 2>&1
done
mv $backup/.bash_history $HOME
# don't leave an empty directory hanging around
rmdir $backup 2>/dev/null || true
mv $backup $HOME 2>/dev/null || true
fi
# install bashrc files
for file in ${files[@]}; do
$install $PWD/$file $HOME/.$file
done
# create prefixed home directories
for dir in ${dirs[@]}; do
mkdir -p $PREFIX/$dir
done