1 Commits
2.5.0 ... 2.3.0

Author SHA1 Message Date
03776ed710 pmt: 2.3.0: add changelog (:P) 2024-07-09 19:36:21 +03:00
60 changed files with 1076 additions and 2805 deletions

View File

@@ -1,112 +0,0 @@
name: Build and release
on: [workflow_dispatch]
jobs:
build-and-rel-pmt:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cleanup
id: cleanup
uses: rokibhasansagar/slimhub_actions@main
- name: Setup GitHub CLI
id: setup-gh
run: |
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
- name: Update and setup packages
id: setup-packages
run: |
sudo apt update \
&& sudo apt upgrade -y \
&& sudo apt install make xz-utils aria2 gawk -y
- name: Save spefic version variables
id: save-vars
run: |
. build/workflow/build.config
echo "PMT_VERSION=${PMT_VERSION}" >> $GITHUB_ENV
echo "PMT_VERSION_CODE=${PMT_VERSION_CODE}" >> $GITHUB_ENV
echo "NDK_VERSION=${NDK_VERSION}" >> $GITHUB_ENV
echo "NDK_LINK=${NDK_LINK}" >> $GITHUB_ENV
echo "NDK_IS=${NDK_IS}" >> $GITHUB_ENV
cd /home
sudo git clone https://github.com/ShawkTeam/pmt -b ${PMT_VERSION}
sudo chmod 777 pmt
echo "PMT_SRCDIR=/home/pmt" >> $GITHUB_ENV
echo "NDK_DIR=/home/ndk/android-ndk" >> $GITHUB_ENV
echo "NDK_IN_DIR=/home/ndk" >> $GITHUB_ENV
sudo mkdir -p "/home/ndk" && cd "/home/ndk" && sudo chmod 777 "/home/ndk"
- name: Download and extract NDK
id: setup-ndk
run: |
echo "Downloading NDK ${{ env.NDK_VERSION }}..."
aria2c "${{ env.NDK_LINK }}"
echo "Extracting..."
unzip -q *.zip && rm *.zip
mv * "${{ env.NDK_IS }}"
sudo chmod -R 777 *
working-directory: ${{ env.NDK_IN_DIR }}
- name: Build pmt
id: build-pmt
run: |
make gen-ndk-makefiles
export NDK_PROJECT_PATH=${PWD}
export NDK_ROOT_DIR=${{ env.NDK_DIR }}
echo "NDK_ROOT_DIR=${NDK_ROOT_DIR}" >> $GITHUB_ENV
bash build/bash/gen-header
cd ${{ env.NDK_DIR }}
./ndk-build
working-directory: ${{ env.PMT_SRCDIR }}
- name: Last small transactions
id: small-transactions
run: |
export CC_64="${PWD}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang"
export CC_32="${PWD}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang"
export AR="${PWD}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"
export CC_VERSION=$(${CC_64} --version | head -n 1)
echo "CC_VERSION=${CC_VERSION}" >> $GITHUB_ENV
. ${{ env.PMT_SRCDIR }}/build/workflow/build.config
. ${{ env.PMT_SRCDIR }}/build/workflow/relnotes > /home/pmt/release_body.txt
cd ${{ env.PMT_SRCDIR }}
zip -rq pmt-objs-local.zip obj/local/arm64-v8a obj/local/armeabi-v7a
xz libs/arm64-v8a/pmt
mv libs/arm64-v8a/pmt.xz ${PWD}/pmt-arm64-v8a.xz
xz libs/armeabi-v7a/pmt
mv libs/armeabi-v7a/pmt.xz ${PWD}/pmt-armeabi-v7a.xz
make CC="${CC_64}" AR="${AR}"
make deb FOR_THIS=64
mv out/debpackage/*.deb .
make clean
make CC="${CC_32}" AR="${AR}"
make deb FOR_THIS=32
mv out/debpackage/*.deb .
make clean
working-directory: ${{ env.NDK_DIR }}
- name: Upload to release
id: upload-to-rels
uses: softprops/action-gh-release@v2
with:
files: |
/home/pmt/pmt*.xz
/home/pmt/pmt*.deb
/home/pmt/pmt-objs-local.zip
name: Partition Manager ${{ env.PMT_VERSION }} Release
tag_name: ${{ env.PMT_VERSION }}
body_path: /home/pmt/release_body.txt
env:
GITHUB_TOKEN: ${{ secrets.PMT_WORKFLOW_GTOKEN }}

View File

@@ -1,35 +0,0 @@
name: Check commit
on: [push]
jobs:
check-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Detect commit type
id: check-commit-type
run: |
echo "BRANCH=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV
COMM_MSG=$(git log -1 --pretty=%B)
if [ "${GITHUB_EVENT_NAME}" == "push" ]; then
if [[ "${COMM_MSG}" == *"initial"* ]]; then
echo "build_and_release=true" >> $GITHUB_ENV
else
echo "build_and_release=false" >> $GITHUB_ENV
fi
elif [ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]; then
echo "build_and_release=true" >> $GITHUB_ENV
fi
- name: Run release workflow
id: run-rel-workflow
if: env.build_and_release == 'true'
uses: benc-uk/workflow-dispatch@v1
with:
workflow: 'build.yml'
token: ${{ secrets.PMT_WORKFLOW_GTOKEN }}
ref: ${{ env.BRANCH }}

View File

@@ -1,134 +0,0 @@
### Add a new language to pmt (guide)
On this page, I will tell you how to add languages to pmt. This is not a difficult thing :)
##### Send ready stuff
- Send ready translations via pull requests. After making the necessary checks, if there is no problem, I will accept it.
- Proper commit messages are required.
- If there is an error, I will mention it in the pull request comments.
- Once you accept it, I (YZBruh) will implement the rest of the necessary things.
- It may take 5 days for me to notice :P
##### Little important notes
- You don't have to be a professional to do this thing.
- There will be only one place you need to pay attention to, I will explain it.
- There is no need to know C.
- You can edit existing translations.
- You may need ready pmt to understand some things.
- If you are on an x86 PC, you can compile and use it, but the functions will never work.
##### Understanding general logic
All the texts (strings) in pmt are like variables in bash. I mean:
```
Bash
export missing_operand="missing operand."
APPLYING:
~ $ echo -n "$missing_operand\n" # for more detail I used the -n argument
missing operand
~ $
C / C++
const char* _Nonnull missing_operand = "missing operand.";
const std::string missing_operand = "missing operand.";
APPLYING (C / C++):
printf("%s\n", missing_operand); // Move to new line with '\n' character
std::cout << missing_operand << std::endl; // Move to new line with std::endl
```
For example, let's take the output directly in pmt without any arguments and process the variables and structures behind the work.
```
Shell
~ $ pmt
pmt: missing operand
Try `pmt --help' for more information.
~ $
Code pieces (C)
struct pmt_langdb_general en = {
// other translations
.missing_operand = "missing operand";
.try_h = "Try";
.for_more = "for more information";
// other translations
}
// pmt code functions [ logging ]
LOGE("%s\n%s `%s --help' %s.\n, missing_operand, try_h, argv[0], for_more); // LOGE is error logger (pmt). argv[0] = execution name
```
In short, there are variables for texts. And I made these dynamic by using [struct](https://chatgpt.com/share/a798b57c-7e29-4b17-8887-f230414e57bd) method in C. You just need to add translation :)
##### Translating main program texts (relevant part)
- Let's open our jni/languages.c source file.
- Now, let's create the translation with the ready-made struct structure (see jni/include/pmt-stringkeys.h for the structure).
```
// main
struct pmt_langdb_general <LANGUAGE_PREFIX> = { // LANGUAGE_PREFIX must be the corresponding abbreviation of the language in English. For example, it's like en in English.
// translations
}
// example
struct pmt_langdb_general en = {
// translation
}
```
- We need to add some information about the language.
```
struct pmt_langdb_general <LANGUAGE_PREFIX> = {
.lang_by_s = // Names of those who made the translation. It's up to you. Do you use & between more than one person?
.language = // Language name. For example English
.lang_prefix = // Language prefix. For example en
// other translations
}
// example
struct pmt_langdb_general en = {
.lang_by_s = "YZBruh & r0manas";
.language = "English";
.lang_prefix = "en";
// other translations
}
// CRITIC WARNING: Do not add ';' to the end of the last translation text. But others always
```
- Now do the others :)
- Now let me explain the documentation...
##### Document texts translation (relevant part)
- Let's open our jni/languages.c source file.
- Now, let's create the translation with the ready-made struct structure (see jni/include/pmt-stringkeys.h for the structure).
```
struct pmt_langdb_docs <LANGUAGE_PREFIX>_docs = {
// translations
}
// example
struct pmt_langdb_docs en_docs = {
// translations
}
```
- Make translations by taking examples from existing ones. And definitely do it regularly by getting help message from pmt :D
##### General things to do in translation
- Open jni/languages.c
- Go down a bit...
```
struct pmt_langdb_langs lang[] = {
{"en"},
{"tr"},
{NULL} // PLEASE DO NOT ADD IT UNDER 'NULL'!
};
// Add the language you are translating into these existing language prefixes. I will fix the errors here (if there is an error)
```
##### Notes
- Apologies for the crappy current language control structure :(
- You can ask your questions: <t.me / ShawkTeam | Topics | pmt>

22
CHANGELOG.md Executable file → Normal file
View File

@@ -1,19 +1,7 @@
### Version 2.5.0 Changelog ### Version 2.3.0 (code 230) changelog
- Fixed some minor bugs in 2.1.0
- Added language switching feature (Turkish and English for now).
- Fixed serious problems with version 2.4.0.
- Stabilization was held.
- The size calculation problem that was during flashtime was corrected.
- Change in the syntax in flash and formatting processes was made.
- Problems in file system selection are corrected in formatting process.
- Deprecation system created for deprecated/changed options.
- License display option deprecated.
- The language configuration file will now be stored and read entirely in /sdcard.
- Enabled C language extention warnings (-pedantic).
- Unnecessary codes were cleared and a more neat code was written.
- It was passed to make as old in the compilation system
- For NDK compilation with iterine make system Android.mk and Application.mk creation support added.
- More advanced make build system than before.
``` | END OF VERSION 2.3.0 CHANGELOG |
END OF 2.5.0 UPDATE CHANGELOG |------------------------------------|
```

View File

@@ -1,11 +1,6 @@
Disclaimer regarding problems caused by PMT WARNING:
Disclaimer of Liability Regarding the Use of the C Library
1. This program is provided as is, without warranty. - This library is intended for the user to manage the C android partitions. However, we do not accept responsibility for any problems or losses that may arise during its use.
2. Not for commercial purposes. - Users should carefully test the library functions and, if necessary, implement their own error management mechanisms.
3. The developer is NOT responsible for any damages, losses or similar problems that may occur as a result of the use of the program. - The authors reserve the right to make any changes or updates related to the library.
4. THE USER IS RESPONSIBLE FOR ANY PROBLEMS THAT MAY COME FROM WRONG OR FAILURE USING THE PROGRAM. - This library is intended for management android partitions and its suitability for any specific project or application is not guaranteed. It is important for users to evaluate the suitability of their own projects.
5. Developers do NOT have to keep the program always updated.
6. There is NO guarantee that updates will be provided in the future.
7. The user must use the program IN ACCORDANCE with the license.
8. The developer has ALL rights to the development and distribution of the program.
9. The developer will only be interested in solving users' queries etc. AND THE UPDATE MAY NOT DO THIS AFTER THE INTERRUPTION.

View File

@@ -1,26 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
THIS_IS = main
NDK_PROG ?= false
FORCE_GEN ?= false
# include needed variables
include Makefile.inc
include $(TOOLS)/gen-makefiles.mk
include $(TOOLS)/clean-makefiles.mk
include $(BUILD)/main.mk

View File

@@ -1,161 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# speficy
VERSION := 2.5.0
VERSION_CODE := 250
TARGET := pmt
# device arch info
ARCH := $(shell uname -m)
# current directory
CUR_DIR = $(shell pwd)
OUT_DIRNAME ?= out
SOURCE_DIRNAME ?= jni
# others needed important variables
ifeq ($(THIS_IS),src)
BUILD := ../build
SOURCE_DIR := $(CUR_DIR)
OUT_DIR := ../$(OUT_DIRNAME)
DEBUTILS_DIR := $(BUILD)/deb
INCLUDE_DIR := ../include
else ifeq ($(THIS_IS),debutils)
BUILD := ..
SOURCE_DIR := ../../$(SOURCE_DIRNAME)
OUT_DIR := ../../$(OUT_DIRNAME)
DEBUTILS_DIR := $(BUILD)/deb
else ifeq ($(THIS_IS),out)
BUILD := ../build
SOURCE_DIR := ../$(SOURCE_DIRNAME)
OUT_DIR := $(CUR_DIR)
DEBUTILS_DIR := $(BÜILD)/deb
else ifeq ($(THIS_IS),main)
BUILD := $(CUR_DIR)/build
SOURCE_DIR := $(CUR_DIR)/$(SOURCE_DIRNAME)
OUT_DIR := $(CUR_DIR)/$(OUT_DIRNAME)
DEBUTILS_DIR := $(BUILD)/deb
endif
BINARY_DIR := $(OUT_DIR)/binary
PACKAGE_DIR := $(OUT_DIR)/package
STATICLIB_DIR := $(OUT_DIR)/static_libs
DEB_DIR := $(OUT_DIR)/debpackage
TOOLS := $(BUILD)/tools
UTILS := $(BUILD)/util
BASH_DIR := $(BUILD)/bash
OTHERS := $(BUILD)/others
TERMUX_USR := /data/data/com.termux/files/usr
TERMUX_BIN := $(TERMUX_USR)/bin
LINUX_BIN := /usr/bin
DEBTERMUX_USR := $(DEBUTILS_DIR)/template$(TERMUX_USR)
ifneq ($(wildcard $(LINUX_BIN)),)
BIN := $(LINUX_BIN)
else
BIN := $(TERMUX_BIN)
endif
include $(UTILS)/utils.mk
ifneq ($(shell basename $(SOURCE_DIR)),$(SOURCE_DIRNAME))
$(error The index name specified with the current source directory name is not the same! Something's wrong)
endif
ifneq ($(shell basename $(OUT_DIR)),$(OUT_DIRNAME))
$(error The index name specified with the current output directory name is not the same! Something's wrong)
endif
# sources
SRCS := $(wildcard $(SOURCE_DIR)/*.c)
OBJS = $(SRCS:.c=.o)
# the presence of all source files that are on this list will be checked
SRCS_REQ := \
$(SOURCE_DIR)/debugging.c \
$(SOURCE_DIR)/docs.c \
$(SOURCE_DIR)/get_stat.c \
$(SOURCE_DIR)/lang_tools.c \
$(SOURCE_DIR)/languages.c \
$(SOURCE_DIR)/partitiontool.c \
$(SOURCE_DIR)/pmt.c \
$(SOURCE_DIR)/root.c \
$(SOURCE_DIR)/tools.c \
$(SOURCE_DIR)/versioner.c
ifeq ($(THIS_IS),src)
HEADERS_REQ := \
$(INCLUDE_DIR)/pmt/deprecates.h \
$(INCLUDE_DIR)/pmt/docs.h \
$(INCLUDE_DIR)/pmt/pmt.h \
$(INCLUDE_DIR)/pmt/stringkeys.h \
$(INCLUDE_DIR)/pmt/versioning.h
endif
# objects to be used wgen static library files is created
STATICLIB_OBJS := \
$(SOURCE_DIR)/root.o \
$(SOURCE_DIR)/debugging.o \
$(SOURCE_DIR)/listpart.o \
$(SOURCE_DIR)/partitiontool.o
# objects to be used when executable file is created
OBJS_EXEC := \
$(SOURCE_DIR)/$(TARGET).o \
$(SOURCE_DIR)/docs.o \
$(SOURCE_DIR)/versioner.o \
$(SOURCE_DIR)/get_stat.o \
$(SOURCE_DIR)/tools.o \
$(SOURCE_DIR)/lang_tools.o \
$(SOURCE_DIR)/languages.o
# other directories in the out directory
IN_OUT_DIR := \
$(BINARY_DIR) \
$(PACKAGE_DIR) \
$(STATICLIB_DIR)
# list of file/directory to be checked when the deb pack is created
DEB_CHECKS := \
$(DEBUTILS_DIR) \
$(DEBUTILS_DIR)/DEBIAN \
$(DEBUTILS_DIR)/DEBIAN/control_32 \
$(DEBUTILS_DIR)/DEBIAN/control_64 \
$(DEBUTILS_DIR)/mandoc \
$(DEBUTILS_DIR)/mandoc/$(TARGET).8.gz \
$(DEBUTILS_DIR)/data \
$(DEBUTILS_DIR)/data/data \
$(DEBUTILS_DIR)/data/data/com.termux \
$(DEBUTILS_DIR)/data/data/com.termux/files \
$(DEBUTILS_DIR)/data/data/com.termux/files/usr \
$(DEBUTILS_DIR)/data/data/com.termux/files/usr/bin \
$(DEBUTILS_DIR)/data/data/com.termux/files/usr/share \
$(DEBUTILS_DIR)/data/data/com.termux/files/usr/share/man \
$(DEBUTILS_DIR)/data/data/com.termux/files/usr/share/man/man8
# for running make with silent mode
hide := @
MAKE_HIDE := $(hide)$(MAKE)
SILENT := -s
# color definations
RESET := \033[0m
RED := \033[0;31m
GREEN := \033[0;32m
YELLOW := \033[0;33m
# end

View File

@@ -1,15 +1,14 @@
## Partition Manager (pmt) ## Partition Manager (pmt)
[![Commit reviewed](https://github.com/ShawkTeam/pmt/actions/workflows/check_commits.yml/badge.svg)](https://github.com/ShawkTeam/pmt/actions/workflows/check_commits.yml) This binary C is for manage partitions of android devices.
It offers a lot of options. I will place these below. But first let me talk about the operation...
This binary, written in C, is for writing/reading and formatting on Android partitions.
#### Presented arguments (options) #### Presented arguments (options)
``` ```
Usage: pmt backup PARTITION [OUTPUT] [OPTIONS]... Usage: pmt [OPTIONS] backup PARTITION [OUTPUT] [OPTIONS]...
or: pmt flash PARTITION FILE [OPTIONS]... or: pmt [OPTIONS] flash FILE PARTITION [OPTIONS]...
or: pmt format PARTITION FILE_SYSTEM[ext/2/3/4] [OPTIONS]... or: pmt [OPTIONS] format FILE_SYSTEM[ext/2/3/4] PARTITION [OPTIONS]...
Options: Options:
-l, --logical It is meant to determine whether the target partition is logical. -l, --logical It is meant to determine whether the target partition is logical.
@@ -20,55 +19,39 @@ Options:
-S, --set-lang Set current language. -S, --set-lang Set current language.
-v, --version See version. -v, --version See version.
--help See this help message. --help See this help message.
-L, --license See license.
Examples: Examples:
pmt backup boot_a -c /dev/block/platform/bootdevice/by-name pmt backup boot_a -c /dev/block/platform/bootdevice/by-name
pmt flash boot_a /sdcard/twrp/boot.img -c /dev/block/platform/bootdevice/by-name pmt flash /sdcard/twrp/boot.img boot_a -c /dev/block/platform/bootdevice/by-name
pmt format system_a ext4 --logical pmt format ext4 system_a --logical
pmt -c /dev/block/platform/bootdevice/by-name --list pmt -c /dev/block/platform/bootdevice/by-name --list
Report bugs to <t.me/ShawkTeam | Topics | pmt> Report bugs to <t.me/YZBruh>
``` ```
#### Some notes #### Some notes
- pmt supports multiple languages. [See languages.](https://github.com/ShawkTeam/pmt/blob/2.5.0/LANGUAGES.md)
- [Add language.](https://github.com/ShawkTeam/pmt/blob/2.5.0/ADD-LANGUAGES.md)
- Feel free to ask any questions you want. - Feel free to ask any questions you want.
- Packages are available in publications. - Packages are available in publications.
- If the logical partition flag is not used, a classic partition is tried to be processing by default. - If the logical partition flag is not used, a classic partition is tried to be processing by default.
- [Click to see special version changes.](https://github.com/ShawkTeam/pmt/blob/2.5.0/CHANGELOG.md) - [Click to see special version changes](https://github.com/YZBruh/pbt/blob/2.3.0/CHANGELOG.md)
- We are always open to your suggestions and support (developing)! - Let me know your suggestions!
### How is it built? ### How is it built?
Make or Android NDK is required to build. Android NDK is required to build.
- [Download](https://developer.android.com/ndk/downloads) and extract the NDK package.
##### Build with NDK
- [Download Android NDK](https://developer.android.com/ndk/downloads) and extract the NDK package.
- Clone this repository. And get access to it. - Clone this repository. And get access to it.
``` ```
git clone https://github.com/ShawkTeam/pmt -b 2.5.0 git clone https://github.com/YZBruh/pbt -b 2.3.0 ./pmt
cd pmt cd pmt
``` ```
- Set the NDK working directory variable. - Set the NDK working directory variable.
``` ```
make gen-ndk-makefiles export NDK_PROJECT_PATH=$(pwd)
# If you fail the audit, etc., use FORCE_GEN.
# Example:
make gen-ndk-makefiles FORCE_GEN=true
# Required by Android NDK
export NDK_PROJECT_PATH="${PWD}"
``` ```
- Go to the NDK directory and start the build - Go to the NDK directory and start the construction
``` ```
# Required for creating clang version information and directory access
export NDK_ROOT_DIR="${PWD}"
cd "${NDK_PROJECT_PATH}" \
&& bash build/bash/gen-header \
&& cd "${NDK_ROOT_DIR}"
# Start build
./ndk-build ./ndk-build
``` ```
- The output files will be inside the `pmt` folder. Binaries are available in two architectures within the `libs` folder. `arm64-v8a` (64-bit) and `armeabi-v7a` (32-bit). - The output files will be inside the `pmt` folder. Binaries are available in two architectures within the `libs` folder. `arm64-v8a` (64-bit) and `armeabi-v7a` (32-bit).
@@ -77,7 +60,7 @@ cd "${NDK_PROJECT_PATH}" \
| |
________________|________________ ________________|________________
| | | | | | | |
jni/ build/ obj/ libs/ jni/ debutils/ obj/ libs/
| |
__________|__________ __________|__________
| | | |
@@ -85,30 +68,24 @@ cd "${NDK_PROJECT_PATH}" \
| | | |
pmt pmt pmt pmt
``` ```
- For the make installable debian package make-deb.sh use the script. It can be created within two architectures. Use the script flags correctly: arm64-v8a, armeabi-v7a. If you want to process with root, add sudo as the second argument. If you don't want, use no-sudo or leave it blank
##### Build with Makefiles
``` ```
make --Usage--
# To specify clang, just use CC=<clang> next to the command (and same logic in AR) ./make-deb.sh [arm64-v8a, armeabi-v7a] [sudo, no-sudo, <blank>]
# Example:
make CC=${PWD}/../toolchain/bin/clang-18
make AR=${PWD}/../toolchain/bin/ar
make CC=${PWD}/../toolchain/bin/clang-18 AR=${PWD}/../toolchain/bin/ar
# Use termux :D
``` ```
- For the make installable debian package:
``` ```
make deb <ARCH_NUM> chmod 777 utils.sh
# Examples # for making 64-bit package
make deb FOR_THIS=64 ./utils.sh make-deb arm64-v8a
make deb FOR_THIS=32
# for making 32-bit package
./utils.sh make-deb armeabi-v7a
``` ```
### Notes ### Notes
If you want to change something, take a look at the configuration. You can change him. If you want to change something, take a look at the configuration. You can change him.
it is located in the `build/config` folder. His name is `env.mk`. I gave the information in the file. You can ask more. it is located in the `jni/config` folder. His name is `env.mk`. I gave the information in the file. You can ask more.

View File

@@ -1,24 +0,0 @@
### Installing pmt deb packages in Termux
It's pretty simple.
###### Package selection
- If the device is 64 bit, you should choose `arm64-v8a` package. If not, choose `armeabi-v7a` package.
- And of course download it.
###### Setup
- Access downloads or wherever the package is located.
```
# Access downloads
cd /sdcard/Download
```
- Now it's time to set up.
```
Syntax:
apt install ./pmt-<VARIANT>.deb
Examples:
apt install ./pmt-armeabi-v7a.deb
apt install ./pmt-arm64-v8a.deb
```
- And enjoy!

View File

@@ -1,6 +0,0 @@
NDK_PROG=false
FORCE_GEN=false
THIS_IS=main
UPDATE_MAKEFILES=false
SOURCE_DIRNAME=src
OUT_DIRNAME=out

View File

@@ -1,36 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[ ! "${THIS_IS}" = "main" ] && abort "The caller is not the main makefile. Something's wrong."
try_with="Try with force mode (FORCE_GEN=true)."
if [ "${NDK_PROG}" = "true" ]; then
mfiles=("${SOURCE_DIR}/Android.mk" "${SOURCE_DIR}/Application.mk")
else
mfiles=("${OUT_DIR}/Makefile" "${SOURCE_DIR}/Makefile")
fi
for mfile in ${mfiles[0]} ${mfiles[1]}; do
[ -f "${mfile}" ] && \
if [ "${FORCE_GEN}" = "true" ]; then
rm -f "${mfile}"
else
abort "$(output=$(dirname ${mfile}) && basename "${output}")/$(basename ${mfile}) exits."
fi
done

View File

@@ -1,42 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
. build/bash/vars
. build/bash/functions
[ ! "${THIS_IS}" = "main" ] && abort "The caller is not the main makefile. Something's wrong."
if [ "${NDK_PROG}" = "true" ]; then
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing Android.mk..."
rm -f ${SOURCE_DIR}/Android.mk
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing Application.mk..."
rm -f ${SOURCE_DIR}/Application.mk
else
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Info: Main makefile won't be deleted."
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing output directory makefile..."
rm -f ${OUT_DIR}/Makefile
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Removing source directory makefile"
rm -f ${SOURCE_DIR}/Makefile
fi
[ "${UPDATE_MAKEFILES}" = "true" ] || print " - Success."

View File

@@ -1,37 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
function abort()
{
[ -n "$1" ] && echo -e " - ${RED}${BOLD}Error:${BOLD_RESET}${RESET} $1"
exit 1
}
function read_file()
{
cat "$1" >> "$2" || abort "failed to read/write $1/$2"
}
function gen()
{
[ "${FORCE_GEN}" = "true" -a "${UPDATE_MAKEFILES}" = "true" ] && rm -f "$1"
touch "$1" || abort "failed to generate: $1"
}
function print()
{
echo -e "$1"
}

View File

@@ -1,29 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[ -z ${NDK_ROOT_DIR} ] && \
echo "Please set NDK_ROOT_DIR variable!" && \
exit 1
[ -z ${NDK_PROJECT_PATH} ] && \
echo "Please set NDK_PROJECT_PATH variable!" && \
exit 1
CC_IS="${NDK_ROOT_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang"
CC_VERS=$(${CC_IS} --version | head -n 1)
mkdir -p ${NDK_PROJECT_PATH}/include/pmt/generated
echo -e "#define __NDK_CC_VERSION__ \"${CC_VERS}\"" > ${NDK_PROJECT_PATH}/include/pmt/generated/clang-version.h

View File

@@ -1,64 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
. build/bash/vars
. build/bash/functions
[ ! "${UPDATE_MAKEFILES}" = "true" ] && . build/bash/check-makefiles
[ ! "${THIS_IS}" = "main" ] && abort "The caller is not the main makefile. Something's wrong."
if [ "${UPDATE_MAKEFILES}" = "true" ]; then
GENR="Re-generating"
else
GENR="Generating"
fi
if [ "${NDK_PROG}" = "true" ]; then
gen "${SOURCE_DIR}/Android.mk"
gen "${SOURCE_DIR}/Application.mk"
else
gen "${CUR_DIR}/Makefile"
gen "${OUT_DIR}/Makefile"
gen "${SOURCE_DIR}/Makefile"
fi
if [ "${NDK_PROG}" = "true" ]; then
print " - ${GENR} Android.mk..."
read_file "${OTHERS}/makefile.androidmk" "${SOURCE_DIR}/Android.mk"
print " - ${GENR} Application.mk"
read_file "${OTHERS}/makefile.applicationmk" "${SOURCE_DIR}/Application.mk"
else
print " - Re-generating main makefile..."
rm -f "${CUR_DIR}/Makefile"
read_file "${OTHERS}/makefile.main" "${CUR_DIR}/Makefile"
print " - ${GENR} output directory makefile..."
read_file "${OTHERS}/makefile.outdir" "${OUT_DIR}/Makefile"
print " - ${GENR} source directory makefile..."
read_file "${OTHERS}/makefile.sourcedir" "${SOURCE_DIR}/Makefile"
fi
print " - Success."

View File

@@ -1,33 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
. build/bash/additional-vars
CUR_DIR=$(pwd)
SOURCE_DIR=${CUR_DIR}/${SOURCE_DIRNAME}
OUT_DIR=${CUR_DIR}/${OUT_DIRNAME}
BUILD=${CUR_DIR}/build
BASH_DIR=$(pwd)
OTHERS=${BUILD}/others
TOOLS=${BUILD}/tools
# font types, colors etc
BOLD="\e[1m"
BOLD_RESET="\e[0m"
RESET="\033[0m"
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[0;33m"

View File

@@ -1 +0,0 @@
INSTALL_SUCCESS := true

View File

@@ -1,52 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
include env.mk
#########################################
# #
# Apply Configuration #
# #
# Warning: please do not edit #
# #
#########################################
CC = clang
CFLAGS ?= "-O3 -I../include -std=c11 -pedantic -Wall -Wextra -Werror -Wno-nullability-extension -Wno-gnu-zero-variadic-macro-arguments $(PMT_EXTRA_CFLAGS)"
# set compiler setting (clang-gcc and ar)
ifneq ($(PMT_CC),)
CC ?= $(PMT_CC)
else
CC ?= clang
endif
ifneq ($(PMT_AR),)
AR ?= $(PMT_AR)
else
AR ?= ar
endif
# compiler flags settings
ifneq ($(PMT_ENABLE_DEBUG),)
CFLAGS += -gdwarf-5 -fsanitize=address
endif
# write current env configuration to oldenv.mk
all:
@echo "CC := $(CC)" > oldenv.mk; \
echo "AR := $(AR)" >> oldenv.mk; \
echo "CFLAGS := $(CFLAGS)" >> oldenv.mk

View File

@@ -1 +0,0 @@
UNINSTALLED_SUCCESS :=

View File

@@ -1,107 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#####
# sub-make for making deb package
#####
THIS_IS := debutils
# include needed variables
include ../../Makefile.inc
TEMP_DIR := $(DEBUTILS_DIR)/template
ifeq ($(FOR_THIS),64)
DEB_ARCH_NAME := arm64-v8a
else ifeq ($(FOR_THIS),32)
DEB_ARCH_NAME := armeabi-v7a
endif
ifneq ($(wildcard /dev/block/by-name),)
SUDO := su
else ifeq ($(wildcard /system/build.prop),)
SUDO := sudo
else
SUDO :=
endif
# controls the presence of file/directory. usage: $(call check_local,<FILE_OR_DIRECTORY_PATH>,<PACKAGE_STAT: 1, NULL>)
define check_local
# the first argument is taken and controlled by the file/directory with -e option
if [ ! -e $1 ]; then \
if [ $2 = 1 ]; then \
printf " - Package not builded! Please build package and try again.\n"; \
else \
printf " ==> Not found: $1\n"; \
fi; \
if [ -d "$(TEMP_DIR)" ]; then \
rm -rf $(TEMP_DIR); \
fi; \
exit 1; \
fi;
endef
# make deb package
all:
$(hide)printf " --------- Making deb package ---------\n"
# remove template directory
$(call erase,$(TEMP_DIR))
$(hide)printf " - Checking files and directories (only neededs)...\n"
# check some files and directories with parsing DEB_CHECKS variable
$(foreach deb_chfile, \
$(DEB_CHECKS), \
$(call check_local,$(deb_chfile)) \
)
# check build status
$(call check_local, \
$(BINARY_DIR)/pmt, \
1 \
)
# make template and output directories
$(call mdir,$(TEMP_DIR),"y")
$(call mdir,$(DEB_DIR),"y")
$(hide)printf " - Copying files...\n"
# prepare
$(hide)cp -r $(DEBUTILS_DIR)/data $(TEMP_DIR) || exit 1
$(hide)rm -f $(DEBTERMUX_USR)/share/man/man8/dummy
$(hide)rm -f $(DEBTERMUX_USR)/bin/dummy
$(call mdir,$(TEMP_DIR)/DEBIAN)
$(hide)abort() { \
if [ -d $(TEMP_DIR) ]; then \
rm -rf $(TEMP_DIR); \
fi; \
if [ -d $(DEB_DIR) ]; then \
rm -rf $(DEB_DIR); \
fi; \
exit 1; \
}; \
if [ ! "$(FOR_THIS)" = "64" ] && [ ! "$(FOR_THIS)" = "32" ]; then \
printf " - İnvalid arch number: $(FOR_THIS)\n" && abort; \
fi; \
printf " - Selected arm-$(FOR_THIS) package control file.\n"; \
cp $(DEBUTILS_DIR)/DEBIAN/control_$(FOR_THIS) $(TEMP_DIR)/DEBIAN/control || abort; \
cp $(DEBUTILS_DIR)/mandoc/$(TARGET).8.gz $(DEBTERMUX_USR)/share/man/man8 || abort; \
cp $(BINARY_DIR)/$(TARGET) $(DEBTERMUX_USR)/bin || abort; \
printf " - Starting dpkg-deb...\n"; \
sleep 2; \
$(SUDO) chmod -R 755 *; \
dpkg-deb -b $(TEMP_DIR) $(DEB_DIR)/$(TARGET)-$(DEB_ARCH_NAME).deb || abort; \
# cleanup template directory
rm -rf $(TEMP_DIR); \
printf " - Done!\n"
# end

Binary file not shown.

View File

@@ -1,135 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
UPDATE_MAKEFILES = false
all:
$(hide)# To save configuration, the makefile in the config directory
$(MAKE_HIDE) $(SILENT) -C $(BUILD)/config || exit 1
$(hide)# start the main build process
$(MAKE_HIDE) $(SILENT) -C $(SOURCE_DIRNAME) INC_OLDENV=true || exit 1
# cleaner functions
.PHONY: clean
clean:
$(hide)printf "Cleaning directories...\n"; \
# cleanup out/binary
$(hide)if [ -d $(BINARY_DIR) ]; then \
printf "==> $(OUT_DIRNAME)/`basename $(BINARY_DIR)`\n"; \
rm -rf "$(BINARY_DIR)"; \
fi; \
# cleanup out/package
$(hide)if [ -d $(PACKAGE_DIR) ]; then \
printf "==> $(OUT_DIRNAME)/`basename $(PACKAGE_DIR)`\n"; \
rm -rf "$(PACKAGE_DIR)"; \
fi; \
# cleanup out/static_libs
$(hide)if [ -d $(STATICLIB_DIR) ]; then \
printf "==> $(OUT_DIRNAME)/`basename $(STATICLIB_DIR)`\n"; \
rm -rf "$(STATICLIB_DIR)"; \
fi; \
# cleanup out/debpackage
$(hide)if [ -d $(DEB_DIR) ]; then \
printf "==> $(OUT_DIRNAME)/`basename $(DEB_DIR)`\n"; \
rm -rf "$(DEB_DIR)"; \
fi; \
sleep 2; \
# clean the objects by calling the receipt in the source directory
$(MAKE_HIDE) $(SILENT) -C $(SOURCE_DIRNAME) clean INC_OLDENV=false || exit 1
$(hide)sleep 1
$(hide)printf "Success.\n"
# helper function
.PHONY: help
help:
$(hide)printf " ------- Partition Manager help -------\n\n"
$(hide)printf " Commands:\n"
$(hide)printf " $(MAKE) ==> Build Partition Manager.\n"
$(hide)printf " $(MAKE) deb ==> Generate debian package for termux.\n"
$(hide)printf " $(MAKE) clean ==> Clear builded binary.\n"
$(hide)printf " $(MAKE) install ==> It installs $(TARGET) into termux.\n"
$(hide)printf " $(MAKE) uninstall ==> It uninstalls $(TARGET) into termux.\n"
$(hide)printf " $(MAKE) gen-makefiles ==> Generate makefiles for build.\n"
$(hide)printf " $(MAKE) gen-ndk-makefiles ==> Generate NDK makefiles for build.\n"
$(hide)printf " $(MAKE) clean-makefiles ==> Cleanup makefiles.\n"
$(hide)printf " $(MAKE) clean-ndk-makefiles ==> Cleanup NDK makefiles.\n"
$(hide)printf " $(MAKE) update-makefiles ==> Re-generate makefiles.\n"
$(hide)printf " $(MAKE) update-ndk-makefiles ==> Re-generate NDK makefiles.\n"
$(hide)printf " $(MAKE) help ==> Display this help message.\n\n"
# deb maker
.PHONY: deb
deb:
$(MAKE_HIDE) $(SILENT) -C $(DEBUTILS_DIR) -f deb.mk FOR_THIS=$(FOR_THIS) || exit 1
$(hide)printf ""
# install pmt in to termux
.PHONY: install
install:
$(MAKE_HIDE) $(SILENT) -C $(OUT_DIRNAME) install || exit 1
# uninstall pmt in to termux
.PHONY: uninstall
uninstall:
$(MAKE_HIDE) $(SILENT) -C $(OUT_DIRNAME) uninstall || exit 1
# clean ndk makefiles
.PHONY: gen-ndk-makefiles
gen-ndk-makefiles:
$(eval NDK_PROG = true)
$(call save-gen-vars)
$(call gen-ndk-mfiles)
$(hide)printf ""
.PHONY: gen-makefiles
gen-makefiles:
$(call save-gen-vars)
$(call gen-mfiles)
$(hide)printf ""
.PHONY: update-ndk-makefiles
update-ndk-makefiles:
$(hide)printf " ------ Updating NDK makefiles ------ \n"
$(eval NDK_PROG = true)
$(eval UPDATE_MAKEFILES = true)
$(call save-gen-vars)
$(call clean-ndk-mfiles)
$(call gen-ndk-mfiles)
$(hide)printf ""
.PHONY: update-makefiles
update-makefiles:
$(hide)printf " ------ Updating makefiles ------ \n"
$(eval UPDATE_MAKEFILES = true)
$(call save-gen-vars)
$(call clean-ndk-mfiles)
$(call gen-mfiles)
$(hide)printf ""
.PHONY: clean-ndk-makefiles
clean-ndk-makefiles:
$(eval NDK_PROG = true)
$(call save-gen-vars)
$(call clean-ndk-mfiles)
$(hide)printf ""
.PHONY: clean-makefiles
clean-makefiles:
$(call save-gen-vars)
$(call clean-mfiles)
$(hide)printf ""
# end

View File

@@ -1,26 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
THIS_IS = main
NDK_PROG ?= false
FORCE_GEN ?= false
# include needed variables
include Makefile.inc
include $(TOOLS)/gen-makefiles.mk
include $(TOOLS)/clean-makefiles.mk
include $(BUILD)/main.mk

View File

@@ -1,126 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#####
# sub-make for installing-uninstalling
#####
THIS_IS := out
# include needed variables
include ../Makefile.inc
-include $(BUILD)/config/INS_STAT.mk
-include $(BUILD)/config/UNINS_STAT.mk
# create an empty target
all:
$(hide)printf ""
# installer
.PHONY: install
install:
# really termux?
$(hide)if [ -f $(TERMUX_BIN)/termux-open ]; then \
printf " ------------ $(TARGET) installer ------------ \n"; \
if [ -f $(TERMUX_BIN)/$(TARGET) ]; then \
printf " - $(TARGET) already installed\n"; \
exit; \
fi; \
if [ ! "$(INSTALL_SUCCESS)" = "true" ] && [ ! "$(INSTALL_SUCCESS)" = "" ]; then \
printf " - $(YELLOW)$(BOLD)Warning:$(BOLD_RESET)$(RESET) a previously-stayed failed installation process found\n"; \
fi; \
if [ -f $(DEB_DIR)/*.deb ]; then \
printf " - The created deb pack was found. It's setup...\n"; \
cd $(DEB_DIR) || exit 1; \
apt install ./*.deb || exit 1; \
if [ ! "$?" = "0" ]; then \
cd $(CUR_DIR); \
printf " - Success.\n\n"; \
echo "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
echo "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk; \
cd ..; \
exit 0; \
else \
cd $(CUR_DIR); \
printf " - $(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) installing failed!\n"; \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
cd ..; \
exit 1; \
fi; \
fi; \
if [ ! -f $(BINARY_DIR)/$(TARGET) ]; then \
printf " - $(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) Package not builded! Please build package and try again \n"; \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
exit 1; \
fi; \
printf " - Installing binary...\n"; \
if [ "`cp $(BINARY_DIR)/$(TARGET) /data/data/com.termux/files/usr/bin/$(TARGET)`" = "" ]; then \
printf " - Setting up permissions...\n"; \
else \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
exit 1; \
fi; \
if [ "`chmod 777 $(TERMUX_BIN)/$(TARGET)`" = "" ]; then \
printf " - Saving current status...\n"; \
echo "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
else \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
exit 1; \
fi; \
printf " - Success.\n\n"; \
echo "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
echo "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk; \
else \
printf " - $(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) This function is only available on Termux.\n"; \
exit 1; \
fi
# uninstaller
.PHONY: uninstall
uninstall:
# really termux?
$(hide)if [ -f $(TERMUX_BIN)/termux-open ]; then \
printf " ----------- $(TARGET) uninstaller ----------- \n"; \
if [ ! -f $(TERMUX_BIN)/$(TARGET) ]; then \
printf " - $(TARGET) already uninstalled\n"; \
exit; \
fi; \
if [ ! "$(UNINSTALL_SUCCESS)" = "true" ] && [ ! "$(UNINSTALL_SUCCESS)" = "" ]; then \
printf " - $(YELLOW)$(BOLD)Warning:$(BOLD_RESET)$(RESET) a previously-stayed failed uninstallation process found\n"; \
fi; \
if [ -f $(TERMUX_USR)/share/man/man8/$(TARGET).8.gz ]; then \
printf " - It was found to be established by $(TARGET)'s deb pack. It's removed with apt...\n"; \
apt remove -y $(TARGET) || exit 1; \
printf " - Success.\n\n"; \
echo "UNINSTALLED_SUCCESS := true" > $(BUILD)/config/UNINS_STAT.mk; \
echo "INSTALL_SUCCESS := " > $(BUILD)/config/INS_STAT.mk; \
else \
printf " - It was found that pmt was manually established (with this makefile or copying). Manually removed...\n"; \
if [ "`rm $(TERMUX_BIN)/$(TARGET)`" = "" ]; then \
printf " - Success.\n\n"; \
echo "UNINSTALLED_SUCCESS := true" > $(BUILD)/config/UNINS_STAT.mk; \
echo "INSTALL_SUCCESS := " > $(BUILD)/config/INS_STAT.mk; \
else \
echo "UNINSTALLED_SUCCESS := false" > $(BUILD)/config/UNINS_STAT.mk; \
exit 1; \
fi; \
fi; \
else \
printf "$(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) This function is only available on Termux.\n"; \
exit 1; \
fi
# end

View File

@@ -1,161 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#####
# sub-make for building package
#####
THIS_IS = src
include ../Makefile.inc
ifeq ($(INC_OLDENV),true)
include $(BUILD)/config/oldenv.mk
endif
# make objects. Usage $(call make_obj,<SRCFILE>)
define make_obj
$(eval OBJ := $(1:.c=.o))
$(call m_stat,CC,`basename $(SOURCE_DIR)`/`basename $(OBJ)`,n)
$(CC) $(CFLAGS) -c "$1" || exit 1;
$(hide)printf "\n"
endef
# make executable file with using static libraries and objects. Usage: $(call make_executable)
define make_executable
printf " - Making executable file...\n"; \
printf " LD $(TARGET)"; \
$(CC) $(CFLAGS) -L$(SOURCE_DIR) \
$(foreach s_obj_b, \
$(shell basename -a $(STATICLIB_OBJS)), \
$(eval s_obj_t_b = $(s_obj_b:.o=)) \
$(shell echo -lpmt_$(s_obj_t_b)) \
) \
-o $(TARGET) $(OBJS_EXEC) || exit 1;
endef
# make static library. Usage $(call make_staticlib,<LIBRARY_NAME>,<OBJECT(S)>)
define make_staticlib
echo -n " AR $1"; \
$(AR) rcs "$1" "$2" || exit 1; \
echo;
endef
# controls the presence of source file. usage: $(call check_cfile,<SOURCE_FILE>)
define check_cfile
# the first argument is taken and controlled by the file with -f option
printf " CHK src/`basename $1`\n"; \
if [ ! -f $1 ]; then \
printf " ==> Couldn't found required source file: src/`basename $1`\n"; \
if [ -d "$(TEMP_DIR)" ]; then \
rm -rf $(TEMP_DIR); \
fi; \
exit 1; \
fi;
endef
# controls the presence of header file. usage: $(call check_hfile,<SOURCE_FILE>)
define check_hfile
# the first argument is taken and controlled by the file with -f option
printf " CHK include/pmt/`basename $1`\n"; \
if [ ! -f $1 ]; then \
printf " ==> Couldn't found required header file: include/pmt/`basename $1`\n"; \
if [ -d "$(TEMP_DIR)" ]; then \
rm -rf $(TEMP_DIR); \
fi; \
exit 1; \
fi;
endef
# all target for building
all:
$(hide)rm -f $(BUILD)/config/oldenv.mk
$(hide)printf " ---- Partition Manager Builder ---- \n\n"
$(hide)printf " - Version: $(VERSION)\n"
$(hide)printf " - Version code: $(VERSION_CODE)\n\n"
$(hide)printf " -------------------------------- \n\n"
$(hide)if [ -f $(SOURCE_DIR)/debugging.o ]; then \
printf " - Please clean up before you build it.\n\n"; \
printf " ----------------------------------- \n"; \
exit 1; \
fi
$(hide)printf " - Checking required source files...\n"
$(hide)sleep 1
$(foreach src_cf, \
$(SRCS_REQ), \
$(call check_cfile,$(src_cf)) \
)
$(foreach src_hf, \
$(HEADERS_REQ), \
$(call check_hfile,$(src_hf)) \
)
$(hide)printf " - Building objects...\n"
$(hide)sleep 2
$(foreach csrc, \
$(SRCS), \
$(call make_obj,$(csrc)) \
)
$(foreach reqdir,$(IN_OUT_DIR),$(call mdir,$(reqdir)))
$(hide)printf " - Making static libraries...\n"
$(foreach s_obj, \
$(shell basename -a $(STATICLIB_OBJS)), \
$(eval s_obj_t = $(s_obj:.o=.a)) \
$(call make_staticlib,libpmt_$(s_obj_t),$(s_obj)) \
)
$(hide)sleep 1
$(call make_executable)
$(hide)sleep 1
$(hide)abort_build() { \
if [ -d "$(PACKAGE_DIR)" ]; then \
rm -rf "$(PACKAGE_DIR)"; \
fi; \
if [ -d "$(BINARY_DIR)" ]; then \
rm -rf "$(BINARY_DIR)"; \
fi; \
if [ -d "$(STATICLIB_DIR)" ]; then \
rm -rf "$(STATICLIB_DIR)"; \
fi; \
exit 1; \
}; \
mv $(TARGET) $(BINARY_DIR) || abort_build; \
mv *.a $(STATICLIB_DIR) || abort_build; \
printf "\n - Generating package...\n"; \
cp $(BINARY_DIR)/$(TARGET) $(PACKAGE_DIR) || abort_build; \
printf " XZ $(OUT_DIRNAME)/package/$(TARGET)-$(ARCH).xz"
xz $(PACKAGE_DIR)/$(TARGET) || abort_build; \
sleep 1; \
mv $(PACKAGE_DIR)/$(TARGET).xz $(PACKAGE_DIR)/$(TARGET)-$(ARCH).xz || abort_build; \
printf "\n - Success"; \
sleep 1; \
printf "\n\n ----------------------------------- \n"
.PHONY: clean
clean:
$(eval STATICLIBS = $(wildcard $(SOURCE_DIR)/*.a))
$(eval OBJS = $(wildcard $(SOURCE_DIR)/*.o))
$(info Cleaning files...)
$(foreach obj, \
$(OBJS), \
$(call m_stat_nn,$(SOURCE_DIRNAME)/$(shell basename $(obj))) \
$(call erase,$(obj)) \
)
$(foreach lib, \
$(STATICLIBS), \
$(call m_stat_nn,$(SOURCE_DIRNAME)/$(shell basename $(lib))) \
$(call erase,$(lib)) \
)
# end

View File

@@ -1,31 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##################
# See "erase" funtion for build/util/utils.mk
##################
include $(TOOLS)/save-gen-vars.mk
define clean-ndk-mfiles
$(hide)[ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Cleaning NDK Makefiles ------ \n"
$(hide)cat $(BASH_DIR)/clean-makefiles | $(BIN)/bash
endef
define clean-mfiles
$(hide)[ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Cleaning Makefiles ------ \n"
$(hide)cat $(BASH_DIR)/clean-makefiles | $(BIN)/bash
endef

View File

@@ -1,31 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##################
# See "save-gen-vars" funtion for build/tools/save-gen-vars.mk
##################
include $(TOOLS)/save-gen-vars.mk
define gen-ndk-mfiles
$(hide)[ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Generating NDK Makefiles ------ \n"
$(hide)cat $(BASH_DIR)/gen-makefiles | $(BIN)/bash
endef
define gen-mfiles
$(hide)[ "$(UPDATE_MAKEFILES)" = "true" ] || printf " ------ Generating Makefiles ------ \n"
$(hide)cat $(BASH_DIR)/gen-makefiles | $(BIN)/bash
endef

View File

@@ -1,26 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
define save-gen-vars
$(hide)rm -f $(BASH_DIR)/additional-vars
$(call touch,$(BASH_DIR)/additional-vars)
$(hide)echo "NDK_PROG=$(NDK_PROG)" >> $(BASH_DIR)/additional-vars
$(hide)echo "FORCE_GEN=$(FORCE_GEN)" >> $(BASH_DIR)/additional-vars
$(hide)echo "THIS_IS=$(THIS_IS)" >> $(BASH_DIR)/additional-vars
$(hide)echo "UPDATE_MAKEFILES=$(UPDATE_MAKEFILES)" >> $(BASH_DIR)/additional-vars
$(hide)echo "SOURCE_DIRNAME=$(SOURCE_DIRNAME)" >> $(BASH_DIR)/additional-vars
$(hide)echo "OUT_DIRNAME=$(OUT_DIRNAME)" >> $(BASH_DIR)/additional-vars
endef

View File

@@ -1,24 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ifneq ($(THIS_IS),main)
$(error The caller is not the main makefile. Something's wrong)
endif
UPDATE_MAKEFILES = true
include $(TOOLS)/clean-makefiles.mk
include $(TOOLS)/gen-makefiles.mk

View File

@@ -1,58 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# generate any text based empty file. Usage: $(call touch,<PATH>)
define touch
$(hide)[ ! "$(FORCE_GEN)" = "true" ] || rm -f "$1"
$(hide)touch "$1" || exit 1
endef
# copy files. Usage: $(call copy,<SOURCE>,<COPY_PATH>)
define copy
cp "$1" "$2" || exit 1
endef
# copy dirs. Usage: $(call copydir,<SOURCE>,<COPY_PATH>)
define copydir
cp -r "$1" "$2" || exit 1
endef
# file/dir are deleted. usage: $(call erase,<file/directory>)
define erase
rm -rf "$1"
endef
# make directories. usage: $(call mdir,<PATH>,<PRINTSTATUS=y/NULL>)
define mdir
[ -z $2 ] || printf " - Generating `basename $1` dir...\n"; \
mkdir -p "$1" || exit 1;
endef
# make status. usage: $(call m_stat,"<MESSAGE>",<NEW_LINE_STATE: RANDOM>)
define m_stat
printf " $1 $2"
endef
# make status (not newline and using make functions). usage: $(call m_stat_nn,"<MESSAGE>")
define m_stat_nn
$(info ==> $(1))
endef
# Get file content and if speficed write target, write speficed file. Usage: $(call cat,<SOURCE>,<WRITE_PATH>)
define cat
[ -z "$2" ] && cat "$1" || exit 1
[ -n "$2" ] && cat "$1" >> "$2" || exit 1
endef

View File

@@ -1,5 +0,0 @@
export PMT_VERSION="2.5.0"
export PMT_VERSION_CODE=250
export NDK_LINK="https://dl.google.com/android/repository/android-ndk-r27-linux.zip"
export NDK_VERSION="r27"
export NDK_IS="android-ndk"

View File

@@ -1,11 +0,0 @@
echo -e "\`${CC_VERSION}\`
Version/Version Code: \`${PMT_VERSION}\`/\`${PMT_VERSION_CODE}\`
Supported architectures: \`arm64-v8a\` (64-bit) and \`armeabi-v7a\` (32-bit)
Notes:
Builded with Android NDK ${NDK_VERSION}
Packages are compressed with xz.
Builded debian packages for termux. [Click](https://github.com/ShawkTeam/pmt/blob/${PMT_VERSION}/SETUP-DEBS.md) for guide.
Report bugs and suggestions.
[Click](https://github.com/ShawkTeam/pmt/blob/${PMT_VERSION}/CHANGELOG.md) for viewing version ${PMT_VERSION} changelog."

View File

@@ -1,6 +1,6 @@
Source: pmt Source: pmt
Package: pmt Package: pmt
Version: 2.5.0 Version: 2.3.0
Architecture: arm Architecture: arm
Description: pmt is for reading, writing and formatting partitions of android devices Description: pmt is for reading, writing and formatting partitions of android devices
Section: misc Section: misc

View File

@@ -1,6 +1,6 @@
Source: pmt Source: pmt
Package: pmt Package: pmt
Version: 2.5.0 Version: 2.3.0
Architecture: aarch64 Architecture: aarch64
Description: pmt is for reading, writing and formatting partitions of android devices Description: pmt is for reading, writing and formatting partitions of android devices
Section: misc Section: misc

BIN
debutils/mandoc/pmt.8.gz Executable file

Binary file not shown.

View File

@@ -1,99 +0,0 @@
/* By YZBruh */
/**
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __PMT_DEPRECATED_H
#define __PMT_DEPRECATED_H
#include <sys/cdefs.h>
__BEGIN_DECLS
#define deprecated_opt 1
#define changed_opt 2
#define end_depr_pointer 0
#define not_changed 0
#define not_changed_long NULL
/* versions */
#define v150 "1.5.0"
#define v160 "1.6.0"
#define v170 "1.7.0"
#define v180 "1.8.0"
#define v190 "1.9.0"
#define v200 "2.0.0"
#define v210 "2.1.0"
#define v220 "2.2.0"
#define v230 "2.3.0"
#define v240 "2.4.0"
#define v250 "2.5.0"
#define vUNK NULL
struct pmt_deprecates {
int depr_type;
int option;
int option_new;
const char* option_long;
const char* option_long_new;
const char* depr_version;
};
static void
__deprecated_opt_handle(int opt, const char* opt_long, const char* depr_msg)
{
static char long_e_msg[250];
static struct pmt_deprecates depr_table[] = {
{deprecated_opt, 'b', not_changed, "backup", not_changed_long, v210},
{deprecated_opt, 'F', not_changed, "flash", not_changed_long, v210},
{deprecated_opt, 'r', not_changed, "format", not_changed_long, v210},
{deprecated_opt, 'L', not_changed, "license", not_changed_long, v250},
{changed_opt, 'D', 'p', "list", not_changed_long, v210},
{end_depr_pointer, not_changed, not_changed, not_changed_long, not_changed_long, vUNK}
};
if (opt_long == NULL)
sprintf(long_e_msg, "%s", current->not_changed_opt);
else
sprintf(long_e_msg, "%s", opt_long);
for (int optctrl = 0; depr_table[optctrl].depr_type != 0; optctrl++)
{
if (depr_table[optctrl].depr_type == 1)
{
if (opt == depr_table[optctrl].option || strcmp(opt_long, depr_table[optctrl].option_long) == 0)
LOGD("%s [%s]: -%c (%s): %s\n", current->depr_opt_str, depr_table[optctrl].depr_version, (char)depr_table[optctrl].option, depr_table[optctrl].option_long, depr_msg);
}
else if (depr_table[optctrl].depr_type == 2)
{
if (opt == depr_table[optctrl].option || strcmp(opt_long, depr_table[optctrl].option_long) == 0)
LOGD("%s [%s]: -%c (%s): %s\n", current->switched_opt_str, depr_table[optctrl].depr_version, (char)depr_table[optctrl].option, long_e_msg, depr_msg);
}
}
}
#define DEPR_HANDLE(x, y, z) __deprecated_opt_handle(x, y, z)
__END_DECLS
#endif
/* end of code */

