-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·120 lines (101 loc) · 2.76 KB
/
install.sh
File metadata and controls
executable file
·120 lines (101 loc) · 2.76 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#! /bin/bash
usage='Usage: ./install.sh [-n] [-f] app1 [app2 app3 ..]
-n dry-run; no filesystem changes
-f force overwrite of existing symlinks'
# DEBUG mode controlled by env var
if [[ -n $DEBUG ]]; then set -x; fi
DRY_RUN=0
FORCE=0
while getopts 'nf' opts
do
case $opts in
n ) DRY_RUN=1;;
f ) FORCE=1;;
* ) echo "$usage"
exit 1;;
esac
done
shift $((OPTIND-1))
if [[ -z $TERMUX_VERSION ]] && [[ $(id -u) -gt 0 ]] && ! command -v sudo >/dev/null 2>&1; then
echo 'Please install sudo and try again'
exit 44
fi
# retrieve all repo submodules
git submodule update --init --recursive
source ./lib.sh
# ensure curl is available
if ! command -v curl >/dev/null 2>&1; then
if [[ $(uname) == 'Darwin' ]]; then
brew install curl
elif [[ -n $TERMUX_VERSION ]]; then
pkg install curl
else
sudo apt-get install -y curl
fi
fi
# ensure stow is available
if ! command -v stow >/dev/null 2>&1; then
if [[ $(uname) == 'Darwin' ]]; then
brew install stow
elif [[ -n $TERMUX_VERSION ]]; then
pkg install stow
else
sudo apt-get install -y stow
fi
fi
function delete_symlinks {
for filename in $1; do
if [[ -f $HOME/$filename || -L $HOME/$filename ]]; then
echo "Deleting file $HOME/$filename"
if [[ $DRY_RUN -eq 0 ]]; then
rm -f "$HOME/$filename"
fi
fi
done
}
for app in "$@"
do
if [[ ! -d $app ]]; then
echo "Subdirectory $app does not exist!"
continue
fi
if [[ $FORCE -eq 1 ]]; then
# forcefully delete any conflicts in stow
IFS=$(echo -en "\n\b")
# check stow version
VERSION=$(stow -V | awk '/stow/ {print $5}')
if [[ ${VERSION:0:1} -eq 1 ]]; then
# v.1.3.3
# parse stow's conficts
CONFLICTS=$(stow -c "$app" 2>&1 | awk '/CONFLICT/ {print $4}')
delete_symlinks "$CONFLICTS"
else
# v2.2.0
# remove existing symlinks
# remove files which would be replaced with symlinks
# remove symlinks which belong to other packages (which may cause trouble later but ho hum)
CONFLICTS=$(stow -nv "$app" 2>&1 | awk '/\* existing target is/ {print $NF}')
if [[ -n $CONFLICTS ]]; then
echo "$CONFLICTS"
delete_symlinks "$CONFLICTS"
fi
fi
fi
# use per-app install.sh, or just symlink with stow
if [[ -x $app/install.sh ]]; then
source ./$app/install.sh
fi
# per-app install scripts can return 255 to indicate that the
# stow step should be skipped here
if [[ ! $? -eq 255 ]]; then
# restow when force flag supplied
if [[ $FORCE -eq 1 ]]; then RESTOW='--restow'; else RESTOW=''; fi
if [[ $DRY_RUN -eq 1 ]]; then DR='-n'; else DR=''; fi
# use stow to create symlinks in $HOME
if ! stow -v --ignore='install.sh' --ignore='.md$' "$app" $RESTOW --target="$HOME" $DR; then
if [[ $DRY_RUN -eq 0 ]]; then
echo 'Stow returned a non-zero result. You may want to re-run with -f (force)'
fi
fi
fi
done