mirror of
https://github.com/egor-white/zaprett.git
synced 2025-12-10 05:19:42 +05:00
create json on zaprett start and fix module
This commit is contained in:
@@ -8,12 +8,12 @@ use nix::sys::signal::{Signal, kill};
|
|||||||
use nix::unistd::{Pid, Uid};
|
use nix::unistd::{Pid, Uid};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::io::ErrorKind;
|
||||||
|
use std::path::Path;
|
||||||
use sysctl::{Ctl, CtlValue, Sysctl};
|
use sysctl::{Ctl, CtlValue, Sysctl};
|
||||||
use sysinfo::{Pid as SysPid, System};
|
use sysinfo::{Pid as SysPid, System};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use tokio::fs::File;
|
|
||||||
use tokio::io::AsyncReadExt;
|
use tokio::io::AsyncReadExt;
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
pub async fn start_service() -> anyhow::Result<()> {
|
pub async fn start_service() -> anyhow::Result<()> {
|
||||||
if !Uid::effective().is_root() {
|
if !Uid::effective().is_root() {
|
||||||
@@ -32,14 +32,26 @@ pub async fn start_service() -> anyhow::Result<()> {
|
|||||||
fs::create_dir_all(&tmp_dir).await?;
|
fs::create_dir_all(&tmp_dir).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let config_path = ZAPRETT_DIR_PATH.join("config.json");
|
||||||
let mut config_contents = String::new();
|
let mut config_contents = String::new();
|
||||||
File::open(ZAPRETT_DIR_PATH.join("config.json"))
|
|
||||||
.await
|
|
||||||
.expect("cannot open config.json")
|
|
||||||
.read_to_string(&mut config_contents)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let config: Config = serde_json::from_str(&config_contents).expect("invalid json");
|
match fs::File::open(&config_path).await {
|
||||||
|
Ok(mut file) => {
|
||||||
|
file.read_to_string(&mut config_contents).await?;
|
||||||
|
}
|
||||||
|
Err(e) if e.kind() == ErrorKind::NotFound => {
|
||||||
|
let default_config = Config::default();
|
||||||
|
let json = serde_json::to_string_pretty(&default_config)?;
|
||||||
|
if let Some(parent) = config_path.parent() {
|
||||||
|
fs::create_dir_all(parent).await?;
|
||||||
|
}
|
||||||
|
fs::write(&config_path, &json).await?;
|
||||||
|
config_contents = json;
|
||||||
|
}
|
||||||
|
Err(e) => return Err(e.into()),
|
||||||
|
}
|
||||||
|
|
||||||
|
let config: Config = serde_json::from_str(&config_contents)?;
|
||||||
|
|
||||||
let start = fs::read_to_string(config.strategy())
|
let start = fs::read_to_string(config.strategy())
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -17,23 +17,6 @@ unzip -o "$ZIPFILE" -x 'META-INF/*' -d $MODPATH >&2
|
|||||||
ui_print "Creating zaprett directory..."
|
ui_print "Creating zaprett directory..."
|
||||||
mkdir /sdcard/zaprett; mkdir /sdcard/zaprett/lists; mkdir /sdcard/zaprett/bin; mkdir /sdcard/zaprett/strategies;
|
mkdir /sdcard/zaprett; mkdir /sdcard/zaprett/lists; mkdir /sdcard/zaprett/bin; mkdir /sdcard/zaprett/strategies;
|
||||||
|
|
||||||
ui_print "Filling configuration file if not exist..."
|
|
||||||
if [ ! -f "/sdcard/zaprett/config.json" ]; then
|
|
||||||
cat > /sdcard/zaprett/config.json << EOL
|
|
||||||
{
|
|
||||||
"active_lists": ["/sdcard/zaprett/lists/include/list-youtube.txt", "/sdcard/zaprett/lists/include/list-discord.txt"],
|
|
||||||
"active_ipsets": [],
|
|
||||||
"active_exclude_lists": [],
|
|
||||||
"active_exclude_ipsets": [],
|
|
||||||
"list_type": "whitelist",
|
|
||||||
"strategy": "",
|
|
||||||
"app_list": "whitelist",
|
|
||||||
"whitelist": [],
|
|
||||||
"blacklist": []
|
|
||||||
}
|
|
||||||
EOL
|
|
||||||
fi
|
|
||||||
|
|
||||||
ui_print "Copying lists and binaries to /sdcard/zaprett..."
|
ui_print "Copying lists and binaries to /sdcard/zaprett..."
|
||||||
cp -r $MODPATH/system/etc/zaprett/. /sdcard/zaprett/
|
cp -r $MODPATH/system/etc/zaprett/. /sdcard/zaprett/
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user