/
elito-image.bbclass
94 lines (72 loc) · 2.77 KB
/
elito-image.bbclass
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
IMAGE_FEATURES[validitems] += "devel-history devel-sshkey no-root-bash"
USER_CONFIG_DIRS ?= "~${USER}/.config/openembedded ~${USER}/.config/oe ~${USER}/.config/elito"
USER_CONFIG_DIRS[doc] = "list of space separated paths where user configuration will be searched"
USER_CONFIG_DIRS[type] = "list"
USER_CONFIG_DIRS_EXPANDED = "${@' '.join(map(lambda x: host_expanduser(x), oe.data.typed_value('USER_CONFIG_DIRS', d)))}"
USER_CONFIG_DIRS_EXPANDED[type] = "list"
USER_CONFIG_DIR ?= "${@find_first_directory(oe.data.typed_value('USER_CONFIG_DIRS_EXPANDED', d))}"
def host_expanduser(dir):
## we have to expand it in an extra subprocess with clean environment
## because function might be run within PSEUDO context
cmd = [sys.executable, '-c', 'import sys, os.path; sys.stdout.write(os.path.expanduser(sys.argv[1]))', dir]
env = { 'PSEUDO_DISABLED' : '1' }
res = bb.process.Popen(cmd, shell = False, env = env).communicate()[0]
return res.decode('ascii')
def find_first_directory(dirs):
for d in dirs:
if os.path.isdir(d):
return d
return ""
elito_add_devel_history() {
d=`hostname -d 2>/dev/null` && d=-$d
h=`hostname -f 2>/dev/null || hostname` && h=-$h
for p in "$h" "$d" ""; do
f='${PROJECT_TOPDIR}'/files/bash_history$p
test -e "$f" || continue
install -D -p -m 0600 "$f" '${IMAGE_ROOTFS}${ROOT_HOME}'/.bash_history
break
done
}
_elito_search_devel_sshkey() {
u='${USER}' || u=
d=`hostname -d 2>/dev/null` || d=
h=`hostname -f 2>/dev/null || hostname` || h=
set --
if test -n "$u"; then
set -- "$@" ${h:+"-$u@$h"} ${d:+"-$u@$d"} "-${u}@"
fi
set -- "$@" ${h:+"-$h"} ${d:+"-$d"} ""
for p in "$@"; do
f="${PROJECT_TOPDIR}"/files/authorized_keys$p
! test -e "$f" || break
done
}
elito_add_devel_sshkey() {
f='${USER_CONFIG_DIR}/authorized_keys'
if ! test -e "$f"; then
_elito_search_devel_sshkey
fi
! test -e "$f" || \
install -D -p -m 0644 "$f" ${IMAGE_ROOTFS}${ROOT_HOME}/.ssh/authorized_keys
}
elito_set_rootbash() {
f=${IMAGE_ROOTFS}/etc/passwd
b=${IMAGE_ROOTFS}/bin/bash
test -w "$f" || return 0
if test -x "$b" || test -L "$b"; then
sed -i -e 's!^\(root:.*:\)/bin/sh$!\1/bin/bash!' "$f"
fi
}
ROOTFS_POSTPROCESS_COMMAND += "${@\
bb.utils.contains('IMAGE_FEATURES', 'devel-history', \
'elito_add_devel_history ;', '', d)}"
ROOTFS_POSTPROCESS_COMMAND += "${@\
bb.utils.contains('IMAGE_FEATURES', 'devel-sshkey', \
'elito_add_devel_sshkey ;', '', d)}"
ROOTFS_POSTPROCESS_COMMAND += "${@\
bb.utils.contains('IMAGE_FEATURES', 'no-root-bash', \
'', 'elito_set_rootbash ;', d)}"
ROOTFS_POSTPROCESS_COMMAND_remove = "${@\
bb.utils.contains('IMAGE_FEATURES', 'devel-sshkey', \
bb.utils.contains('IMAGE_FEATURES', 'allow-empty-password', \
'', 'ssh_allow_empty_password;', d), '', d)}"