summaryrefslogtreecommitdiff
path: root/policy/updates/update-policy-to-v8.sh
blob: 7eb4f582db1e682660d5d071afb6e599797d645d (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
#!/bin/sh -e

#
# Copyright (c) 2018-2020 Samsung Electronics Co., Ltd. All rights reserved.
#
# This file is licensed under the terms of MIT License or the Apache License
# Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details.
# See the LICENSE file or the notice below for Apache License Version 2.0
# details.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

export PATH=/sbin:/usr/sbin:/bin:/usr/bin

. /etc/tizen-platform.conf

### In case there is no systemd or no systemd configuration on image (ie. some TV images)
### this can be still run...
set +e
systemctl stop security-manager.service security-manager.socket || echo "Problem with systemd (no .service/.socket files?), continuing"
set -e

### ...but we have to be sure that the daemon is not running;
### manually choosing file descriptor number (9) as sh on some images is quite old
### doesn't seem to support the exec {fd_var}>/path/to/file syntax
lock_taken=false
if [ -d "$TZ_SYS_RUN/lock" ]; then
exec 9>"$TZ_SYS_RUN/lock/security-manager.lock"
flock -n 9 || { echo "ERROR: flock() failed, security-manager daemon is probably running, exiting from update" >&2; exit 1; }
lock_taken=true
fi

temp_dir=`mktemp -d`

for dir in "$TZ_SYS_VAR"/security-manager/*/
do
    user_name=`basename "$dir"`
    if user_id=`id -u $user_name` 2>&1; then
        mv "$dir" $temp_dir/$user_id
    fi
done

for dir in $temp_dir/*/
do
    mv "$dir" "$TZ_SYS_VAR"/security-manager/
done

rmdir $temp_dir

### Still needed in case systemd is managing service, otherwise systemctl will fail to start daemon
if [ "$lock_taken" = true ]; then
flock -u 9
fi

### +/-e needed as systemd can be unavailable or purposedly lacking configuration on some images (ie. TV)
set +e
systemctl start security-manager.service security-manager.socket || echo "Problem with systemd (no .service/.socket files?), continuing"
set -e