View File

@@ -14,44 +14,33 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
########
# 2.5.0
########
LOCAL_PATH := $(call my-dir) LOCAL_PATH := $(call my-dir)
include $(LOCAL_PATH)/../build/config/env.mk include $(LOCAL_PATH)/config/env.mk
PMT_CFLAGS = \ ifeq ($(ENABLE_DEBUGGING), true)
-O3 \ PMT_CFLAGS := -O3 -g -Wall -Wextra $(EXTRA_COMPILER_FLAGS)
-std=c11 \ else ifeq ($(ENABLE_DEBUGGING), false)
-pedantic \ PMT_CFLAGS := -O3 -Wall $(EXTRA_COMPILER_FLAGS)
-Wall \ else
-Wextra \ $(warning Unknown debugging flag: $(ENABLE_DEBUGGING). Please see: $(PREDIR)/config/env.mk. Using non-debugging flags)
-Werror \ PMT_CFLAGS := -O3 -Wall $(EXTRA_COMPILER_FLAGS)
-Wno-nullability-extension \
-Wno-gnu-zero-variadic-macro-arguments \
-D__NDK_BUILD \
$(EXTRA_COMPILER_FLAGS)
ifneq ($(PMT_ENABLE_DEBUG),)
PMT_CFLAGS += -gdwarf-5 -fsanitize=address
endif endif
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := libpmt_root LOCAL_MODULE := libpmt_root
LOCAL_SRC_FILES := root.c LOCAL_SRC_FILES := root.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_CFLAGS := $(PMT_CFLAGS) LOCAL_CFLAGS := $(PMT_CFLAGS)
include $(BUILD_STATIC_LIBRARY) include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := libpmt_debugging LOCAL_MODULE := libpmt_error
LOCAL_SRC_FILES := debugging.c LOCAL_SRC_FILES := error.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_CFLAGS := $(PMT_CFLAGS) LOCAL_CFLAGS := $(PMT_CFLAGS)
include $(BUILD_STATIC_LIBRARY) include $(BUILD_STATIC_LIBRARY)
@@ -60,7 +49,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE := libpmt_partitiontool LOCAL_MODULE := libpmt_partitiontool
LOCAL_SRC_FILES := partitiontool.c LOCAL_SRC_FILES := partitiontool.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_CFLAGS := $(PMT_CFLAGS) LOCAL_CFLAGS := $(PMT_CFLAGS)
include $(BUILD_STATIC_LIBRARY) include $(BUILD_STATIC_LIBRARY)
@@ -69,7 +58,7 @@ include $(CLEAR_VARS)
LOCAL_MODULE := libpmt_list LOCAL_MODULE := libpmt_list
LOCAL_SRC_FILES := listpart.c LOCAL_SRC_FILES := listpart.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_CFLAGS := $(PMT_CFLAGS) LOCAL_CFLAGS := $(PMT_CFLAGS)
include $(BUILD_STATIC_LIBRARY) include $(BUILD_STATIC_LIBRARY)
@@ -80,15 +69,14 @@ LOCAL_MODULE := pmt
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
pmt.c \ pmt.c \
versioner.c \ versioner.c \
get_stat.c \
tools.c \ tools.c \
lang_tools.c \ lang_tools.c \
languages.c \ languages.c \
docs.c docs.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_STATIC_LIBRARIES := \ LOCAL_STATIC_LIBRARIES := \
libpmt_root \ libpmt_root \
libpmt_debugging \ libpmt_error \
libpmt_partitiontool \ libpmt_partitiontool \
libpmt_list libpmt_list
LOCAL_CFLAGS := $(PMT_CFLAGS) LOCAL_CFLAGS := $(PMT_CFLAGS)

