diff options
author | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
commit | 972dcfcdbfe75dcfeb777150c136576cf1a71e99 (patch) | |
tree | 97a61cd7e293d7ae9d56ef7ed0f81253365bb026 /meta/recipes-core/systemd/systemd-systemctl/systemctl | |
download | poky-972dcfcdbfe75dcfeb777150c136576cf1a71e99.tar.gz |
initial commit for Enea Linux 5.0 arm
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'meta/recipes-core/systemd/systemd-systemctl/systemctl')
-rwxr-xr-x | meta/recipes-core/systemd/systemd-systemctl/systemctl | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl new file mode 100755 index 0000000000..b37f27abfb --- /dev/null +++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl | |||
@@ -0,0 +1,153 @@ | |||
1 | #!/bin/sh | ||
2 | echo "Started $0 $*" | ||
3 | |||
4 | ROOT= | ||
5 | |||
6 | # parse command line params | ||
7 | action= | ||
8 | while [ $# != 0 ]; do | ||
9 | opt="$1" | ||
10 | |||
11 | case "$opt" in | ||
12 | enable) | ||
13 | shift | ||
14 | |||
15 | action="$opt" | ||
16 | services="$1" | ||
17 | cmd_args="1" | ||
18 | shift | ||
19 | ;; | ||
20 | disable) | ||
21 | shift | ||
22 | |||
23 | action="$opt" | ||
24 | services="$1" | ||
25 | cmd_args="1" | ||
26 | shift | ||
27 | ;; | ||
28 | mask) | ||
29 | shift | ||
30 | |||
31 | action="$opt" | ||
32 | services="$1" | ||
33 | cmd_args="1" | ||
34 | shift | ||
35 | ;; | ||
36 | preset) | ||
37 | shift | ||
38 | |||
39 | action="$opt" | ||
40 | services="$1" | ||
41 | cmd_args="1" | ||
42 | shift | ||
43 | ;; | ||
44 | --root=*) | ||
45 | ROOT=${opt##--root=} | ||
46 | cmd_args="0" | ||
47 | shift | ||
48 | ;; | ||
49 | *) | ||
50 | if [ "$cmd_args" = "1" ]; then | ||
51 | services="$services $opt" | ||
52 | shift | ||
53 | else | ||
54 | echo "'$opt' is an unkown option; exiting with error" | ||
55 | exit 1 | ||
56 | fi | ||
57 | ;; | ||
58 | esac | ||
59 | done | ||
60 | if [ "$action" = "preset" -a "$service_file" = "" ]; then | ||
61 | services=$(for f in `find $ROOT/etc/systemd/system $ROOT/lib/systemd/system $ROOT/usr/lib/systemd/system -type f 2>1`; do basename $f; done) | ||
62 | services="$services $opt" | ||
63 | presetall=1 | ||
64 | fi | ||
65 | |||
66 | for service in $services; do | ||
67 | if [ "$presetall" = "1" ]; then | ||
68 | action="preset" | ||
69 | fi | ||
70 | if [ "$action" = "mask" ]; then | ||
71 | if [ ! -d $ROOT/etc/systemd/system/ ]; then | ||
72 | mkdir -p $ROOT/etc/systemd/system/ | ||
73 | fi | ||
74 | cmd="ln -s /dev/null $ROOT/etc/systemd/system/$service" | ||
75 | echo "$cmd" | ||
76 | $cmd | ||
77 | exit 0 | ||
78 | fi | ||
79 | |||
80 | echo "Try to find location of $service..." | ||
81 | # find service file | ||
82 | for p in $ROOT/etc/systemd/system \ | ||
83 | $ROOT/lib/systemd/system \ | ||
84 | $ROOT/usr/lib/systemd/system; do | ||
85 | if [ -e $p/$service ]; then | ||
86 | service_file=$p/$service | ||
87 | service_file=${service_file##$ROOT} | ||
88 | fi | ||
89 | done | ||
90 | if [ -z "$service_file" ]; then | ||
91 | echo "'$service' couldn't be found; exiting with error" | ||
92 | exit 1 | ||
93 | fi | ||
94 | echo "Found $service in $service_file" | ||
95 | |||
96 | # If any new unit types are added to systemd they should be added | ||
97 | # to this regular expression. | ||
98 | unit_types_re='\.\(service\|socket\|device\|mount\|automount\|swap\|target\|path\|timer\|snapshot\)$' | ||
99 | if [ "$action" = "preset" ]; then | ||
100 | action=`egrep -sh $service $ROOT/etc/systemd/user-preset/*.preset | cut -f1 -d' '` | ||
101 | if [ -z "$action" ]; then | ||
102 | globalpreset=`egrep -sh '\*' $ROOT/etc/systemd/user-preset/*.preset | cut -f1 -d' '` | ||
103 | if [ -n "$globalpreset" ]; then | ||
104 | action="$globalpreset" | ||
105 | else | ||
106 | action="enable" | ||
107 | fi | ||
108 | fi | ||
109 | fi | ||
110 | # create the required symbolic links | ||
111 | wanted_by=$(sed '/^WantedBy[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file" \ | ||
112 | | tr ',' '\n' \ | ||
113 | | grep "$unit_types_re") | ||
114 | |||
115 | for r in $wanted_by; do | ||
116 | echo "WantedBy=$r found in $service" | ||
117 | if [ "$action" = "enable" ]; then | ||
118 | mkdir -p $ROOT/etc/systemd/system/$r.wants | ||
119 | ln -s $service_file $ROOT/etc/systemd/system/$r.wants | ||
120 | echo "Enabled $service for $wanted_by." | ||
121 | else | ||
122 | rm -f $ROOT/etc/systemd/system/$r.wants/$service | ||
123 | rmdir --ignore-fail-on-non-empty -p $ROOT/etc/systemd/system/$r.wants | ||
124 | echo "Disabled $service for $wanted_by." | ||
125 | fi | ||
126 | done | ||
127 | |||
128 | # create the required symbolic 'Alias' links | ||
129 | alias=$(sed '/^Alias[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file" \ | ||
130 | | tr ',' '\n' \ | ||
131 | | grep "$unit_types_re") | ||
132 | |||
133 | for r in $alias; do | ||
134 | if [ "$action" = "enable" ]; then | ||
135 | mkdir -p $ROOT/etc/systemd/system | ||
136 | ln -s $service_file $ROOT/etc/systemd/system/$r | ||
137 | echo "Enabled $service for $alias." | ||
138 | else | ||
139 | rm -f $ROOT/etc/systemd/system/$r | ||
140 | echo "Disabled $service for $alias." | ||
141 | fi | ||
142 | done | ||
143 | |||
144 | # call us for the other required scripts | ||
145 | also=$(sed '/^Also[[:space:]]*=/s,[^=]*=,,p;d' "$ROOT/$service_file" \ | ||
146 | | tr ',' '\n') | ||
147 | for a in $also; do | ||
148 | echo "Also=$a found in $service" | ||
149 | if [ "$action" = "enable" ]; then | ||
150 | $0 --root=$ROOT enable $a | ||
151 | fi | ||
152 | done | ||
153 | done | ||