代码拉取完成,页面将自动刷新
#!/bin/bash
# A simple loongarch64 => loong64 .deb converter to help traverse the worlds.
#
# Mingcong Bai <jeffbai@aosc.io>, 2024
_display_usage() {
printf "\
Usage:
loong64-it [PACKAGE1] [PACKAGE2] ...
- PACKAGE{1..N}: Path to the old-world .deb package to convert.
"
}
# Autobuild-like echo functions.
abwarn() { echo -e "[\e[33mWARN\e[0m]: \e[1m$*\e[0m"; }
aberr() { echo -e "[\e[31mERROR\e[0m]: \e[1m$*\e[0m"; exit 1; }
abinfo() { echo -e "[\e[96mINFO\e[0m]: \e[1m$*\e[0m"; }
abdbg() { echo -e "[\e[32mDEBUG\e[0m]: \e[1m$*\e[0m"; }
_convert_loong64() {
PKG_PATH=$(realpath $1)
PKG_NAME=$(dpkg-deb -f "$PKG_PATH" Package)
VERSION=$(dpkg-deb -f "$PKG_PATH" Version)
BASEDIR=$(dirname $PKG_PATH)
abinfo "Examining package information: $1 ..."
dpkg -I "$PKG_PATH" || \
aberr "Invalid dpkg package: control (metadata) archive not found: $?"
CONTROL_EXT="$(ar t "$PKG_PATH" | grep control.tar* | cut -f3 -d'.')"
case "${CONTROL_EXT}" in
gz)
TAR_COMP_FLAG="z"
;;
xz)
TAR_COMP_FLAG="J"
;;
bz2)
TAR_COMP_FLAG="j"
;;
"")
TAR_COMP_FLAG=""
;;
*)
aberr "Invalid control archive extension ${CONTROL_EXT}!"
;;
esac
abinfo "Unpacking: $1 ..."
cd $(mktemp -d) || \
aberr "Failed to create temporary directory to unpack $1: $?."
DEBDIR="$(pwd)"
ar xv "$PKG_PATH" || \
aberr "Failed to unpack $1: $?."
abinfo "Unpacking metadata archive: $1 ..."
mkdir "$DEBDIR"/metadata || \
aberr "Failed to create temporary directory for extracting the metdata archive from $1: $?."
tar -C "$DEBDIR"/metadata -xvf control.tar."${CONTROL_EXT}" || \
aberr "Failed to unpack metadata archive from $1: $?."
abinfo "Converting dpkg Architecture key: $1 ..."
if ! egrep '^Architecture: loongarch64$' "$DEBDIR"/metadata/control; then
aberr "Failed to detect a \"loongarch64\" architecture signature in control file - this is not a valid old-world LoongArch package!"
fi
sed -e 's|^Architecture: loongarch64$|Architecture: loong64|g' \
-i "$DEBDIR"/metadata/control
if grep -q "Depends:" "$DEBDIR"/metadata/control; then
sed -i '/Depends:/ s/$/, liblol,liblol-dkms/' "$DEBDIR"/metadata/control
else
echo "Depends: liblol" >> "$DEBDIR"/metadata/control
fi
abinfo "Building metadata archive (control.tar.${CONTROL_EXT}): $1 ..."
cd "$DEBDIR"/metadata
tar cvf${TAR_COMP_FLAG} "$DEBDIR"/control.tar."${CONTROL_EXT}" * || \
aberr "Failed to build metadata archive (control.tar.${CONTROL_EXT}) for $1: $?."
cd "$DEBDIR"
abinfo "Rebuilding dpkg package $1: loong64 ..."
ar rv "$PKG_PATH" control.tar.${CONTROL_EXT} || \
aberr "Failed to rebuild dpkg package $1: $?."
#abinfo "Cleaning up: $1 ..."
#rm -r "$DEBDIR"
mv $PKG_PATH ${BASEDIR}/${PKG_NAME}_${VERSION}_loong64.deb
abinfo """Your requested package:
$1
Has been successfully converted as a loong64 package and renamed as ${PKG_NAME}_${VERSION}_loong64.deb
However, you may still need to install libLoL for old-world applications to
work properly. Please refer to the libLoL home page:
https://liblol.aosc.io
For details on how to install and configure libLoL.
"""
}
# Display usage info if `-h' or `--help' is specified.
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
_display_usage
exit 0
fi
# Display usage info with directions if no option is specified.
if [ -z "$1" ]; then
abwarn "Please specify package(s) to convert.\n"
_display_usage
exit 1
fi
# Record working directory.
SRCDIR="$(pwd)"
# Rebuilding all requested packages.
for i in "$@"; do
_convert_loong64 $i
done
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。