View File

@@ -14,10 +14,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
########
# 2.5.0
########
# architecture # architecture
APP_ABI := \ APP_ABI := \
arm64-v8a \ arm64-v8a \

View File

@@ -1,161 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#####
# sub-make for building package
#####
THIS_IS = src
include ../Makefile.inc
ifeq ($(INC_OLDENV),true)
include $(BUILD)/config/oldenv.mk
endif
# make objects. Usage $(call make_obj,<SRCFILE>)
define make_obj
$(eval OBJ := $(1:.c=.o))
$(call m_stat,CC,`basename $(SOURCE_DIR)`/`basename $(OBJ)`,n)
$(CC) $(CFLAGS) -c "$1" || exit 1;
$(hide)printf "\n"
endef
# make executable file with using static libraries and objects. Usage: $(call make_executable)
define make_executable
printf " - Making executable file...\n"; \
printf " LD $(TARGET)"; \
$(CC) $(CFLAGS) -L$(SOURCE_DIR) \
$(foreach s_obj_b, \
$(shell basename -a $(STATICLIB_OBJS)), \
$(eval s_obj_t_b = $(s_obj_b:.o=)) \
$(shell echo -lpmt_$(s_obj_t_b)) \
) \
-o $(TARGET) $(OBJS_EXEC) || exit 1;
endef
# make static library. Usage $(call make_staticlib,<LIBRARY_NAME>,<OBJECT(S)>)
define make_staticlib
echo -n " AR $1"; \
$(AR) rcs "$1" "$2" || exit 1; \
echo;
endef
# controls the presence of source file. usage: $(call check_cfile,<SOURCE_FILE>)
define check_cfile
# the first argument is taken and controlled by the file with -f option
printf " CHK $(SOURCE_DIRNAME)/`basename $1`\n"; \
if [ ! -f $1 ]; then \
printf " ==> Couldn't found required source file: $(SOURCE_DIRNAME)/`basename $1`\n"; \
if [ -d "$(TEMP_DIR)" ]; then \
rm -rf $(TEMP_DIR); \
fi; \
exit 1; \
fi;
endef
# controls the presence of header file. usage: $(call check_hfile,<SOURCE_FILE>)
define check_hfile
# the first argument is taken and controlled by the file with -f option
printf " CHK include/pmt/`basename $1`\n"; \
if [ ! -f $1 ]; then \
printf " ==> Couldn't found required header file: include/pmt/`basename $1`\n"; \
if [ -d "$(TEMP_DIR)" ]; then \
rm -rf $(TEMP_DIR); \
fi; \
exit 1; \
fi;
endef
# all target for building
all:
$(hide)rm -f $(BUILD)/config/oldenv.mk
$(hide)printf " ---- Partition Manager Builder ---- \n\n"
$(hide)printf " - Version: $(VERSION)\n"
$(hide)printf " - Version code: $(VERSION_CODE)\n\n"
$(hide)printf " -------------------------------- \n\n"
$(hide)if [ -f $(SOURCE_DIR)/debugging.o ]; then \
printf " - Please clean up before you build it.\n\n"; \
printf " ----------------------------------- \n"; \
exit 1; \
fi
$(hide)printf " - Checking required source files...\n"
$(hide)sleep 1
$(foreach src_cf, \
$(SRCS_REQ), \
$(call check_cfile,$(src_cf)) \
)
$(foreach src_hf, \
$(HEADERS_REQ), \
$(call check_hfile,$(src_hf)) \
)
$(hide)printf " - Building objects...\n"
$(hide)sleep 2
$(foreach csrc, \
$(SRCS), \
$(call make_obj,$(csrc)) \
)
$(foreach reqdir,$(IN_OUT_DIR),$(call mdir,$(reqdir)))
$(hide)printf " - Making static libraries...\n"
$(foreach s_obj, \
$(shell basename -a $(STATICLIB_OBJS)), \
$(eval s_obj_t = $(s_obj:.o=.a)) \
$(call make_staticlib,libpmt_$(s_obj_t),$(s_obj)) \
)
$(hide)sleep 1
$(call make_executable)
$(hide)sleep 1
$(hide)abort_build() { \
if [ -d "$(PACKAGE_DIR)" ]; then \
rm -rf "$(PACKAGE_DIR)"; \
fi; \
if [ -d "$(BINARY_DIR)" ]; then \
rm -rf "$(BINARY_DIR)"; \
fi; \
if [ -d "$(STATICLIB_DIR)" ]; then \
rm -rf "$(STATICLIB_DIR)"; \
fi; \
exit 1; \
}; \
mv $(TARGET) $(BINARY_DIR) || abort_build; \
mv *.a $(STATICLIB_DIR) || abort_build; \
printf "\n - Generating package...\n"; \
cp $(BINARY_DIR)/$(TARGET) $(PACKAGE_DIR) || abort_build; \
printf " XZ $(OUT_DIRNAME)/package/$(TARGET)-`date +%Y%m%d`.xz"
xz $(PACKAGE_DIR)/$(TARGET) || abort_build; \
sleep 1; \
mv $(PACKAGE_DIR)/$(TARGET).xz $(PACKAGE_DIR)/$(TARGET)-`date +%Y%m%d`.xz || abort_build; \
printf "\n - Success"; \
sleep 1; \
printf "\n\n ----------------------------------- \n"
.PHONY: clean
clean:
$(eval STATICLIBS = $(wildcard $(SOURCE_DIR)/*.a))
$(eval OBJS = $(wildcard $(SOURCE_DIR)/*.o))
$(info Cleaning files...)
$(foreach obj, \
$(OBJS), \
$(call m_stat_nn,$(SOURCE_DIRNAME)/$(shell basename $(obj))) \
$(call erase,$(obj)) \
)
$(foreach lib, \
$(STATICLIBS), \
$(call m_stat_nn,$(SOURCE_DIRNAME)/$(shell basename $(lib))) \
$(call erase,$(lib)) \
)
# end

View File

@@ -22,17 +22,10 @@
# # # #
######################################### #########################################
# speficy c compiler (cc)
PMT_CC ?=
# speficy ar
PMT_AR ?=
# addionital compiler flags # addionital compiler flags
PMT_EXTRA_CFLAGS ?= EXTRA_COMPILER_FLAGS ?=
# debugging mode (binary). it's enabling address sanitizer and source level debug information with dwarf version 5 # debugging mode (binary)
PMT_ENABLE_DEBUG ?= ENABLE_DEBUGGING ?= false
######################################### # end of environment configuration
#########################################

View File

@@ -1,73 +0,0 @@
/* By YZBruh */
/**
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef __cplusplus
extern "C" {
#endif
#define INC_MAIN_LIBS
#include <pmt/pmt.h>
#include <pmt/stringkeys.h>
void debug(LogLevel status, const char* _Nullable fmt, ...)
{
if (fmt == NULL) exit(1);
va_list args;
va_start(args, fmt);
switch (status)
{
case LOG_LEVEL_ERR:
if (!pmt_silent)
{
fprintf(stderr, "%s: ", bin_name);
vfprintf(stderr, fmt, args);
}
exit(1);
break;
case LOG_LEVEL_WARN:
if (!pmt_silent)
{
fprintf(stderr, "%s: ", current->warn);
vfprintf(stderr, fmt, args);
}
break;
case LOG_LEVEL_FATAL:
if (!pmt_silent)
{
fprintf(stderr, "%s: ", current->fatal);
vfprintf(stderr, fmt, args);
}
abort();
break;
case LOG_LEVEL_DEBUG:
if (!pmt_silent)
vfprintf(stdout, fmt, args);
break;
}
va_end(args);
}
#ifdef __cplusplus
}
#endif
/* end of code */

View File

@@ -16,28 +16,43 @@
* limitations under the License. * limitations under the License.
*/ */
#ifdef __cplusplus #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
#define INC_MAIN_LIBS #define INC_MAIN_LIBS
#define INC_DOCS_REQS
#include <pmt/pmt.h> #include <pmt.h>
#include <pmt/stringkeys.h>
#include <pmt/docs.h>
extern char* bin_name; extern char* bin_name;
extern char* curr_lang; extern char* pmt_langdb_langs_docs[];
struct pmt_langdb_docs* curr_docs = NULL; struct pmt_langdb_docs* curr_docs = NULL;
extern struct pmt_langdb_docs en_docs;
extern struct pmt_langdb_docs tr_docs;
static void static void
prepare_langconf_docs(void) prepare_langconf_docs(void)
{ {
if (strcmp(curr_lang, "en") == 0) static char* langctrl_str;
curr_docs = &en_docs; langctrl_str = loadlang();
else if (strcmp(curr_lang, "tr") == 0)
curr_docs = &tr_docs; if (strcmp(langctrl_str, "en") == 0) curr_docs = &en_docs;
else if (strcmp(langctrl_str, "tr") == 0) curr_docs = &tr_docs;
}
void licenses(void)
{
printf("Copyright 2024 Partition Manager\n");
printf("Licensed under the Apache License, Version 2.0 (the \"License\");\n");
printf("you may not use this file except in compliance with the License.\n");
printf("You may obtain a copy of the License at\n\n");
printf(" http://www.apache.org/licenses/LICENSE-2.0\n\n");
printf("Unless required by applicable law or agreed to in writing, software\n");
printf("distributed under the License is distributed on an \"AS IS\" BASIS,\n");
printf("WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n");
printf("See the License for the specific language governing permissions and limitations under the License.\n");
} }
void help(void) void help(void)
@@ -54,16 +69,17 @@ void help(void)
printf(" -f, --force %s\n", curr_docs->docs_strs_l9); printf(" -f, --force %s\n", curr_docs->docs_strs_l9);
printf(" -S, --set-lang %s\n", curr_docs->docs_strs_l10); printf(" -S, --set-lang %s\n", curr_docs->docs_strs_l10);
printf(" -v, --version %s\n", curr_docs->docs_strs_l11); printf(" -v, --version %s\n", curr_docs->docs_strs_l11);
printf(" --help %s\n\n", curr_docs->docs_strs_l12); printf(" --help %s\n", curr_docs->docs_strs_l12);
printf("%s:\n", curr_docs->docs_strs_l13); printf(" -L, --license %s\n\n", curr_docs->docs_strs_l13);
printf("%s:\n", curr_docs->docs_strs_l14);
printf(" %s backup boot_a -c /dev/block/platform/bootdevice/by-name\n", bin_name); printf(" %s backup boot_a -c /dev/block/platform/bootdevice/by-name\n", bin_name);
printf(" %s flash boot_a /sdcard/twrp/boot.img -c /dev/block/platform/bootdevice/by-name\n", bin_name); printf(" %s flash /sdcard/twrp/boot.img boot_a -c /dev/block/platform/bootdevice/by-name\n", bin_name);
printf(" %s format system_a ext4 --logical\n", bin_name); printf(" %s format ext4 system_a --logical\n", bin_name);
printf(" %s -c /dev/block/platform/bootdevice/by-name --list\n\n", bin_name); printf(" %s -c /dev/block/platform/bootdevice/by-name --list\n\n", bin_name);
printf("%s <t.me/ShawkTeam | Topics | pmt>\n", curr_docs->docs_strs_l14); printf("%s <t.me/YZBruh>\n", curr_docs->docs_strs_l15);
} }
#ifdef __cplusplus #if defined(__cplusplus)
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

