Customizable number of packages for search + broken pkg signing
This commit is contained in:
parent
4a23489c1c
commit
ffc5ca7a16
|
@ -29,7 +29,7 @@ $ $env:TELOXIDE_TOKEN=<Your token here>
|
|||
```
|
||||
4. Создайте симлинк до вашего локального репозитория
|
||||
```bash
|
||||
ln -s /path/to/bot/repo /path/to/repo
|
||||
ln -s /path/to/bot_dir/repo /path/to/repo
|
||||
```
|
||||
|
||||
### Docker
|
||||
|
@ -63,7 +63,7 @@ docker compose up -d
|
|||
## Использоание
|
||||
|
||||
1. Поиск пакетов в AUR
|
||||
`/search <название пакета>`
|
||||
`/search <название пакета> <кол-во отображаемых пакетов 1-255>`
|
||||
|
||||
2. Добавление пакетов в репозиторий
|
||||
`/upload <название пакета>`
|
||||
|
|
58
src/build.rs
58
src/build.rs
|
@ -1,34 +1,53 @@
|
|||
use git2::{Error, Repository};
|
||||
use std::process::Command;
|
||||
use glob::glob;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub fn clone(pkg: String, dir: String) -> Result<Repository, Error> {
|
||||
let repo = format!("https://aur.archlinux.org/{}.git", pkg);
|
||||
Repository::clone(repo.as_str(), dir.as_str())
|
||||
}
|
||||
|
||||
pub async fn copy(dir: String, local_repo: String) -> Result<(), Box<dyn std::error::Error>> {
|
||||
pub fn copy(dir: String, local_repo: String) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let entries = fs::read_dir(dir)?;
|
||||
for entry in entries {
|
||||
let entry = entry?;
|
||||
let file_path = entry.path();
|
||||
|
||||
if file_path.is_file() && file_path.extension().unwrap_or_default() == "zst" {
|
||||
let file_name = file_path.file_name().unwrap();
|
||||
let local_repo = Path::new(local_repo.as_str()).join(file_name);
|
||||
fs::copy(&file_path, &local_repo)?;
|
||||
match std::env::var("GPGKEY") {
|
||||
Ok(_) => {
|
||||
zst(file_path.clone(), local_repo.clone())?;
|
||||
if file_path.is_file() && file_path.extension().unwrap_or_default() == "sig" {
|
||||
let file_name = file_path.file_name().unwrap();
|
||||
let local_repo = Path::new(local_repo.as_str()).join(file_name);
|
||||
fs::copy(&file_path, &local_repo)?;
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
zst(file_path, local_repo.clone())?
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn build() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Command::new("makepkg")
|
||||
.arg("-s")
|
||||
.arg("--noconfirm")
|
||||
.output()?;
|
||||
pub fn build(default_dir: PathBuf) -> Result<(), Box<dyn std::error::Error>> {
|
||||
match std::env::var("GPGKEY") {
|
||||
Ok(value) => {
|
||||
Command::new("makepkg")
|
||||
.arg("-s")
|
||||
.arg("--sign")
|
||||
.arg(format!("--key {}/{}",default_dir.as_os_str().to_str().unwrap() , value))
|
||||
.arg("--noconfirm")
|
||||
.output()?;
|
||||
}
|
||||
Err(_) => {
|
||||
Command::new("makepkg")
|
||||
.arg("-s")
|
||||
.arg("--noconfirm")
|
||||
.output()?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -36,8 +55,8 @@ pub fn delete(dir: String) -> std::io::Result<()> {
|
|||
fs::remove_dir_all(dir)
|
||||
}
|
||||
|
||||
pub async fn repo_add() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let files: Vec<String> = glob("*.pkg.tar.zst")
|
||||
pub fn repo_add() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let files: Vec<String> = glob::glob("*.pkg.tar.zst")
|
||||
.expect("Failed to read glob pattern")
|
||||
.filter_map(|entry| entry.ok())
|
||||
.filter_map(|path| path.to_str().map(String::from))
|
||||
|
@ -53,4 +72,13 @@ pub async fn repo_add() -> Result<(), Box<dyn std::error::Error>> {
|
|||
.arg(format!("{}", vec_of_str_refs.join(", ")))
|
||||
.output()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn zst(file_path: PathBuf, local_repo: String) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if file_path.is_file() && file_path.extension().unwrap_or_default() == "zst" {
|
||||
let file_name = file_path.file_name().unwrap();
|
||||
let local_repo = Path::new(local_repo.as_str()).join(file_name);
|
||||
fs::copy(&file_path, &local_repo)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
use aur_rpc;
|
||||
pub async fn search(pkg: String) -> String {
|
||||
pub async fn search(pkg: String, num: u8) -> String {
|
||||
let mut packages = aur_rpc::search(pkg).await.unwrap();
|
||||
packages.sort_by(|a, b| b.num_votes.cmp(&a.num_votes));
|
||||
let mut result = Vec::new();
|
||||
|
||||
for (index, package) in packages.iter().enumerate().take(10) {
|
||||
for (index, package) in packages.iter().enumerate().take(num as usize) {
|
||||
result.push(format!("{}. {}", index+1, package.name));
|
||||
}
|
||||
let response = result.iter().map(|x| x.to_string()).collect::<Vec<String>>().join("\n");
|
||||
|
|
|
@ -2,15 +2,18 @@ use teloxide::{prelude::*, utils::command::BotCommands};
|
|||
use crate::build::{clone, copy, build, delete, repo_add};
|
||||
use crate::search;
|
||||
use std::env;
|
||||
|
||||
pub async fn main(bot: Bot){
|
||||
Commands::repl(bot, answer).await;
|
||||
}
|
||||
|
||||
#[derive(BotCommands, Clone)]
|
||||
#[command(rename_rule = "lowercase", description = "Commands:")]
|
||||
pub(crate) enum Commands{
|
||||
enum Commands{
|
||||
#[command(description = "Build package.")]
|
||||
Upload(String),
|
||||
Search(String)
|
||||
#[command(description = "Search packages", parse_with = "split")]
|
||||
Search{ pkg: String, num: u8 }
|
||||
}
|
||||
async fn answer(bot: Bot, msg: Message, cmd: Commands) -> ResponseResult<()> {
|
||||
match cmd {
|
||||
|
@ -26,14 +29,14 @@ async fn answer(bot: Bot, msg: Message, cmd: Commands) -> ResponseResult<()> {
|
|||
bot.send_message(msg.chat.id, clone).await?;
|
||||
|
||||
env::set_current_dir(pkg_dir.clone())?;
|
||||
let build = match build().await {
|
||||
let build = match build(default_dir.clone()) {
|
||||
Ok(..) => { format!("Builded") },
|
||||
Err(e) => { format!("Build error: {}", e) }
|
||||
};
|
||||
bot.send_message(msg.chat.id, build).await?;
|
||||
|
||||
env::set_current_dir(default_dir.clone())?;
|
||||
let copy = match copy(pkg_dir.clone(), repo_dir.clone()).await {
|
||||
let copy = match copy(pkg_dir.clone(), repo_dir.clone()) {
|
||||
Ok(..) => { format!("Copied") },
|
||||
Err(e) => { format!("Copy error: {}", e) }
|
||||
};
|
||||
|
@ -46,7 +49,7 @@ async fn answer(bot: Bot, msg: Message, cmd: Commands) -> ResponseResult<()> {
|
|||
bot.send_message(msg.chat.id, delete).await?;
|
||||
|
||||
env::set_current_dir(repo_dir)?;
|
||||
let repo_add = match repo_add().await {
|
||||
let repo_add = match repo_add() {
|
||||
Ok(..) => { format!("Added to repo") },
|
||||
Err(e) => { format!("Error adding package to repository: {}", e) }
|
||||
};
|
||||
|
@ -54,9 +57,9 @@ async fn answer(bot: Bot, msg: Message, cmd: Commands) -> ResponseResult<()> {
|
|||
env::set_current_dir(default_dir)?;
|
||||
|
||||
}
|
||||
Commands::Search(pkg) => {
|
||||
bot.send_message(msg.chat.id, search::search(pkg).await).await?;
|
||||
Commands::Search{pkg, num} => {
|
||||
bot.send_message(msg.chat.id, search::search(pkg, num).await).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue