4 # Copyright (C) 2013-2014 FUJITSU LIMITED
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 if [ ${EUID:-$UID} -ne 0 ] ; then
23 echo "error: Because you are not root, you cannot execute this command."
27 # make queue and message
28 mkdir -p /var/lib/lxcf
29 touch /var/lib/lxcf/hqueue
30 chmod 644 /var/lib/lxcf/hqueue
31 touch /var/lib/lxcf/qqueue
32 chmod 644 /var/lib/lxcf/qqueue
33 touch /var/lib/lxcf/lqueue
34 chmod 644 /var/lib/lxcf/lqueue
35 touch /var/lib/lxcf/exjob
36 chmod 644 /var/lib/lxcf/exjob
37 mkdir -p /var/log/lxcf
38 touch /var/log/lxcf/lxcf-messages
39 chmod 644 /var/log/lxcf/lxcf-messages
41 # check systemd for lxcf and lxcf-sched service
42 if [ -x /usr/bin/systemctl ] ; then
43 if ! systemctl -q is-enabled lxcf.service ; then
44 systemctl -q enable lxcf.service
46 if ! systemctl -q is-active lxcf.service ; then
47 systemctl start lxcf.service
49 if ! systemctl -q is-enabled lxcf-sched.service ; then
50 systemctl -q enable lxcf-sched.service
52 if ! systemctl -q is-active lxcf-sched.service ; then
53 systemctl start lxcf-sched.service
57 # check upstart for lxcf and lxcf-sched service
58 if [ -x /sbin/initctl ] ; then
59 initctl status lxcf-sched |& grep "start/running" >& /dev/null
60 if [ $? -ne 0 ] ; then
61 initctl start lxcf-init >& /dev/null
62 initctl start lxcf-sched >& /dev/null
63 initctl restart libvirt-bin >& /dev/null
64 /etc/init.d/libvirt-bin restart >& /dev/null
69 # check on repetition execution
70 if [ -f /etc/lxcf/container_name ] ; then
71 echo "The lxcf command is executed in the LXCF container."
77 cat <<- EOF | awk -f -
79 print levdist("$word1", "$word2")
81 function levdist(str1, str2, i, j, l1, l2, x, t, a, b, c) {
84 } else if (str1 == "" || str2 == "") {
85 return length(str1 str2)
86 } else if (substr(str1, 1, 1) == substr(str2, 1, 1)) {
87 for (i = 2; substr(str1, i, 1) == substr(str2, i, 1); i++)
89 return levdist(substr(str1, i), substr(str2, i))
90 } else if (substr(str1, l1 = length(str1), 1) \\
91 == substr(str2, l2 = length(str2), 1)) {
92 for (i = 1; substr(str1, l1 - i, 1) == substr(str2, l2 - i, 1); i++)
94 return levdist(substr(str1, 1, l1 - i), substr(str2, 1, l2 - i))
96 for (i = 0; i < l2 + 1; i++)
98 for (i = t = 0; i < l1; i++) {
100 for (j = 0; j < l2; j++) {
103 c = x[!t, j] + (substr(str1, i + 1, 1) != substr(str2, j + 1, 1))
104 x[t, j + 1] = (a < b && a < c) ? a : (b < a && b < c) ? b : c
112 export PATH=/usr/lib64/lxcf/sbin:$PATH
114 if [ $# -eq 0 ] ; then
118 GNU GENERAL PUBLIC LICENSE Version 2
119 Type: 'helpcmd' for help with commands
120 'exit' or '^d' to quit
123 PS1="LXCF # " exec /bin/sh
125 cmds=(`ls -f --ind=none /usr/lib64/lxcf/sbin | sed '/^\.\{1,2\}$/d'`)
126 for c in "${cmds[@]}" ; do [ "$c" == "$1" ] && exec "$@" ; done
127 dist=() ; for c in "${cmds[@]}" ; do dist+=(`levenshtein "$c" "$1"`) ; done
128 min=$dist ; for d in ${dist[@]} ; do [ $d -lt $min ] && min=$d ; done
130 for c in "${cmds[@]}" ; do
131 [ ${dist[$i]} -eq $min ] && cand+=("$c") ; let i++
133 [ ${#cand[@]} -eq 1 ] && object="this" || object="one of these"
135 ${0##*/}: '$1' is not a ${0##*/} command. See '${0##*/} helpcmd'.
137 Did you mean $object?
139 for c in "${cand[@]}" ; do echo $'\t'"$c" ; done