pmt: initial 3.0.2 update
This commit is contained in:
345
pmt-termux.sh
345
pmt-termux.sh
@@ -3,8 +3,8 @@
|
||||
# By YZBruh | ShawkTeam
|
||||
|
||||
# Variables
|
||||
LOCAL_VERSION="2.9.6"
|
||||
LOCAL_RELDATE="20241026"
|
||||
LOCAL_VERSION="3.0.2"
|
||||
LOCAL_RELDATE="20241214"
|
||||
LOCAL_OWNER="ShawkTeam"
|
||||
LOCAL_REPO="pmt"
|
||||
LOCAL_RELEASE_TAG="${LOCAL_VERSION}"
|
||||
@@ -24,19 +24,19 @@ YELLOW="\033[0;33m"
|
||||
function printc() { ${SILENT} || echo -e "$*" >&2; }
|
||||
function print()
|
||||
{
|
||||
if echo "$*" | grep "Success" &>/dev/null; then
|
||||
${SILENT} || echo -e " - ${GREEN}${1:0:7}${RESET}." >&2
|
||||
else
|
||||
${SILENT} || echo -e " - $*" >&2
|
||||
fi
|
||||
if echo "$*" | grep "Success" &>/dev/null; then
|
||||
${SILENT} || echo -e " - ${GREEN}${1:0:7}${RESET}." >&2
|
||||
else
|
||||
${SILENT} || echo -e " - $*" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
# Print error and exit
|
||||
function abort()
|
||||
{
|
||||
print "${RED}Error:${RESET} ${@}"
|
||||
cleanup
|
||||
exit 1
|
||||
print "${RED}Error:${RESET} ${@}"
|
||||
cleanup
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Print warnings
|
||||
@@ -48,53 +48,37 @@ function script_head() { printc " --- Partition Manager Termux Helper Script ---
|
||||
# For display help message
|
||||
function view_help()
|
||||
{
|
||||
${SILENT} || echo -n "Usage: "
|
||||
if echo "${0}" | grep "./" >&/dev/null; then
|
||||
printc "${0} [OPTIONS]..."
|
||||
else
|
||||
printc "(bash) ${0} [OPTIONS]"
|
||||
fi
|
||||
${SILENT} || echo -n "Usage: "
|
||||
if echo "${0}" | grep "./" >&/dev/null; then
|
||||
printc "${0} [OPTIONS]..."
|
||||
else
|
||||
printc "(bash) ${0} [OPTIONS]"
|
||||
fi
|
||||
|
||||
printc "Install, uninstall, install status checker for Partition Manager binary.\n"
|
||||
printc "Options:"
|
||||
printc " install, -i [OPTS] Download and install Partition Manager."
|
||||
printc " uninstall, -u Uninstall Partition Manager."
|
||||
printc " status, -s Display install/uninstall status."
|
||||
printc " --quiet, -q Silent mode. No output."
|
||||
printc " --setup, -S Setup required packages."
|
||||
printc " --package <FILE> If you already have a pmt package, make\n setup by specifying this way."
|
||||
printc "Report bugs to <t.me/ShawkTeam | Topics | pmt>"
|
||||
printc "Install, uninstall, install status checker for Partition Manager binary.\n"
|
||||
printc "Options:"
|
||||
printc " install, -i [OPTS] Download and install Partition Manager."
|
||||
printc " uninstall, -u Uninstall Partition Manager."
|
||||
printc " status, -s Display install/uninstall status."
|
||||
printc " --quiet, -q Silent mode. No output."
|
||||
printc " --setup, -S Setup required packages."
|
||||
printc " --package <FILE> If you already have a pmt package, make\n setup by specifying this way."
|
||||
printc "Report bugs to <t.me/ShawkTeam | Topics | pmt>"
|
||||
}
|
||||
|
||||
# Script really operated termux proclamation?
|
||||
function really_termux()
|
||||
{
|
||||
basename -a ${LOCAL_PREFIX}/bin/* | grep "termux" &>/dev/null \
|
||||
|| abort "Are you sure you're in termux?"
|
||||
basename -a ${LOCAL_PREFIX}/bin/* | grep "termux" &>/dev/null \
|
||||
|| abort "Are you sure you're in termux?"
|
||||
}
|
||||
|
||||
# Get architecture info
|
||||
function get_architecture()
|
||||
{
|
||||
local arch=$(uname -m)
|
||||
local archs_64=("aarch64" "armv8" "arm64-v8a" "armv8-a")
|
||||
local archs_32=("aarch32" "armv7" "armeabi-v7a" "armv7l")
|
||||
LOCAL_ARCH=$(getprop ro.product.cpu.abi)
|
||||
|
||||
print "Device architecture: '${arch}'."
|
||||
|
||||
for a in ${archs_64[@]}; do
|
||||
[ "${arch}" = "${a}" ] \
|
||||
&& LOCAL_ARCH="arm64-v8a" \
|
||||
&& return
|
||||
done
|
||||
|
||||
for a in ${archs_32[@]}; do
|
||||
[ "${arch}" = "${a}" ] \
|
||||
&& LOCAL_ARCH="armeabi-v7a" \
|
||||
&& return
|
||||
done
|
||||
|
||||
LOCAL_ARCH="arm64-v8a"
|
||||
print "Device architecture: ${arch}."
|
||||
}
|
||||
|
||||
# Generate template dir
|
||||
@@ -106,124 +90,125 @@ function cleanup() { rm -rf "${LOCAL_TMPDIR}"; }
|
||||
# Check install/uninstall status
|
||||
function check_status()
|
||||
{
|
||||
local installed="${RED}false${RESET}"
|
||||
[ -f "${LOCAL_PREFIX}/bin/pmt" ] \
|
||||
&& installed="${GREEN}true${RESET}"
|
||||
local installed="${RED}false${RESET}"
|
||||
/system/bin/which pmt &>/dev/null \
|
||||
&& installed="${GREEN}true${RESET}"
|
||||
|
||||
print "Installed: ${installed}"
|
||||
exit 0
|
||||
print "Installed: ${installed}"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# check xz-utils install status
|
||||
function check_xz()
|
||||
{
|
||||
# The outflow of the APT is not controlled in use
|
||||
[ -f ${LOCAL_PREFIX}/bin/xz ] \
|
||||
|| abort "xz-utils not installed! Run setup command."
|
||||
# The outflow of the APT is not controlled in use
|
||||
[ -f ${LOCAL_PREFIX}/bin/xz ] \
|
||||
|| abort "xz-utils not installed! Run setup command."
|
||||
}
|
||||
|
||||
# Check internet connection
|
||||
function net_control()
|
||||
{
|
||||
curl "https://github.com" &>/dev/null \
|
||||
|| abort "You need internet connection to this process."
|
||||
curl "https://github.com" &>/dev/null \
|
||||
|| abort "You need internet connection to this process."
|
||||
}
|
||||
|
||||
# Download Partition Manager
|
||||
function download()
|
||||
{
|
||||
local URL="https://github.com/${LOCAL_OWNER}/${LOCAL_REPO}/releases/tag/${LOCAL_RELEASE_TAG}/download/pmt-${LOCAL_ARCH}-${LOCAL_RELDATE}.xz"
|
||||
local URL_MANDOC="https://github.com/${LOCAL_OWNER}/${LOCAL_REPO}/releases/tag/${LOCAL_RELEASE_TAG}/download/mandoc.gz"
|
||||
local URL="https://github.com/${LOCAL_OWNER}/${LOCAL_REPO}/releases/tag/${LOCAL_RELEASE_TAG}/download/pmt-${LOCAL_ARCH}-${LOCAL_RELDATE}.xz"
|
||||
local URL_MANDOC="https://github.com/${LOCAL_OWNER}/${LOCAL_REPO}/releases/tag/${LOCAL_RELEASE_TAG}/download/mandoc.gz"
|
||||
|
||||
cd "${LOCAL_TMPDIR}"
|
||||
print "Downloading: 'pmt-${LOCAL_ARCH}-${LOCAL_RELDATE}.xz'..."
|
||||
wget "${URL}" &>/dev/null \
|
||||
|| abort "Download failed!"
|
||||
cd - &>/dev/null
|
||||
cd "${LOCAL_TMPDIR}"
|
||||
print "Downloading: 'pmt-${LOCAL_ARCH}-${LOCAL_RELDATE}.xz'..."
|
||||
wget "${URL}" &>/dev/null \
|
||||
|| abort "Download failed!"
|
||||
cd - &>/dev/null
|
||||
|
||||
HAVE_MANDOC=true
|
||||
print "Downloading mandoc..."
|
||||
curl -L "${URL_MANDOC}" -o "${LOCAL_TMPDIR}/pmt.8.gz" &>/dev/null \
|
||||
|| warning "Download failed! (mandoc)"
|
||||
HAVE_MANDOC=true
|
||||
print "Downloading mandoc..."
|
||||
curl -L "${URL_MANDOC}" -o "${LOCAL_TMPDIR}/pmt.8.gz" &>/dev/null \
|
||||
|| warning "Download failed! (mandoc)"
|
||||
|
||||
chmod -R 755 "${LOCAL_TMPDIR}" &>/dev/null \
|
||||
|| warning "Cannot set mode '777' on downloaded files."
|
||||
chmod -R 755 "${LOCAL_TMPDIR}" &>/dev/null \
|
||||
|| warning "Cannot set mode '777' on downloaded files."
|
||||
}
|
||||
|
||||
# For installing required packages
|
||||
function setup_packages()
|
||||
{
|
||||
net_control
|
||||
net_control
|
||||
|
||||
print "Updating mirrors..."
|
||||
pkg update &>/dev/null || abort "Updating failed!"
|
||||
print "Updating mirrors..."
|
||||
pkg update &>/dev/null || abort "Updating failed!"
|
||||
|
||||
print "Installing xz-utils, wget..."
|
||||
pkg install -y xz-utils wget &>/dev/null \
|
||||
|| abort "Installing failed!"
|
||||
print "Installing xz-utils, wget..."
|
||||
pkg install -y xz-utils wget &>/dev/null \
|
||||
|| abort "Installing failed!"
|
||||
|
||||
print "Success."
|
||||
exit 0
|
||||
print "Success."
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Install deb package
|
||||
function install_fn()
|
||||
{
|
||||
local mydir="${PWD}"
|
||||
[ "${LOCAL_PACKAGE}" = "" ] || local bname=$(basename ${LOCAL_PACKAGE})
|
||||
local mydir="${PWD}"
|
||||
[ "${LOCAL_PACKAGE}" = "" ] || local bname=$(basename ${LOCAL_PACKAGE})
|
||||
|
||||
${PACKAGE} && \
|
||||
if [ ! -f "${LOCAL_PACKAGE}" ]; then
|
||||
[ -d "${LOCAL_PACKAGE}" ] \
|
||||
&& abort "\`${LOCAL_PACKAGE}': is directory."
|
||||
${PACKAGE} && \
|
||||
if [ ! -f "${LOCAL_PACKAGE}" ]; then
|
||||
[ -d "${LOCAL_PACKAGE}" ] \
|
||||
&& abort "\`${LOCAL_PACKAGE}': is directory."
|
||||
|
||||
abort "\`${LOCAL_PACKAGE}': no such file."
|
||||
else
|
||||
cp "${LOCAL_PACKAGE}" "${LOCAL_TMPDIR}/pmt-${LOCAL_ARCH}.xz"
|
||||
fi
|
||||
abort "\`${LOCAL_PACKAGE}': no such file."
|
||||
else
|
||||
cp "${LOCAL_PACKAGE}" "${LOCAL_TMPDIR}/pmt-${LOCAL_ARCH}.xz"
|
||||
fi
|
||||
|
||||
cd "${LOCAL_TMPDIR}"
|
||||
cd "${LOCAL_TMPDIR}"
|
||||
|
||||
print "Extracting package..."
|
||||
if unxz "$(basename *.xz)" &>/dev/null; then
|
||||
rm -f "pmt*.xz"
|
||||
else
|
||||
abort "Failed! Cannot extract pmt package."
|
||||
fi
|
||||
print "Extracting package..."
|
||||
if unxz "$(basename *.xz)" &>/dev/null; then
|
||||
rm -f "pmt*.xz"
|
||||
else
|
||||
abort "Failed! Cannot extract pmt package."
|
||||
fi
|
||||
|
||||
[ -z $(basename "pmt-*") ] \
|
||||
&& abort "Extracted binary file was not found!"
|
||||
mv "$(basename pmt-*)" pmt
|
||||
[ -z $(basename "pmt-*") ] \
|
||||
&& abort "Extracted binary file was not found!"
|
||||
mv "$(basename pmt-*)" pmt
|
||||
|
||||
print "Installing..."
|
||||
cp pmt "${LOCAL_PREFIX}/bin/pmt" &>/dev/null \
|
||||
|| abort "Installing failed!"
|
||||
print "Installing..."
|
||||
cp pmt "${LOCAL_PREFIX}/bin/pmt" &>/dev/null \
|
||||
|| abort "Installing failed!"
|
||||
|
||||
if ${HAVE_MANDOC}; then
|
||||
print "Installing mandoc (force)..."
|
||||
cp -f pmt.8.gz ${LOCAL_PREFIX}/share/man/man8 &>/dev/null
|
||||
chmod 755 ${LOCAL_PREFIX}/share/man/man8/pmt.8.gz &>/dev/null
|
||||
fi
|
||||
${HAVE_MANDOC} && {
|
||||
print "Installing mandoc (force)..."
|
||||
cp -f pmt.8.gz ${LOCAL_PREFIX}/share/man/man8 &>/dev/null
|
||||
chmod 755 ${LOCAL_PREFIX}/share/man/man8/pmt.8.gz &>/dev/null
|
||||
}
|
||||
|
||||
print "Setting up permissions for binary..."
|
||||
chmod 755 "${LOCAL_PREFIX}/bin/pmt" &>/dev/null \
|
||||
|| abort "Failed to set permissions!"
|
||||
print "Setting up permissions for binary..."
|
||||
chmod 755 "${LOCAL_PREFIX}/bin/pmt" &>/dev/null \
|
||||
|| abort "Failed to set permissions!"
|
||||
|
||||
print "Success."
|
||||
cd "${mydir}"
|
||||
print "Success."
|
||||
cd "${mydir}"
|
||||
}
|
||||
|
||||
# Uninstall deb package
|
||||
function uninstall_fn()
|
||||
{
|
||||
print "Uninstalling Partition Manager..." && \
|
||||
if rm "${LOCAL_PREFIX}/bin/pmt" &>/dev/null; then
|
||||
print "Success."
|
||||
else
|
||||
abort "Failed!"
|
||||
fi
|
||||
print "Uninstalling Partition Manager..."
|
||||
|
||||
rm -f ${LOCAL_PREFIX}/share/man/man8/pmt.8.gz
|
||||
if rm "${LOCAL_PREFIX}/bin/pmt" &>/dev/null; then
|
||||
print "Success."
|
||||
else
|
||||
abort "Failed!"
|
||||
fi
|
||||
|
||||
rm -f ${LOCAL_PREFIX}/share/man/man8/pmt.8.gz
|
||||
}
|
||||
|
||||
trap "abort Interrupt." SIGINT
|
||||
@@ -234,80 +219,80 @@ HAVE_MANDOC=false
|
||||
|
||||
# Process arguments
|
||||
while (($# >= 1)); do
|
||||
SOME_SPEC=1
|
||||
SOME_SPEC=1
|
||||
|
||||
case "${1}" in
|
||||
install|-i)
|
||||
PROCESS=1
|
||||
;;
|
||||
uninstall|-u)
|
||||
PROCESS=2
|
||||
;;
|
||||
status|-s)
|
||||
script_head
|
||||
check_status y
|
||||
;;
|
||||
--quiet|-q)
|
||||
SILENT=true
|
||||
;;
|
||||
--setup|-S)
|
||||
script_head
|
||||
print "Starting package setupper..."
|
||||
setup_packages
|
||||
;;
|
||||
--package)
|
||||
PACKAGE=true
|
||||
[ -z ${2} ] && \
|
||||
{ printc "Option '--package' requires an argument (file)."
|
||||
exit 1
|
||||
}
|
||||
LOCAL_PACKAGE="${2}"
|
||||
ALREADY_SHIFT=true && shift 1
|
||||
;;
|
||||
--help)
|
||||
view_help
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
if echo ${1} | grep "-" &>/dev/null; then
|
||||
if ! echo ${1} | grep ".xz" &>/dev/null; then
|
||||
printc "Unknown option: ${1}"
|
||||
exit 1
|
||||
else
|
||||
break;
|
||||
fi
|
||||
else
|
||||
break
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
case "${1}" in
|
||||
install|-i)
|
||||
PROCESS=1
|
||||
;;
|
||||
uninstall|-u)
|
||||
PROCESS=2
|
||||
;;
|
||||
status|-s)
|
||||
script_head
|
||||
check_status y
|
||||
;;
|
||||
--quiet|-q)
|
||||
SILENT=true
|
||||
;;
|
||||
--setup|-S)
|
||||
script_head
|
||||
print "Starting package setupper..."
|
||||
setup_packages
|
||||
;;
|
||||
--package)
|
||||
PACKAGE=true
|
||||
[ -z ${2} ] && {
|
||||
printc "Option '--package' requires an argument (file)."
|
||||
exit 1
|
||||
}
|
||||
LOCAL_PACKAGE="${2}"
|
||||
ALREADY_SHIFT=true && shift 1
|
||||
;;
|
||||
--help)
|
||||
view_help
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
if echo ${1} | grep "-" &>/dev/null; then
|
||||
if ! echo ${1} | grep ".xz" &>/dev/null; then
|
||||
printc "Unknown option: ${1}"
|
||||
exit 1
|
||||
else
|
||||
break;
|
||||
fi
|
||||
else
|
||||
break
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
${ALREADY_SHIFT} || shift 1
|
||||
${ALREADY_SHIFT} || shift 1
|
||||
done
|
||||
|
||||
### Main ###
|
||||
[ -z "${1}" -a "${SOME_SPEC}" != 1 ] && { view_help; exit 1; }
|
||||
|
||||
if [ "${PROCESS}" = 1 -o "${PROCESS}" = 2 ]; then
|
||||
script_head
|
||||
really_termux
|
||||
gen_tempdir
|
||||
fi
|
||||
[ "${PROCESS}" = 1 -o "${PROCESS}" = 2 ] && {
|
||||
script_head
|
||||
really_termux
|
||||
gen_tempdir
|
||||
}
|
||||
|
||||
if [ "${PROCESS}" = 1 ]; then
|
||||
[ -f "${LOCAL_PREFIX}/bin/pmt" ] \
|
||||
&& abort "Partition Manager already installed."
|
||||
${PACKAGE} || net_control
|
||||
check_xz
|
||||
get_architecture
|
||||
print "Starting install process..."
|
||||
${PACKAGE} || download
|
||||
install_fn
|
||||
/system/bin/which pmt &>/dev/null \
|
||||
&& abort "Partition Manager already installed."
|
||||
${PACKAGE} || net_control
|
||||
check_xz
|
||||
get_architecture
|
||||
print "Starting install process..."
|
||||
${PACKAGE} || download
|
||||
install_fn
|
||||
elif [ "${PROCESS}" = 2 ]; then
|
||||
[ ! -f "${LOCAL_PREFIX}/bin/pmt" ] \
|
||||
&& abort "Partition Manager already uninstalled."
|
||||
print "Starting uninstall process..."
|
||||
uninstall_fn
|
||||
/system/bin/which pmt &>/dev/null \
|
||||
&& abort "Partition Manager already uninstalled."
|
||||
print "Starting uninstall process..."
|
||||
uninstall_fn
|
||||
fi
|
||||
|
||||
cleanup
|
||||
|
||||
Reference in New Issue
Block a user