-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
68 lines (56 loc) · 1.69 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
#!/bin/bash
#set -x
function generate_script_alias() {
local script="${1}"
local name="$(basename ${script})"
read -r exline < $1
local interpreter="${exline#\#!}"
echo "alias ${name}='${interpreter} ${script}'"
}
shopt -s dotglob
shopt -s nullglob
#command -v realpath >/dev/null 2>&1 || realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" }
# Change to dotfiles directory
cd "$(dirname $(realpath "$0"))"
# Recursively download git submodules
git submodule update --init --recursive
# Copy files to ~/
for file in ${HOME}/dotfiles/copy/*; do
cp "${file}" "${HOME}/$(basename ${file})"
done
# Symnlink files to ~/
for file in $HOME/dotfiles/link/*; do
targetlink="${HOME}/$(basename ${file})"
if [ ! -L "${targetlink}" ] && [ -f "${targetlink}" ]; then
mv "${targetlink}" "${targetlink}.bak"
fi
if [ ! -L "${targetlink}" ]; then
ln -sf "${file}" "${targetlink}"
fi
done
# Symnlink bin files
binlink="${HOME}/bin"
if [ ! -L "${binlink}" ]; then
ln -sf "${HOME}/dotfiles/bin" "${binlink}"
fi
ALIAS_FILE="${HOME}/.aliases"
for file in ${HOME}/bin/*; do
# Make bin files executable
chmod +x "${file}"
## If its locked down and can't make files executable workaround this by generating aliases for bin files
if [[ ! -x "${file}" ]]; then
# Generate aliases for bin files
isFile=$(file -0 "${file}" | cut -d $'\0' -f2)
case "${isFile}" in
(*text*)
generate_script_alias "${file}" >> "${ALIAS_FILE}"
;;
(*)
echo "Can't generate script alias for ${file} it is not a text file"
;;
esac
fi
done
if [[ -f "${ALIAS_FILE}" ]]; then
echo "# Aliases for bin scripts generated $(date) by $(whoami)" > "${ALIAS_FILE}"
fi