Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update linglong-bin.postinst #508

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 66 additions & 63 deletions debian/linglong-bin.postinst
Original file line number Diff line number Diff line change
@@ -1,98 +1,101 @@
#!/bin/sh
#!/bin/bash

Owensuwu marked this conversation as resolved.
Show resolved Hide resolved
# SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: LGPL-3.0-or-later
Owensuwu marked this conversation as resolved.
Show resolved Hide resolved

log_file="/var/log/linglong-bin.log" # Log file path

Owensuwu marked this conversation as resolved.
Show resolved Hide resolved
# Ensure log file exists
mkdir -p "$(dirname "$log_file")"
touch "$log_file"

# This systemd config is automatically generated from dh_installsysusers/13.11.4.
# When the dh-compat < 13, some of them will not be generated.
# So we just make this hard code.
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
systemd-sysusers ${DPKG_ROOT:+--root="$DPKG_ROOT"} linglong.conf
systemd-sysusers ${DPKG_ROOT:+--root="$DPKG_ROOT"} linglong.conf | tee -a "$log_file" # Add logging
fi

if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
if [ -z "${DPKG_ROOT:-}" ] ; then
# The following line should be removed in trixie or trixie+1
deb-systemd-helper --user unmask 'linglong-upgrade.service' >/dev/null || true
if [ -z "${DPKG_ROOT:-}" ] ; then
# The following line should be removed in trixie or trixie+1
deb-systemd-helper --user unmask 'linglong-upgrade.service' >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet --user was-enabled 'linglong-upgrade.service' ; then
# Enables the unit on first installation, creates new
# symlinks on upgrades if the unit file has changed.
deb-systemd-helper --user enable 'linglong-upgrade.service' >/dev/null || true
else
# Update the statefile to add new symlinks (if any), which need to be
# cleaned up on purge. Also remove old symlinks.
deb-systemd-helper --user update-state 'linglong-upgrade.service' >/dev/null || true
fi
# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet --user was-enabled 'linglong-upgrade.service' ; then
# Enables the unit on first installation, creates new
# symlinks on upgrades if the unit file has changed.
deb-systemd-helper --user enable 'linglong-upgrade.service' >/dev/null || true
else
# Update the statefile to add new symlinks (if any), which need to be
# cleaned up on purge. Also remove old symlinks.
deb-systemd-helper --user update-state 'linglong-upgrade.service' >/dev/null || true
fi
fi
fi

if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
if [ -z "${DPKG_ROOT:-}" ] ; then
# The following line should be removed in trixie or trixie+1
deb-systemd-helper --user unmask 'linglong-upgrade.timer' >/dev/null || true
if [ -z "${DPKG_ROOT:-}" ] ; then
# The following line should be removed in trixie or trixie+1
deb-systemd-helper --user unmask 'linglong-upgrade.timer' >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet --user was-enabled 'linglong-upgrade.timer' ; then
# Enables the unit on first installation, creates new
# symlinks on upgrades if the unit file has changed.
deb-systemd-helper --user enable 'linglong-upgrade.timer' >/dev/null || true
else
# Update the statefile to add new symlinks (if any), which need to be
# cleaned up on purge. Also remove old symlinks.
deb-systemd-helper --user update-state 'linglong-upgrade.timer' >/dev/null || true
fi
# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet --user was-enabled 'linglong-upgrade.timer' ; then
# Enables the unit on first installation, creates new
# symlinks on upgrades if the unit file has changed.
deb-systemd-helper --user enable 'linglong-upgrade.timer' >/dev/null || true
else
# Update the statefile to add new symlinks (if any), which need to be
# cleaned up on purge. Also remove old symlinks.
deb-systemd-helper --user update-state 'linglong-upgrade.timer' >/dev/null || true
fi
fi
fi

if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
# The following line should be removed in trixie or trixie+1
deb-systemd-helper unmask 'org.deepin.linglong.PackageManager.service' >/dev/null || true
# The following line should be removed in trixie or trixie+1
deb-systemd-helper unmask 'org.deepin.linglong.PackageManager.service' >/dev/null || true

# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled 'org.deepin.linglong.PackageManager.service'; then
# Enables the unit on first installation, creates new
# symlinks on upgrades if the unit file has changed.
deb-systemd-helper enable 'org.deepin.linglong.PackageManager.service' >/dev/null || true
else
# Update the statefile to add new symlinks (if any), which need to be
# cleaned up on purge. Also remove old symlinks.
deb-systemd-helper update-state 'org.deepin.linglong.PackageManager.service' >/dev/null || true
fi
# was-enabled defaults to true, so new installations run enable.
if deb-systemd-helper --quiet was-enabled 'org.deepin.linglong.PackageManager.service'; then
# Enables the unit on first installation, creates new
# symlinks on upgrades if the unit file has changed.
deb-systemd-helper enable 'org.deepin.linglong.PackageManager.service' >/dev/null || true
else
# Update the statefile to add new symlinks (if any), which need to be
# cleaned up on purge. Also remove old symlinks.
deb-systemd-helper update-state 'org.deepin.linglong.PackageManager.service' >/dev/null || true
fi
fi

# Add logging to systemctl command
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
if [ -n "$2" ]; then
_dh_action=restart
else
_dh_action=start
fi
deb-systemd-invoke $_dh_action 'org.deepin.linglong.PackageManager.service' >/dev/null || true
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true | tee -a "$log_file"
if [ -n "$2" ]; then
_dh_action=restart
else
_dh_action=start
fi
deb-systemd-invoke $_dh_action 'org.deepin.linglong.PackageManager.service' >/dev/null || true | tee -a "$log_file"
fi
fi
# End automatically added section

# End automatically added section
case "$1" in
configure)
version=$2
shift
# enable kernel.unprivileged_userns_clone
if [ -f /etc/sysctl.d/linglong.conf ];then
sysctl -p /etc/sysctl.d/linglong.conf
fi
;;
# enable kernel.unprivileged_userns_clone
sysctl_config="/etc/sysctl.d/linglong.conf"
if [ -f "$sysctl_config" ]; then
echo "Enabling kernel.unprivileged_userns_clone..." | tee -a "$log_file"
sysctl -p "$sysctl_config" | tee -a "$log_file"
Owensuwu marked this conversation as resolved.
Show resolved Hide resolved
fi
;;
abort-upgrade | abort-remove | abort-deconfigure) ;;
*)
echo "postinst called with unknown argument '$1'" >&2
exit 0
;;

echo "postinst called with unknown argument '$1'" >&2 | tee -a "$log_file"
exit 0
;;
esac

exit 0

# vi: ft=sh
141 changes: 72 additions & 69 deletions debian/linglong-bin.preinst
Original file line number Diff line number Diff line change
@@ -1,89 +1,92 @@
#!/bin/sh
#!/bin/bash

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

log_file="/var/log/linglong-bin.log" # Log file path

# Ensure log file exists
mkdir -p "$(dirname "$log_file")"
touch "$log_file"