42
jni/error.c Executable file
View File

@@ -0,0 +1,42 @@
/* By YZBruh */
/**
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
#define INC_MAIN_LIBS
#include <pmt.h>
__noreturn void error(int __status, const char* _Nullable __fmt, ...)
{
if (__fmt == NULL) exit(__status);
va_list err_args;
va_start(err_args, __fmt);
fprintf(stderr, "%s: ", bin_name);
vfprintf(stderr, __fmt, err_args);
fprintf(stderr, "\n");
va_end(err_args);
exit(__status);
}
#if defined(__cplusplus)
}
#endif /* __cplusplus */

View File

@@ -1,79 +0,0 @@
/* By YZBruh */
/**
* Copyright 2024 Partition Manager
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef __cplusplus
extern "C" {
#endif
#define INC_MAIN_LIBS
#define INC_STAT
#include <pmt/pmt.h>
#include <pmt/stringkeys.h>
/**
* The target file is controlled by the stat function.
* Files, directories, links and blocks (disks) are for.
* If it is never found, it returns 1 value.
* If he finds 0 value is returned.
* If the desired type is not in -1 value is returned.
*/
int get_stat(const char* _Nonnull filepath, const char* _Nonnull stype)
{
static struct stat get_stat;
if (stat(filepath, &get_stat) != 0)
return 1;
if (strcmp(stype, "dir") == 0)
{
if (S_ISDIR(get_stat.st_mode))
return 0;
else
return -1;
}
else if (strcmp(stype, "file") == 0)
{
if (S_ISREG(get_stat.st_mode))
return 0;
else
return -1;
}
else if (strcmp(stype, "blk") == 0)
{
if (S_ISBLK(get_stat.st_mode))
return 0;
else
return -1;
}
else if (strcmp(stype, "link") == 0)
{
if (S_ISLNK(get_stat.st_mode))
return 0;
else
return -1;
}
return 2;
}
#ifdef __cplusplus
}
#endif
/* end of code */

View File

@@ -16,15 +16,11 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef __PMT_DOCS_H
#define __PMT_DOCS_H
__BEGIN_DECLS __BEGIN_DECLS
void help(void); void help(void);
void licenses(void);
__END_DECLS __END_DECLS
#endif
/* end */ /* end */

View File

