static linking

This commit is contained in:
spitkov 2025-01-05 15:29:19 +01:00
parent fd53ef08fb
commit e19ba7ac5e
4 changed files with 99 additions and 198 deletions

39
.gitignore vendored
View file

@ -1,42 +1,5 @@
# Build directories deps/
build/ build/
cmake-build-*/
# IDE specific files
.idea/
.vscode/ .vscode/
*.swp
*.swo
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o *.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Compiled Static libraries
*.lai
*.la
*.a *.a
*.lib
# Executables
*.exe
*.out
*.app
# Package manager specific
/var/cache/yns/
/var/lib/yns/

View file

@ -1,38 +1,31 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(yns VERSION 1.0) project(yns)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Find required packages set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
find_package(CURL REQUIRED) set(BUILD_SHARED_LIBS OFF)
find_package(nlohmann_json REQUIRED) set(CMAKE_EXE_LINKER_FLAGS "-static")
set(CURL_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/deps/install/include")
set(CURL_LIBRARY "${CMAKE_SOURCE_DIR}/deps/install/lib/libcurl.a")
find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)
# Add executable
add_executable(yns add_executable(yns
src/main.cpp src/main.cpp
src/package_manager.cpp src/package_manager.cpp)
)
# Include directories
target_include_directories(yns PRIVATE target_include_directories(yns PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/include
${CURL_INCLUDE_DIRS} ${CURL_INCLUDE_DIR})
)
# Link libraries
target_link_libraries(yns PRIVATE target_link_libraries(yns PRIVATE
${CURL_LIBRARIES} ${CURL_LIBRARY}
nlohmann_json::nlohmann_json OpenSSL::SSL
) OpenSSL::Crypto
ZLIB::ZLIB
# Installation -static
install(TARGETS yns DESTINATION bin) -pthread)
# Create required directories during installation
install(CODE "
execute_process(
COMMAND mkdir -p /var/cache/yns
COMMAND mkdir -p /var/lib/yns
)
")

157
README.md
View file

@ -1,150 +1,45 @@
# YNS Package Manager # YNS Package Manager
A lightweight package manager for Linux that uses a single repository source. Simple package manager for Linux. Uses JSON for package definitions.
## Dependencies ## Build
- CMake (>= 3.10) Install dependencies:
- C++17 compiler
- libcurl
- nlohmann-json
On Ubuntu/Debian, you can install the dependencies with:
```bash ```bash
sudo apt-get install build-essential cmake libcurl4-openssl-dev nlohmann-json3-dev sudo apt-get install build-essential cmake libssl-dev zlib1g-dev
``` ```
## Building We build our own curl to make a static binary that works everywhere without dependencies.
Build steps:
```bash ```bash
mkdir build bash build_curl.sh
cd build mkdir build && cd build
cmake .. cmake ..
make make
``` ```
## Installation
After building, you can install the package manager with:
```bash
sudo make install
```
This will:
- Install the `yns` binary to `/usr/local/bin`
- Create necessary directories:
- `/var/cache/yns/` - For package cache
- `/var/lib/yns/` - For installed package database
## Usage ## Usage
### Update package cache
```bash ```bash
yns update yns update # Update package cache
yns install <package> # Install package
yns remove <package> # Remove package
yns upgrade <package> # Upgrade package
yns list # List packages
yns debug # Show debug info
yns interactive # Interactive mode
``` ```
### Install a package ## Package Format
```bash
yns install <package_name>
```
### Remove a package ```json
```bash {
yns remove <package_name> "packages": {
``` "package-name": {
"version": "1.0.0",
### Upgrade a package "description": "Package description",
```bash "install_script": "#!/bin/bash\n# Installation commands"
yns upgrade <package_name> }
``` }
}
### List all packages
```bash
yns list
```
### Interactive Mode
```bash
yns interactive
```
Interactive mode provides a shell-like interface where you can execute multiple commands without the `yns` prefix. Available commands in interactive mode:
- `help` - Show available commands
- `update` - Update package cache
- `install <package>` - Install a package
- `remove <package>` - Remove a package
- `upgrade <package>` - Upgrade a package
- `list` - List all packages
- `clear` - Clear the screen
- `exit` - Exit interactive mode
Example interactive session:
```
$ yns interactive
YNS Package Manager Interactive Mode
Type 'help' for available commands or 'exit' to quit
yns> update
[100%] Package cache updated successfully
yns> list
Available packages:
==================
calc [installed 1.1, update available 2.0]
notepad [available 2.0]
yns> install notepad
[50%] Installing notepad@2.0
notepad@2.0 installed successfully
yns> exit
Goodbye!
```
## Color Coding
The package manager uses color-coded output for better visibility:
🔵 Blue:
- Progress indicators (e.g., "[50%] Installing package...")
- Available but not installed packages in `yns list`
- Interactive mode prompt
🟢 Green:
- Success messages
- Installed packages that are up to date in `yns list`
- Interactive mode welcome message
🟡 Yellow:
- Installed packages with updates available in `yns list`
🔴 Red:
- Error messages
Example `yns list` output:
```
Available packages:
==================
calc [installed 1.1, update available 2.0] # Yellow
notepad [available 2.0] # Blue
vim [installed 3.0] # Green
```
## Repository Structure
The package manager uses a single repository source at:
`https://raw.githubusercontent.com/spitkov/ynsrepo/refs/heads/main/repo.json`
The repository contains package information in JSON format, including:
- Package name
- Version
- Installation script URL
- Update script URL
- Remove script URL
## Features
- Colored terminal output
- Progress indicators
- Automatic package cache management
- Version tracking for installed packages
- Secure script execution
- Error handling and recovery
- Interactive shell mode

50
build_curl.sh Executable file
View file

@ -0,0 +1,50 @@
#!/bin/bash
# Exit on error
set -e
CURL_VERSION="8.6.0"
BUILD_DIR="$(pwd)/deps"
INSTALL_DIR="$(pwd)/deps/install"
# Create directories
mkdir -p "$BUILD_DIR"
mkdir -p "$INSTALL_DIR"
# Download and extract curl
cd "$BUILD_DIR"
wget "https://curl.se/download/curl-${CURL_VERSION}.tar.gz"
tar xf "curl-${CURL_VERSION}.tar.gz"
cd "curl-${CURL_VERSION}"
# Configure with minimal features
./configure \
--prefix="$INSTALL_DIR" \
--disable-shared \
--enable-static \
--disable-ldap \
--disable-ldaps \
--disable-rtsp \
--disable-dict \
--disable-telnet \
--disable-tftp \
--disable-pop3 \
--disable-imap \
--disable-smtp \
--disable-gopher \
--disable-smb \
--disable-mqtt \
--without-librtmp \
--without-libidn2 \
--without-libpsl \
--without-nghttp2 \
--without-libssh2 \
--without-zstd \
--without-brotli \
--without-gssapi \
--with-openssl \
CFLAGS="-fPIC"
# Build and install
make -j$(nproc)
make install