blob: 333f72be319ad786227c015d3d4173e01be3394a (
plain)
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
|
_esh_target_user() {
if [ -n "${SUDO_USER:-}" ] && [ "${SUDO_USER}" != "root" ]; then
printf '%s\n' "$SUDO_USER"
return 0
fi
return 1
}
_esh_init_user_files() {
local user_name user_home config_home data_home
if ! user_name="$(_esh_target_user)"; then
cat <<'EOF'
EikaShell installed as: /usr/bin/esh
Per-user files were not created automatically because the target user
could not be detected.
To initialize manually, run as your normal user:
mkdir -p ~/.config/esh/scripts
mkdir -p ~/.local/share/esh/scripts
touch ~/.config/esh/eshrc
touch ~/.local/share/esh/history
Per-user config is read from:
~/.config/esh/eshrc
EOF
return 0
fi
user_home="$(getent passwd "$user_name" | cut -d: -f6)"
if [ -z "$user_home" ] || [ ! -d "$user_home" ]; then
echo "EikaShell: could not determine home directory for user '$user_name'"
return 0
fi
config_home="${user_home}/.config"
data_home="${user_home}/.local/share"
install -d -m755 "${config_home}/esh/scripts"
install -d -m755 "${data_home}/esh/scripts"
install -d -m755 "${data_home}/esh"
if [ ! -f "${config_home}/esh/eshrc" ]; then
: >"${config_home}/esh/eshrc"
fi
if [ ! -f "${data_home}/esh/history" ]; then
: >"${data_home}/esh/history"
fi
chown -R "${user_name}:${user_name}" \
"${config_home}/esh" \
"${data_home}/esh"
cat <<EOF
EikaShell installed as: /usr/bin/esh
Per-user files initialized for: ${user_name}
Config:
${config_home}/esh/eshrc
Script directories:
${config_home}/esh/scripts
${data_home}/esh/scripts
History:
${data_home}/esh/history
EOF
}
_esh_add_to_shells() {
if [ ! -f /etc/shells ]; then
: >/etc/shells
fi
if ! grep -qx '/usr/bin/esh' /etc/shells; then
echo '/usr/bin/esh' >>/etc/shells
fi
}
_esh_remove_from_shells() {
if [ -f /etc/shells ]; then
sed -i '\|^/usr/bin/esh$|d' /etc/shells
fi
}
post_install() {
_esh_add_to_shells
_esh_init_user_files
}
post_upgrade() {
_esh_add_to_shells
_esh_init_user_files
}
post_remove() {
_esh_remove_from_shells
}
|