# Handle upgrade from 1.3.x
# Move system level linglong repository from old location to /var/lib/linglong
upgrade_from_1_3_x() {
version=$1
shift
if dpkg --compare-versions "$version" ge "1.4.0"; then
return
fi
echo "upgrade from 1.3.x"

if [ -f /etc/X11/Xsession.d/21linglong ] &&
[ "$(sha256sum /etc/X11/Xsession.d/21linglong)" = \
"5b82ac8e6b02cdae66294139e7db7cbe80af8cef6b0e2eddf8d509166afce544" ]; then
rm /etc/X11/Xsession.d/21linglong
fi

if [ -d /var/lib/linglong ]; then
echo "'/var/lib/linglong' directory exists."
echo "Finish upgrading from 1.3.x without touch anything."
return
fi

if [ ! -d /persistent/linglong ]; then
echo "Old linglong repository not found."
echo "Finish upgrading from 1.3.x without touch anything."
return
fi

echo "Moving old deepin v23 linglong repository to new location..."
mv /persistent/linglong /var/lib/linglong
ln -s /var/lib/linglong /persistent/linglong # Quick fix for old files exported in old location.
echo "Done"

# This is good enough,
# as linglong has only one repository publicly right now.
echo "Removing old configuration file..."
rm /var/lib/linglong/config.json -f
echo "Done"
old_version="$1"

if dpkg --compare-versions "$old_version" ge "1.4.0"; then
return
fi

echo "Upgrading from 1.3.x..." | tee -a "$log_file"

if [ -f /etc/X11/Xsession.d/21linglong ] &&
[ "$(sha256sum /etc/X11/Xsession.d/21linglong)" = \
"5b82ac8e6b02cdae66294139e7db7cbe80af8cef6b0e2eddf8d509166afce544" ]; then
rm /etc/X11/Xsession.d/21linglong
fi

old_repo="/persistent/linglong"
new_repo="/var/lib/linglong"

if [ -d "$new_repo" ]; then
echo "'$new_repo' directory exists. Upgrade from 1.3.x already completed." | tee -a "$log_file"
return
elif [ ! -d "$old_repo" ]; then
echo "Old linglong repository not found at '$old_repo'. Nothing to upgrade." | tee -a "$log_file"
return
fi

echo "Moving old deepin v23 linglong repository from $old_repo to $new_repo..." | tee -a "$log_file"
if ! mv "$old_repo" "$new_repo"; then
echo "Error moving repository. Check permissions and disk space." | tee -a "$log_file"
exit 1
fi
ln -s "$new_repo" "$old_repo" # Quick fix for old files exported in old location.

# Remove old config (good enough for now as linglong only has one public repo)
echo "Removing old configuration file..." | tee -a "$log_file"
rm -f "$new_repo/config.json"
}

# Handle upgrade from 1.4.x
upgrade_from_1_4_x() {
version=$1
shift
if dpkg --compare-versions "$version" ge "1.5.0"; then
return
fi
echo "upgrade from 1.4.x"

if [ ! -d /var/lib/linglong/layers ]; then
echo "Old data not found."
echo "Finish upgrading from 1.4.x without touch anything."
return
fi

echo "Backup old data..."
oldPackageList="/var/lib/linglong/old-package.list"
ls /var/lib/linglong/layers | grep -v "org.deepin.Runtime" >$oldPackageList
oldData=$(mktemp --tmpdir=/var/lib/linglong -d old-data-XXXXXXXX)
mv /var/lib/linglong/layers "$oldData"
mv /var/lib/linglong/entries "$oldData"
# chmod is for linglong-repair-tool.desktop(TryExec=$oldPackageList).
chmod +x $oldPackageList
chown deepin-linglong:deepin-linglong $oldPackageList
chown -R deepin-linglong:deepin-linglong $oldData
old_version="$1"

if dpkg --compare-versions "$old_version" ge "1.5.0"; then
return
fi

echo "Upgrading from 1.4.x..." | tee -a "$log_file"

if [ ! -d "/var/lib/linglong/layers" ]; then
echo "Old data not found. Nothing to upgrade." | tee -a "$log_file"
return
fi

echo "Backing up old data..." | tee -a "$log_file"
old_package_list="/var/lib/linglong/old-package.list"
ls /var/lib/linglong/layers | grep -v "org.deepin.Runtime" > "$old_package_list"
old_data=$(mktemp --tmpdir=/var/lib/linglong -d old-data-XXXXXXXX)
mv /var/lib/linglong/layers "$old_data"
mv /var/lib/linglong/entries "$old_data"
# chmod is for linglong-repair-tool.desktop (TryExec=$oldPackageList).
chmod +x "$old_package_list"
chown deepin-linglong:deepin-linglong "$old_package_list"
chown -R deepin-linglong:deepin-linglong "$old_data"
}

case "$1" in
upgrade)
upgrade_from_1_3_x $2
upgrade_from_1_4_x $2
upgrade)
upgrade_from_1_3_x "$2"
upgrade_from_1_4_x "$2"
;;
abort-upgrade | abort-remove | abort-deconfigure)
;;
abort-upgrade | abort-remove | abort-deconfigure) ;;
*)
echo "postinst called with unknown argument '$1'" >&2
*)
echo "postinst called with unknown argument '$1'" >&2 | tee -a "$log_file"
exit 0
;;

esac

exit 0

# vi: ft=sh
Loading