-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstall.sh
executable file
·59 lines (50 loc) · 1.55 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
#!/bin/bash
if [[ "${1}" != "--prefix" ]] ; then
echo -e "Usage:\n ${0} --prefix PREFIX"
exit -1
fi
prefix=$(echo "${2}" | sed 's:/*$::')
if [[ -z "${prefix}" ]] ; then
echo -e "Missing PREFIX operand"
exit -1
fi
if [[ -z "${SUDO_USER}" ]] ; then
THEUSER="${USER}"
cargo build --release
else
THEUSER="${SUDO_USER}"
echo "Detected as sudo. Build as normal user: ${SUDO_USER}"
su "${SUDO_USER}" -c "cargo build --release"
fi
echo "Install in '${prefix}'" && \
mkdir -p "${prefix}" && \
mkdir -p "${prefix}/bin" && \
mkdir -p "${prefix}/lib/systemd/user" && \
mkdir -p "${prefix}/env" && \
install ./target/release/i3-autolayout "${prefix}/bin" && \
sed "s#ExecStart=i3-autolayout#ExecStart=${prefix}/bin/i3-autolayout#g" \
./systemd/i3-autolayout.service \
> "${prefix}/lib/systemd/user/i3-autolayout.service" && \
sed "s#AUTOLAYOUT_BIN_DIR=%%%#AUTOLAYOUT_BIN_DIR=${prefix}/bin#g" \
./env/env \
> "${prefix}/env/env"
THEHOME=$(eval echo "~${THEUSER}")
read -r -p "Source environment for user '${THEUSER}'? [y/N]: " ans
case "${ans}" in
[yY])
line=". \"${prefix}/env/env\""
envs=".profile .bashrc"
for vv in ${envs}; do
file="${THEHOME}/${vv}"
if [[ -f "${file}" ]]; then
if ! grep -Fxq "${line}" "${file}"
then
echo -e "\n${line}" >> "${file}"
echo " Sourced file '${file}'"
fi
fi
done
;;
*)
;;
esac