@@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef __PMT_STRINGKEYS_ #if !defined(__PMT_STRINGKEYS_)
#define __PMT_STRINGKEYS_ #define __PMT_STRINGKEYS_
__BEGIN_DECLS __BEGIN_DECLS
@@ -33,7 +33,6 @@ struct pmt_langdb_general {
const char* _Nonnull not_open; const char* _Nonnull not_open;
const char* _Nonnull not_block; const char* _Nonnull not_block;
const char* _Nonnull not_read; const char* _Nonnull not_read;
const char* _Nonnull not_readdir;
const char* _Nonnull not_write; const char* _Nonnull not_write;
const char* _Nonnull not_gen; const char* _Nonnull not_gen;
const char* _Nonnull no_root; const char* _Nonnull no_root;
@@ -51,12 +50,6 @@ struct pmt_langdb_general {
const char* _Nonnull ffile_more_part; const char* _Nonnull ffile_more_part;
const char* _Nonnull cannot_get_bsz; const char* _Nonnull cannot_get_bsz;
const char* _Nonnull format_fail; const char* _Nonnull format_fail;
const char* _Nonnull depr_backup_opt;
const char* _Nonnull depr_flash_opt;
const char* _Nonnull depr_format_opt;
const char* _Nonnull depr_Vlicense_opt;
const char* _Nonnull depr_ch_list_opt;
const char* _Nonnull not_spec_opt;
const char* _Nonnull logical_warn; const char* _Nonnull logical_warn;
const char* _Nonnull ab_warn; const char* _Nonnull ab_warn;
const char* _Nonnull out_not_spec; const char* _Nonnull out_not_spec;
@@ -65,21 +58,16 @@ struct pmt_langdb_general {
const char* _Nonnull flash_file_sz; const char* _Nonnull flash_file_sz;
const char* _Nonnull part_disk_sz_fail; const char* _Nonnull part_disk_sz_fail;
const char* _Nonnull flash_file_sz_fail; const char* _Nonnull flash_file_sz_fail;
const char* _Nonnull unknown_opr;
const char* _Nonnull list_of_dir; const char* _Nonnull list_of_dir;
const char* _Nonnull see_license;
const char* _Nonnull success_backup; const char* _Nonnull success_backup;
const char* _Nonnull success_flash; const char* _Nonnull success_flash;
const char* _Nonnull warn;
const char* _Nonnull fatal;
const char* _Nonnull switching_lang; const char* _Nonnull switching_lang;
const char* _Nonnull welcome; const char* _Nonnull welcome;
const char* _Nullable welcome_; const char* _Nullable welcome_;
const char* _Nonnull for_more; const char* _Nonnull for_more;
const char* _Nonnull try_h; const char* _Nonnull try_h;
const char* _Nonnull usage_head; const char* _Nonnull usage_head;
const char* _Nonnull depr_opt_str;
const char* _Nonnull switched_opt_str;
const char* _Nonnull not_changed_opt;
const char* _Nonnull compiler_str; const char* _Nonnull compiler_str;
const char* _Nonnull version_str; const char* _Nonnull version_str;
const char* _Nonnull bin_str; const char* _Nonnull bin_str;
@@ -87,7 +75,7 @@ struct pmt_langdb_general {
const char* _Nonnull by_str; const char* _Nonnull by_str;
}; };
/* docs etc. */ /* docs, licenses etc. */
struct pmt_langdb_docs { struct pmt_langdb_docs {
const char* _Nonnull docs_strs_l1; const char* _Nonnull docs_strs_l1;
const char* _Nonnull docs_strs_l2; const char* _Nonnull docs_strs_l2;
@@ -103,15 +91,11 @@ struct pmt_langdb_docs {
const char* _Nonnull docs_strs_l12; const char* _Nonnull docs_strs_l12;
const char* _Nonnull docs_strs_l13; const char* _Nonnull docs_strs_l13;
const char* _Nonnull docs_strs_l14; const char* _Nonnull docs_strs_l14;
const char* _Nonnull docs_strs_l15;
const char* _Nonnull or_str; const char* _Nonnull or_str;
const char* _Nonnull usage_docstr; const char* _Nonnull usage_docstr;
}; };
/* for checks etc */
struct pmt_langdb_langs {
const char* _Nullable lang_pr;
};
__END_DECLS __END_DECLS
#endif /* __PMT_STRINGKEYS_ */ #endif /* __PMT_STRINGKEYS_ */

View File

@@ -16,23 +16,27 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef __PMT_VERSIONING_H
#define __PMT_VERSIONING_H
__BEGIN_DECLS __BEGIN_DECLS
#ifdef __NDK_BUILD
#include <android/ndk-version.h> #include <android/ndk-version.h>
#include <pmt/generated/clang-version.h>
#if __NDK_MINOR__ == 1
#define __NDK_MINOR_STATUS__ "b"
#else
#define __NDK_MINOR_STATUS__ ""
#endif
#if __NDK_BETA__ == 1 || __NDK_BETA__ == 2
#define __NDK_BETA_STATUS__ "beta"
#else
#define __NDK_BETA_STATUS__ ""
#endif #endif
/* versioning */ /* versioning */
#define PMT_MAJOR 2 #define PMT_MAJOR 2
#define PMT_MINOR 5 #define PMT_MINOR 3
#define PMT_PATCHLEVEL 0 #define PMT_PATCHLEVEL 0
__END_DECLS __END_DECLS
#endif
/* end */ /* end */

View File

@@ -20,38 +20,55 @@
__BEGIN_DECLS __BEGIN_DECLS
#ifndef __PMT_H_ #if !defined(__PMT_H_)
#define __PMT_H_ #define __PMT_H_
#define PMT_PACKAGE_NAME "Partition Manager" #define PMT_PACKAGE_NAME "Partition Manager"
#ifdef INC_MAIN_LIBS #if defined(INC_MAIN_LIBS)
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <pmt-stringkeys.h>
#endif #endif
#ifdef INC_GETOPT #if defined(INC_GETOPT)
#include <getopt.h> #include <getopt.h>
#endif #endif
#ifdef INC_DIRENT #if defined(INC_DIRENT)
#include <dirent.h> #include <dirent.h>
#endif #endif
#ifdef INC_STAT #if defined(INC_STAT)
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
#ifdef INC_DEBUGERS #if defined(INC_DEBUGERS)
#include <errno.h> #include <errno.h>
/* from <err.h>. Modified. */
__noreturn void error(int __status, const char* _Nullable __fmt, ...);
void warning(const char* _Nullable __fmt, ...) __printflike(1, 2);
#endif #endif
#ifdef INC_TOOLS_REQS #if defined(INC_PMT_LANGS)
#include <pmt-langs.h>
#endif
#if defined(INC_DOCS_REQS)
#include <pmt-docs.h>
#endif
#if defined(INC_VERSIONER_REQS)
#include <pmt-versioning.h>
#endif
#if defined(INC_TOOLS_REQS)
#include <fcntl.h> #include <fcntl.h>
#include <sys/statvfs.h> #include <sys/statvfs.h>
#endif #endif
@@ -83,31 +100,15 @@ extern struct pmt_langdb_general tr;
extern struct pmt_langdb_docs en_docs; extern struct pmt_langdb_docs en_docs;
extern struct pmt_langdb_docs tr_docs; extern struct pmt_langdb_docs tr_docs;
/* logging levels */
typedef enum {
LOG_LEVEL_FATAL,
LOG_LEVEL_ERR,
LOG_LEVEL_WARN,
LOG_LEVEL_DEBUG
} LogLevel;
/* function definations */ /* function definations */
int listpart(void); int listpart(void);
void check_dev_point(void); void check_dev_point(void);
void check_root(void); void check_root(void);
int pmt(unsigned short progress_code); int pmt(unsigned short progress_code);
void version(void); void version(void);
void setlang(const char* _Nonnull lang, int null_conf_stat); void setlang(const char* _Nonnull lang);
int search_sls(void); int search_sls(void);
int loadlang(void); char* _Nonnull loadlang(void);
int get_stat(const char* _Nonnull filepath, const char* _Nonnull stype);
void debug(LogLevel status, const char* _Nullable fmt, ...);
/* logging macros */
#define LOGF(fmt, ...) debug(LOG_LEVEL_FATAL, fmt, ##__VA_ARGS__)
#define LOGE(fmt, ...) debug(LOG_LEVEL_ERR, fmt, ##__VA_ARGS__)
#define LOGW(fmt, ...) debug(LOG_LEVEL_WARN, fmt, ##__VA_ARGS__)
#define LOGD(fmt, ...) debug(LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
#endif #endif

View File

@@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifdef __cplusplus #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
@@ -24,61 +24,104 @@ extern "C" {
#define INC_DEBUGERS #define INC_DEBUGERS
#define INC_STAT #define INC_STAT
#include <pmt/pmt.h> #include <pmt.h>
#include <pmt/stringkeys.h>
/* pmt's man doc file path on termux */ /* pmt's man doc file path on termux */
#define TERMUX_PMT_MANDOC "/data/data/com.termux/files/usr/share/man/man8/pmt.8.gz" #define TERMUX_PMT_MANDOC "/data/data/com.termux/files/usr/share/man/man8/pmt.8.gz"
#define PMTLANG_CONF "/sdcard/.pmtlang.conf" /* language configuration paths */
#define PMT_SW_POINT "/sdcard/.pmtlangsw" /* for termux */
#define TERMUX_PMTLANG_CONF "/data/data/com.termux/files/usr/etc/pmtlang.conf"
extern struct pmt_langdb_langs lang[]; /* for internal storage */
struct pmt_langdb_general* current = NULL; #define INTRNL_PMTLANG_CONF "/sdcard/.pmtlang.conf"
char* curr_lang; /* shortcuts to check that language is changed */
static FILE *langconf;
static const char* /* for termux */
#define TERMUX_PMT_SW_POINT "/data/data/com.termux/files/usr/etc/pmtlangsw"
/* for internal storage */
#define INTRNL_PMT_SW_POINT "/sdcard/.pmtlangsw"
extern bool pmt_inst_on_termux;
extern char* bin_name;
extern char* pmt_langdb_langs[];
extern int pmt_langdb_total;
extern int pmt_langdb_ctrl;
FILE *langconf;
/**
* The target file is controlled by the stat function.
* Files, directories, links and blocks (disks) are for.
* If it is never found, it returns 1 value.
* If he finds 0 value is returned.
* If the desired type is not in -1 value is returned.
*/
static int
search_stat(const char* _Nonnull filepath, const char* _Nonnull stype)
{
struct stat search_stat;
if (stat(filepath, &search_stat) != 0) return 1;
if (strcmp(stype, "dir") == 0)
{
if (S_ISDIR(search_stat.st_mode)) return 0;
else return -1;
}
else if (strcmp(stype, "file") == 0)
{
if (S_ISREG(search_stat.st_mode)) return 0;
else return -1;
}
else if (strcmp(stype, "blk") == 0)
{
if (S_ISBLK(search_stat.st_mode)) return 0;
else return -1;
}
else if (strcmp(stype, "link") == 0)
{
if (S_ISLNK(search_stat.st_mode)) return 0;
else return -1;
}
return 2;
}
static int
langctrl(const char* _Nonnull lang_) langctrl(const char* _Nonnull lang_)
{ {
for (int langct = 0; lang[langct].lang_pr != NULL; langct++) if (strcmp(lang_, "en") == 0 || strcmp(lang_, "tr") == 0) return 0;
{
if (strcmp(lang_, lang[langct].lang_pr) == 0) return 1;
return lang_;
} }
return NULL; char* loadlang(void)
}
int loadlang(void)
{ {
static char lang_fpr[10] = "en"; static char lang_fpr[10] = "en";
langconf = NULL; langconf = NULL;
if (get_stat(TERMUX_PMT_MANDOC, "file") == 0) if (search_stat(TERMUX_PMT_MANDOC, "file") == 0) pmt_inst_on_termux = true;
pmt_inst_on_termux = true;
if (pmt_inst_on_termux)
langconf = fopen(PMTLANG_CONF, "r+"); {
if (search_stat(TERMUX_PMTLANG_CONF, "file") == 0)
{
langconf = fopen(TERMUX_PMTLANG_CONF, "r+");
if (langconf == NULL) if (langconf == NULL)
{ {
langconf = fopen(PMTLANG_CONF, "w+"); langconf = fopen(TERMUX_PMTLANG_CONF, "w+");
if (langconf == NULL || langconf != NULL) if (langconf == NULL)
{ {
setlang("en", 1); setlang("en");
current = &en; return "en";
curr_lang = "en";
if (langconf != NULL)
fclose(langconf);
return 0;
} }
fclose(langconf);
} }
else else
{ {
@@ -87,78 +130,111 @@ int loadlang(void)
if (strcmp(lang_fpr, "en") == 0) if (strcmp(lang_fpr, "en") == 0)
{ {
fclose(langconf); fclose(langconf);
current = &en; return "en";
curr_lang = "en";
return 0;
} }
else if (strcmp(lang_fpr, "tr") == 0) else if (strcmp(lang_fpr, "tr") == 0)
{ {
fclose(langconf); fclose(langconf);
current = &tr; return "tr";
curr_lang = "tr"; }
return 0; }
fclose(langconf);
}
}
} }
else else
{ {
fclose(langconf); if (search_stat(INTRNL_PMTLANG_CONF, "file") == 0)
setlang("en", 0);
loadlang();
return 0;
}
}
if (fgets(lang_fpr, sizeof(lang_fpr), langconf) == NULL)
{ {
setlang("en", 1); langconf = fopen(INTRNL_PMTLANG_CONF, "r");
loadlang();
return 0;
}
}
return 1;
}
void setlang(const char* _Nonnull lang, int null_conf_stat)
{
if (langctrl(lang) == NULL)
LOGE("Unknown language: %s.\n", lang);
if (get_stat(PMTLANG_CONF, "file") == 0)
remove(PMTLANG_CONF);
langconf = NULL;
langconf = fopen(PMTLANG_CONF, "w");
if (langconf == NULL) if (langconf == NULL)
LOGE("Failed!!! Cannot open/write config file.\n"); {
langconf = fopen(INTRNL_PMTLANG_CONF, "w+");
if (fprintf(langconf, "%s", lang) < 2) if (langconf == NULL)
LOGE("Failed!!! Couldn't write config!\n"); {
else setlang("en");
return "en";
}
fclose(langconf); fclose(langconf);
}
else
{
while (fgets(lang_fpr, sizeof(lang_fpr), langconf) != NULL)
{
if (strcmp(lang_fpr, "en") == 0)
{
fclose(langconf);
return "en";
}
else if (strcmp(lang_fpr, "tr") == 0)
{
fclose(langconf);
return "tr";
}
}
fclose(langconf);
}
}
else return "en";
}
return "en";
}
void setlang(const char* _Nonnull lang)
{
static char* lcf_path;
if (pmt_inst_on_termux) lcf_path = TERMUX_PMTLANG_CONF;
else lcf_path = INTRNL_PMTLANG_CONF;
if (search_stat(lcf_path, "file") == 0) remove(lcf_path);
langconf = NULL;
if (pmt_inst_on_termux) langconf = fopen(TERMUX_PMTLANG_CONF, "w");
else langconf = fopen(INTRNL_PMTLANG_CONF, "w");
if (langconf == NULL) error(1, "%s: Failed!!! Cannot open/write config file.\n", bin_name);
if (langctrl(lang) == 0)
{
if (fprintf(langconf, "%s", lang) < 2) error(1, "Failed!!! Couldn't write config!\n");
else fclose(langconf);
}
else error(1, "Unknown language: %s.", bin_name, lang);
static int status; static int status;
if (null_conf_stat != 1) if (pmt_inst_on_termux)
{ {
status = open(PMT_SW_POINT, O_WRONLY | O_CREAT | O_TRUNC, 0666); status = open(TERMUX_PMT_SW_POINT, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (status == 0) if (status == 0) close(status);
close(status); }
else
{
status = open(INTRNL_PMT_SW_POINT, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (status == 0) close(status);
} }
} }
int search_sls(void) int search_sls(void)
{ {
if (get_stat(PMT_SW_POINT, "file") == 0) static char* sw_point_path;
if (pmt_inst_on_termux) sw_point_path = TERMUX_PMT_SW_POINT;
else sw_point_path = INTRNL_PMT_SW_POINT;
if (search_stat(sw_point_path, "file") == 0)
{ {
remove(PMT_SW_POINT); remove(sw_point_path);
return 0; return 0;
} }
else else return 1;
return 1;
} }
#ifdef __cplusplus #if defined(__cplusplus)
} }
#endif #endif

View File

@@ -16,73 +16,60 @@
* limitations under the License. * limitations under the License.
*/ */
#ifdef __cplusplus #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
#define INC_MAIN_LIBS #define INC_MAIN_LIBS
#include <pmt/pmt.h> #include <pmt.h>
#include <pmt/stringkeys.h>
struct pmt_langdb_general en = { struct pmt_langdb_general en = {
.lang_by_s = "YZBruh & r0manas", .lang_by_s = "YZBruh",
.language = "English", .language = "English",
.lang_prefix = "en", .lang_prefix = "en",
.not_logical = "This device does not have logical partitions!", .not_logical = "This device does not have logical partitions!",
.not_file = "is not a file.", .not_file = "is a not file.",
.not_dir = "is not a directory.", .not_dir = "is a not directory.",
.not_in_dev = "Nothing found in /dev. Use force mode to avoid this error.", .not_in_dev = "You're going through my wave? There's nothing about this /dev. Use force mode if you don't want this error.",
.not_open = "Couldn't open", .not_open = "Could not open",
.not_block = "The specified partition is not recognized as a block device.", .not_block = "The specified partition is not the block. I mean, it's not actually an episode (disc). I'm sure it needs to applaud those mistakes.",
.not_read = "Couldn't read", .not_read = "Couldn't read",
.not_readdir = "Couldn't read directory",
.not_write = "Couldn't write", .not_write = "Couldn't write",
.not_gen = "Couldn't generate", .not_gen = "Couldn't generate",
.no_root = "Root access could not be detected! Please run this with root permissions.", .no_root = "Root access could not be detected! Please run this binary with root.",
.no_target = "No target specified (backup, flash, or format)", .no_target = "No target (backup, flash or format).",
.expected_backup_arg = "Expected backup argument 2 (1 of them are not mandatory), retrieved", .expected_backup_arg = "Expected backup argument 2 (1 of them are not mandatory), retrieved",
.expected_flash_arg = "Expected flash argument 2, retrieved", .expected_flash_arg = "Expected flash argument 2, retrieved",
.expected_format_arg = "Expected format argument 2, retrieved", .expected_format_arg = "Expected format argument 2, retrieved",
.missing_operand = "Missing operand", .missing_operand = "missing operand",
.multiple_wiewers = "Multiple viewers can't be used on the same line.", .multiple_wiewers = "Multiple viewers cannot be used at the same line.",
.common_symbol_rule = "When specifying arguments for an option, ensure they do not begin with '-'. Each argument must correspond correctly to its respective option.", .common_symbol_rule = "When entering the attached argument of an option, an argument of another option type cannot be used. In short, the rule is: there can be no '-' at the beginning of the attached argument.",
.req_part_name = "Partition name required.", .req_part_name = "Required partition name.",
.part_not_found = "Partition not found!", .part_not_found = "Partition not found!",
.unsupported_fs = "Formatter: unsupported filesystem", .unsupported_fs = "Formatter: unsupported filesystem",
.cannot_stat = "Can't retrieve file status", .cannot_stat = "Cannot stat",
.ffile_more_part = "Flash file size exceeds partition capacity.", .ffile_more_part = "Size of the file to flash more than the partition size.",
.cannot_get_bsz = "Failed to retrieve partition block size.", .cannot_get_bsz = "The partition block size could not be obtained!",
.format_fail = "Formatting failed! There is a possibility of data damage.", .format_fail = "Formatting failed! There may be a chance that something has been damaged!",
.depr_backup_opt = "These options for the backup are unavailable.", .logical_warn = "Warning: device using logical partition type.",
.depr_flash_opt = "These options for the flash are unavailable.", .ab_warn = "Warning: device using A/B partition style.",
.depr_format_opt = "These options for the format are unavailable.", .out_not_spec = "Warning: The output file name was not specified. The output file name will be",
.depr_Vlicense_opt = "No memory for unnecessary options!", .please_rerun = "Please re run",
.depr_ch_list_opt = "Use -p argument for listing partitions.", .part_disk_sz = "Disk size of the partition",
.not_spec_opt = "Specify the necessary arguments, not option", .flash_file_sz = "Size of flash file",
.logical_warn = "This device uses logical partitions.", .part_disk_sz_fail = "Warning: failed to get target partition disk size",
.ab_warn = "This device uses A/B partition style.", .flash_file_sz_fail = "Warning: failed to get flash file size.",
.out_not_spec = "Output file name not specified. Using default name", .list_of_dir = "List of dir",
.please_rerun = "Please rerun the command.", .see_license = "See licenses with -L argument.",
.part_disk_sz = "Partition disk size", .success_backup = "Success. Output",
.flash_file_sz = "Flash file size", .success_flash = "Success.",
.part_disk_sz_fail = "Failed to retrieve partition disk size.",
.flash_file_sz_fail = "Failed to retrieve flash file size.",
.unknown_opr = "Unknown operand",
.list_of_dir = "Directory listing",
.success_backup = "Backup successful. Output",
.success_flash = "Flash successful",
.warn = "WARNING",
.fatal = "FATAL ERROR",
.switching_lang = "Switching language...", .switching_lang = "Switching language...",
.welcome = "language!", .welcome = "language!",
.welcome_ = "Welcome to ", .welcome_ = "Welcome to ",
.for_more = "for more information", .for_more = "for more information.",
.try_h = "Try", .try_h = "Try",
.usage_head = "Usage", .usage_head = "Usage",
.depr_opt_str = "DEPRECATED OPTION",
.switched_opt_str = "SWITCHED OPTION",
.not_changed_opt = "not changed",
.compiler_str = "Compiler", .compiler_str = "Compiler",
.version_str = "version", .version_str = "version",
.bin_str = "binary", .bin_str = "binary",
@@ -101,7 +88,6 @@ struct pmt_langdb_general tr = {
.not_open = "ılamıyor", .not_open = "ılamıyor",
.not_block = "Belirtilen bölüm bir blok değil. Yani aslında bu bir bölüm bile değil (disk). Bu hatayı almak için şanslı olmak gerek..!", .not_block = "Belirtilen bölüm bir blok değil. Yani aslında bu bir bölüm bile değil (disk). Bu hatayı almak için şanslı olmak gerek..!",
.not_read = "Veri okunamıyor", .not_read = "Veri okunamıyor",
.not_readdir = "Dizin verisi okunamıyor",
.not_write = "Veri yazılamıyor", .not_write = "Veri yazılamıyor",
.not_gen = "Oluşturulamıyor", .not_gen = "Oluşturulamıyor",
.no_root = "Root erişimi tespit edilemedi! Lütfen root erişimi ile çalıştırın.", .no_root = "Root erişimi tespit edilemedi! Lütfen root erişimi ile çalıştırın.",
@@ -109,7 +95,7 @@ struct pmt_langdb_general tr = {
.expected_backup_arg = "Beklenen yedekleme argümanı 2 (bir tanesi zorunlu değil), alınan", .expected_backup_arg = "Beklenen yedekleme argümanı 2 (bir tanesi zorunlu değil), alınan",
.expected_flash_arg = "Beklenen flaş argümanı 2, alınan", .expected_flash_arg = "Beklenen flaş argümanı 2, alınan",
.expected_format_arg = "Beklenen format argümanı 2, alınan", .expected_format_arg = "Beklenen format argümanı 2, alınan",
.missing_operand = "İşlem belirtilmedi", .missing_operand = "işlem belirtilmedi",
.multiple_wiewers = "Birden fazla görüntüleme işlemi yapan fonksiyonlar bir arada kullanılamaz. Aynı anda sadece bir tanesi kullanılabilir.", .multiple_wiewers = "Birden fazla görüntüleme işlemi yapan fonksiyonlar bir arada kullanılamaz. Aynı anda sadece bir tanesi kullanılabilir.",
.common_symbol_rule = "Bir seçeneğin argümanını verirken argüman önüne '-' sembolü getirilemez. Sembolü kaldırın ve tekrar deneyin.", .common_symbol_rule = "Bir seçeneğin argümanını verirken argüman önüne '-' sembolü getirilemez. Sembolü kaldırın ve tekrar deneyin.",
.req_part_name = "Bölüm adı gereklidir.", .req_part_name = "Bölüm adı gereklidir.",
@@ -119,13 +105,7 @@ struct pmt_langdb_general tr = {
.ffile_more_part = "Flaşlanacak dosyanın boyutu mevcut bölüm boyutundan fazla.", .ffile_more_part = "Flaşlanacak dosyanın boyutu mevcut bölüm boyutundan fazla.",
.cannot_get_bsz = "Bölüm blok boyutu tespit edilemedi!", .cannot_get_bsz = "Bölüm blok boyutu tespit edilemedi!",
.format_fail = "Formatlama başarısız oldu. Bazı şeyler zarar görmüş olabilir!", .format_fail = "Formatlama başarısız oldu. Bazı şeyler zarar görmüş olabilir!",
.depr_backup_opt = "Yedek için artık bu seçeneği kullanamazsınız.",
.depr_flash_opt = "Flaşlama için artık bu seçeneği kullanamazsınız.",
.depr_format_opt = "Formatlama için artıi bu seçeneği kullanamazsınız.",
.depr_Vlicense_opt = "Gereksiz seçeneklere bellek yok!",
.depr_ch_list_opt = "Listeleme için -p seçeneğini kullanabilirsiniz.",
.logical_warn = "Uyarı: bu cihaz mantıksal (logical) bölümlere sahip.", .logical_warn = "Uyarı: bu cihaz mantıksal (logical) bölümlere sahip.",
.not_spec_opt = "Seçenek değil, gerekli argümanları belirtin",
.ab_warn = "Uyarı: bu cihazın bazı bölümleri A/B kullanıyor.", .ab_warn = "Uyarı: bu cihazın bazı bölümleri A/B kullanıyor.",
.out_not_spec = "Uyarı: çıktı dosya belirtilmedi. Çıktı dosya adı bölüm adına göre belirlenecek.", .out_not_spec = "Uyarı: çıktı dosya belirtilmedi. Çıktı dosya adı bölüm adına göre belirlenecek.",
.please_rerun = "Lütfen yeniden çalıştırın", .please_rerun = "Lütfen yeniden çalıştırın",
@@ -133,21 +113,16 @@ struct pmt_langdb_general tr = {
.flash_file_sz = "Flaşlanacak dosyanın boyutu", .flash_file_sz = "Flaşlanacak dosyanın boyutu",
.flash_file_sz_fail = "Uyarı: flaşlanacak dosyanın boyutu tespit edilemedi.", .flash_file_sz_fail = "Uyarı: flaşlanacak dosyanın boyutu tespit edilemedi.",
.part_disk_sz_fail = "Uyarı: bölüm boyutunun boyutu tespit edilemedi.", .part_disk_sz_fail = "Uyarı: bölüm boyutunun boyutu tespit edilemedi.",
.unknown_opr = "Bilinmeyen işlem",
.list_of_dir = "Dizin içeriğinin listesi", .list_of_dir = "Dizin içeriğinin listesi",
.see_license = "Lisansı -L seçeneği ile görüntüleyebilirsiniz.",
.success_backup = "Başarılı. Çıktı", .success_backup = "Başarılı. Çıktı",
.success_flash = "Başarılı.", .success_flash = "Başarılı.",
.warn = "UYARI",
.fatal = "KRİTİK HATA",
.switching_lang = "Dil değiştiriliyor...", .switching_lang = "Dil değiştiriliyor...",
.welcome = "diline hoş geldiniz!", .welcome = "diline hoş geldiniz!",
.welcome_ = NULL, .welcome_ = NULL,
.for_more = "komutunu kullanabilirsiniz", .for_more = "komutunu kullanabilirsiniz",
.try_h = "Daha fazla bilgi", .try_h = "Daha fazla bilgi",
.usage_head = "Kullanımı", .usage_head = "Kullanımı",
.depr_opt_str = "KALDIRILMIŞ SEÇENEK",
.switched_opt_str = "DEĞİŞTİRİLMİŞ SEÇENEK",
.not_changed_opt = "değiştirilmedi",
.compiler_str = "Derleyici", .compiler_str = "Derleyici",
.version_str = "versiyon", .version_str = "versiyon",
.bin_str = "yapı", .bin_str = "yapı",
@@ -156,9 +131,9 @@ struct pmt_langdb_general tr = {
}; };
struct pmt_langdb_docs en_docs = { struct pmt_langdb_docs en_docs = {
.docs_strs_l1 = "backup PARTITION [OUTPUT] [OPTIONS]...", .docs_strs_l1 = "[OPTIONS] backup PARTITION [OUTPUT] [OPTIONS]...",
.docs_strs_l2 = "flash PARTITION FILE [OPTIONS]...", .docs_strs_l2 = "[OPTIONS] flash FILE PARTITION [OPTIONS]...",
.docs_strs_l3 = "format PARTITION FILE_SYSTEM[ext/2/3/4] [OPTIONS]...", .docs_strs_l3 = "[OPTIONS] format FILE_SYSTEM[ext/2/3/4] PARTITION [OPTIONS]...",
.docs_strs_l4 = "Options", .docs_strs_l4 = "Options",
.docs_strs_l5 = "It is meant to determine whether the target partition is logical.", .docs_strs_l5 = "It is meant to determine whether the target partition is logical.",
.docs_strs_l6 = "It is meant to specify a custom /dev context. Only classic partitions (default: /dev/block/by-name).", .docs_strs_l6 = "It is meant to specify a custom /dev context. Only classic partitions (default: /dev/block/by-name).",
@@ -168,38 +143,42 @@ struct pmt_langdb_docs en_docs = {
.docs_strs_l10 = "Set current language.", .docs_strs_l10 = "Set current language.",
.docs_strs_l11 = "See version.", .docs_strs_l11 = "See version.",
.docs_strs_l12 = "See this help message.", .docs_strs_l12 = "See this help message.",
.docs_strs_l13 = "Examples", .docs_strs_l13 = "See license.",
.docs_strs_l14 = "Report bugs to", .docs_strs_l14 = "Examples",
.docs_strs_l15 = "Report bugs to",
.or_str = "or", .or_str = "or",
.usage_docstr = "Usage" .usage_docstr = "Usage"
}; };
struct pmt_langdb_docs tr_docs = { struct pmt_langdb_docs tr_docs = {
.docs_strs_l1 = "backup BÖLÜM [ÇIKTI] [SEÇENEKLER]...", .docs_strs_l1 = "[SEÇENEKLER] backup BÖLÜM [ÇIKTI] [SEÇENEKLER]...",
.docs_strs_l2 = "flash BÖLÜM DOSYA [SEÇENEKLER]...", .docs_strs_l2 = "[SEÇENEKLER] flash DOSYA BÖLÜM [SEÇENEKLER]...",
.docs_strs_l3 = "format BÖLÜM DOSYA_SİSTEMİ[ext/2/3/4] [SEÇENEKLER]...", .docs_strs_l3 = "[SEÇENEKLER] format DOSYA_SİSTEMİ[ext/2/3/4] BÖLÜM [SEÇENEKLER]...",
.docs_strs_l4 = "Seçenekler", .docs_strs_l4 = "Seçenekler",
.docs_strs_l5 = "Mantıksal (logical) bölüm ile işlem yapın.", .docs_strs_l5 = "Bu seçeneği kullanarak mantıksal (logical) bir bölümle işlem yapılacağını belirtebilirsiniz.",
.docs_strs_l6 = "Özel /dev bağlamı belirtin. Sadece normal bölümler içindir (Varsayılan: /dev/block/by-name).", .docs_strs_l6 = "Bu seçeneği kullanarak özel /dev bağlamı belirtebilirsiniz. Sadece normal (mantıksal olmayan) bölümler içindir (Varsayılan: /dev/block/by-name).",
.docs_strs_l7 = "Bölümler listelenir.", .docs_strs_l7 = "Bölümler listelenir.",
.docs_strs_l8 = "Bilgi ve uyarı mesajları susturulur.", .docs_strs_l8 = "Bilgi ve uyarı mesajları susturulur.",
.docs_strs_l9 = "Zorlama modu. Bazı şeyler göz ardı edilir.", .docs_strs_l9 = "Zorlama modu. Bazı şeyler göz ardı edilir.",
.docs_strs_l10 = "Mevcut dili ayarlayın.", .docs_strs_l10 = "Mevcut dili ayarlayın.",
.docs_strs_l11 = "Sürümü görüntüleyin.", .docs_strs_l11 = "Sürümü görüntüleyin.",
.docs_strs_l12 = "Bu yardım mesajını görüntüleyin.", .docs_strs_l12 = "Bu yardım mesajını görüntüleyin.",
.docs_strs_l13 = "Örnekler", .docs_strs_l13 = "Lisansı gorüntüleyin.",
.docs_strs_l14 = "Sorunları şu adrese bildirin:", .docs_strs_l14 = "Örnekler",
.docs_strs_l15 = "Sorunları şu adrese bildirin:",
.or_str = "yada", .or_str = "yada",
.usage_docstr = "Kullanımı" .usage_docstr = "Kullanımı"
}; };
struct pmt_langdb_langs lang[] = { char* pmt_langdb_langs[] = {
{"en"}, "en",
{"tr"}, "tr"
{NULL}
}; };
#ifdef __cplusplus int pmt_langdb_total = 2;
int pmt_langdb_ctrl = 1;
#if defined(__cplusplus)
} }
#endif #endif

View File

@@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifdef __cplusplus #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
@@ -24,8 +24,7 @@ extern "C" {
#define INC_DEBUGERS #define INC_DEBUGERS
#define INC_DIRENT #define INC_DIRENT
#include <pmt/pmt.h> #include <pmt.h>
#include <pmt/stringkeys.h>
/* current /dev context */ /* current /dev context */
#define CUR_DEV_CNTX "/dev/block/by-name" #define CUR_DEV_CNTX "/dev/block/by-name"
@@ -33,102 +32,91 @@ extern "C" {
/* for logical partitions */ /* for logical partitions */
#define LGC_DEV_CNTX "/dev/block/mapper" #define LGC_DEV_CNTX "/dev/block/mapper"
static DIR *dir; extern bool pmt_use_cust_cxt;
extern bool pmt_ab;
extern bool pmt_logical;
extern bool pmt_silent;
extern bool pmt_force_mode;
extern char* cust_cxt;
extern char* bin_name;
extern struct pmt_langdb_general* current;
extern struct pmt_langdb_general en;
extern struct pmt_langdb_general tr;
DIR *dir;
static int static int
list(const char* operation, const char* target_dir) list(const char* operation, const char* target_dir)
{ {
static bool list = false; static bool list = false;
static int count; struct dirent *entry;
struct dirent **nlist;
dir = NULL; dir = NULL;
if (strcmp(operation, "access") == 0) if (strcmp(operation, "access") == 0) list = false;
list = false; else if (strcmp(operation, "print") == 0) list = true;
else if (strcmp(operation, "print") == 0) else return -1;
list = true;
else
return -1;
dir = opendir(target_dir); dir = opendir(target_dir);
if (dir != NULL) if (dir != NULL)
{
if (!list)
{ {
closedir(dir); closedir(dir);
return 0; return 0;
} }
else else
return -1;
if (list)
{ {
count = scandir(target_dir, &nlist, NULL, alphasort); printf("%s: `%s'\n", current->list_of_dir, target_dir);
while ((entry = readdir(dir)) != NULL) printf("%s\n", entry->d_name);
if (count < 0) closedir(dir);
LOGE("%s: `%s': %s\n", current->not_readdir, target_dir, strerror(errno));
for (int cont_count = 0; cont_count < count; cont_count++)
{
if (nlist[cont_count]->d_name[0] != '.')
LOGD("%s\n", nlist[cont_count]->d_name);
free(nlist[cont_count]);
}
free(nlist);
return 0; return 0;
} }
}
else return -1;
return 2; return 2;
} }
/* list existing partitions */ /* list existing partitions */
int listpart(void) int listpart(void) {
{
if (pmt_use_cust_cxt) if (pmt_use_cust_cxt)
{ {
if (list("access", cust_cxt) != 0) if (list("access", cust_cxt) != 0)
{ {
if (!pmt_force_mode) if (!pmt_force_mode) error(1, "%s: `%s': %s", current->not_open, cust_cxt, strerror(errno));
LOGE("%s: `%s': %s\n", current->not_open, cust_cxt, strerror(errno)); else return 1;
else
return 1;
} }
else else list("print", cust_cxt);
list("print", cust_cxt);
} }
else else
{ {
if (list("access", CUR_DEV_CNTX) != 0) if (list("access", CUR_DEV_CNTX) != 0)
{ {
if (!pmt_force_mode) if (!pmt_force_mode) error(1, "%s: `%s': %s", current->not_open, CUR_DEV_CNTX, strerror(errno));
LOGE("%s: `%s': %s\n", current->not_open, CUR_DEV_CNTX, strerror(errno)); else return 1;
else
return 1;
} }
else else list("print", CUR_DEV_CNTX);
list("print", CUR_DEV_CNTX);
} }
if (pmt_logical) if (pmt_logical)
{ {
if (list("access", LGC_DEV_CNTX) != 0) if (list("access", LGC_DEV_CNTX) != 0)
LOGE("%s: `%s': %s\n", current->not_open, LGC_DEV_CNTX, strerror(errno)); {
else if (!pmt_silent) error(1, "%s: `%s': %s", current->not_open, LGC_DEV_CNTX, strerror(errno));
list("print", LGC_DEV_CNTX); else return 1;
}
else list("print", LGC_DEV_CNTX);
} }
if (pmt_ab) if (pmt_ab && !pmt_silent) printf("%s: %s\n", bin_name, current->ab_warn);
LOGD("%s: %s\n", bin_name, current->ab_warn);
if (pmt_logical) if (pmt_logical && !pmt_silent) printf("%s: %s\n", bin_name, current->logical_warn);
LOGD("%s: %s\n", bin_name, current->logical_warn);
return 0; return 0;
} }
#ifdef __cplusplus #if defined(__cplusplus)
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@@ -16,37 +16,37 @@
* limitations under the License. * limitations under the License.
*/ */
#ifdef __cplusplus #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
#define INC_MAIN_LIBS #define INC_MAIN_LIBS
#include <pmt/pmt.h> #include <pmt.h>
extern bool pmt_use_cust_cxt;
extern bool pmt_ab;
extern bool pmt_logical;
extern char* cust_cxt;
static int static int
accf(const char* _Nonnull target) { return access(target, F_OK); } search(const char* _Nonnull target) { return access(target, F_OK); }
/* check parts */ /* check parts */
void check_dev_point(void) void check_dev_point()
{ {
/* true = ab | false = a */ /* true = ab | false = a */
if (pmt_use_cust_cxt) if (pmt_use_cust_cxt)
{ {
static char cust_cxt_ck_path[150]; static char cust_cxt_ck_path[150];
sprintf(cust_cxt_ck_path, "%s/boot_a", cust_cxt); sprintf(cust_cxt_ck_path, "%s/boot_a", cust_cxt);
if (search(cust_cxt_ck_path) != 0) pmt_ab = false;
if (accf(cust_cxt_ck_path) != 0) else pmt_ab = true;
pmt_ab = false;
else
pmt_ab = true;
} }
else else
{ {
if (accf("/dev/block/by-name/boot_a") != 0) if (search("/dev/block/by-name/boot_a") != 0) pmt_ab = false;
pmt_ab = false; else pmt_ab = true;
else
pmt_ab = true;
} }
/* true = logical | false = classic */ /* true = logical | false = classic */
@@ -54,22 +54,17 @@ void check_dev_point(void)
{ {
static char cust_cxt_ckl_path[150]; static char cust_cxt_ckl_path[150];
sprintf(cust_cxt_ckl_path, "%s/super", cust_cxt); sprintf(cust_cxt_ckl_path, "%s/super", cust_cxt);
if (search(cust_cxt_ckl_path) != 0) pmt_logical = false;
if (accf(cust_cxt_ckl_path) != 0) else pmt_logical = true;
pmt_logical = false;
else
pmt_logical = true;
} }
else else
{ {
if (accf("/dev/block/by-name/super") != 0) if (search("/dev/block/by-name/super") != 0) pmt_logical = false;
pmt_logical = false; else pmt_logical = true;
else
pmt_logical = true;
} }
} }
#ifdef __cplusplus #if defined(__cplusplus)
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

395
jni/pmt.c
View File

@@ -17,7 +17,7 @@
*/ */
/* force use C std (if default is C++) */ /* force use C std (if default is C++) */
#ifdef __cplusplus #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
@@ -25,11 +25,9 @@ extern "C" {
#define INC_DEBUGERS #define INC_DEBUGERS
#define INC_STAT #define INC_STAT
#define INC_GETOPT #define INC_GETOPT
#define INC_DOCS_REQS
#include <pmt/pmt.h> #include <pmt.h>
#include <pmt/stringkeys.h>
#include <pmt/deprecates.h>
#include <pmt/docs.h>
/* add value to variables that are added globally and are not worth */ /* add value to variables that are added globally and are not worth */
char* out = NULL; char* out = NULL;
@@ -50,46 +48,67 @@ bool pmt_format = false;
bool pmt_force_mode = false; bool pmt_force_mode = false;
bool pmt_inst_on_termux = false; bool pmt_inst_on_termux = false;
/* import language structs etc. */
struct pmt_langdb_general* current = NULL;
extern struct pmt_langdb_general en;
extern struct pmt_langdb_general tr;
extern const char* pmt_langdb_langs[];
extern int pmt_langdb_total;
/* variable for use in control of '-' expression */ /* variable for use in control of '-' expression */
static const char* opt_symbol = "-"; static const char* opt_symbol = "-";
static char common_symbol_rule[350]; static char common_symbol_rule[350];
#if !defined(__clang__)
static char*
strdup(const char* s)
{
size_t len = strlen(s) + 1;
char* copy = malloc(len);
if (copy) {
memcpy(copy, s, len);
}
return copy;
}
#endif
/** /**
* He controls whether the '-' sign at * He controls whether the '-' sign at
* the beginning of the given word * the beginning of the given word
*/ */
static void static void
check_optsym(const char* _Nullable symbol) check_optsym(const char* _Nonnull mystring)
{ {
if (symbol != NULL) if (strncmp(mystring, opt_symbol, 1) == 0)
{ {
if (strncmp(symbol, opt_symbol, 1) == 0) if (!pmt_force_mode) error(1, "%s", common_symbol_rule);
LOGE("%s\n", common_symbol_rule); else exit(1);
} }
} }
static bool /**
ctrl_arg(const char* _Nullable argv_holder) * The target file is controlled by the stat function.
* Files, directories, links and blocks (disks) are for.
* If it is never found, it returns 1 value.
* If he finds 0 value is returned.
* If the desired type is not in -1 value is returned.
*/
static int
search_stat(const char* _Nonnull filepath, const char* _Nonnull stype)
{ {
if (strcmp(argv_holder, "--logical") != 0 && strcmp(argv_holder, "--context") != 0 && strcmp(argv_holder, "--silent") != 0 && strcmp(argv_holder, "-l") != 0 && strcmp(argv_holder, "-c") != 0 && strcmp(argv_holder, "-s") != 0) struct stat search_stat;
return true;
return false; if (stat(filepath, &search_stat) != 0) return 0;
if (strcmp(stype, "dir") == 0)
{
if (S_ISDIR(search_stat.st_mode)) return 0;
else return -1;
}
else if (strcmp(stype, "file") == 0)
{
if (S_ISREG(search_stat.st_mode)) return 0;
else return -1;
}
else if (strcmp(stype, "blk") == 0)
{
if (S_ISBLK(search_stat.st_mode)) return 0;
else return -1;
}
else if (strcmp(stype, "link") == 0)
{
if (S_ISLNK(search_stat.st_mode)) return 0;
else return -1;
}
return 0;
} }
/* classic main function (C binary here xd) */ /* classic main function (C binary here xd) */
@@ -98,32 +117,25 @@ int main(int argc, char* argv[])
bin_name = argv[0]; bin_name = argv[0];
/* load language */ /* load language */
if (loadlang() != 0) static char* langctrl_str;
{ langctrl_str = loadlang();
printf("loadlang fail\n");
exit(1);
}
sprintf(common_symbol_rule, "%s", current->common_symbol_rule); if (strcmp(langctrl_str, "en") == 0) current = &en;
else if (strcmp(langctrl_str, "tr") == 0) current = &tr;
sprintf(common_symbol_rule, "%s\n", current->common_symbol_rule);
if (search_sls() == 0) if (search_sls() == 0)
{ {
if (current->welcome_ != NULL) if (current->welcome_ != NULL) printf("%s", current->welcome_);
LOGD("%s", current->welcome_); printf("%s %s %s %s.\n", current->language, current->welcome, current->by_str, current->lang_by_s);
LOGD("%s %s %s %s.\n", current->language, current->welcome, current->by_str, current->lang_by_s);
} }
/* check argument total */ /* check argument total */
if (argc < 2) if (argc < 2) error(1, "%s\n%s `%s --help' %s.", current->missing_operand, current->try_h, argv[0], current->for_more);
LOGE("%s.\n%s `%s --help' %s.\n", current->missing_operand, current->try_h, argv[0], current->for_more);
/* a structure for long arguments */ /* a structure for long arguments */
struct option option_table[] = { struct option long_options[] = {
{"backup", no_argument, 0, 'b'},
{"flash", no_argument, 0, 'F'},
{"format", no_argument, 0, 'r'},
{"is_dummy", no_argument, 0, 'D'},
{"logical", no_argument, 0, 'l'}, {"logical", no_argument, 0, 'l'},
{"context", required_argument, 0, 'c'}, {"context", required_argument, 0, 'c'},
{"list", no_argument, 0, 'p'}, {"list", no_argument, 0, 'p'},
@@ -138,125 +150,49 @@ int main(int argc, char* argv[])
/* boolean statements (only valid in this file) to distinguish. and pointer from a shortcut for the symbol rule */ /* boolean statements (only valid in this file) to distinguish. and pointer from a shortcut for the symbol rule */
static bool wiew_help = false; static bool wiew_help = false;
static bool wiew_licenses = false;
static bool wiew_version = false; static bool wiew_version = false;
static bool logical_spec = false;
static bool list_partitions = false; static bool list_partitions = false;
static bool combo_wiewers = false; static bool combo_wiewers = false;
static bool pmt_setlang = false; static bool pmt_setlang = false;
static char* langpr; static char* langpr;
static int search_result = 3; static int search_result = 3;
static int getvar_temp;
static int check_getvar_temp;
static int opt; static int opt;
if (strcmp(argv[1], "backup") == 0)
{
if (argc <= 2)
LOGE("%s 0.\n", current->expected_backup_arg);
if (ctrl_arg(argv[2]))
target_partition = argv[2];
else
LOGE("%s.\n", current->not_spec_opt);
out = target_partition;
if (argc > 3 && ctrl_arg(argv[3]))
out = argv[3];
check_optsym(target_partition);
check_optsym(out);
pmt_backup = true;
}
else if (strcmp(argv[1], "flash") == 0)
{
if (argc <= 2)
LOGE("%s 0.\n", current->expected_flash_arg);
if (argc <= 3)
LOGE("%s 1.\n", current->expected_flash_arg);
if (ctrl_arg(argv[2]))
target_partition = argv[2];
else
LOGE("%s.\n", current->not_spec_opt);
if (ctrl_arg(argv[3]))
target_flash_file = argv[3];
else
LOGE("%s.\n", current->not_spec_opt);
check_optsym(target_flash_file);
check_optsym(target_partition);
pmt_flash = true;
}
else if (strcmp(argv[1], "format") == 0)
{
if (argc <= 2)
LOGE("%s 0.\n", current->expected_format_arg);
if (argc <= 3)
LOGE("%s 1.\n", current->expected_format_arg);
if (ctrl_arg(argv[2]))
target_partition = argv[2];
else
LOGE("%s.\n", current->not_spec_opt);
if (ctrl_arg(argv[3]))
format_fs = argv[3];
else
LOGE("%s.\n", current->not_spec_opt);
check_optsym(format_fs);
check_optsym(target_partition);
pmt_format = true;
}
/* control for each argument */ /* control for each argument */
while ((opt = getopt_long(argc, argv, "bFrDlc:psfS:vL", option_table, NULL)) != -1) while ((opt = getopt_long(argc, argv, "lc:psfS:vL", long_options, NULL)) != -1)
{ {
/* process arguments */ /* process arguments */
switch (opt) switch (opt)
{ {
/* handle deprecates */
case 'b':
DEPR_HANDLE('b', "backup", current->depr_backup_opt);
exit(1);
break;
case 'F':
DEPR_HANDLE('F', "flash", current->depr_flash_opt);
exit(1);
break;
case 'r':
DEPR_HANDLE('r', "format", current->depr_format_opt);
exit(1);
break;
case 'D':
DEPR_HANDLE('D', "NULLPTR", current->depr_ch_list_opt);
exit(1);
break;
case 'L':
DEPR_HANDLE('L', "license", current->depr_Vlicense_opt);
exit(1);
break;
/* logical partitions option */ /* logical partitions option */
case 'l': case 'l':
logical_spec = true; check_root();
check_dev_point();
if (pmt_logical) pmt_use_logical = true;
else
{
if (!pmt_force_mode) error(1, "%s", current->not_logical);
else return 1;
}
break; break;
/* context selector option */ /* context selector option */
case 'c': case 'c':
pmt_use_cust_cxt = true; pmt_use_cust_cxt = true;
cust_cxt = strdup(optarg); cust_cxt = strdup(optarg);
check_optsym(cust_cxt); if (strncmp(cust_cxt, opt_symbol, 1) == 0)
{
if (!pmt_force_mode) error(1, "%s", common_symbol_rule);
else return 1;
}
break; break;
/* partition lister function */ /* partition lister function */
case 'p': case 'p':
list_partitions = true; list_partitions = true;
/* check combo wiewer options and progress */ /* check combo wiewer options and progress */
if (wiew_version || wiew_help) combo_wiewers = true; if (wiew_version || wiew_help || wiew_licenses) combo_wiewers = true;
break; break;
/* force mode option */ /* force mode option */
case 'f': case 'f':
@@ -275,28 +211,33 @@ int main(int argc, char* argv[])
case 'v': case 'v':
wiew_version = true; wiew_version = true;
/* check combo wiewer options and progress */ /* check combo wiewer options and progress */
if (list_partitions || wiew_help) combo_wiewers = true; if (list_partitions || wiew_help || wiew_licenses) combo_wiewers = true;
break; break;
/* help message opption */ /* help message opption */
case 0: case 0:
wiew_help = true; wiew_help = true;
/* check combo wiewer options and progress */ /* check combo wiewer options and progress */
if (wiew_version || list_partitions) combo_wiewers = true; if (wiew_version || list_partitions || wiew_licenses) combo_wiewers = true;
break;
/* license wiewer option */
case 'L':
wiew_licenses = true;
/* check combo wiewer options and progress */
if (wiew_version || wiew_help || list_partitions) combo_wiewers = true;
break; break;
/* for invalid options */ /* for invalid options */
case '?': case '?':
LOGD("%s `%s --help' %s\n", current->try_h, argv[0], current->for_more); printf("%s `%s --help' %s\n", current->try_h, argv[0], current->for_more);
return 1; return 1;
break; break;
default: default:
LOGD("%s: %s [backup] [flash] [format] [-l | --logical] [-c | --context] [-p | --list] [-s | --silent] [-v | --version] [--help]\n", current->usage_head, argv[0]); printf("%s: %s [backup] [flash] [format] [-l | --logical] [-c | --context] [-D | --list] [-v | --version] [--help] [-L | --license]\n", current->usage_head, argv[0]);
return 1; return 1;
} }
} }
/* stop the program if multiple viewer is used */ /* stop the program if multiple viewer is used */
if (combo_wiewers) if (combo_wiewers) error(1, "%s", current->multiple_wiewers);
LOGE("%s", current->multiple_wiewers);
/* controller to handle viewer */ /* controller to handle viewer */
if (wiew_help) if (wiew_help)
@@ -309,6 +250,11 @@ int main(int argc, char* argv[])
version(); version();
return 0; return 0;
} }
else if (wiew_licenses)
{
licenses();
return 0;
}
else if (list_partitions) else if (list_partitions)
{ {
check_root(); check_root();
@@ -317,62 +263,163 @@ int main(int argc, char* argv[])
if (pmt_setlang) if (pmt_setlang)
{ {
LOGD("%s: %s\n", argv[0], current->switching_lang); printf("%s: %s\n", argv[0], current->switching_lang);
setlang(langpr, 0); setlang(langpr);
sleep(2); sleep(2);
LOGD("%s: %s.\n", argv[0], current->please_rerun); printf("%s: %s.\n", argv[0], current->please_rerun);
return 0; return 0;
} }
if (!pmt_backup && !pmt_flash && !pmt_format) /* detect target mode */
LOGE("%s.\n%s `%s --help` %s\n", current->no_target, current->try_h, argv[0], current->for_more); static char arg1[20];
sprintf(arg1, "%s", argv[1]);
if (pmt_format) for (int argtest = 2; argtest == argc; argtest++)
{ {
if (strcmp(format_fs, "ext4") != 0 && strcmp(format_fs, "ext3") != 0 && strcmp(format_fs, "ext2") != 0) getvar_temp = argtest;
LOGE("%s: %s\n", current->unsupported_fs, format_fs); check_getvar_temp = getvar_temp;
getvar_temp++;
if (strcmp(argv[argtest], "backup") == 0)
{
check_getvar_temp++;
if (argc < check_getvar_temp)
{
if (!pmt_silent) error(1, "%s 0.", current->expected_backup_arg);
else return 1;
} }
target_partition = argv[getvar_temp];
if (argc == check_getvar_temp) out = target_partition;
else
{
getvar_temp++;
out = argv[getvar_temp];
}
check_optsym(target_partition);
check_optsym(out);
pmt_backup = true;
break;
}
else if (strcmp(argv[argtest], "flash") == 0)
{
check_getvar_temp++;
if (argc < check_getvar_temp)
{
if (!pmt_force_mode || !pmt_silent) error(1, "%s 0.", current->expected_flash_arg);
else return 1;
}
if (argc == check_getvar_temp)
{
if (!pmt_force_mode || !pmt_silent) error(1, "%s 1.", current->expected_flash_arg);
else return 1;
}
target_flash_file = argv[getvar_temp];
getvar_temp++;
target_partition = argv[getvar_temp];
check_optsym(target_flash_file);
check_optsym(target_partition);
pmt_flash = true;
break;
}
else if (strcmp(argv[argtest], "format") == 0)
{
check_getvar_temp++;
if (argc < check_getvar_temp)
{
if (!pmt_force_mode) error(1, "%s 0.", current->expected_format_arg);
else return 1;
}
if (argc == check_getvar_temp)
{
if (!pmt_force_mode) error(1, "%s 1.", current->expected_format_arg);
else return 1;
}
format_fs = argv[getvar_temp];
getvar_temp++;
target_partition = argv[getvar_temp];
check_optsym(format_fs);
check_optsym(target_partition);
pmt_format = true;
break;
}
}
/* target control is done */
if (!pmt_backup && !pmt_flash && !pmt_format && !pmt_silent) error(1, "%s\n%s `%s --help` %s", argv[0], current->missing_operand, current->try_h, current->for_more);
else return 1;
/* checks */ /* checks */
check_root(); check_root();
check_dev_point(); check_dev_point();
if (logical_spec) if (pmt_format)
{ {
if (pmt_logical) if (strcmp(format_fs, "ext4") != 0 || strcmp(format_fs, "ext3") != 0 || strcmp(format_fs, "ext2") != 0)
pmt_use_logical = true; {
else if (!pmt_force_mode) error(1, "%s: %s", current->unsupported_fs, format_fs);
LOGE("%s\n", current->not_logical); else return 1;
}
} }
if (pmt_flash) if (pmt_flash)
{ {
search_result = get_stat(target_flash_file, "file"); search_result = search_stat(target_flash_file, "file");
if (search_result == 1) if (search_result == 1)
LOGE("%s `%s': %s\n", current->cannot_stat, target_flash_file, strerror(errno)); {
if (!pmt_silent) error(1, "%s `%s': %s", current->cannot_stat, target_flash_file, strerror(errno));
else return 1;
}
else if (search_result == -1) else if (search_result == -1)
LOGE("`%s': %s\n", target_flash_file, current->not_file); {
if (!pmt_silent) error(1, "`%s': %s", target_flash_file, current->not_file);
else return 1;
}
} }
/* custom context checker */ /* custom context checker */
if (pmt_use_cust_cxt) if (pmt_use_cust_cxt)
{ {
search_result = get_stat(cust_cxt, "dir"); search_result = search_stat(cust_cxt, "dir");
if (search_result == 1) if (search_result == 1)
LOGE("%s `%s': %s\n", current->cannot_stat, cust_cxt, strerror(errno)); {
if (!pmt_silent) error(1, "%s `%s': %s", current->cannot_stat, cust_cxt, strerror(errno));
else return 1;
}
else if (search_result == -1) else if (search_result == -1)
LOGE("`%s': %s\n", cust_cxt, current->not_dir); {
if (!pmt_silent) error(1, "`%s': %s", cust_cxt, current->not_dir);
else return 1;
}
if (strstr(cust_cxt, "/dev") == NULL && !pmt_force_mode) if (strstr(cust_cxt, "/dev") == NULL && !pmt_force_mode) error(1, "%s", current->not_in_dev);
LOGE("%s\n", current->not_in_dev);
} }
if (target_partition == NULL) if (target_partition == NULL)
{ {
if (!pmt_force_mode) if (!pmt_force_mode)
LOGE("%s\n%s `%s --help' %s\n", current->req_part_name, current->try_h, argv[0], current->for_more); {
if (!pmt_silent) error(1, "%s\n%s `%s --help' %s", current->req_part_name, current->try_h, argv[0], current->for_more);
}
else return 1;
} }
else else
{ {
@@ -383,16 +430,14 @@ int main(int argc, char* argv[])
* *
* 3 = format * 3 = format
*/ */
if (pmt_backup) if (pmt_backup) return pmt(1);
return pmt(1); else if (pmt_flash) return pmt(2);
else if (pmt_flash) else if (pmt_format) return pmt(3);
return pmt(2); else if (!pmt_silent) error(1, "%s\n%s `%s --help' %s", current->no_target, current->try_h, argv[0], current->for_more);
else if (pmt_format)
return pmt(3);
} }
} }
#ifdef __cplusplus #if defined(__cplusplus)
} }
#endif #endif

View File

@@ -16,25 +16,31 @@
* limitations under the License. * limitations under the License.
*/ */
#ifdef __cplusplus #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
#define INC_MAIN_LIBS #define INC_MAIN_LIBS
#define INC_DEBUGERS #define INC_DEBUGERS
#include <pmt/pmt.h> #include <pmt.h>
#include <pmt/stringkeys.h>
extern struct pmt_langdb_general* current;
extern struct pmt_langdb_general en;
extern struct pmt_langdb_general tr;
/* root checker function */ /* root checker function */
void check_root(void) void check_root(void)
{ {
/* a quick, easy method for verifying root */ /* a quick, easy method for verifying root */
if (getuid() != 0) if (getuid() != 0)
LOGE("%s\n", current->no_root); {
if (!pmt_force_mode) error(1, "%s", current->no_root);
else exit(1);
}
} }
#ifdef __cplusplus #if defined(__cplusplus)
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifdef __cplusplus #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
@@ -26,8 +26,25 @@ extern "C" {
#define INC_DEBUGERS #define INC_DEBUGERS
#define INC_TOOLS_REQS #define INC_TOOLS_REQS
#include <pmt/pmt.h> #include <pmt.h>
#include <pmt/stringkeys.h>
extern char* out;
extern char* format_fs;
extern char* cust_cxt;
extern char* target_partition;
extern char* target_flash_file;
extern char* partition_type;
extern bool pmt_use_logical;
extern bool pmt_use_cust_cxt;
extern bool pmt_logical;
extern bool pmt_flash;
extern bool pmt_backup;
extern bool pmt_silent;
extern bool pmt_force_mode;
extern struct pmt_langdb_general* current;
extern struct pmt_langdb_general en;
extern struct pmt_langdb_general tr;
/** /**
* it is meant to calculate the size of the quickly given file. * it is meant to calculate the size of the quickly given file.
@@ -38,16 +55,13 @@ calc_flsz(const char* _Nonnull filepath)
{ {
static int calc_flsz_file; static int calc_flsz_file;
calc_flsz_file = open(filepath, O_RDONLY); calc_flsz_file = open(filepath, O_RDONLY);
if (calc_flsz_file == -1) return calc_flsz_file;
if (calc_flsz_file == -1)
return calc_flsz_file;
static off_t flsz; static off_t flsz;
flsz = lseek(calc_flsz_file, 0, SEEK_END); flsz = lseek(calc_flsz_file, 0, SEEK_END);
close(calc_flsz_file); close(calc_flsz_file);
if (flsz == (off_t)-1) if (flsz == (off_t)-1) return -1;
return -1;
return (double)flsz / (1024 * 1024); return (double)flsz / (1024 * 1024);
} }
@@ -56,23 +70,64 @@ calc_flsz(const char* _Nonnull filepath)
* error that the partition is not found. * error that the partition is not found.
* It's for quick action. * It's for quick action.
*/ */
static void static int
partition_not_found(void) { LOGE("%s\n", current->part_not_found); } partition_not_found(void)
{
if (!pmt_silent) error(1, "%s", current->part_not_found);
else return 1;
}
/* to stop use of function type */ /* to stop use of function type */
#define partition_not_found partition_not_found() #define partition_not_found partition_not_found()
/**
* The target file is controlled by the stat function.
* Files, directories, links and blocks (disks) are for.
* If it is never found, it returns 1 value.
* If he finds 0 value is returned.
* If the desired type is not in -1 value is returned.
*/
static int
search_stat(const char* _Nonnull filepath, const char* _Nonnull stype)
{
struct stat search_stat;
if (stat(filepath, &search_stat) != 0) return 1;
if (strcmp(stype, "dir") == 0)
{
if (S_ISDIR(search_stat.st_mode)) return 0;
else return -1;
}
else if (strcmp(stype, "file") == 0)
{
if (S_ISREG(search_stat.st_mode)) return 0;
else return -1;
}
else if (strcmp(stype, "blk") == 0)
{
if (S_ISBLK(search_stat.st_mode)) return 0;
else return -1;
}
else if (strcmp(stype, "link") == 0)
{
if (S_ISLNK(search_stat.st_mode)) return 0;
else return -1;
}
return 2;
}
/* the partitions are meant to quickly find. */ /* the partitions are meant to quickly find. */
static void static void
search_partition(const char* _Nonnull partition) search_partition(const char* _Nonnull partition)
{ {
static int partition_results = 0; static int partition_results = 0;
partition_results = get_stat(partition, "blk"); partition_results = search_stat(partition, "blk");
if (partition_results == 1) if (partition_results == 1) partition_not_found;
partition_not_found; else if (partition_results == -1 && !pmt_silent) error(1, "%s", current->not_block);
else if (partition_results == -1) else exit(1);
LOGE("%s\n", current->not_block);
} }
int pmt(unsigned short progress_code) int pmt(unsigned short progress_code)
@@ -93,37 +148,37 @@ int pmt(unsigned short progress_code)
{ {
if (!pmt_use_logical) if (!pmt_use_logical)
{ {
if (pmt_use_cust_cxt) if (pmt_use_cust_cxt) sprintf(backupper_path, "%s/%s", cust_cxt, target_partition);
sprintf(backupper_path, "%s/%s", cust_cxt, target_partition); else sprintf(backupper_path, "/dev/block/by-name/%s", target_partition);
else
sprintf(backupper_path, "/dev/block/by-name/%s", target_partition);
} }
else else if (pmt_use_logical) sprintf(backupper_path, "/dev/block/mapper/%s", target_partition);
sprintf(backupper_path, "/dev/block/mapper/%s", target_partition);
search_partition(backupper_path); search_partition(backupper_path);
if (calc_flsz(backupper_path) != -1) if (calc_flsz(backupper_path) != -1 && !pmt_silent) printf("%s: %.2f\n", current->part_disk_sz, calc_flsz(backupper_path));
LOGD("%s: %.2f\n", current->part_disk_sz, calc_flsz(backupper_path)); else if (!pmt_silent) warning("%s", current->part_disk_sz_fail);
else
LOGW("%s\n", current->part_disk_sz_fail);
srcf = open(backupper_path, O_RDONLY); srcf = open(backupper_path, O_RDONLY);
if (srcf == -1) if (srcf == -1)
LOGE("%s: %s: %s\n", current->not_read, backupper_path, strerror(errno)); {
if (!pmt_silent) error(1, "%s: %s: %s", current->not_read, backupper_path, strerror(errno));
else return 1;
}
/* determine output */ /* determine output */
if (strcmp(out, target_partition) == 0) if (strcmp(out, target_partition) == 0)
{ {
sprintf(outf, "%s.img", out); sprintf(outf, "%s.img", target_partition);
LOGW("%s: %s\n", current->out_not_spec, outf); if (!pmt_silent) warning("%s: %s", current->out_not_spec, outf);
} }
else else sprintf(outf, "%s", target_partition);
sprintf(outf, "%s", out);
targetf = open(outf, O_WRONLY | O_CREAT | O_TRUNC, 0660); targetf = open(outf, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (targetf == -1) if (targetf == -1)
LOGE("%s: %s: %s\n", current->not_gen, outf, strerror(errno)); {
if (!pmt_silent) error(1, "%s: %s: %s", current->not_gen, outf, strerror(errno));
else return 1;
}
/* start writing */ /* start writing */
while ((readed_data = read(srcf, buffer, BFSIZE)) > 0 && copied_data < count) while ((readed_data = read(srcf, buffer, BFSIZE)) > 0 && copied_data < count)
@@ -131,9 +186,11 @@ int pmt(unsigned short progress_code)
ssize_t writed_data = write(targetf, buffer, readed_data); ssize_t writed_data = write(targetf, buffer, readed_data);
if (writed_data != readed_data) if (writed_data != readed_data)
{ {
if (get_stat(outf, "file") == 0) if (!pmt_silent) warning("%s: %s: %s", current->not_write, backupper_path, strerror(errno));
remove(outf); close(srcf);
LOGF("%s: %s: %s\n", current->not_write, backupper_path, strerror(errno)); close(targetf);
if (search_stat(outf, "file") == 0) remove(outf);
return 1;
} }
copied_data += writed_data; copied_data += writed_data;
@@ -143,7 +200,7 @@ int pmt(unsigned short progress_code)
close(srcf); close(srcf);
close(targetf); close(targetf);
LOGD("%s: %s\n", current->success_backup, outf); if (!pmt_silent) printf("%s: %s\n", current->success_backup, outf);
} }
else if (progress_code == 2) else if (progress_code == 2)
{ {
@@ -151,48 +208,49 @@ int pmt(unsigned short progress_code)
/* for classic */ /* for classic */
if (!pmt_use_logical) if (!pmt_use_logical)
{ {
if (pmt_use_cust_cxt) if (pmt_use_cust_cxt) sprintf(flasher_path, "%s/%s", cust_cxt, target_partition);
sprintf(flasher_path, "%s/%s", cust_cxt, target_partition); else sprintf(flasher_path, "/dev/block/by-name/%s", target_partition);
else
sprintf(flasher_path, "/dev/block/by-name/%s", target_partition);
/* for logical */ /* for logical */
} }
else else if (pmt_use_logical) sprintf(flasher_path, "/dev/block/mapper/%s", target_partition);
sprintf(flasher_path, "/dev/block/mapper/%s", target_partition);
/* check partition */ /* check partition */
search_partition(flasher_path); search_partition(flasher_path);
if (calc_flsz(target_flash_file) != -1) if (calc_flsz(target_flash_file) != -1 && !pmt_force_mode) printf("%s: %.2f\n", current->flash_file_sz, calc_flsz(target_flash_file));
LOGD("%s: %.2f\n", current->flash_file_sz, calc_flsz(target_flash_file)); else warning("%s", current->flash_file_sz_fail);
else
LOGW("%s\n", current->flash_file_sz_fail);
if (calc_flsz(flasher_path) != -1) if (calc_flsz(target_partition) != -1 && !pmt_force_mode) printf("%s: %.2f\n", current->part_disk_sz, calc_flsz(target_partition));
LOGD("%s: %.2f\n", current->part_disk_sz, calc_flsz(flasher_path)); else warning("%s", current->part_disk_sz_fail);
else
LOGW("%s\n", current->part_disk_sz_fail);
if (calc_flsz(target_flash_file) != -1 && calc_flsz(flasher_path) != -1) if (calc_flsz(target_flash_file) > calc_flsz(target_partition) && !pmt_silent) error(1, "%s", current->ffile_more_part);
{ else return 1;
if (calc_flsz(target_flash_file) > calc_flsz(flasher_path))
LOGE("%s\n", current->ffile_more_part);
}
srcf = open(target_flash_file, O_RDONLY); srcf = open(target_flash_file, O_RDONLY);
if (srcf == -1) if (srcf == -1)
LOGF("%s: %s: %s\n", current->not_read, target_flash_file, strerror(errno)); {
if (!pmt_force_mode) error(1, "%s: %s: %s", current->not_read, target_flash_file, strerror(errno));
else return 1;
}
targetf = open(target_partition, O_WRONLY | O_CREAT | O_TRUNC, 0660); targetf = open(target_partition, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (targetf == -1) if (targetf == -1)
LOGF("%s: %s: %s\n", current->not_read, target_partition, strerror(errno)); {
if (!pmt_force_mode) error(1, "%s: %s: %s", current->not_read, target_partition, strerror(errno));
else return 1;
}
/* start writing */ /* start writing */
while ((readed_data = read(srcf, buffer, BFSIZE)) > 0 && copied_data < count) while ((readed_data = read(srcf, buffer, BFSIZE)) > 0 && copied_data < count)
{ {
ssize_t writed_data = write(targetf, buffer, readed_data); ssize_t writed_data = write(targetf, buffer, readed_data);
if (writed_data != readed_data) if (writed_data != readed_data)
LOGF("%s: %s: %s\n", current->not_write, backupper_path, strerror(errno)); {
warning("%s: %s: %s", current->not_write, backupper_path, strerror(errno));
close(srcf);
close(targetf);
return 1;
}
copied_data += writed_data; copied_data += writed_data;
} }
@@ -200,21 +258,18 @@ int pmt(unsigned short progress_code)
close(srcf); close(srcf);
close(targetf); close(targetf);
LOGD("%s.\n", current->success_flash); if (!pmt_force_mode) printf("%s.\n", current->success_flash);
} }
else if (progress_code == 3) else if (progress_code == 3)
{ {
/* generate partition extn */ /* generate partition extn */
if (!pmt_use_logical) if (!pmt_use_logical)
{ {
if (pmt_use_cust_cxt) if (pmt_use_cust_cxt) sprintf(ppath, "%s/%s", cust_cxt, target_partition);
sprintf(ppath, "%s/%s", cust_cxt, target_partition); else sprintf(ppath, "/dev/block/by-name/%s", target_partition);
else
sprintf(ppath, "/dev/block/by-name/%s", target_partition);
/* for logical */ /* for logical */
} }
else else if (pmt_use_logical) sprintf(ppath, "/dev/block/mapper/%s", target_partition);
sprintf(ppath, "/dev/block/mapper/%s", target_partition);
/* check partition */ /* check partition */
search_partition(ppath); search_partition(ppath);
@@ -222,20 +277,26 @@ int pmt(unsigned short progress_code)
/* get target partition block size */ /* get target partition block size */
struct statvfs file_sys_inf; struct statvfs file_sys_inf;
if (statvfs(ppath, &file_sys_inf) != 0) if (statvfs(ppath, &file_sys_inf) != 0)
LOGE("%s\n", current->cannot_get_bsz); {
if (!pmt_force_mode) error(1, "%s", current->cannot_get_bsz);
else return 1;
}
/* generate mke2fs command */ /* generate mke2fs command */
sprintf(formatter_cmd, "mke2fs -Fq -t %s -b %lu %s", format_fs, file_sys_inf.f_bsize, ppath); sprintf(formatter_cmd, "mke2fs -Fq -t %s -b %lu %s", format_fs, file_sys_inf.f_bsize, ppath);
/* run command */ /* run command */
if (system(formatter_cmd) != 0) if (system(formatter_cmd) != 0)
LOGF("%s\n", current->format_fail); {
if (!pmt_force_mode) error(1, "%s", current->format_fail);
else return 1;
}
} }
return 0; return 0;
} }
#ifdef __cplusplus #if defined(__cplusplus)
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@@ -16,36 +16,41 @@
* limitations under the License. * limitations under the License.
*/ */
#ifdef __cplusplus #if defined(__cplusplus)
extern "C" { extern "C" {
#endif #endif
#define INC_MAIN_LIBS #define INC_MAIN_LIBS
#define INC_VERSIONER_REQS
#include <pmt/pmt.h> #include <pmt.h>
#include <pmt/stringkeys.h>
#include <pmt/versioning.h> extern char* bin_name;
extern struct pmt_langdb_general* current;
extern struct pmt_langdb_general en;
extern struct pmt_langdb_general tr;
void version(void) void version(void)
{ {
LOGD("%s %s %d.%d.%d (%d%d%d) ", bin_name, current->version_str, PMT_MAJOR, PMT_MINOR, PMT_PATCHLEVEL, PMT_MAJOR, PMT_MINOR, PMT_PATCHLEVEL); printf("%s %s %d.%d.%d (%d%d%d) ", bin_name, current->version_str, PMT_MAJOR, PMT_MINOR, PMT_PATCHLEVEL, PMT_MAJOR, PMT_MINOR, PMT_PATCHLEVEL);
#if __SIZEOF_POINTER__ == 4 #if __SIZEOF_POINTER__ == 4
LOGD("32-bit %s\n", current->bin_str); printf("32-bit %s\n", current->bin_str);
#elif __SIZEOF_POINTER__ == 8 #elif __SIZEOF_POINTER__ == 8
LOGD("64-bit %s\n", current->bin_str); printf("64-bit %s\n", current->bin_str);
#else #else
LOGD("<%s> %s\n", current->unknw_str, current->bin_str); printf("<%s> %s\n", current->unknw_str, current->bin_str);
#endif #endif
#if defined(__clang__) && !defined(__NDK_BUILD) #if defined(__clang__)
LOGD("%s: clang %d.%d.%d\n", current->compiler_str, __clang_major__, __clang_minor__, __clang_patchlevel__); printf("%s: clang %d.%d.%d (NDK r%d%s %s)\n", current->compiler_str, __clang_major__, __clang_minor__, __clang_patchlevel__, __NDK_MAJOR__, __NDK_MINOR_STATUS__, __NDK_BETA_STATUS__);
#elif defined(__clang__) && defined(__NDK_BUILD)
LOGD("%s\n", __NDK_CC_VERSION__);
#endif #endif
printf("%s\n", current->see_license);
} }
#ifdef __cplusplus #if defined(__cplusplus)
} }
#endif #endif

View File

@@ -1,126 +0,0 @@
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#####
# sub-make for installing-uninstalling
#####
THIS_IS := out
# include needed variables
include ../Makefile.inc
-include $(BUILD)/config/INS_STAT.mk
-include $(BUILD)/config/UNINS_STAT.mk
# create an empty target
all:
$(hide)printf ""
# installer
.PHONY: install
install:
# really termux?
$(hide)if [ -f $(TERMUX_BIN)/termux-open ]; then \
printf " ------------ $(TARGET) installer ------------ \n"; \
if [ -f $(TERMUX_BIN)/$(TARGET) ]; then \
printf " - $(TARGET) already installed\n"; \
exit; \
fi; \
if [ ! "$(INSTALL_SUCCESS)" = "true" ] && [ ! "$(INSTALL_SUCCESS)" = "" ]; then \
printf " - $(YELLOW)$(BOLD)Warning:$(BOLD_RESET)$(RESET) a previously-stayed failed installation process found\n"; \
fi; \
if [ -f $(DEB_DIR)/*.deb ]; then \
printf " - The created deb pack was found. It's setup...\n"; \
cd $(DEB_DIR) || exit 1; \
apt install ./*.deb || exit 1; \
if [ ! "$?" = "0" ]; then \
cd $(CUR_DIR); \
printf " - Success.\n\n"; \
echo "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
echo "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk; \
cd ..; \
exit 0; \
else \
cd $(CUR_DIR); \
printf " - $(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) installing failed!\n"; \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
cd ..; \
exit 1; \
fi; \
fi; \
if [ ! -f $(BINARY_DIR)/$(TARGET) ]; then \
printf " - $(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) Package not builded! Please build package and try again \n"; \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
exit 1; \
fi; \
printf " - Installing binary...\n"; \
if [ "`cp $(BINARY_DIR)/$(TARGET) /data/data/com.termux/files/usr/bin/$(TARGET)`" = "" ]; then \
printf " - Setting up permissions...\n"; \
else \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
exit 1; \
fi; \
if [ "`chmod 777 $(TERMUX_BIN)/$(TARGET)`" = "" ]; then \
printf " - Saving current status...\n"; \
echo "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
else \
echo "INSTALL_SUCCESS := false" > $(BUILD)/config/INS_STAT.mk; \
exit 1; \
fi; \
printf " - Success.\n\n"; \
echo "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
echo "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk; \
else \
printf " - $(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) This function is only available on Termux.\n"; \
exit 1; \
fi
# uninstaller
.PHONY: uninstall
uninstall:
# really termux?
$(hide)if [ -f $(TERMUX_BIN)/termux-open ]; then \
printf " ----------- $(TARGET) uninstaller ----------- \n"; \
if [ ! -f $(TERMUX_BIN)/$(TARGET) ]; then \
printf " - $(TARGET) already uninstalled\n"; \
exit; \
fi; \
if [ ! "$(UNINSTALL_SUCCESS)" = "true" ] && [ ! "$(UNINSTALL_SUCCESS)" = "" ]; then \
printf " - $(YELLOW)$(BOLD)Warning:$(BOLD_RESET)$(RESET) a previously-stayed failed uninstallation process found\n"; \
fi; \
if [ -f $(TERMUX_USR)/share/man/man8/$(TARGET).8.gz ]; then \
printf " - It was found to be established by $(TARGET)'s deb pack. It's removed with apt...\n"; \
apt remove -y $(TARGET) || exit 1; \
printf " - Success.\n\n"; \
echo "UNINSTALLED_SUCCESS := true" > $(BUILD)/config/UNINS_STAT.mk; \
echo "INSTALL_SUCCESS := " > $(BUILD)/config/INS_STAT.mk; \
else \
printf " - It was found that pmt was manually established (with this makefile or copying). Manually removed...\n"; \
if [ "`rm $(TERMUX_BIN)/$(TARGET)`" = "" ]; then \
printf " - Success.\n\n"; \
echo "UNINSTALLED_SUCCESS := true" > $(BUILD)/config/UNINS_STAT.mk; \
echo "INSTALL_SUCCESS := " > $(BUILD)/config/INS_STAT.mk; \
else \
echo "UNINSTALLED_SUCCESS := false" > $(BUILD)/config/UNINS_STAT.mk; \
exit 1; \
fi; \
fi; \
else \
printf "$(RED)$(BOLD)Error:$(BOLD_RESET)$(RESET) This function is only available on Termux.\n"; \
exit 1; \
fi
# end

208
utils.sh Executable file
View File

@@ -0,0 +1,208 @@
#!/usr/bin/bash
# By YZBruh
# Copyright 2024 Partition Manager
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ANSI color codes
RED='\e[31m'
NC='\e[0m'
# needed variables
VERSION="2.3.0"
CUR_DIR=$(pwd)
LIB_DIR=${CUR_DIR}/libs
ARMV8A_DIR=${LIB_DIR}/arm64-v8a
ARMV7A_DIR=${LIB_DIR}/armeabi-v7a
DEB_DIR=${CUR_DIR}/deb
DEBUTILS_DIR=${CUR_DIR}/debutils
DEBTERMUX_USR=${DEBUTILS_DIR}/data/data/com.termux/files/usr
# set file modes (all) to 755
${SUDO} chmod -R 755 *
# error messages
abort()
{
if [ ! "$1" = "" ]; then
printf "${RED}${1}${NC}\n"
fi
if [ -d ${DEBUTILS_DIR}/temp ]; then
rm -rf ${DEBUTILS_DIR}/temp
fi
exit 1
}
gen_deb()
{
printf " --------- Making pmt deb package ---------\n";
printf " - Checking all files and directories (only
eededs)...\n";
# check important files
if [ ! -d ${DEBUTILS_DIR} ]; then
abort " - Not found: ${DEBUTILS_DIR}\n"
fi
if [ ! -d ${DEBUTILS_DIR}/DEBIAN ]; then
abort " - Not found: ${DEBUTILS_DIR}/DEBIAN\n"
fi
if [ ! -d ${DEBUTILS_DIR}/mandoc ]; then
abort " - Not found: ${DEBUTILS_DIR}/mandoc\n"
fi
if [ ! -d ${DEBUTILS_DIR}/data/data/com.termux ]; then
abort " - Not found: ${DEBUTILS_DIR}/data/data/com.termux\n"
fi
if [ ! -d ${DEBUTILS_DIR}/data/data/com.termux/files/usr ]; then
abort " - Not found: ${DEBUTILS_DIR}/data/data/com.termux/files/usr\n"
fi
if [ ! -d ${DEBUTILS_DIR}/data/data/com.termux/files/usr/bin ]; then
abort " - Not found: ${DEBUTILS_DIR}/data/data/com.termux/files/usr/bin\n"
fi
if [ ! -d ${DEBUTILS_DIR}/data/data/com.termux/files/usr/share/man/man8 ]; then
abort " - Not found: ${DEBUTILS_DIR}/data/data/com.termux/files/usr/share/man/man8\n"
fi
if [ ! -f ${DEBUTILS_DIR}/mandoc/pmt.8.gz ]; then
abort " - Not found: ${DEBUTILS_DIR}/mandoc/pmt.8.gz\n"
fi
if [ ! -f ${DEBUTILS_DIR}/DEBIAN/control_32 ]; then
abort " - Not found: ${DEBUTILS_DIR}/DEBIAN/control_32\n"
fi
if [ ! -f ${DEBUTILS_DIR}/DEBIAN/control_64 ]; then
abort " - Not found: ${DEBUTILS_DIR}/DEBIAN/control_64\n"
fi
if [ ! -f ${ARMV8A_DIR}/pmt ]; then
abort " - Package not comptely builded! Please build package and try again\n"
elif [ ! -f ${ARMV7A_DIR}/pmt ]; then
abort " - Package not comptely builded! Please build package and try again\n"
fi
# generate template dir
printf " - Generating template dir...\n"
${SUDO} mkdir -p ${DEBUTILS_DIR}/temp || abort
# generate out dir
printf " - Generating out dir...\n"
${SUDO} mkdir -p ${DEB_DIR} || abort
# copy files
printf " - Copying files...\n"
${SUDO} cp -r ${DEBUTILS_DIR}/data ${DEBUTILS_DIR}/temp || abort
${SUDO} rm -f ${DEBTERMUX_USR}/share/man/man8/dummy
${SUDO} rm -f ${DEBTERMUX_USR}/bin/dummy
${SUDO} mkdir -p ${DEBUTILS_DIR}/temp/DEBIAN || abort
# select control file
printf " - Selected arm-${PREFIX} package control file.\n"
${SUDO} cp ${DEBUTILS_DIR}/DEBIAN/control_${PREFIX} ${DEBUTILS_DIR}/temp/DEBIAN/control || exit 1
${SUDO} cp ${DEBUTILS_DIR}/mandoc/pmt.8.gz ${DEBTERMUX_USR}/share/man/man8 || abort
if [ "${PREFIX}" = "64" ]; then
${SUDO} cp ${ARMV8A_DIR}/pmt ${DEBTERMUX_USR}/bin || abort
elif [ "${PREFIX}" = "32" ]; then
${SUDO} cp ${ARMV7A_DIR}/pmt ${DEBTERMUX_USR}/bin || abort
fi
# start dpkg-deb
printf " - Starting dpkg-deb...\n"
sleep 2
${SUDO} chmod -R 755 *
# if ARM_PREFIX is '-v7a', unset ARM_PREFIX and PREFIX. Re set PREFIX
if [ "${PREFIX}" = "32" ]; then
unset PREFIX
PREFIX="eabi-v7a"
fi
${SUDO} dpkg-deb -b ${DEBUTILS_DIR}/temp ${DEB_DIR}/pmt-${VERSION}-arm${PREFIX}${ARM_PREFIX}.deb || abort
${SUDO} rm -rf ${DEBUTILS_DIR}/temp
printf " - Done! Package: ${DEB_DIR}/pmt-${VERSION}-arm${PREFIX}${ARM_PREFIX}.deb\n"
}
gen_modpack()
{
printf " ----------- Making static lib package -----------\n"
printf " - Checking files...\n"
if [ ! -f $(STATICLIB_DIR)/libpmt_root.a ]; then
printf " - Not found: $(STATICLIB_DIR)/libpmt_root.a\n"
exit 1
fi
if [ ! -f $(STATICLIB_DIR)/libpmt_lister.a ]; then
printf " - Not found: $(STATICLIB_DIR)/libpmt_lister.a\n"
exit 1
fi
if [ ! -f $(STATICLIB_DIR)/libpmtpartition_tool.a ]; then
printf " - Not found: $(STATICLIB_DIR)/libpmtpartition_tool.a\n"
exit 1
fi
printf " - Compressing...\n"
mkdir -p static-lib-pack
cd static-lib-pack
cp jni/include/pmt.h .
mkdir -p include
mv pmt.h include/
zip -rq pmt-static-lib-pack.zip *.a include || exit 1
rm -rf include
sleep 1
printf " - Success.\n\n"
cd ..
}
case "${1}" in
make-deb)
case "${2}" in
arm64-v8a)
PREFIX="64"
ARM_PREFIX="-v8a"
;;
armeabi-v7a)
PREFIX="32"
ARM_PREFIX=""
;;
*)
abort " - Error: unknown architecture flag: $2. Avaiable: arm64-v8a & armeabi-v7a.\n"
esac
case "${3}" in
sudo)
SUDO="sudo"
;;
no-sudo)
SUDO=""
;;
*)
SUDO=""
esac
gen_deb
;;
modpack)
case "${2}" in
arm64-v8a)
STATICLIB_DIR="${CUR_DIR}/obj/local/${2}"
;;
armeabi-v7a)
STATICLIB_DIR="${CUR_DIR}/obj/local/${2}"
;;
*)
abort " - Error: unknown architecture flag: ${2}. Avaiable: arm64-v8a & armeabi-v7a.\n"
esac
gen_modpack
;;
*)
abort "${0}: invalid operand.\nUse the make-deb flag to create a deb package, and the modpack flag to create packages for static libraries."
esac
# end of script