linglong/debian/linglong-bin.postinst

107 lines
4.4 KiB
Bash
Executable File

#!/bin/bash
case "$1" in
configure)
LINGLONG_ROOT="/var/lib/linglong"
VERSION=0
if [ -f /etc/os-release ]; then
VERSION=$(sed -ne '/^VERSION_ID=.*$/P' /etc/os-release | awk -F = '{print $2}' | sed -e 's/"//g' | awk -F . '{print $1}')
if [ -z "${VERSION}" ]; then
VERSION=0
fi
if [ ${VERSION} -eq 20 ]; then
LINGLONG_ROOT="/data/linglong"
elif [ ${VERSION} -eq 23 ]; then
LINGLONG_ROOT="/persistent/linglong"
fi
fi
if [ ! -d ${LINGLONG_ROOT}/repo ]; then
mkdir -p ${LINGLONG_ROOT}/layers
ostree --repo=${LINGLONG_ROOT}/repo init --mode=bare-user-only
ostree --repo=${LINGLONG_ROOT}/repo config set --group core min-free-space-size 600MB
ostree --repo=${LINGLONG_ROOT}/repo remote add --no-gpg-verify repo https://repo-dev.linglong.space/repos/repo
chmod -R 0775 ${LINGLONG_ROOT}
else
echo "Directory is already exists."
fi
#copy config.json to LINGLONG_ROOT
if [ ! -f ${LINGLONG_ROOT}/config.json ]; then
cp /usr/share/linglong/config.json ${LINGLONG_ROOT}/config.json
fi
#daemon-reload for /usr/lib/systemd/user-environment-generators/61-linglong
if [ -f /usr/lib/systemd/user-environment-generators/61-linglong ]; then
systemctl daemon-reload
fi
useruid=400
usergid=400
if [ $(grep -cw "deepin-linglong" /etc/passwd) -gt '0' ]; then
deepinlinglonguid=$(id deepin-linglong | awk -F= '{print $2}' | awk -F"(" '{print $1}')
if [ $deepinlinglonguid -ge 400 ] && [ $deepinlinglonguid -le 499 ]; then
useruid=$deepinlinglonguid
else
while [ $(getent passwd $useruid | wc -l) -gt 0 ]; do
useruid=$(expr $useruid + 1)
if [ $useruid -ge 499 ]; then
echo "uid400-499被占用"
fi
done
fi
deepinlinglonggid=$(id deepin-linglong | awk -F= '{print $3}' | awk -F"(" '{print $1}')
if [ $deepinlinglonggid -ge 400 ] && [ $deepinlinglonggid -le 499 ]; then
usergid=$deepinlinglonggid
else
while [ $(getent passwd $usergid | wc -l) -gt 0 ]; do
usergid=$(expr $usergid + 1)
if [ $usergid -ge 499 ]; then
echo "gid400-499被占用"
fi
done
fi
groupmod -g $usergid deepin-linglong
usermod -u $useruid -s /sbin/nologin deepin-linglong
if ! $(groups deepin-linglong | grep -qw "users"); then
gpasswd -a deepin-linglong users
fi
else
while [ $(getent passwd $useruid | wc -l) -gt 0 ]; do
useruid=$(expr $useruid + 1)
if [ $useruid -ge 499 ]; then
echo "uid400-499被占用"
fi
done
while [ $(getent group $usergid | wc -l) -gt 0 ]; do
usergid=$(expr $usergid + 1)
if [ $usergid -ge 499 ]; then
echo "gid400-499被占用"
fi
done
groupadd -g $usergid deepin-linglong
useradd -u $useruid -g deepin-linglong -s /sbin/nologin deepin-linglong
gpasswd -a deepin-linglong users
fi
chown deepin-linglong:users /usr/bin/ll-package-manager >/dev/null 2<&1
chown -R deepin-linglong:users ${LINGLONG_ROOT} >/dev/null 2<&1
if [ -d /var/log/linglong ]; then
chmod o+w /var/log/linglong
fi
sed -i '/.*store-llrepo.deepin.com.*/ c \url=https://store-llrepo.deepin.com/repos/repo' ${LINGLONG_ROOT}/repo/config
;;
abort-upgrade | abort-remove | abort-deconfigure) ;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
#DEBHELPER#
exit 0