#!/bin/env bash

# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: LGPL-3.0-or-later

# This script should be called by systemd in the ExecStartPre field of
# org.deepin.linglong.PackageManager.service to create LINGLONG_ROOT dir.

set -e

if [[ $(id -u) -ne 0 ]]; then
    echo "This script must be run as root."
    exit 255
fi

LINGLONG_ROOT="@LINGLONG_ROOT@"
LINGLONG_USERNAME="@LINGLONG_USERNAME@"

function create_linglong_root(){
    if [[ -d "$LINGLONG_ROOT" ]]; then
        return
    fi

    mkdir -p "$LINGLONG_ROOT"
    chown "$LINGLONG_USERNAME:$LINGLONG_USERNAME" "$LINGLONG_ROOT"
}

create_linglong_root
