-
Notifications
You must be signed in to change notification settings - Fork 10
/
surc
executable file
·62 lines (54 loc) · 1.43 KB
/
surc
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
#!/usr/bin/env bash
ANYRC_ENV='su'
init() {
SU_OPTS=''
while [[ -n "$1" ]]; do
case $1 in
-* )
SU_OPTS="${SU_OPTS} $1" ;;
* )
if [ -z "${SU_USER:+_}" ]; then
SU_USER="$1"
fi; ;;
esac
shift
done
if [ -z "${SU_USER:+_}" ]; then
exit 1
fi
}
mk_tmp_dir() {
TMP_DIR="$(mktemp -d /tmp/anyrc.XXXXXX)"
}
transfer() {
cp "${ANYRC_DANYRC}" "${TMP_DIR}/${DANYRC_NAME}"
cp -r "${ANYRC_DANYRCD}" "${TMP_DIR}/${DANYRCD_NAME}"
# Transfer *rc
local CMD_DIR="$(abs_dirname $0)"
for cmd in "${ANYRC_CMD}" "${ANYRC_CMDS[@]}"; do
if [ -f "${CMD_DIR}/${cmd}" ]; then
cp "${CMD_DIR}/${cmd}" "${TMP_DIR}/${cmd}"
fi
done
chmod -R 777 "${TMP_DIR}"
}
connect() {
sudo -s -u "${SU_USER}" ${SU_OPTS} bash -c "\
export DANYRC_NAME=\"${DANYRC_NAME}\" && \
export DANYRCD_NAME=\"${DANYRCD_NAME}\" && \
export ANYRC_ROOT=\"${TMP_DIR}\" && \
export ANYRC_DANYRC=\"\${ANYRC_ROOT}/\${DANYRC_NAME}\" && \
export ANYRC_DANYRCD=\"\${ANYRC_ROOT}/\${DANYRCD_NAME}\" && \
export ANYRC_HOME=\"\${ANYRC_DANYRCD}\" && \
export PATH=\"\${ANYRC_ROOT}:\${PATH}\" && \
trap \"rm -rf \${ANYRC_ROOT}/*; exit\" 0 && \
mkdir -p \${ANYRC_DANYRCD} && \
source \${ANYRC_DANYRC}
if [ \"\${SHELL##*/}\" = 'bash' ]; then
bash --rcfile \${ANYRC_DANYRC};
else
\${SHELL};
fi"
rm -rf "${TMP_DIR}" # FIXME
}
source anyrc