Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d7ddaa8621 |
24
.github/build.config
vendored
24
.github/build.config
vendored
@@ -1,24 +0,0 @@
|
||||
#
|
||||
# Build config for pmt workflows
|
||||
#
|
||||
# 2.4.0 config
|
||||
#
|
||||
|
||||
# Version
|
||||
export BUILD_VERSION="2.4.0"
|
||||
|
||||
# Relese tag
|
||||
export BUILD_RELTAG="240"
|
||||
|
||||
# Target architures
|
||||
export BUILD_ARCH="arm64-v8a, armeabi-v7a"
|
||||
|
||||
# NDK environ for getting clang version
|
||||
export NDK="/home/workdir/android-ndk"
|
||||
export TC="${NDK}/toolchains/llvm/prebuilt/linux-x86_64"
|
||||
export TARGET_TEMPLATE="aarch64-linux-android"
|
||||
export API_TEMPLATE="21"
|
||||
export NDK_CLANG="${TC}/bin/${TARGET_TEMPLATE}${API}-clang"
|
||||
|
||||
# get version
|
||||
export CLANG_VERSION=$(${NDK_CLANG} --version | head -n 1)
|
||||
136
ADD-LANGUAGES.md
136
ADD-LANGUAGES.md
@@ -1,136 +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";
|
||||
.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...
|
||||
```
|
||||
char* pmt_langdb_langs[] = {
|
||||
"en",
|
||||
"tr"
|
||||
};
|
||||
// Add the language you are translating into these existing language prefixes. I will fix the errors here (if there is an error)
|
||||
|
||||
int pmt_langdb_total = <NUM>; // add one to the existing one and write (replacing with existing)
|
||||
int pmt_langdb_ctrl = <NUM>; // add one to the existing one and write (replacing with existing)
|
||||
```
|
||||
|
||||
##### Notes
|
||||
- Apologies for the crappy current language control structure :(
|
||||
- You can ask your questions: <t.me/YZBruh>
|
||||
10
CHANGELOG.md
10
CHANGELOG.md
@@ -1,7 +1,7 @@
|
||||
### Version 2.4.0 (code 240) changelog
|
||||
- Logging type has been changed.
|
||||
- More understandable syntax.
|
||||
- And one or two more things but I don't remember :P
|
||||
### Version 2.0.0 (code 200) changelog
|
||||
- Instead of make, it was switched to build with NDK
|
||||
- File/partition sizes were given during backup/flash operations.
|
||||
- The use of `fprintf` has started for all error messages.
|
||||
|
||||
| END OF VERSION 2.4.0 CHANGELOG |
|
||||
| END OF VERSION 2.0.0 CHANGELOG |
|
||||
|------------------------------------|
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
### Supported languages
|
||||
|
||||
- Türkçe (Turkish) (TR)
|
||||
- English (EN)
|
||||
83
README.md
Executable file → Normal file
83
README.md
Executable file → Normal file
@@ -3,49 +3,53 @@
|
||||
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...
|
||||
|
||||
```
|
||||
1. The partition name is obtained (with the -p or --partition argument)
|
||||
2. Other arguments (if used) are processed.
|
||||
3. The backup and flashing processes were written according to DD's code. So there is a piece of toybox code
|
||||
```
|
||||
|
||||
#### Presented arguments (options)
|
||||
|
||||
```
|
||||
Usage: pmt [OPTIONS] backup PARTITION [OUTPUT] [OPTIONS]...
|
||||
or: pmt [OPTIONS] flash FILE PARTITION [OPTIONS]...
|
||||
or: pmt [OPTIONS] format FILE_SYSTEM[ext/2/3/4] PARTITION [OPTIONS]...
|
||||
|
||||
Options:
|
||||
-l, --logical It is meant to determine whether the target partition is logical.
|
||||
-c, --context It is meant to specify a custom /dev context. Only classic partitions (default: /dev/block/by-name).
|
||||
-p, --list List partitions.
|
||||
-s, --silent Information and warning messages are silenced in normal work.
|
||||
-f, --force Force mode. Some things are ignored.
|
||||
-S, --set-lang Set current language.
|
||||
-v, --version See version.
|
||||
--help See this help message.
|
||||
-L, --license See license.
|
||||
Usage:
|
||||
-b | --backup backup mode
|
||||
-F | --flash flash mode
|
||||
-r | --format format mode (only ext2/3/4 file systems)
|
||||
-p | --partition name of the partition to be backed up
|
||||
-l | --logical know that the partition that will be backed up is logical
|
||||
-o | --out (only backups) the output name of the backed-up partition (default: partition name)
|
||||
-d | --outdir (only backups) directory where the backup partition will be saved (default: /storage/emulated/0)
|
||||
-c | --context it is meant to specify a custom /dev context. Only classic partitions (default: /dev/block/by-name)
|
||||
-D | --list list partitions
|
||||
-f | --force force mode. Output is not produced. Even if it's a mistake. But if the target is not a mode, the error is given. If you want to work stable, it is important to specify this option first.
|
||||
-v | --version see version
|
||||
--help see help message
|
||||
-L | --license see license
|
||||
|
||||
Examples:
|
||||
pmt backup boot_a -c /dev/block/platform/bootdevice/by-name
|
||||
pmt flash /sdcard/twrp/boot.img boot_a -c /dev/block/platform/bootdevice/by-name
|
||||
pmt format ext4 system_a --logical
|
||||
pmt -c /dev/block/platform/bootdevice/by-name --list
|
||||
-b --partition boot_a -o boot_slot_a_image -d /sdcard/backup -c /dev/block/platform/bootdevice/by-name
|
||||
--flash /sdcard/twrp/boot.img -p boot_a -c /dev/block/platform/bootdevice/by-name
|
||||
-c /dev/block/platform/bootdevice/by-name --list
|
||||
|
||||
Report bugs to <t.me / ShawkTeam | Community / Topics -- pmt>
|
||||
Report bugs to <t.me/YZBruh>
|
||||
```
|
||||
|
||||
#### Some notes
|
||||
|
||||
- pmt supports multiple languages. [See languages.](https://github.com/ShawkTeam/pmt/blob/2.4.0/LANGUAGES.md)
|
||||
- [Add language.](https://github.com/ShawkTeam/pmt/blob/2.4.0/ADD-LANGUAGES.md)
|
||||
- Feel free to ask any questions you want.
|
||||
- Packages are available in publications.
|
||||
- İt is mandatory to use the `-b` | `--backup` or `-f` | `--flash` and `-p` | `--partition` argument. After all, a partition name and progress type is required to be progress.
|
||||
- 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.4.0/CHANGELOG.md)
|
||||
- We are always open to your suggestions and support (developing)!
|
||||
- [Click to see special version changes](https://github.com/YZBruh/pbt/blob/2.0.0-en/CHANGELOG.md)
|
||||
- Let me know your suggestions!
|
||||
|
||||
### How is it built?
|
||||
Android NDK is required to build.
|
||||
- [Download](https://developer.android.com/ndk/downloads) and extract the NDK package.
|
||||
- Clone this repository. And get access to it.
|
||||
```
|
||||
git clone https://github.com/ShawkTeam/pmt -b 2.4.0
|
||||
git clone https://github.com/YZBruh/pbt -b 2.0.0 ./pmt
|
||||
cd pmt
|
||||
```
|
||||
- Set the NDK working directory variable.
|
||||
@@ -60,32 +64,23 @@ export NDK_PROJECT_PATH=$(pwd)
|
||||
```
|
||||
pmt/
|
||||
|
|
||||
________________|________________
|
||||
| | | |
|
||||
jni/ debutils/ obj/ libs/
|
||||
|
|
||||
__________|__________
|
||||
| |
|
||||
arm64-v8a/ armeabi-v7a/
|
||||
| |
|
||||
pmt pmt
|
||||
libs/
|
||||
|
|
||||
__________|__________
|
||||
| |
|
||||
arm64-v8a/ armeabi-v7a/
|
||||
| |
|
||||
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
|
||||
|
||||
- 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
|
||||
```
|
||||
--Usage--
|
||||
|
||||
./make-deb.sh [arm64-v8a, armeabi-v7a] [sudo, no-sudo, <blank>]
|
||||
```
|
||||
|
||||
```
|
||||
chmod 777 utils.sh
|
||||
chmod 777 make-deb.sh
|
||||
|
||||
# for making 64-bit package
|
||||
./utils.sh make-deb arm64-v8a
|
||||
./make-deb.sh arm64-v8a
|
||||
|
||||
# for making 32-bit package
|
||||
./utils.sh make-deb armeabi-v7a
|
||||
./make-deb.sh armeabi-v7a
|
||||
```
|
||||
|
||||
### Notes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Source: pmt
|
||||
Package: pmt
|
||||
Version: 2.4.0
|
||||
Version: 2.0.0
|
||||
Architecture: arm
|
||||
Description: pmt is for reading, writing and formatting partitions of android devices
|
||||
Section: misc
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Source: pmt
|
||||
Package: pmt
|
||||
Version: 2.4.0
|
||||
Version: 2.0.0
|
||||
Architecture: aarch64
|
||||
Description: pmt is for reading, writing and formatting partitions of android devices
|
||||
Section: misc
|
||||
|
||||
24
debutils/mandoc/pmt.1
Executable file
24
debutils/mandoc/pmt.1
Executable file
@@ -0,0 +1,24 @@
|
||||
PMT Android Partition Manager 1.8.0
|
||||
|
||||
OPTIONS:
|
||||
-b | --backup backup mode
|
||||
-F | --flash flash mode
|
||||
-r | --format format mode (only ext2/3/4 file systems)
|
||||
-p | --partition name of the partition to be backed up
|
||||
-l | --logical know that the partition that will be backed up is logical
|
||||
-o | --out (only backups) the output name of the backed-up partition (default: partition name)
|
||||
-d | --outdir (only backups) directory where the backup partition will be saved (default: /storage/emulated/0)
|
||||
-c | --context it is meant to specify a custom /dev context. Only classic partitions (default: /dev/block/by-name)
|
||||
-D | --list list partitions
|
||||
-f | --force force mode. Output is not produced. Even if it's a mistake. But if the target is not a mode, the error is given. If you want to work stable, it is important to specify this option first.
|
||||
-v | --version see version
|
||||
--help see help message
|
||||
-L | --license see license
|
||||
|
||||
EXAMPLES:
|
||||
-b --partition boot_a -o boot_slot_a_image -d /sdcard/backup -c /dev/block/platform/bootdevice/by-name
|
||||
--flash /sdcard/twrp/boot.img -p boot_a -c /dev/block/platform/bootdevice/by-name
|
||||
-c /dev/block/platform/bootdevice/by-name --list
|
||||
|
||||
BUGS:
|
||||
Report bugs to <yagizzengin73@gmail.com>
|
||||
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
# By YZBruh | ShawkTeam
|
||||
# By YZBruh
|
||||
|
||||
# Copyright 2024 Partition Manager
|
||||
#
|
||||
@@ -15,72 +15,34 @@
|
||||
# limitations under the License.
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(LOCAL_PATH)/config/env.mk
|
||||
|
||||
PMT_CFLAGS = -O3 -std=c11 -Wall $(EXTRA_COMPILER_FLAGS)
|
||||
|
||||
ifeq ($(ENABLE_DEBUGGING), true)
|
||||
PMT_CFLAGS += -g -Wextra
|
||||
else
|
||||
$(warning Unknown debugging flag: $(ENABLE_DEBUGGING). Please see: src/config/env.mk. Using non-debugging flags)
|
||||
endif
|
||||
ENVCONF := $(LOCAL_PATH)/config/env.mk
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
include $(ENVCONF)
|
||||
|
||||
LOCAL_MODULE := libpmt_root
|
||||
LOCAL_SRC_FILES := root.c
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
|
||||
LOCAL_CFLAGS := $(PMT_CFLAGS)
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := libpmt_debugging
|
||||
LOCAL_SRC_FILES := debugging.c
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
|
||||
LOCAL_CFLAGS := $(PMT_CFLAGS)
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := libpmt_partitiontool
|
||||
LOCAL_SRC_FILES := partitiontool.c
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
|
||||
LOCAL_CFLAGS := $(PMT_CFLAGS)
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := libpmt_list
|
||||
LOCAL_SRC_FILES := listpart.c
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
|
||||
LOCAL_CFLAGS := $(PMT_CFLAGS)
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := pmt
|
||||
LOCAL_SRC_FILES := \
|
||||
# configration
|
||||
LOCAL_MODULE = pmt
|
||||
LOCAL_SRC_FILES = \
|
||||
pmt.c \
|
||||
versioner.c \
|
||||
get_stat.c \
|
||||
tools.c \
|
||||
lang_tools.c \
|
||||
languages.c \
|
||||
checkers.c \
|
||||
listpart.c \
|
||||
docs.c
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libpmt_root \
|
||||
libpmt_debugging \
|
||||
libpmt_partitiontool \
|
||||
libpmt_list
|
||||
LOCAL_CFLAGS := $(PMT_CFLAGS)
|
||||
|
||||
# include dirs
|
||||
LOCAL_C_INCLUDES = $(LOCAL_PATH)/include
|
||||
|
||||
# compiler flags settings
|
||||
ifeq ($(ENABLE_DEBUGGING), true)
|
||||
LOCAL_CFLAGS = -O3 -g -Wall -Wextra $(EXTRA_COMPILER_FLAGS)
|
||||
else ifeq ($(ENABLE_DEBUGGING), false)
|
||||
LOCAL_CFLAGS = -O3 -Wall $(EXTRA_COMPILER_FLAGS)
|
||||
else
|
||||
$(warning Unknown debugging flag: $(ENABLE_DEBUGGING). Please see: $(PREDIR)/config/env.mk. Using non-debugging flags)
|
||||
LOCAL_CFLAGS = -O3 -Wall $(EXTRA_COMPILER_FLAGS)
|
||||
endif
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
# end
|
||||
# end
|
||||
@@ -1,4 +1,4 @@
|
||||
# By YZBruh | ShawkTeam
|
||||
# By YZBruh
|
||||
|
||||
# Copyright 2024 Partition Manager
|
||||
#
|
||||
@@ -23,4 +23,4 @@ APP_PLATFORM := android-21
|
||||
|
||||
APP_OPTIM := release
|
||||
|
||||
# end
|
||||
# end
|
||||
@@ -1,4 +1,4 @@
|
||||
/* By YZBruh | ShawkTeam */
|
||||
/* By YZBruh */
|
||||
|
||||
/**
|
||||
* Copyright 2024 Partition Manager
|
||||
@@ -20,38 +20,33 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define INC_MAIN_LIBS
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
#include <pmt.h>
|
||||
|
||||
extern bool pmt_use_cust_cxt;
|
||||
extern bool pmt_ab;
|
||||
extern bool pmt_logical;
|
||||
extern char* cust_cxt;
|
||||
|
||||
static int
|
||||
accf(const char* _Nonnull target) { return access(target, F_OK); }
|
||||
extern bool pmt_force_mode;
|
||||
extern char *cust_cxt;
|
||||
|
||||
/* check parts */
|
||||
void check_dev_point()
|
||||
void check_psf()
|
||||
{
|
||||
/* true = ab | false = a */
|
||||
if (pmt_use_cust_cxt)
|
||||
{
|
||||
static char cust_cxt_ck_path[150];
|
||||
sprintf(cust_cxt_ck_path, "%s/boot_a", cust_cxt);
|
||||
|
||||
if (accf(cust_cxt_ck_path) != 0)
|
||||
pmt_ab = false;
|
||||
else
|
||||
pmt_ab = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (accf("/dev/block/by-name/boot_a") != 0)
|
||||
pmt_ab = false;
|
||||
else
|
||||
pmt_ab = true;
|
||||
if (access(cust_cxt_ck_path, F_OK) != 0) pmt_ab = false;
|
||||
else pmt_ab = true;
|
||||
} else {
|
||||
if (access("/dev/block/by-name/boot_a", F_OK) != 0) pmt_ab = false;
|
||||
else pmt_ab = true;
|
||||
}
|
||||
|
||||
/* true = logical | false = classic */
|
||||
@@ -59,18 +54,25 @@ void check_dev_point()
|
||||
{
|
||||
static char cust_cxt_ckl_path[150];
|
||||
sprintf(cust_cxt_ckl_path, "%s/super", cust_cxt);
|
||||
|
||||
if (accf(cust_cxt_ckl_path) != 0)
|
||||
pmt_logical = false;
|
||||
else
|
||||
pmt_logical = true;
|
||||
if (access(cust_cxt_ckl_path, F_OK) != 0) pmt_logical = false;
|
||||
else pmt_logical = true;
|
||||
} else {
|
||||
if (access("/dev/block/by-name/super", F_OK) != 0) pmt_logical = false;
|
||||
else pmt_logical = true;
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
/* root checker function */
|
||||
void check_root()
|
||||
{
|
||||
/* a quick, easy method to verify root :D */
|
||||
if (getuid() != 0)
|
||||
{
|
||||
if (accf("/dev/block/by-name/super") != 0)
|
||||
pmt_logical = false;
|
||||
else
|
||||
pmt_logical = true;
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, ANSI_RED "Root privileges could not be detected! Please run this binary with root. Error reason: %s\n" ANSI_RESET, strerror(errno));
|
||||
exit(27);
|
||||
} else exit(27);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,4 +80,4 @@ void check_dev_point()
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* end */
|
||||
/* end of code */
|
||||
@@ -1,79 +0,0 @@
|
||||
/* By YZBruh | ShawkTeam */
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
#define INC_MAIN_LIBS
|
||||
|
||||
#include <pmt.h>
|
||||
|
||||
extern char* bin_name;
|
||||
extern bool pmt_silent;
|
||||
|
||||
extern struct pmt_langdb_general* current;
|
||||
extern struct pmt_langdb_general en;
|
||||
extern struct pmt_langdb_general tr;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* end of code */
|
||||
70
jni/docs.c
70
jni/docs.c
@@ -1,4 +1,4 @@
|
||||
/* By YZBruh | ShawkTeam */
|
||||
/* By YZBruh */
|
||||
|
||||
/*
|
||||
* Copyright 2024 Partition Manager
|
||||
@@ -20,31 +20,10 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define INC_MAIN_LIBS
|
||||
#define INC_DOCS_REQS
|
||||
#include <stdio.h>
|
||||
#include <pmt-docs.h>
|
||||
|
||||
#include <pmt.h>
|
||||
|
||||
extern char* bin_name;
|
||||
extern char* pmt_langdb_langs_docs[];
|
||||
|
||||
struct pmt_langdb_docs* curr_docs = NULL;
|
||||
extern struct pmt_langdb_docs en_docs;
|
||||
extern struct pmt_langdb_docs tr_docs;
|
||||
|
||||
static void
|
||||
prepare_langconf_docs(void)
|
||||
{
|
||||
static char* langctrl_str;
|
||||
langctrl_str = loadlang();
|
||||
|
||||
if (strcmp(langctrl_str, "en") == 0)
|
||||
curr_docs = &en_docs;
|
||||
else if (strcmp(langctrl_str, "tr") == 0)
|
||||
curr_docs = &tr_docs;
|
||||
}
|
||||
|
||||
void licenses(void)
|
||||
void licenses()
|
||||
{
|
||||
printf("Copyright 2024 Partition Manager\n");
|
||||
printf("Licensed under the Apache License, Version 2.0 (the \"License\");\n");
|
||||
@@ -57,28 +36,27 @@ void licenses(void)
|
||||
printf("See the License for the specific language governing permissions and limitations under the License.\n");
|
||||
}
|
||||
|
||||
void help(void)
|
||||
void help()
|
||||
{
|
||||
prepare_langconf_docs();
|
||||
printf("%s: %s %s\n", curr_docs->usage_docstr, bin_name, curr_docs->docs_strs_l1);
|
||||
printf(" %s: %s %s\n", curr_docs->or_str, bin_name, curr_docs->docs_strs_l2);
|
||||
printf(" %s: %s %s\n\n", curr_docs->or_str, bin_name, curr_docs->docs_strs_l3);
|
||||
printf("%s: \n", curr_docs->docs_strs_l4);
|
||||
printf(" -l, --logical %s\n", curr_docs->docs_strs_l5);
|
||||
printf(" -c, --context %s\n", curr_docs->docs_strs_l6);
|
||||
printf(" -p, --list %s\n", curr_docs->docs_strs_l7);
|
||||
printf(" -s, --silent %s\n", curr_docs->docs_strs_l8);
|
||||
printf(" -f, --force %s\n", curr_docs->docs_strs_l9);
|
||||
printf(" -S, --set-lang %s\n", curr_docs->docs_strs_l10);
|
||||
printf(" -v, --version %s\n", curr_docs->docs_strs_l11);
|
||||
printf(" --help %s\n", curr_docs->docs_strs_l12);
|
||||
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 flash /sdcard/twrp/boot.img boot_a -c /dev/block/platform/bootdevice/by-name\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 <t.me / ShawkTeam | Community / Topics -- pmt>\n", curr_docs->docs_strs_l15);
|
||||
printf("Usage: \n");
|
||||
printf(" -b | --backup backup mode\n");
|
||||
printf(" -F | --flash flash mode\n");
|
||||
printf(" -r | --format format mode (only ext2/3/4 file systems)\n");
|
||||
printf(" -p | --partition name of the partition to be backed up\n");
|
||||
printf(" -l | --logical know that the partition that will be backed up is logical\n");
|
||||
printf(" -o | --out (only backups) the output name of the backed-up partition (default: partition name)\n");
|
||||
printf(" -d | --outdir (only backups) directory where the backup partition will be saved (default: /storage/emulated/0)\n");
|
||||
printf(" -c | --context it is meant to specify a custom /dev context. Only classic partitions (default: /dev/block/by-name)\n");
|
||||
printf(" -D | --list list partitions\n");
|
||||
printf(" -f | --force force mode. Output is not produced. Even if it's a mistake. But if the target is not a mode, the error is given. If you want to work stable, it is important to specify this option first.\n");
|
||||
printf(" -v | --version see version\n");
|
||||
printf(" --help see help message\n");
|
||||
printf(" -L | --license see license\n\n");
|
||||
printf("Examples:\n");
|
||||
printf(" -b --partition boot_a -o boot_slot_a_image -d /sdcard/backup -c /dev/block/platform/bootdevice/by-name\n");
|
||||
printf(" --flash /sdcard/twrp/boot.img -p boot_a -c /dev/block/platform/bootdevice/by-name\n");
|
||||
printf(" -c /dev/block/platform/bootdevice/by-name --list\n\n");
|
||||
printf("Report bugs to <t.me/YZBruh>\n");
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/* By YZBruh | ShawkTeam */
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
#define INC_MAIN_LIBS
|
||||
#define INC_STAT
|
||||
|
||||
#include <pmt.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;
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* end of code */
|
||||
@@ -16,11 +16,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
__BEGIN_DECLS
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void help(void);
|
||||
void licenses(void);
|
||||
void help();
|
||||
void licenses();
|
||||
|
||||
__END_DECLS
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* end */
|
||||
@@ -1,105 +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.
|
||||
*/
|
||||
|
||||
#if !defined(__PMT_STRINGKEYS_)
|
||||
#define __PMT_STRINGKEYS_
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/* The struct is a very good option for setting the languages of texts etc. */
|
||||
struct pmt_langdb_general {
|
||||
const char* _Nonnull lang_by_s;
|
||||
const char* _Nonnull language;
|
||||
const char* _Nonnull lang_prefix;
|
||||
const char* _Nonnull not_logical;
|
||||
const char* _Nonnull not_file;
|
||||
const char* _Nonnull not_dir;
|
||||
const char* _Nonnull not_in_dev;
|
||||
const char* _Nonnull not_open;
|
||||
const char* _Nonnull not_block;
|
||||
const char* _Nonnull not_read;
|
||||
const char* _Nonnull not_write;
|
||||
const char* _Nonnull not_gen;
|
||||
const char* _Nonnull no_root;
|
||||
const char* _Nonnull no_target;
|
||||
const char* _Nonnull expected_backup_arg;
|
||||
const char* _Nonnull expected_flash_arg;
|
||||
const char* _Nonnull expected_format_arg;
|
||||
const char* _Nonnull missing_operand;
|
||||
const char* _Nonnull multiple_wiewers;
|
||||
const char* _Nonnull common_symbol_rule;
|
||||
const char* _Nonnull req_part_name;
|
||||
const char* _Nonnull part_not_found;
|
||||
const char* _Nonnull unsupported_fs;
|
||||
const char* _Nonnull cannot_stat;
|
||||
const char* _Nonnull ffile_more_part;
|
||||
const char* _Nonnull cannot_get_bsz;
|
||||
const char* _Nonnull format_fail;
|
||||
const char* _Nonnull logical_warn;
|
||||
const char* _Nonnull ab_warn;
|
||||
const char* _Nonnull out_not_spec;
|
||||
const char* _Nonnull please_rerun;
|
||||
const char* _Nonnull part_disk_sz;
|
||||
const char* _Nonnull flash_file_sz;
|
||||
const char* _Nonnull part_disk_sz_fail;
|
||||
const char* _Nonnull flash_file_sz_fail;
|
||||
const char* _Nonnull list_of_dir;
|
||||
const char* _Nonnull see_license;
|
||||
const char* _Nonnull success_backup;
|
||||
const char* _Nonnull success_flash;
|
||||
const char* _Nonnull warn;
|
||||
const char* _Nonnull fatal;
|
||||
const char* _Nonnull switching_lang;
|
||||
const char* _Nonnull welcome;
|
||||
const char* _Nullable welcome_;
|
||||
const char* _Nonnull for_more;
|
||||
const char* _Nonnull try_h;
|
||||
const char* _Nonnull usage_head;
|
||||
const char* _Nonnull compiler_str;
|
||||
const char* _Nonnull version_str;
|
||||
const char* _Nonnull bin_str;
|
||||
const char* _Nonnull unknw_str;
|
||||
const char* _Nonnull by_str;
|
||||
};
|
||||
|
||||
/* docs, licenses etc. */
|
||||
struct pmt_langdb_docs {
|
||||
const char* _Nonnull docs_strs_l1;
|
||||
const char* _Nonnull docs_strs_l2;
|
||||
const char* _Nonnull docs_strs_l3;
|
||||
const char* _Nonnull docs_strs_l4;
|
||||
const char* _Nonnull docs_strs_l5;
|
||||
const char* _Nonnull docs_strs_l6;
|
||||
const char* _Nonnull docs_strs_l7;
|
||||
const char* _Nonnull docs_strs_l8;
|
||||
const char* _Nonnull docs_strs_l9;
|
||||
const char* _Nonnull docs_strs_l10;
|
||||
const char* _Nonnull docs_strs_l11;
|
||||
const char* _Nonnull docs_strs_l12;
|
||||
const char* _Nonnull docs_strs_l13;
|
||||
const char* _Nonnull docs_strs_l14;
|
||||
const char* _Nonnull docs_strs_l15;
|
||||
const char* _Nonnull or_str;
|
||||
const char* _Nonnull usage_docstr;
|
||||
};
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* __PMT_STRINGKEYS_ */
|
||||
|
||||
/* end of code */
|
||||
@@ -16,27 +16,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#include <android/ndk-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
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* versioning */
|
||||
#define PMT_MAJOR 2
|
||||
#define PMT_MINOR 4
|
||||
#define PMT_PATCHLEVEL 0
|
||||
#define PMT_LEVEL 0
|
||||
#define PMT_PATCH 0
|
||||
|
||||
__END_DECLS
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* end */
|
||||
@@ -16,112 +16,49 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(__PMT_H_)
|
||||
#define __PMT_H_
|
||||
|
||||
#define PMT_PACKAGE_NAME "Partition Manager"
|
||||
/* some definations */
|
||||
#define ANSI_RED "\033[31m"
|
||||
#define ANSI_YELLOW "\033[33m"
|
||||
#define ANSI_GREEN "\033[32m"
|
||||
#define ANSI_RESET "\033[0m"
|
||||
|
||||
#if defined(INC_MAIN_LIBS)
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <pmt-stringkeys.h>
|
||||
#endif
|
||||
|
||||
#if defined(INC_GETOPT)
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
|
||||
#if defined(INC_DIRENT)
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
#if defined(INC_STAT)
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#if defined(INC_DEBUGERS)
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#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 <sys/statvfs.h>
|
||||
#endif
|
||||
#define PMT_PACKAGE_NAME "Partition Manager"
|
||||
|
||||
/* variable definations */
|
||||
extern char* _Nullable out;
|
||||
extern char* _Nullable cust_cxt;
|
||||
extern char* _Nullable target_partition;
|
||||
extern char* _Nullable target_flash_file;
|
||||
extern char* _Nullable format_fs;
|
||||
extern char* _Nullable partition_type;
|
||||
extern char* _Nullable bin_name;
|
||||
extern char *out;
|
||||
extern char *outdir;
|
||||
extern char *cust_cxt;
|
||||
extern char *target_partition;
|
||||
extern char *target_flash_file;
|
||||
extern char *format_fs;
|
||||
extern char *partition_type;
|
||||
extern bool pmt_use_logical;
|
||||
extern bool pmt_use_cust_cxt;
|
||||
extern bool pmt_ab;
|
||||
extern bool pmt_logical;
|
||||
extern bool pmt_silent;
|
||||
extern bool pmt_flash;
|
||||
extern bool pmt_backup;
|
||||
extern bool pmt_format;
|
||||
extern bool pmt_force_mode;
|
||||
extern bool pmt_inst_on_termux;
|
||||
|
||||
/* language struces configurations */
|
||||
extern struct pmt_langdb_general* _Nullable current;
|
||||
extern struct pmt_langdb_docs* _Nullable curr_docs;
|
||||
extern struct pmt_langdb_general en;
|
||||
extern struct pmt_langdb_general tr;
|
||||
extern struct pmt_langdb_docs en_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 */
|
||||
int listpart(void);
|
||||
void check_dev_point(void);
|
||||
void check_root(void);
|
||||
int pmt(unsigned short progress_code);
|
||||
void version(void);
|
||||
void setlang(const char* _Nonnull lang);
|
||||
int search_sls(void);
|
||||
char* _Nonnull loadlang(void);
|
||||
void debug(LogLevel status, const char* _Nullable fmt, ...);
|
||||
void listpart();
|
||||
void check_psf();
|
||||
void check_root();
|
||||
void pmt(unsigned short progress_code);
|
||||
void version();
|
||||
|
||||
/* 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 /* __PMT_H_ */
|
||||
|
||||
#endif
|
||||
|
||||
__END_DECLS
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* end of code */
|
||||
|
||||
220
jni/lang_tools.c
220
jni/lang_tools.c
@@ -1,220 +0,0 @@
|
||||
/* By YZBruh | ShawkTeam */
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
#define INC_MAIN_LIBS
|
||||
#define INC_DEBUGERS
|
||||
#define INC_STAT
|
||||
|
||||
#include <pmt.h>
|
||||
|
||||
/* pmt's man doc file path on termux */
|
||||
#define TERMUX_PMT_MANDOC "/data/data/com.termux/files/usr/share/man/man8/pmt.8.gz"
|
||||
|
||||
/* language configuration paths */
|
||||
|
||||
/* for termux */
|
||||
#define TERMUX_PMTLANG_CONF "/data/data/com.termux/files/usr/etc/pmtlang.conf"
|
||||
|
||||
/* for internal storage */
|
||||
#define INTRNL_PMTLANG_CONF "/sdcard/.pmtlang.conf"
|
||||
|
||||
/* shortcuts to check that language is changed */
|
||||
|
||||
/* 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;
|
||||
|
||||
static int
|
||||
langctrl(const char* _Nonnull lang_)
|
||||
{
|
||||
if (strcmp(lang_, "en") == 0 || strcmp(lang_, "tr") == 0)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* loadlang(void)
|
||||
{
|
||||
static char lang_fpr[10] = "en";
|
||||
langconf = NULL;
|
||||
|
||||
if (get_stat(TERMUX_PMT_MANDOC, "file") == 0)
|
||||
pmt_inst_on_termux = true;
|
||||
|
||||
if (pmt_inst_on_termux)
|
||||
{
|
||||
if (get_stat(TERMUX_PMTLANG_CONF, "file") == 0)
|
||||
{
|
||||
langconf = fopen(TERMUX_PMTLANG_CONF, "r+");
|
||||
|
||||
if (langconf == NULL)
|
||||
{
|
||||
langconf = fopen(TERMUX_PMTLANG_CONF, "w+");
|
||||
|
||||
if (langconf == NULL)
|
||||
{
|
||||
setlang("en");
|
||||
return "en";
|
||||
}
|
||||
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
|
||||
{
|
||||
if (get_stat(INTRNL_PMTLANG_CONF, "file") == 0)
|
||||
{
|
||||
langconf = fopen(INTRNL_PMTLANG_CONF, "r");
|
||||
|
||||
if (langconf == NULL)
|
||||
{
|
||||
langconf = fopen(INTRNL_PMTLANG_CONF, "w+");
|
||||
|
||||
if (langconf == NULL)
|
||||
{
|
||||
setlang("en");
|
||||
return "en";
|
||||
}
|
||||
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 (get_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)
|
||||
LOGE("Failed!!! Cannot open/write config file.\n");
|
||||
|
||||
if (langctrl(lang) == 0)
|
||||
{
|
||||
if (fprintf(langconf, "%s", lang) < 2)
|
||||
LOGE("Failed!!! Couldn't write config!\n");
|
||||
else
|
||||
fclose(langconf);
|
||||
}
|
||||
else
|
||||
LOGE("Unknown language: %s.\n", lang);
|
||||
|
||||
static int status;
|
||||
|
||||
if (pmt_inst_on_termux)
|
||||
{
|
||||
status = open(TERMUX_PMT_SW_POINT, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
if (status == 0)
|
||||
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)
|
||||
{
|
||||
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 (get(sw_point_path, "file") == 0)
|
||||
{
|
||||
remove(sw_point_path);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* end of code */
|
||||
189
jni/languages.c
189
jni/languages.c
@@ -1,189 +0,0 @@
|
||||
/* By YZBruh | ShawkTeam */
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
#define INC_MAIN_LIBS
|
||||
|
||||
#include <pmt.h>
|
||||
|
||||
struct pmt_langdb_general en = {
|
||||
.lang_by_s = "YZBruh & r0manas",
|
||||
.language = "English",
|
||||
.lang_prefix = "en",
|
||||
.not_logical = "This device does not have logical partitions!",
|
||||
.not_file = "is not a file.",
|
||||
.not_dir = "is not a directory.",
|
||||
.not_in_dev = "Nothing found in /dev. Use force mode to avoid this error.",
|
||||
.not_open = "Couldn't open",
|
||||
.not_block = "The specified partition is not recognized as a block device.",
|
||||
.not_read = "Couldn't read",
|
||||
.not_write = "Couldn't write",
|
||||
.not_gen = "Couldn't generate",
|
||||
.no_root = "Root access could not be detected! Please run this with root permissions.",
|
||||
.no_target = "No target specified (backup, flash, or format).",
|
||||
.expected_backup_arg = "Expected backup argument 2 (1 of them are not mandatory), retrieved",
|
||||
.expected_flash_arg = "Expected flash argument 2, retrieved",
|
||||
.expected_format_arg = "Expected format argument 2, retrieved",
|
||||
.missing_operand = "Missing operand",
|
||||
.multiple_wiewers = "Multiple viewers can't be used on 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.",
|
||||
.req_part_name = "Partition name required.",
|
||||
.part_not_found = "Partition not found!",
|
||||
.unsupported_fs = "Formatter: unsupported filesystem",
|
||||
.cannot_stat = "Can't retrieve file status",
|
||||
.ffile_more_part = "Flash file size exceeds partition capacity.",
|
||||
.cannot_get_bsz = "Failed to retrieve partition block size.",
|
||||
.format_fail = "Formatting failed! There is a possibility of data damage.",
|
||||
.logical_warn = "This device uses logical partitions.",
|
||||
.ab_warn = "This device uses A/B partition style.",
|
||||
.out_not_spec = "Output file name not specified. Using default name:",
|
||||
.please_rerun = "Please rerun the command.",
|
||||
.part_disk_sz = "Partition disk size",
|
||||
.flash_file_sz = "Flash file size",
|
||||
.part_disk_sz_fail = "Failed to retrieve partition disk size.",
|
||||
.flash_file_sz_fail = "Failed to retrieve flash file size.",
|
||||
.list_of_dir = "Directory listing",
|
||||
.see_license = "View licenses using the -L argument.",
|
||||
.success_backup = "Backup successful. Output:",
|
||||
.success_flash = "Flash successful.",
|
||||
.warn = "WARNING",
|
||||
.fatal = "FATAL ERROR",
|
||||
.switching_lang = "Switching language...",
|
||||
.welcome = "language!",
|
||||
.welcome_ = "Welcome to ",
|
||||
.for_more = "for more information",
|
||||
.try_h = "Try",
|
||||
.usage_head = "Usage",
|
||||
.compiler_str = "Compiler",
|
||||
.version_str = "version",
|
||||
.bin_str = "binary",
|
||||
.unknw_str = "unknown",
|
||||
.by_str = "By"
|
||||
};
|
||||
|
||||
struct pmt_langdb_general tr = {
|
||||
.lang_by_s = "YZBruh",
|
||||
.language = "Türkçe",
|
||||
.lang_prefix = "tr",
|
||||
.not_logical = "Bu cihaz mantıksal (logical) bölümlere sahip değil!",
|
||||
.not_file = "Bu bir dosya değil",
|
||||
.not_dir = "Bu bir dizin değil",
|
||||
.not_in_dev = "Bu bir şakamı? Bunun /dev dizini ile bi r ilgisi yok (içermiyor). Bu hatayla karşılaşmak istemiyorsanız zorlama (force) modu kullanın.",
|
||||
.not_open = "Açı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_read = "Veri okunamıyor",
|
||||
.not_write = "Veri yazılamıyor",
|
||||
.not_gen = "Oluşturulamıyor",
|
||||
.no_root = "Root erişimi tespit edilemedi! Lütfen root erişimi ile çalıştırın.",
|
||||
.no_target = "Hedef işlem yok (yedek, flaş veya format).",
|
||||
.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_format_arg = "Beklenen format argümanı 2, alınan",
|
||||
.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.",
|
||||
.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.",
|
||||
.part_not_found = "Bölüm bulunamadı!",
|
||||
.unsupported_fs = "Formatlayıcı: desteklenmeyen dosya sistemi:",
|
||||
.cannot_stat = "Durumu tespit edilemedi",
|
||||
.ffile_more_part = "Flaşlanacak dosyanın boyutu mevcut bölüm boyutundan fazla.",
|
||||
.cannot_get_bsz = "Bölüm blok boyutu tespit edilemedi!",
|
||||
.format_fail = "Formatlama başarısız oldu. Bazı şeyler zarar görmüş olabilir!",
|
||||
.logical_warn = "Uyarı: bu cihaz mantıksal (logical) bölümlere sahip.",
|
||||
.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.",
|
||||
.please_rerun = "Lütfen yeniden çalıştırın",
|
||||
.part_disk_sz = "Bölümün disk boyutu",
|
||||
.flash_file_sz = "Flaşlanacak dosyanın boyutu",
|
||||
.flash_file_sz_fail = "Uyarı: flaşlanacak dosyanın boyutu tespit edilemedi.",
|
||||
.part_disk_sz_fail = "Uyarı: bölüm boyutunun boyutu tespit edilemedi.",
|
||||
.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_flash = "Başarılı.",
|
||||
.warn = "UYARI",
|
||||
.fatal = "KRİTİK HATA",
|
||||
.switching_lang = "Dil değiştiriliyor...",
|
||||
.welcome = "diline hoş geldiniz!",
|
||||
.welcome_ = NULL,
|
||||
.for_more = "komutunu kullanabilirsiniz",
|
||||
.try_h = "Daha fazla bilgi",
|
||||
.usage_head = "Kullanımı",
|
||||
.compiler_str = "Derleyici",
|
||||
.version_str = "versiyon",
|
||||
.bin_str = "yapı",
|
||||
.unknw_str = "bilinmeyen",
|
||||
.by_str = "Çeviriyi yapan(lar):"
|
||||
};
|
||||
|
||||
struct pmt_langdb_docs en_docs = {
|
||||
.docs_strs_l1 = "backup PARTITION [OUTPUT] [OPTIONS]...",
|
||||
.docs_strs_l2 = "flash FILE PARTITION [OPTIONS]...",
|
||||
.docs_strs_l3 = "format FILE_SYSTEM[ext/2/3/4] PARTITION [OPTIONS]...",
|
||||
.docs_strs_l4 = "Options",
|
||||
.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_l7 = "List partitions.",
|
||||
.docs_strs_l8 = "Information and warning messages are silenced in normal work.",
|
||||
.docs_strs_l9 = "Force mode. Some things are ignored.",
|
||||
.docs_strs_l10 = "Set current language.",
|
||||
.docs_strs_l11 = "See version.",
|
||||
.docs_strs_l12 = "See this help message.",
|
||||
.docs_strs_l13 = "See license.",
|
||||
.docs_strs_l14 = "Examples",
|
||||
.docs_strs_l15 = "Report bugs to",
|
||||
.or_str = "or",
|
||||
.usage_docstr = "Usage"
|
||||
};
|
||||
|
||||
struct pmt_langdb_docs tr_docs = {
|
||||
.docs_strs_l1 = "backup BÖLÜM [ÇIKTI] [SEÇENEKLER]...",
|
||||
.docs_strs_l2 = "flash DOSYA BÖLÜM [SEÇENEKLER]...",
|
||||
.docs_strs_l3 = "format DOSYA_SİSTEMİ[ext/2/3/4] BÖLÜM [SEÇENEKLER]...",
|
||||
.docs_strs_l4 = "Seçenekler",
|
||||
.docs_strs_l5 = "Bu seçeneği kullanarak mantıksal (logical) bir bölümle işlem yapılacağını belirtebilirsiniz.",
|
||||
.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_l8 = "Bilgi ve uyarı mesajları susturulur.",
|
||||
.docs_strs_l9 = "Zorlama modu. Bazı şeyler göz ardı edilir.",
|
||||
.docs_strs_l10 = "Mevcut dili ayarlayın.",
|
||||
.docs_strs_l11 = "Sürümü görüntüleyin.",
|
||||
.docs_strs_l12 = "Bu yardım mesajını görüntüleyin.",
|
||||
.docs_strs_l13 = "Lisansı gorüntüleyin.",
|
||||
.docs_strs_l14 = "Örnekler",
|
||||
.docs_strs_l15 = "Sorunları şu adrese bildirin:",
|
||||
.or_str = "yada",
|
||||
.usage_docstr = "Kullanımı"
|
||||
};
|
||||
|
||||
char* pmt_langdb_langs[] = {
|
||||
"en",
|
||||
"tr"
|
||||
};
|
||||
|
||||
int pmt_langdb_total = 2;
|
||||
int pmt_langdb_ctrl = 1;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* end of code */
|
||||
130
jni/listpart.c
130
jni/listpart.c
@@ -1,4 +1,4 @@
|
||||
/* By YZBruh | ShawkTeam */
|
||||
/* By YZBruh */
|
||||
|
||||
/**
|
||||
* Copyright 2024 Partition Manager
|
||||
@@ -20,115 +20,67 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define INC_MAIN_LIBS
|
||||
#define INC_DEBUGERS
|
||||
#define INC_DIRENT
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
#include <pmt.h>
|
||||
|
||||
/* current /dev context */
|
||||
#define CUR_DEV_CNTX "/dev/block/by-name"
|
||||
|
||||
/* for logical partitions */
|
||||
#define LGC_DEV_CNTX "/dev/block/mapper"
|
||||
|
||||
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
|
||||
list(const char* operation, const char* target_dir)
|
||||
{
|
||||
static bool list = false;
|
||||
struct dirent *entry;
|
||||
dir = NULL;
|
||||
|
||||
if (strcmp(operation, "access") == 0)
|
||||
list = false;
|
||||
else if (strcmp(operation, "print") == 0)
|
||||
list = true;
|
||||
else
|
||||
return -1;
|
||||
|
||||
dir = opendir(target_dir);
|
||||
|
||||
if (dir != NULL)
|
||||
{
|
||||
if (!list)
|
||||
{
|
||||
closedir(dir);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGD("%s: `%s'\n", current->list_of_dir, target_dir);
|
||||
while ((entry = readdir(dir)) != NULL)
|
||||
{
|
||||
LOGD("%s\n", entry->d_name);
|
||||
}
|
||||
closedir(dir);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
|
||||
return 2;
|
||||
}
|
||||
extern char *cust_cxt;
|
||||
|
||||
/* list existing partitions */
|
||||
int listpart(void)
|
||||
{
|
||||
void listpart() {
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
||||
if (pmt_use_cust_cxt)
|
||||
{
|
||||
if (list("access", cust_cxt) != 0)
|
||||
dir = opendir(cust_cxt);
|
||||
if (dir == NULL)
|
||||
{
|
||||
if (!pmt_force_mode) {
|
||||
fprintf(stderr, "Could not open: `%s`. Error reason: %s\n", cust_cxt, strerror(errno));
|
||||
exit(62);
|
||||
} else exit(62);
|
||||
}
|
||||
} else {
|
||||
dir = opendir("/dev/block/by-name");
|
||||
if (dir == NULL)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
LOGE("%s: `%s': %s\n", current->not_open, cust_cxt, strerror(errno));
|
||||
else
|
||||
return 1;
|
||||
{
|
||||
fprintf(stderr, "Could not open: `/dev/block/by-name`. Error reason: %s\n", strerror(errno));
|
||||
exit(63);
|
||||
} else exit(63);
|
||||
}
|
||||
else
|
||||
list("print", cust_cxt);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (list("access", CUR_DEV_CNTX) != 0)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
LOGE("%s: `%s': %s\n", current->not_open, CUR_DEV_CNTX, strerror(errno));
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
list("print", CUR_DEV_CNTX);
|
||||
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
printf("%s\n", entry->d_name);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
||||
if (pmt_logical)
|
||||
{
|
||||
if (list("access", LGC_DEV_CNTX) != 0)
|
||||
LOGE("%s: `%s': %s\n", current->not_open, LGC_DEV_CNTX, strerror(errno));
|
||||
else
|
||||
list("print", LGC_DEV_CNTX);
|
||||
printf("List of logical partitions (/dev/block/mapper): \n");
|
||||
if (system("ls /dev/block/mapper") != 0 && !pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "%sAn error occurred when the logical partition list appears!%s\n", ANSI_RED, ANSI_RESET);
|
||||
exit(64);
|
||||
}
|
||||
}
|
||||
|
||||
if (pmt_ab)
|
||||
LOGD("%s: %s\n", bin_name, current->ab_warn);
|
||||
if (pmt_ab && !pmt_force_mode) printf("%sWarning: device using A/B partition style.%s\n", ANSI_YELLOW, ANSI_RESET);
|
||||
|
||||
if (pmt_logical)
|
||||
LOGD("%s: %s\n", bin_name, current->logical_warn);
|
||||
|
||||
return 0;
|
||||
if (pmt_logical && !pmt_force_mode) printf("%sWarning: device using logical partition type.%s\n", ANSI_YELLOW, ANSI_RESET);
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
469
jni/pmt.c
469
jni/pmt.c
@@ -1,4 +1,4 @@
|
||||
/* By YZBruh | ShawkTeam */
|
||||
/* By YZBruh */
|
||||
|
||||
/**
|
||||
* Copyright 2024 Partition Manager
|
||||
@@ -21,96 +21,57 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define INC_MAIN_LIBS
|
||||
#define INC_DEBUGERS
|
||||
#define INC_STAT
|
||||
#define INC_GETOPT
|
||||
#define INC_DOCS_REQS
|
||||
|
||||
/* include needed libs (headers) */
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <getopt.h>
|
||||
#include <errno.h>
|
||||
#include <pmt.h>
|
||||
#include <pmt-docs.h>
|
||||
|
||||
/* add value to variables that are added globally and are not worth */
|
||||
char* out = NULL;
|
||||
char* cust_cxt = NULL;
|
||||
char* target_partition = NULL;
|
||||
char* target_flash_file = NULL;
|
||||
char* partition_type = NULL;
|
||||
char* format_fs = NULL;
|
||||
char* bin_name = NULL;
|
||||
bool pmt_use_logical = false;
|
||||
bool pmt_use_cust_cxt = false;
|
||||
char *out = NULL;
|
||||
char *outdir = NULL;
|
||||
char *cust_cxt = NULL;
|
||||
char *target_partition = NULL;
|
||||
char *target_flash_file = NULL;
|
||||
char *partition_type = NULL;
|
||||
char *format_fs = NULL;
|
||||
bool pmt_use_logical = NULL;
|
||||
bool pmt_use_cust_cxt = NULL;
|
||||
bool pmt_ab = false;
|
||||
bool pmt_logical = false;
|
||||
bool pmt_silent = false;
|
||||
bool pmt_flash = false;
|
||||
bool pmt_backup = false;
|
||||
bool pmt_format = false;
|
||||
bool pmt_force_mode = 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 */
|
||||
static const char* opt_symbol = "-";
|
||||
static char common_symbol_rule[350];
|
||||
|
||||
/**
|
||||
* He controls whether the '-' sign at
|
||||
* the beginning of the given word
|
||||
*/
|
||||
static void
|
||||
check_optsym(const char* _Nonnull mystring)
|
||||
{
|
||||
if (strncmp(mystring, opt_symbol, 1) == 0)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
LOGE("%s\n", common_symbol_rule);
|
||||
else
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* classic main function (C binary here xd) */
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
bin_name = argv[0];
|
||||
|
||||
/* load language */
|
||||
static char* langctrl_str;
|
||||
langctrl_str = loadlang();
|
||||
|
||||
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 (current->welcome_ != NULL)
|
||||
LOGD("%s", current->welcome_);
|
||||
|
||||
LOGD("%s %s %s %s.\n", current->language, current->welcome, current->by_str, current->lang_by_s);
|
||||
}
|
||||
|
||||
/* check argument total */
|
||||
if (argc < 2)
|
||||
LOGE("%s\n%s `%s --help' %s.\n", current->missing_operand, current->try_h, argv[0], current->for_more);
|
||||
{
|
||||
fprintf(stderr, "%s: missing operand\nTry `%s --help' for more information.\n", argv[0], argv[0]);
|
||||
exit(44);
|
||||
}
|
||||
|
||||
/* a structure for long arguments */
|
||||
/* a structure for long arguments... */
|
||||
struct option long_options[] = {
|
||||
{"backup", no_argument, 0, 'b'},
|
||||
{"flash", required_argument, 0, 'F'},
|
||||
{"format", required_argument, 0, 'r'},
|
||||
{"partition", required_argument, 0, 'p'},
|
||||
{"logical", no_argument, 0, 'l'},
|
||||
{"out", required_argument, 0, 'o'},
|
||||
{"outdir", required_argument, 0, 'd'},
|
||||
{"context", required_argument, 0, 'c'},
|
||||
{"list", no_argument, 0, 'p'},
|
||||
{"silent", no_argument, 0, 's'},
|
||||
{"list", no_argument, 0, 'D'},
|
||||
{"force", no_argument, 0, 'f'},
|
||||
{"set-language", required_argument, 0, 'S'},
|
||||
{"version", no_argument, 0, 'v'},
|
||||
{"help", no_argument, 0, 0},
|
||||
{"license", no_argument, 0, 'L'},
|
||||
@@ -123,36 +84,108 @@ int main(int argc, char* argv[])
|
||||
static bool wiew_version = false;
|
||||
static bool list_partitions = false;
|
||||
static bool combo_wiewers = false;
|
||||
static bool pmt_setlang = false;
|
||||
static char* langpr;
|
||||
static int search_result = 3;
|
||||
static int getvar_temp;
|
||||
static int check_getvar_temp;
|
||||
static int opt;
|
||||
static bool use_cust_outdir = false;
|
||||
static char *opt_symbol = "-";
|
||||
static char *common_symbol_rule;
|
||||
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.";
|
||||
|
||||
int opt;
|
||||
|
||||
/* control for each argument */
|
||||
while ((opt = getopt_long(argc, argv, "lc:psfS:vL", long_options, NULL)) != -1)
|
||||
while ((opt = getopt_long(argc, argv, "bF:rp:lo:d:c:DfvL", long_options, NULL)) != -1)
|
||||
{
|
||||
/* process arguments */
|
||||
switch (opt)
|
||||
{
|
||||
/* backup mode */
|
||||
case 'b':
|
||||
pmt_backup = true;
|
||||
break;
|
||||
/* flash mode */
|
||||
case 'F':
|
||||
target_flash_file = strdup(optarg);
|
||||
if (strncmp(target_flash_file, opt_symbol, 1) == 0)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "%s%s%s\n", ANSI_RED, common_symbol_rule, ANSI_RESET);
|
||||
exit(19);
|
||||
} else exit(19);
|
||||
}
|
||||
pmt_flash = true;
|
||||
break;
|
||||
/* format mode */
|
||||
case 'r':
|
||||
format_fs = strdup(optarg);
|
||||
if (strncmp(format_fs, opt_symbol, 1) == 0)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "%s%s%s\n", ANSI_RED, common_symbol_rule, ANSI_RESET);
|
||||
exit(19);
|
||||
} else exit(19);
|
||||
}
|
||||
pmt_format = true;
|
||||
break;
|
||||
/* partition selector option */
|
||||
case 'p':
|
||||
target_partition = strdup(optarg);
|
||||
if (strncmp(target_partition, opt_symbol, 1) == 0)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "%s%s%s\n", ANSI_RED, common_symbol_rule, ANSI_RESET);
|
||||
exit(19);
|
||||
} else exit(19);
|
||||
}
|
||||
break;
|
||||
/* logical partitions option */
|
||||
case 'l':
|
||||
check_root();
|
||||
check_dev_point();
|
||||
check_psf();
|
||||
if (pmt_logical)
|
||||
{
|
||||
pmt_use_logical = true;
|
||||
else
|
||||
LOGE("%s\n", current->not_logical);
|
||||
} else {
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "This device does not have logical partitions!\n");
|
||||
exit(17);
|
||||
} else exit(17);
|
||||
}
|
||||
break;
|
||||
/* output file option */
|
||||
case 'o':
|
||||
out = strdup(optarg);
|
||||
if (strncmp(out, opt_symbol, 1) == 0)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "%s%s%s\n", ANSI_RED, common_symbol_rule, ANSI_RESET);
|
||||
exit(19);
|
||||
} else exit(19);
|
||||
}
|
||||
break;
|
||||
/* output dir option */
|
||||
case 'd':
|
||||
use_cust_outdir = true;
|
||||
outdir = strdup(optarg);
|
||||
break;
|
||||
/* context selector option */
|
||||
case 'c':
|
||||
pmt_use_cust_cxt = true;
|
||||
cust_cxt = strdup(optarg);
|
||||
check_optsym(cust_cxt);
|
||||
if (strncmp(cust_cxt, opt_symbol, 1) == 0)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "%s%s%s\n", ANSI_RED, common_symbol_rule, ANSI_RESET);
|
||||
exit(19);
|
||||
} else exit(19);
|
||||
}
|
||||
break;
|
||||
/* partition lister function */
|
||||
case 'p':
|
||||
case 'D':
|
||||
list_partitions = true;
|
||||
/* check combo wiewer options and progress */
|
||||
if (wiew_version || wiew_help || wiew_licenses) combo_wiewers = true;
|
||||
@@ -161,15 +194,6 @@ int main(int argc, char* argv[])
|
||||
case 'f':
|
||||
pmt_force_mode = true;
|
||||
break;
|
||||
/* silent mode option */
|
||||
case 's':
|
||||
pmt_silent = true;
|
||||
break;
|
||||
/* language setter option */
|
||||
case 'S':
|
||||
pmt_setlang = true;
|
||||
langpr = strdup(optarg);
|
||||
break;
|
||||
/* version info option */
|
||||
case 'v':
|
||||
wiew_version = true;
|
||||
@@ -190,175 +214,165 @@ int main(int argc, char* argv[])
|
||||
break;
|
||||
/* for invalid options */
|
||||
case '?':
|
||||
LOGD("%s `%s --help' %s\n", current->try_h, argv[0], current->for_more);
|
||||
return 1;
|
||||
printf("Try `%s --help' for more information.\n", argv[0]);
|
||||
exit(43);
|
||||
break;
|
||||
default:
|
||||
LOGD("%s: %s [backup] [flash] [format] [-l | --logical] [-c | --context] [-D | --list] [-v | --version] [--help] [-L | --license]\n", current->usage_head, argv[0]);
|
||||
return 1;
|
||||
printf("Usage: %s [-b | --backup] [-f | --flash FILE] [-r | --format FS_TYPE] [-p | --partition PARTITION] [-l | --logical] [-o | --out OUTNAME] [-d | --outdir OUTDIR] [-c | --context] [-D | --list] [-v | --version] [--help] [-L | --license]\n", argv[0]);
|
||||
exit(44);
|
||||
}
|
||||
}
|
||||
|
||||
/* stop the program if multiple viewer is used */
|
||||
if (combo_wiewers)
|
||||
LOGE("%s", current->multiple_wiewers);
|
||||
{
|
||||
fprintf(stderr, "%s: Multiple wiewers cannot be used at the same line.\n", argv[0]);
|
||||
exit(81);
|
||||
}
|
||||
|
||||
/* controller to handle viewer */
|
||||
if (wiew_help)
|
||||
{
|
||||
help();
|
||||
return 0;
|
||||
}
|
||||
else if (wiew_version)
|
||||
exit(EXIT_SUCCESS);
|
||||
} else if (wiew_version)
|
||||
{
|
||||
version();
|
||||
return 0;
|
||||
}
|
||||
else if (wiew_licenses)
|
||||
exit(EXIT_SUCCESS);
|
||||
} else if (wiew_licenses)
|
||||
{
|
||||
licenses();
|
||||
return 0;
|
||||
}
|
||||
else if (list_partitions)
|
||||
exit(EXIT_SUCCESS);
|
||||
} else if (list_partitions)
|
||||
{
|
||||
check_root();
|
||||
return listpart();
|
||||
}
|
||||
|
||||
if (pmt_setlang)
|
||||
{
|
||||
LOGD("%s: %s\n", argv[0], current->switching_lang);
|
||||
setlang(langpr);
|
||||
sleep(2);
|
||||
LOGD("%s: %s.\n", argv[0], current->please_rerun);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* detect target mode */
|
||||
static char arg1[20];
|
||||
sprintf(arg1, "%s", argv[1]);
|
||||
|
||||
for (int argtest = 2; argtest == argc; argtest++)
|
||||
{
|
||||
getvar_temp = argtest;
|
||||
check_getvar_temp = getvar_temp;
|
||||
getvar_temp++;
|
||||
|
||||
if (strcmp(argv[argtest], "backup") == 0)
|
||||
{
|
||||
check_getvar_temp++;
|
||||
|
||||
if (argc < check_getvar_temp)
|
||||
LOGE("%s 0.\n", current->expected_backup_arg);
|
||||
|
||||
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)
|
||||
LOGE("%s 0.\n", current->expected_flash_arg);
|
||||
|
||||
if (argc == check_getvar_temp)
|
||||
LOGE("%s 1.\n", current->expected_flash_arg);
|
||||
|
||||
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)
|
||||
LOGE("%s 0.\n", current->expected_format_arg);
|
||||
|
||||
if (argc == check_getvar_temp)
|
||||
LOGE("%s 1.\n", current->expected_format_arg);
|
||||
|
||||
format_fs = argv[getvar_temp];
|
||||
|
||||
getvar_temp++;
|
||||
target_partition = argv[getvar_temp];
|
||||
|
||||
check_optsym(format_fs);
|
||||
check_optsym(target_partition);
|
||||
|
||||
pmt_format = true;
|
||||
|
||||
break;
|
||||
}
|
||||
listpart();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/* target control is done */
|
||||
if (!pmt_backup && !pmt_flash && !pmt_format)
|
||||
LOGE("%s `%s --help` %s\n", current->missing_operand, current->try_h, current->for_more);
|
||||
{
|
||||
fprintf(stderr, "%s: missing operand.\nTry `%s --help` for more information.\n", argv[0], argv[0]);
|
||||
exit(3);
|
||||
}
|
||||
|
||||
/* prevent multiple mode use */
|
||||
if (pmt_backup && pmt_flash)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "Backup and flash functions cannot be used in the same command.\n");
|
||||
exit(9);
|
||||
} else exit(9);
|
||||
}
|
||||
|
||||
/* checks */
|
||||
check_root();
|
||||
check_dev_point();
|
||||
check_psf();
|
||||
|
||||
if (pmt_format)
|
||||
{
|
||||
if (strcmp(format_fs, "ext4") != 0 || strcmp(format_fs, "ext3") != 0 || strcmp(format_fs, "ext2") != 0)
|
||||
LOGE("%s: %s\n", current->unsupported_fs, format_fs);
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "%s: formatter: unsupported filesystem: %s", argv[0], format_fs);
|
||||
exit(41);
|
||||
} else exit(41);
|
||||
}
|
||||
}
|
||||
|
||||
if (use_cust_outdir)
|
||||
{
|
||||
if (strncmp(outdir, opt_symbol, 1) == 0)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "%s\n", common_symbol_rule);
|
||||
exit(19);
|
||||
} else exit(19);
|
||||
}
|
||||
struct stat out_info;
|
||||
if (stat(outdir, &out_info) != 0)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "%s: cannot stat '%s': %s\n", argv[0], outdir, strerror(errno));
|
||||
exit(18);
|
||||
} else exit(18);
|
||||
} else {
|
||||
if (!S_ISDIR(out_info.st_mode))
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "%s: %s: is a not directory.\n", argv[0], outdir);
|
||||
exit(20);
|
||||
} else exit(20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pmt_flash)
|
||||
{
|
||||
search_result = get_stat(target_flash_file, "file");
|
||||
|
||||
if (search_result == 1)
|
||||
LOGE("%s `%s': %s\n", current->cannot_stat, target_flash_file, strerror(errno));
|
||||
else if (search_result == -1)
|
||||
LOGE("`%s': %s\n", target_flash_file, current->not_file);
|
||||
struct stat flashf_info;
|
||||
if (stat(target_flash_file, &flashf_info) != 0)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "%s: cannot stat '%s': %s\n", argv[0], target_flash_file, strerror(errno));
|
||||
exit(15);
|
||||
} else exit(15);
|
||||
} else {
|
||||
if (!S_ISREG(flashf_info.st_mode))
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "%s: %s: is a not file.\n", argv[0], target_flash_file);
|
||||
exit(16);
|
||||
} else exit(16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* custom context checker */
|
||||
if (pmt_use_cust_cxt)
|
||||
{
|
||||
search_result = get_stat(cust_cxt, "dir");
|
||||
|
||||
if (search_result == 1)
|
||||
LOGE("%s `%s': %s\n", current->cannot_stat, cust_cxt, strerror(errno));
|
||||
else if (search_result == -1)
|
||||
LOGE("`%s': %s\n", cust_cxt, current->not_dir);
|
||||
|
||||
struct stat cxtinfo;
|
||||
if (stat(cust_cxt, &cxtinfo) == 0)
|
||||
{
|
||||
if (!S_ISREG(cxtinfo.st_mode))
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "%s: %s: is a not directory.\n", argv[0], cust_cxt);
|
||||
exit(8);
|
||||
} else exit(8);
|
||||
}
|
||||
} else {
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "%s: %s: %s\n", argv[0], cust_cxt, strerror(errno));
|
||||
exit(6);
|
||||
} else exit(6);
|
||||
}
|
||||
if (strstr(cust_cxt, "/dev") == NULL && !pmt_force_mode)
|
||||
LOGE("%s\n", current->not_in_dev);
|
||||
{
|
||||
fprintf(stderr, "%sYou're going through my wave? There's nothing about this /dev. Use force mode if you don't want this error%s\n", ANSI_YELLOW, ANSI_RESET);
|
||||
exit(81);
|
||||
}
|
||||
}
|
||||
|
||||
if (target_partition == NULL)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
LOGE("%s\n%s `%s --help' %s\n", current->req_part_name, current->try_h, argv[0], current->for_more);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
fprintf(stderr, "%s: required partition name.\nTry `%s --help' for more information.\n", argv[0], argv[0]);
|
||||
exit(5);
|
||||
} else exit(5);
|
||||
} else {
|
||||
/**
|
||||
*
|
||||
* 1 = backup mode
|
||||
*
|
||||
* 2 = flash mode
|
||||
@@ -366,13 +380,20 @@ int main(int argc, char* argv[])
|
||||
* 3 = format
|
||||
*/
|
||||
if (pmt_backup)
|
||||
return pmt(1);
|
||||
else if (pmt_flash)
|
||||
return pmt(2);
|
||||
else if (pmt_format)
|
||||
return pmt(3);
|
||||
else
|
||||
LOGE("%s\n%s `%s --help' %s\n", current->no_target, current->try_h, argv[0], current->for_more);
|
||||
{
|
||||
pmt(1);
|
||||
exit(EXIT_SUCCESS);
|
||||
} else if (pmt_flash)
|
||||
{
|
||||
pmt(2);
|
||||
exit(EXIT_SUCCESS);
|
||||
} else if (pmt_format)
|
||||
{
|
||||
pmt(3);
|
||||
} else {
|
||||
fprintf(stderr, "%s: no target (backup or flash).\nTry `%s --help` for more information.\n", argv[0], argv[0]);
|
||||
exit(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
44
jni/root.c
44
jni/root.c
@@ -1,44 +0,0 @@
|
||||
/* By YZBruh | ShawkTeam */
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
#define INC_MAIN_LIBS
|
||||
#define INC_DEBUGERS
|
||||
|
||||
#include <pmt.h>
|
||||
|
||||
extern struct pmt_langdb_general* current;
|
||||
extern struct pmt_langdb_general en;
|
||||
extern struct pmt_langdb_general tr;
|
||||
|
||||
/* root checker function */
|
||||
void check_root(void)
|
||||
{
|
||||
/* a quick, easy method for verifying root */
|
||||
if (getuid() != 0)
|
||||
LOGE("%s\n", current->no_root);
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* end of code */
|
||||
298
jni/tools.c
298
jni/tools.c
@@ -1,4 +1,4 @@
|
||||
/* By YZBruh | ShawkTeam */
|
||||
/* By YZBruh */
|
||||
|
||||
/**
|
||||
* Copyright 2024 Partition Manager
|
||||
@@ -20,82 +20,60 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define BFSIZE 1024
|
||||
#define INC_MAIN_LIBS
|
||||
#define INC_STAT
|
||||
#define INC_DEBUGERS
|
||||
#define INC_TOOLS_REQS
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pmt.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 char* bin_name;
|
||||
#define BFSIZE 1024
|
||||
|
||||
extern char *out;
|
||||
extern char *outdir;
|
||||
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.
|
||||
* its purpose is for rapid processing
|
||||
*
|
||||
* if progress_code is a
|
||||
* 1 = backup mode
|
||||
*
|
||||
* 2 = flash mode
|
||||
*
|
||||
* 3 = format mode
|
||||
*/
|
||||
|
||||
static double
|
||||
calc_flsz(const char* _Nonnull filepath)
|
||||
calc_flsz(char *filepath)
|
||||
{
|
||||
static int calc_flsz_file;
|
||||
calc_flsz_file = open(filepath, O_RDONLY);
|
||||
if (calc_flsz_file == -1) return -1;
|
||||
|
||||
if (calc_flsz_file == -1)
|
||||
return calc_flsz_file;
|
||||
|
||||
static off_t flsz;
|
||||
flsz = lseek(calc_flsz_file, 0, SEEK_END);
|
||||
off_t flsz = lseek(calc_flsz_file, 0, SEEK_END);
|
||||
close(calc_flsz_file);
|
||||
|
||||
if (flsz == (off_t)-1)
|
||||
return -1;
|
||||
if (flsz == (off_t)-1) return -1;
|
||||
|
||||
return (double)flsz / (1024 * 1024);
|
||||
}
|
||||
|
||||
/**
|
||||
* error that the partition is not found.
|
||||
* It's for quick action.
|
||||
*/
|
||||
static void
|
||||
partition_not_found(void) { LOGE("%s\n", current->part_not_found); }
|
||||
|
||||
/* to stop use of function type */
|
||||
#define partition_not_found partition_not_found()
|
||||
|
||||
|
||||
|
||||
/* the partitions are meant to quickly find. */
|
||||
static void
|
||||
search_partition(const char* _Nonnull partition)
|
||||
{
|
||||
static int partition_results = 0;
|
||||
partition_results = get_stat(partition, "blk");
|
||||
|
||||
if (partition_results == 1)
|
||||
partition_not_found;
|
||||
else if (partition_results == -1)
|
||||
LOGE("%s\n", current->not_block);
|
||||
}
|
||||
|
||||
int pmt(unsigned short progress_code)
|
||||
void pmt(unsigned short progress_code)
|
||||
{
|
||||
/* required variables */
|
||||
static int srcf, targetf;
|
||||
@@ -105,151 +83,213 @@ int pmt(unsigned short progress_code)
|
||||
static char outf[512];
|
||||
static char flasher_path[512];
|
||||
static char buffer[BFSIZE];
|
||||
static ssize_t readed_data;
|
||||
static unsigned long long copied_data = 0;
|
||||
static ssize_t bytesRead;
|
||||
static unsigned long long bytesCopied = 0;
|
||||
static unsigned long long count = 1024 * 1024 * 1024;
|
||||
|
||||
if (progress_code == 1)
|
||||
{
|
||||
if (!pmt_use_logical)
|
||||
{
|
||||
if (pmt_use_cust_cxt)
|
||||
sprintf(backupper_path, "%s/%s", cust_cxt, target_partition);
|
||||
else
|
||||
sprintf(backupper_path, "/dev/block/by-name/%s", target_partition);
|
||||
if (pmt_use_cust_cxt) sprintf(backupper_path, "%s/%s", cust_cxt, target_partition);
|
||||
else sprintf(backupper_path, "/dev/block/by-name/%s", target_partition);
|
||||
} else if (pmt_use_logical) sprintf(backupper_path, "/dev/block/mapper/%s", target_partition);
|
||||
else {
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "İnvalid partition type!\n");
|
||||
exit(28);
|
||||
} else exit(28);
|
||||
}
|
||||
else
|
||||
sprintf(backupper_path, "/dev/block/mapper/%s", target_partition);
|
||||
|
||||
search_partition(backupper_path);
|
||||
if (access(backupper_path, F_OK) == -1)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "Partition not found!\n");
|
||||
exit(29);
|
||||
} else exit(29);
|
||||
}
|
||||
|
||||
if (calc_flsz(backupper_path) != -1)
|
||||
LOGD("%s: %.2f\n", current->part_disk_sz, calc_flsz(backupper_path));
|
||||
else
|
||||
LOGW("%s\n", current->part_disk_sz_fail);
|
||||
if (calc_flsz(backupper_path) != -1 && !pmt_force_mode) printf("Disk size of the partition to be backed up: %.2f\n", calc_flsz(backupper_path));
|
||||
else printf("%sFailed to target partition disk size%s\n", ANSI_YELLOW, ANSI_RESET);
|
||||
|
||||
srcf = open(backupper_path, O_RDONLY);
|
||||
if (srcf == -1)
|
||||
LOGE("%s: %s: %s\n", current->not_read, backupper_path, strerror(errno));
|
||||
if (srcf == -1) {
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "Couldn't read: %s: %s", backupper_path, strerror(errno));
|
||||
exit(39);
|
||||
} else exit(39);
|
||||
}
|
||||
|
||||
/* determine output */
|
||||
if (strcmp(out, target_partition) == 0)
|
||||
if (outdir != NULL)
|
||||
{
|
||||
sprintf(outf, "%s.img", target_partition);
|
||||
LOGW("%s: %s\n", current->out_not_spec, outf);
|
||||
if (out != NULL) sprintf(outf, "%s/%s.img", outdir, out);
|
||||
else sprintf(outf, "%s/%s.img", outdir, target_partition);
|
||||
} else {
|
||||
if (out != NULL) sprintf(outf, "/storage/emulated/0/%s.img", out);
|
||||
else sprintf(outf, "/storage/emulated/0/%s.img", target_partition);
|
||||
}
|
||||
else
|
||||
sprintf(outf, "%s", target_partition);
|
||||
|
||||
targetf = open(outf, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
if (targetf == -1)
|
||||
LOGE("%s: %s: %s\n", current->not_gen, outf, strerror(errno));
|
||||
if (targetf == -1) {
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "Couldn't generate: %s: %s", outf, strerror(errno));
|
||||
exit(37);
|
||||
} else exit(37);
|
||||
}
|
||||
|
||||
|
||||
/* start writing */
|
||||
while ((readed_data = read(srcf, buffer, BFSIZE)) > 0 && copied_data < count)
|
||||
while ((bytesRead = read(srcf, buffer, BFSIZE)) > 0 && bytesCopied < count)
|
||||
{
|
||||
ssize_t writed_data = write(targetf, buffer, readed_data);
|
||||
if (writed_data != readed_data)
|
||||
ssize_t bytesWritten = write(targetf, buffer, bytesRead);
|
||||
if (bytesWritten != bytesRead)
|
||||
{
|
||||
if (get_stat(outf, "file") == 0)
|
||||
remove(outf);
|
||||
LOGF("%s: %s: %s\n", current->not_write, backupper_path, strerror(errno));
|
||||
fprintf(stderr, "Couldn't write: %s: %s", backupper_path, strerror(errno));
|
||||
close(srcf);
|
||||
close(targetf);
|
||||
exit(81);
|
||||
}
|
||||
|
||||
copied_data += writed_data;
|
||||
bytesCopied += bytesWritten;
|
||||
}
|
||||
|
||||
/* close files */
|
||||
close(srcf);
|
||||
close(targetf);
|
||||
|
||||
LOGD("%s: %s\n", current->success_backup, outf);
|
||||
}
|
||||
else if (progress_code == 2)
|
||||
/* Print the output information by evaluating all situations */
|
||||
if (outdir != NULL)
|
||||
{
|
||||
if (out != NULL) printf("%sSuccess. Output: %s/%s.img%s\n", ANSI_GREEN, outdir, out, ANSI_RESET);
|
||||
else printf("%sSuccess. Output: %s/%s.img%s\n", ANSI_GREEN, outdir, target_partition, ANSI_RESET);
|
||||
} else {
|
||||
if (out != NULL) printf("%sSuccess. Output: /storage/emulated/0/%s.img%s\n", ANSI_GREEN, out, ANSI_RESET);
|
||||
else printf("%sSuccess. Output: /storage/emulated/0/%s.img%s\n", ANSI_GREEN, target_partition, ANSI_RESET);
|
||||
}
|
||||
} else if (progress_code == 2)
|
||||
{
|
||||
/* determine device block */
|
||||
/* for classic */
|
||||
if (!pmt_use_logical)
|
||||
{
|
||||
if (pmt_use_cust_cxt)
|
||||
sprintf(flasher_path, "%s/%s", cust_cxt, target_partition);
|
||||
else
|
||||
sprintf(flasher_path, "/dev/block/by-name/%s", target_partition);
|
||||
if (pmt_use_cust_cxt) sprintf(flasher_path, "%s/%s", cust_cxt, target_partition);
|
||||
else sprintf(flasher_path, "/dev/block/by-name/%s", target_partition);
|
||||
/* for logical */
|
||||
} else if (pmt_use_logical) sprintf(flasher_path, "/dev/block/mapper/%s", target_partition);
|
||||
else {
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "İnvalid partition type!\n");
|
||||
exit(30);
|
||||
} else exit(30);
|
||||
}
|
||||
else
|
||||
sprintf(flasher_path, "/dev/block/mapper/%s", target_partition);
|
||||
|
||||
/* check partition */
|
||||
search_partition(flasher_path);
|
||||
if (access(flasher_path, F_OK) == -1)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "Partition not found!\n");
|
||||
exit(31);
|
||||
} else exit(31);
|
||||
}
|
||||
|
||||
if (calc_flsz(target_flash_file) != -1)
|
||||
LOGD("%s: %.2f\n", current->flash_file_sz, calc_flsz(target_flash_file));
|
||||
else
|
||||
LOGW("%s\n", current->flash_file_sz_fail);
|
||||
if (calc_flsz(target_flash_file) != -1 && !pmt_force_mode) printf("Size of flash file: %.2f\n", calc_flsz(target_flash_file));
|
||||
else printf("%sFailed to get flash file size%s\n", ANSI_YELLOW, ANSI_RESET);
|
||||
|
||||
if (calc_flsz(target_partition) != -1)
|
||||
LOGD("%s: %.2f\n", current->part_disk_sz, calc_flsz(target_partition));
|
||||
else
|
||||
LOGW("%s\n", current->part_disk_sz_fail);
|
||||
|
||||
if (calc_flsz(target_flash_file) > calc_flsz(target_partition))
|
||||
LOGE("%s\n", current->ffile_more_part);
|
||||
if (calc_flsz(target_partition) != -1 && !pmt_force_mode) printf("Disk size of the target partition: %.2f\n", calc_flsz(target_partition));
|
||||
else printf("%sFailed to get target partition disk size%s\n", ANSI_YELLOW, ANSI_RESET);
|
||||
|
||||
srcf = open(target_flash_file, O_RDONLY);
|
||||
if (srcf == -1)
|
||||
LOGF("%s: %s: %s\n", current->not_read, target_flash_file, strerror(errno));
|
||||
if (srcf == -1) {
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "Couldn't read: %s: %s", target_flash_file, strerror(errno));
|
||||
exit(39);
|
||||
} else exit(39);
|
||||
}
|
||||
|
||||
targetf = open(target_partition, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
if (targetf == -1)
|
||||
LOGF("%s: %s: %s\n", current->not_read, target_partition, strerror(errno));
|
||||
if (targetf == -1) {
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "Couldn't read: %s: %s", target_partition, strerror(errno));
|
||||
exit(37);
|
||||
} else exit(37);
|
||||
}
|
||||
|
||||
/* start writing */
|
||||
while ((readed_data = read(srcf, buffer, BFSIZE)) > 0 && copied_data < count)
|
||||
{
|
||||
ssize_t writed_data = write(targetf, buffer, readed_data);
|
||||
if (writed_data != readed_data)
|
||||
LOGF("%s: %s: %s\n", current->not_write, backupper_path, strerror(errno));
|
||||
while ((bytesRead = read(srcf, buffer, BFSIZE)) > 0 && bytesCopied < count) {
|
||||
ssize_t bytesWritten = write(targetf, buffer, bytesRead);
|
||||
if (bytesWritten != bytesRead) {
|
||||
fprintf(stderr, "Couldn't write: %s: %s", backupper_path, strerror(errno));
|
||||
close(srcf);
|
||||
close(targetf);
|
||||
exit(81);
|
||||
}
|
||||
|
||||
copied_data += writed_data;
|
||||
bytesCopied += bytesWritten;
|
||||
}
|
||||
|
||||
close(srcf);
|
||||
close(targetf);
|
||||
|
||||
LOGD("%s.\n", current->success_flash);
|
||||
}
|
||||
else if (progress_code == 3)
|
||||
if (!pmt_force_mode) printf("%sSuccess.%s\n", ANSI_GREEN, ANSI_RESET);
|
||||
} else if (progress_code == 3)
|
||||
{
|
||||
/* generate partition extn */
|
||||
if (!pmt_use_logical)
|
||||
{
|
||||
if (pmt_use_cust_cxt)
|
||||
sprintf(ppath, "%s/%s", cust_cxt, target_partition);
|
||||
else
|
||||
sprintf(ppath, "/dev/block/by-name/%s", target_partition);
|
||||
if (pmt_use_cust_cxt) sprintf(ppath, "%s/%s", cust_cxt, target_partition);
|
||||
else sprintf(ppath, "/dev/block/by-name/%s", target_partition);
|
||||
/* for logical */
|
||||
} else if (pmt_use_logical) sprintf(ppath, "/dev/block/mapper/%s", target_partition);
|
||||
else {
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "İnvalid partition type!\n");
|
||||
exit(49);
|
||||
} else exit(49);
|
||||
}
|
||||
else
|
||||
sprintf(ppath, "/dev/block/mapper/%s", target_partition);
|
||||
|
||||
/* check partition */
|
||||
search_partition(ppath);
|
||||
if (access(ppath, F_OK) == -1)
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "Partition not found!\n");
|
||||
} else exit(31);
|
||||
}
|
||||
|
||||
/* get target partition block size */
|
||||
struct statvfs file_sys_inf;
|
||||
if (statvfs(ppath, &file_sys_inf) != 0)
|
||||
LOGE("%s\n", current->cannot_get_bsz);
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "The partition block size could not be obtained!\n");
|
||||
exit(49);
|
||||
} else exit(49);
|
||||
}
|
||||
|
||||
/* generate mke2fs command */
|
||||
sprintf(formatter_cmd, "mke2fs -Fq -t %s -b %lu %s", format_fs, file_sys_inf.f_bsize, ppath);
|
||||
|
||||
/* run command */
|
||||
if (system(formatter_cmd) != 0)
|
||||
LOGF("%s\n", current->format_fail);
|
||||
{
|
||||
if (!pmt_force_mode)
|
||||
{
|
||||
fprintf(stderr, "Formatting failed! There may be a chance that something has been damaged!\n");
|
||||
exit(71);
|
||||
} else exit(71);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* By YZBruh | ShawkTeam */
|
||||
/* By YZBruh */
|
||||
|
||||
/**
|
||||
* Copyright 2024 Partition Manager
|
||||
@@ -20,38 +20,32 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define INC_MAIN_LIBS
|
||||
#define INC_VERSIONER_REQS
|
||||
#include <stdio.h>
|
||||
#include <pmt-versioning.h>
|
||||
|
||||
#include <pmt.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()
|
||||
{
|
||||
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("Version: %d.%d.%d (code %d%d%d) ", PMT_MAJOR, PMT_LEVEL, PMT_PATCH, PMT_MAJOR, PMT_LEVEL, PMT_PATCH);
|
||||
|
||||
#if __SIZEOF_POINTER__ == 4
|
||||
LOGD("32-bit %s\n", current->bin_str);
|
||||
printf("32-bit binary\n");
|
||||
#elif __SIZEOF_POINTER__ == 8
|
||||
LOGD("64-bit %s\n", current->bin_str);
|
||||
printf("64-bit binary\n");
|
||||
#else
|
||||
LOGD("<%s> %s\n", current->unknw_str, current->bin_str);
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
#if defined(__clang__)
|
||||
LOGD("%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__);
|
||||
printf("Compiler: clang %s\n", __clang_version__);
|
||||
#elif defined(__gcc__)
|
||||
printf("Compiler: gcc %s\n", __gcc_version__)
|
||||
#endif
|
||||
|
||||
LOGD("%s\n", current->see_license);
|
||||
printf("See licenses with -L argument.\n");
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* end of code */
|
||||
|
||||
116
make-deb.sh
Executable file
116
make-deb.sh
Executable file
@@ -0,0 +1,116 @@
|
||||
#!/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.
|
||||
|
||||
RED='\e[31m'
|
||||
NC='\e[0m'
|
||||
|
||||
abort() {
|
||||
printf "${RED}$1${NC}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
case $1 in
|
||||
arm64-v8a)
|
||||
PREFIX="64"
|
||||
;;
|
||||
armeabi-v7a)
|
||||
PREFIX="32"
|
||||
;;
|
||||
*)
|
||||
abort " - Error: unknown architecture flag: $1. Avaiable: arm64-v8a & armeabi-v7a\n"
|
||||
esac
|
||||
|
||||
VERSION="2.0.0"
|
||||
CUR_DIR=$(pwd)
|
||||
LIB_DIR=${CUR_DIR}/libs
|
||||
ARMV8A_DIR=${OUT_DIR}/arm64-v8a
|
||||
ARMV7A_DIR=${OUT_DIR}/armeabi-v7a
|
||||
DEB_DIR=${OUT_DIR}/deb
|
||||
DEBUTILS_DIR=${CUR_DIR}/debutils
|
||||
DEBTERMUX_USR=${DEBUTILS_DIR}/data/data/com.termux/files/usr
|
||||
|
||||
chmod -R 755 *
|
||||
|
||||
printf " --------- Making pmt deb package ---------\n";
|
||||
printf " - Checking all files and directories (only
|
||||
eededs)...\n";
|
||||
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/man1 ]; then
|
||||
abort " - Not found: ${DEBUTILS_DIR}/data/data/com.termux/files/usr/share/man/man1\n"
|
||||
fi
|
||||
if [ ! -f ${DEBUTILS_DIR}/mandoc/pmt.1 ]; then
|
||||
abort " - Not found: ${DEBUTILS_DIR}/mandoc/pmt.1\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
|
||||
|
||||
printf " - Generating template dir...\n"
|
||||
mkdir -p ${DEBUTILS_DIR}/temp
|
||||
|
||||
printf " - Generating out dir...\n"
|
||||
mkdir -p ${DEB_DIR}
|
||||
|
||||
printf " - Copying files...\n"
|
||||
cp -r ${DEBUTILS_DIR}/data ${DEBUTILS_DIR}/temp || exit 1
|
||||
rm -f ${DEBTERMUX_USR}/share/man/man1/dummy
|
||||
rm -f ${DEBTERMUX_USR}/bin/dummy
|
||||
mkdir -p ${DEBUTILS_DIR}/temp/DEBIAN
|
||||
|
||||
printf " - Selected arm-${PREFIX} package control file.\n"
|
||||
cp ${DEBUTILS_DIR}/DEBIAN/control_${PREFIX} ${DEBUTILS_DIR}/temp/DEBIAN/control || exit 1
|
||||
cp ${DEBUTILS_DIR}/mandoc/pmt.1 ${DEBTERMUX_USR}/share/man/man1 || exit 1
|
||||
if [ "${PREFIX}" = "64" ]; then
|
||||
cp ${ARMV8A_DIR}/pmt ${DEBTERMUX_USR}/bin || exit 1
|
||||
elif [ "${PREFIX}" = "32" ]; then
|
||||
cp ${ARMV7A_DIR}/pmt ${DEBTERMUX_USR}/bin || exit 1
|
||||
fi
|
||||
|
||||
printf " - Starting dpkg-deb...\n"
|
||||
sleep 2
|
||||
chmod -R 755 *
|
||||
dpkg-deb -b ${DEBUTILS_DIR}/temp ${DEB_DIR}/pmt-${VERSION}-arm${PREFIX}.deb || exit 1;
|
||||
rm -rf ${DEBUTILS_DIR}/temp || exit 1;
|
||||
|
||||
printf " - Done! Package: ${DEB_DIR}/pmt-${VERSION}.deb\n"
|
||||
|
||||
# end of script
|
||||
208
utils.sh
208
utils.sh
@@ -1,208 +0,0 @@
|
||||
#!/usr/bin/bash
|
||||
# By YZBruh | ShawkTeam
|
||||
|
||||
# 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.4.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
|
||||
Reference in New Issue
Block a user