From 9e900d3b79c6640b15eb5045f1c7ec9b829367e9 Mon Sep 17 00:00:00 2001 From: Artur Gurgul Date: Sun, 3 Aug 2025 14:47:59 +0200 Subject: [PATCH 01/12] save --- lib/make.rb | 17 ++++++++++++++--- lib/system/debian.rb | 7 +++++++ lib/system/macos.rb | 7 +++++++ recipes/dry-run.yml | 2 +- recipes/python.yml | 9 ++++++--- recipes/ruby/macos.yml | 2 +- 6 files changed, 36 insertions(+), 8 deletions(-) diff --git a/lib/make.rb b/lib/make.rb index be1d190..e36943f 100644 --- a/lib/make.rb +++ b/lib/make.rb @@ -56,7 +56,9 @@ module Make @steps = makefile["steps"] || [] @environment = ENV.to_h.merge( - "PREFIX" => get_prefix + "PREFIX" => get_prefix, + "CPUS" => System.cpus.to_s, + "SUDO" => (@target == :user ? "" : "sudo") ) environment = makefile["environment"] @@ -69,13 +71,22 @@ module Make end def get_prefix + sys_prefix = case System.os_name + when :macos + "/usr" + else + "" + end + case @target when :user "#{ENV["HOME"]}/.local" when :package - "/pkg/#{@name}/#{@repository.branch}" + "#{sys_prefix}/pkg/#{@name}/#{@repository.branch}" when :system - "/" + "#{sys_prefix}/" + else + raise "Unknown target: #{@target.inspect}" end end diff --git a/lib/system/debian.rb b/lib/system/debian.rb index 61170c8..6504a2f 100644 --- a/lib/system/debian.rb +++ b/lib/system/debian.rb @@ -1,8 +1,15 @@ +require 'open3' + module DebianSystem def os_name "Debian Linux" end + def cpus + stdout, stderr, status = Open3.capture3("nproc") + stdout.strip.to_i + end + def install(packages) missing_packages = packages.reject { |pkg| package_installed?(pkg) } diff --git a/lib/system/macos.rb b/lib/system/macos.rb index 7cacd3d..b2a6a22 100644 --- a/lib/system/macos.rb +++ b/lib/system/macos.rb @@ -1,8 +1,15 @@ +require 'open3' + module MacOSSystem def os_name "macOS" end + def cpus + stdout, stderr, status = Open3.capture3("sysctl -n hw.ncpu") + stdout.strip.to_i + end + def install(packages) missing_packages = packages.reject { |pkg| package_installed?(pkg) } diff --git a/recipes/dry-run.yml b/recipes/dry-run.yml index f5258b5..77e8509 100644 --- a/recipes/dry-run.yml +++ b/recipes/dry-run.yml @@ -9,7 +9,7 @@ repository: branch: main steps: - - echo installing in $PREFIX + - echo installing in $PREFIX and cpus $CPUS - cd $WORK_DIR - ls diff --git a/recipes/python.yml b/recipes/python.yml index e476fd0..c25a402 100644 --- a/recipes/python.yml +++ b/recipes/python.yml @@ -18,6 +18,9 @@ repository: branch: v3.13.5 steps: - - ./configure --enable-optimizations --prefix=$HOME/.local - - make -j"$(nproc)" - - make install +# dat make -t pkg --cache --name python +# - ./configure --enable-optimizations --prefix=$HOME/.local +# - make -j"$(nproc)" + - ./configure --enable-optimizations --prefix=$PREFIX + - make -j$CPUS + - $SUDO make install diff --git a/recipes/ruby/macos.yml b/recipes/ruby/macos.yml index f55ec6e..c628e74 100644 --- a/recipes/ruby/macos.yml +++ b/recipes/ruby/macos.yml @@ -19,4 +19,4 @@ steps: # --with-readline-dir=$(brew --prefix readline) # --with-yaml-dir=$(brew --prefix libyaml) - make -j$(sysctl -n hw.ncpu) - - make install \ No newline at end of file + - make install From 9dc5c7bba6711ab16c4cd3d32dd9614bc8616e22 Mon Sep 17 00:00:00 2001 From: Artur Gurgul Date: Sun, 3 Aug 2025 16:36:03 +0200 Subject: [PATCH 02/12] update --- bin/zshrc/init | 3 ++- readme.md | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/zshrc/init b/bin/zshrc/init index 151a61e..8f7e2a3 100644 --- a/bin/zshrc/init +++ b/bin/zshrc/init @@ -5,7 +5,8 @@ export PATH="$DAT_ROOT/bin:$HOME/.local/bin:$PATH" export RUBYLIB="$DAT_ROOT/lib" -export PASSWORD_STORE_DIR=$HOME/.local/secure-vault/passwords +export PASSWORD_STORE_DIR=$HOME/.local/lib/secure-vault/passwords +export NOTES_DIR=$HOME/.local/lib/notes path=("$GEM_HOME/bin" $path) diff --git a/readme.md b/readme.md index 0bae34a..0403984 100644 --- a/readme.md +++ b/readme.md @@ -2,5 +2,5 @@ # Installing the environment ```bash -curl -sSL https://gitlab.com/artur.gurgul/home/-/raw/main/install | bash +curl -sSL https://gurgul.pro/artur/environment/raw/branch/main/install | bash ``` From 7360824eab16fc5b04994fa1761b2d01a81d012a Mon Sep 17 00:00:00 2001 From: Artur Gurgul Date: Sun, 3 Aug 2025 16:53:58 +0200 Subject: [PATCH 03/12] add scripts to configure macos --- bin/macos-config/macos-dock.sh | 16 ++++++++++++++++ bin/macos-config/macos-settings.sh | 24 ++++++++++++++++++++++++ bin/macos-config/readme.md | 1 + 3 files changed, 41 insertions(+) create mode 100644 bin/macos-config/macos-dock.sh create mode 100644 bin/macos-config/macos-settings.sh create mode 100644 bin/macos-config/readme.md diff --git a/bin/macos-config/macos-dock.sh b/bin/macos-config/macos-dock.sh new file mode 100644 index 0000000..4bfae25 --- /dev/null +++ b/bin/macos-config/macos-dock.sh @@ -0,0 +1,16 @@ + +defaults write com.apple.dock persistent-apps -array +defaults write com.apple.dock orientation -string "left" +defaults write com.apple.dock autohide -bool true + +#Set icon size +defaults write com.apple.dock tilesize -int 32 + +killall Dock + +## Exporting the settings +# defaults export com.apple.dock ~/dock-backup.plist + +## Restoring +# defaults import com.apple.dock ~/dock-backup.plist +# killall Dock \ No newline at end of file diff --git a/bin/macos-config/macos-settings.sh b/bin/macos-config/macos-settings.sh new file mode 100644 index 0000000..8501430 --- /dev/null +++ b/bin/macos-config/macos-settings.sh @@ -0,0 +1,24 @@ +defaults write com.apple.menuextra.clock ShowSeconds -bool true +defaults write NSGlobalDomain KeyRepeat -int 2 # 2 min -120 max +defaults write NSGlobalDomain InitialKeyRepeat -int 15 + +## If when holding a key you get the accent menu (e.g., “é”, “ö”) instead of repeats: +# defaults write -g ApplePressAndHoldEnabled -bool false + + + +## Control Center Settings +#18 → Show in Menu Bar +#2 → Show in Control Center only +#8 → Don't show at all + +# defaults write com.apple.controlcenter Battery -int 18 +defaults write com.apple.controlcenter Bluetooth -int 18 +defaults write com.apple.controlcenter Sound -int 18 + +killall ControlCenter +killall SystemUIServer + +osascript -e 'tell application "System Events" to tell appearance preferences to set dark mode to true' +## Toggling the theme mode +#osascript -e 'tell application "System Events" to tell appearance preferences to set dark mode to not dark mode' diff --git a/bin/macos-config/readme.md b/bin/macos-config/readme.md new file mode 100644 index 0000000..f4c205c --- /dev/null +++ b/bin/macos-config/readme.md @@ -0,0 +1 @@ +# Reinstall macOS \ No newline at end of file From 368ebfaba224923fcb605c1cb6c4a5af5b1a4c1f Mon Sep 17 00:00:00 2001 From: Artur Gurgul Date: Sun, 3 Aug 2025 20:53:36 +0200 Subject: [PATCH 04/12] save --- bin/apas | 28 ++++++++ bin/cht | 98 +++++++++++++++++++++++++++ bin/index | 16 +++++ bin/zshrc/brew | 2 + bin/zshrc/init | 3 + home/.local/bin/{index => index-list} | 0 6 files changed, 147 insertions(+) create mode 100755 bin/apas create mode 100755 bin/cht create mode 100755 bin/index rename home/.local/bin/{index => index-list} (100%) diff --git a/bin/apas b/bin/apas new file mode 100755 index 0000000..6e2ebdb --- /dev/null +++ b/bin/apas @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +function lhash { + echo -n "${1}" | openssl dgst -sha512 | cut -d' ' -f2 | openssl dgst -md5 | cut -d' ' -f2 +} + +# Prompt user for input +read -p "Website: " url +read -p "Login: " login +read -s -p "Password: " password +echo + +domain=$(echo "$url" | sed -E 's~https?://([^/]+).*~\1~') +hash=$(lhash "$login") +pass_path="web/${domain}/${hash}" + +# Entry content +entry="${password} +url: ${url} +login: ${login} +" + +echo "$entry" | pass insert -m "$pass_path" + +# url +# login +# tags +# note \ No newline at end of file diff --git a/bin/cht b/bin/cht new file mode 100755 index 0000000..67ebfd0 --- /dev/null +++ b/bin/cht @@ -0,0 +1,98 @@ +#!/usr/bin/env node + +import path from "path" +import fs from "fs" + +// DAT_ROOT should exists in ~/.zshrc-local +const indexPath = path.join(process.env["NOTES_DIR"], "") +const processFile = path.join(process.cwd(), process.argv[2]) + + +const data = fs.readFileSync(processFile, 'utf8') +const jsonData = JSON.parse(data) + +function wantSave(str) { + return typeof str == "string" && str.split("\n").length > 10 +} + +function saveToFileSync(content, file) { + const dir = path.dirname(file); + try { + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, { recursive: true }) + } + + fs.writeFileSync(file, content, 'utf8') + } catch (err) { + console.error('Error saving file:', err) + } +} + +const toSave = jsonData.flatMap(o => { + const date = new Date(o.create_time * 1000) + + // const formattedDate = date.toLocaleDateString('en-GB', { + // day: '2-digit', + // month: '2-digit', + // year: '2-digit', + // }) + // return formattedDate + + const day = String(date.getDate()).padStart(2, '0') + const month = String(date.getMonth() + 1).padStart(2, '0') + const year = String(date.getFullYear()).slice(-2) + + let baseNotePath = path.join(indexPath, "gpt", `${day}-${month}-${year}`, `${o.title}`) + + let conversations = [] + for (const [key, value] of Object.entries(o.mapping)) { + //console.log(key, value) + + conversations.push({ + path: path.join(baseNotePath, `${key}.json`), + content: JSON.stringify(value, null, 2) + }) + + let parts = value?.message?.content.parts + if (Array.isArray(parts)) { + + if (parts.length == 0) { + // skip + } else if (parts.length == 1) { + let fileName = path.join(baseNotePath, `${key}.md`) + let md = parts[0] + + if (wantSave(md)) { + conversations.push({ + path: fileName, + content: md + }) + } + } else { + + for (const [key, value] of parts.entries()) { + let fileName = path.join(baseNotePath, `${key}-${key+1}.md`) + let md = parts[key] + + if (wantSave(md)) { + conversations.push({ + path: fileName, + content: md + }) + } + } + } + } + + //process.exit(-1) + + } + + return conversations +}) + + +for(const f of toSave) { +//for(const f of toSave.slice(0,5)) { + saveToFileSync(f.content,f.path) +} diff --git a/bin/index b/bin/index new file mode 100755 index 0000000..fd6a40d --- /dev/null +++ b/bin/index @@ -0,0 +1,16 @@ +#!/bin/bash + +# find $NOTES_DIR/gpt -type d -path "$NOTES_DIR/gpt/[0-9][0-9]-[0-9][0-9]-[0-9][0-9]/*" | while read -r path; do +# echo $(basename "$path") +# done | sort -u | fzf + +SEARCH_DIR="$NOTES_DIR/gpt" +DELIMITER="|" + +selected=$(find "$SEARCH_DIR" -type d -path "$SEARCH_DIR/[0-9][0-9]-[0-9][0-9]-[0-9][0-9]/*" | while read -r path; do + topic=$(basename "$path") + echo -e "$topic\t$path" +done | fzf --delimiter='\t' --with-nth=1) + +selected_path=$(echo "$selected" | cut -f2) +echo "Path: $selected_path" diff --git a/bin/zshrc/brew b/bin/zshrc/brew index 4e13a77..6e3f24d 100644 --- a/bin/zshrc/brew +++ b/bin/zshrc/brew @@ -6,4 +6,6 @@ if [[ "$OSTYPE" == "darwin"* ]]; then elif [[ "$ARCH" == "x86_64" ]]; then eval "$(/usr/local/bin/brew shellenv)" fi + + export PATH="$(brew --prefix ruby)/bin:$PATH" fi \ No newline at end of file diff --git a/bin/zshrc/init b/bin/zshrc/init index 8f7e2a3..c32fcf1 100644 --- a/bin/zshrc/init +++ b/bin/zshrc/init @@ -3,6 +3,9 @@ export PATH="$DAT_ROOT/bin:$HOME/.local/bin:$PATH" +export GEM_HOME="$HOME/.gems" +export GEM_PATH=$HOME/.gems + export RUBYLIB="$DAT_ROOT/lib" export PASSWORD_STORE_DIR=$HOME/.local/lib/secure-vault/passwords diff --git a/home/.local/bin/index b/home/.local/bin/index-list similarity index 100% rename from home/.local/bin/index rename to home/.local/bin/index-list From 0fb2502e5333e4394a4e31d8d7bdb4a2c81b2799 Mon Sep 17 00:00:00 2001 From: Artur Gurgul Date: Sun, 3 Aug 2025 19:09:25 +0000 Subject: [PATCH 05/12] update --- bin/zshrc/init | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/zshrc/init b/bin/zshrc/init index 8f7e2a3..8bcae92 100644 --- a/bin/zshrc/init +++ b/bin/zshrc/init @@ -19,4 +19,6 @@ function cdd { . $DAT_ROOT/bin/zshrc/prompt . $DAT_ROOT/bin/zshrc/utils -bindkey '^e' edit-command-line \ No newline at end of file +bindkey '^e' edit-command-line + +export PATH="$HOME/.local/bin:$PATH" From 0ef37ad846245252eec478f6a9a20eb67473baab Mon Sep 17 00:00:00 2001 From: Artur Gurgul Date: Mon, 4 Aug 2025 09:44:22 +0200 Subject: [PATCH 06/12] Add command that retreive data from backend and use zstd compression to transfer --- bin/get | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 bin/get diff --git a/bin/get b/bin/get new file mode 100755 index 0000000..ebd45b1 --- /dev/null +++ b/bin/get @@ -0,0 +1,35 @@ +ARCHIVE=false +DESTINATION_LOCAL_DIR="./" + +if [[ "$1" == "--archive" ]]; then + ARCHIVE=true + shift +fi + +if [[ $# -lt 2 ]]; then + echo "Usage: $0 [--archive] user@host remote_source_dir [local_destination_dir]" + exit 1 +fi + +USER_HOST="$1" +REMOTE_USER="${USER_HOST%@*}" +HOST="${USER_HOST#*@}" + +REMOTE_SOURCE_DIR="$2" +if [[ -n "$3" ]]; then + DESTINATION_LOCAL_DIR="$3" +fi + +echo "ARCHIVE=$ARCHIVE" +echo "REMOTE_USER=$REMOTE_USER" +echo "HOST=$HOST" +echo "REMOTE_SOURCE_DIR=$REMOTE_SOURCE_DIR" +echo "DESTINATION_LOCAL_DIR=$DESTINATION_LOCAL_DIR" + + +# Example that works +# ssh debian@gurgul.org "tar --zstd -cf - -C /home/debian .dat" | tar --zstd -xf - -C . +# get debian@gurgul.org .dat + +TAR_COMMAND="tar --zstd -cf - -C /home/$REMOTE_USER $REMOTE_SOURCE_DIR" +ssh $REMOTE_USER@$HOST $TAR_COMMAND | tar --zstd -xf - -C $DESTINATION_LOCAL_DIR \ No newline at end of file From a4f3987b97efe4f8e418564db2301d4123c22fab Mon Sep 17 00:00:00 2001 From: Artur Gurgul Date: Mon, 4 Aug 2025 10:46:03 +0200 Subject: [PATCH 07/12] Add possibility to download absolute dirs --- bin/get | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/bin/get b/bin/get index ebd45b1..299ffb7 100755 --- a/bin/get +++ b/bin/get @@ -20,16 +20,38 @@ if [[ -n "$3" ]]; then DESTINATION_LOCAL_DIR="$3" fi +if [[ "$REMOTE_SOURCE_DIR" = /* ]]; then + IS_ABSOLUTE=true +else + IS_ABSOLUTE=false +fi + + echo "ARCHIVE=$ARCHIVE" echo "REMOTE_USER=$REMOTE_USER" echo "HOST=$HOST" echo "REMOTE_SOURCE_DIR=$REMOTE_SOURCE_DIR" echo "DESTINATION_LOCAL_DIR=$DESTINATION_LOCAL_DIR" +REMOTE_BASE_DIR="" + +if $IS_ABSOLUTE; then + REMOTE_BASE_DIR="/" +else + REMOTE_BASE_DIR=/home/$REMOTE_USER +fi + # Example that works # ssh debian@gurgul.org "tar --zstd -cf - -C /home/debian .dat" | tar --zstd -xf - -C . # get debian@gurgul.org .dat -TAR_COMMAND="tar --zstd -cf - -C /home/$REMOTE_USER $REMOTE_SOURCE_DIR" -ssh $REMOTE_USER@$HOST $TAR_COMMAND | tar --zstd -xf - -C $DESTINATION_LOCAL_DIR \ No newline at end of file +# get --archive debian@gurgul.org /etc + +TAR_COMMAND="tar --zstd -cf - -C $REMOTE_BASE_DIR $REMOTE_SOURCE_DIR" + +if $ARCHIVE; then + ssh $REMOTE_USER@$HOST $TAR_COMMAND > "$DESTINATION_LOCAL_DIR/$(basename "$REMOTE_SOURCE_DIR")-$(date +"%d-%m-%Y").tar.zst" +else + ssh $REMOTE_USER@$HOST $TAR_COMMAND | tar --zstd -xf - -C $DESTINATION_LOCAL_DIR +fi \ No newline at end of file From 68e1bac4b394352a2b9fee33a878128599de5cc2 Mon Sep 17 00:00:00 2001 From: Artur Gurgul Date: Mon, 4 Aug 2025 19:41:41 +0200 Subject: [PATCH 08/12] parse archive param --- lib/make.rb | 34 +++++++++++++++++++++++++++++++--- recipes/nginx/generate.rb | 34 ++++++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/lib/make.rb b/lib/make.rb index e36943f..1609f01 100644 --- a/lib/make.rb +++ b/lib/make.rb @@ -28,7 +28,7 @@ module Make class Context attr_accessor :name, :use_cache, :environment, :steps, :packages, :repository - attr_accessor :target + attr_accessor :target, :archive, :source_type def initialize(options: OpenStruct.new) @target = options.target || :user @@ -52,7 +52,21 @@ module Make # puts makefile @packages = makefile["packages"] || [] + + project_sources = { + repository: makefile["repository"] != nil, + archive: makefile["archive"] != nil + }.select { |_, v| v } + + if project_sources.size == 1 + @source_type = project_sources.keys.first + else + raise "Exactly one type of source: 'repository' or 'archive'" + end + puts @source_type + @repository = Make.rostruct(makefile["repository"] || OpenStruct.new) + @archive = Make.rostruct(makefile["archive"] || OpenStruct.new) @steps = makefile["steps"] || [] @environment = ENV.to_h.merge( @@ -147,7 +161,14 @@ module Make install @context.rpd do | path | @cwd = path - checkout + + case @context.source_type + when :repository + checkout + when :archive + download_and_extract + end + puts "path: #{path}" Dir.chdir(path) @@ -160,6 +181,13 @@ module Make end end end + + def download_and_extract + archive = @context.archive + + puts archive + exit -1 + end def checkout repo_path = @context.local_repo @@ -195,4 +223,4 @@ module Make builder = Builder.new(context) builder.build end -end \ No newline at end of file +end diff --git a/recipes/nginx/generate.rb b/recipes/nginx/generate.rb index 6f51fd4..cb9f0cc 100644 --- a/recipes/nginx/generate.rb +++ b/recipes/nginx/generate.rb @@ -3,27 +3,47 @@ require 'erb' class NGINXProxy class << self - attr_accessor :domain, :port, :service + attr_accessor :domain, :port, :service, :user def domain(value = nil) @domain = value unless value.nil? @domain end + def user(value = nil) + @user = value unless value.nil? + @user + end + def port(value = nil) @port = value unless value.nil? @port end - + + # This is name of the daemon that will be installed + # This is also master name user as user if not provided def service(value = nil) @service = value unless value.nil? @service end def generate - template = File.read("proxy.erb") - template = ERB.new(template) - template.result(binding) + template = File.read("proxy.erb") + template = ERB.new(template) + template.result(binding) + end + + def available_path + "/etc/nginx/sites-available/#{service}.#{domain}" + end + + def enabled_path + "/etc/nginx/sites-available/#{service}.#{domain}" + end + + def install + config = generate + File.write end end end @@ -31,7 +51,9 @@ end class ExampleProxy < NGINXProxy domain "gurgul.org" service "forgejo" + user "git" port 3000 end -puts ExampleProxy.generate \ No newline at end of file +puts ExampleProxy.generate +puts ExampleProxy.path From 3013fda863b0a680455bb87485ffa0a0d71a5fc3 Mon Sep 17 00:00:00 2001 From: Artur Gurgul Date: Mon, 4 Aug 2025 19:43:28 +0200 Subject: [PATCH 09/12] Add download manager --- lib/archive.rb | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 lib/archive.rb diff --git a/lib/archive.rb b/lib/archive.rb new file mode 100644 index 0000000..d8fde1b --- /dev/null +++ b/lib/archive.rb @@ -0,0 +1,93 @@ +require 'net/http' +require 'uri' +require 'open3' +require 'fileutils' +require 'open-uri' + +module Archive + MAGIC_NUMBERS = { + "\x1F\x8B" => 'gzip', + "\x50\x4B\x03\x04" => 'zip', + "\x28\xB5\x2F\xFD" => 'zstd', + "\xFD\x37\x7A\x58" => 'xz' + } + + def self.detect_format_from_url(url) + case File.extname(url) + when '.gz', '.tgz' then 'gzip' + when '.zip' then 'zip' + when '.zst' then 'zstd' + when '.xz' then 'xz' + else nil + end + end + + def self.detect_format_from_headers(uri) + response = Net::HTTP.get_response(uri) + content_type = response['content-type'] + case content_type + when /gzip/ then 'gzip' + when /zip/ then 'zip' + when /zstd/ then 'zstd' + when /xz/ then 'xz' + else nil + end + end + + def self.detect_format_from_magic(file_path) + File.open(file_path, 'rb') do |f| + bytes = f.read(4) + MAGIC_NUMBERS.each do |magic, format| + return format if bytes.start_with?(magic) + end + end + nil + end + + def self.download_file(uri, output_path) + URI.open(uri) do |input| + File.open(output_path, 'wb') do |output| + IO.copy_stream(input, output) + end + end + end + + def self.extract_archive(file_path, format) + case format + when 'gzip' + system("tar -xzf #{Shellwords.escape(file_path)}") + when 'zip' + system("unzip #{Shellwords.escape(file_path)}") + when 'zstd' + system("unzstd #{Shellwords.escape(file_path)}") + when 'xz' + system("tar -xJf #{Shellwords.escape(file_path)}") + else + raise "Unsupported archive format: #{format}" + end + end + + def self.fetch_and_extract(url) + uri = URI.parse(url) + file_name = File.basename(uri.path) + tmp_path = "/tmp/#{file_name}" + + format = detect_format_from_url(url) + puts "format #{format}" + download_file(uri, tmp_path) + + unless format + format = detect_format_from_headers(uri) + end + + unless format + format = detect_format_from_magic(tmp_path) + end + + raise "Could not determine archive format" unless format + + extract_archive(tmp_path, format) + end +end + # Example usage: + # fetch_and_extract("https://codeberg.org/forgejo/forgejo/releases/download/v12.0.1/forgejo-12.0.1-linux-amd64.xz") From f3bb91d09e0387a34ff60cd60b61c6cccd513664 Mon Sep 17 00:00:00 2001 From: Artur Gurgul Date: Tue, 5 Aug 2025 10:48:11 +0200 Subject: [PATCH 10/12] save --- lib/archive.rb | 56 +++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/lib/archive.rb b/lib/archive.rb index d8fde1b..3f71694 100644 --- a/lib/archive.rb +++ b/lib/archive.rb @@ -3,6 +3,7 @@ require 'uri' require 'open3' require 'fileutils' require 'open-uri' +require 'shellwords' module Archive MAGIC_NUMBERS = { @@ -12,6 +13,32 @@ module Archive "\xFD\x37\x7A\x58" => 'xz' } + def self.fetch_and_extract(url, cache_path, destination_dir) + uri = URI.parse(url) + file_name = File.basename(uri.path) + archive_path = File.join(destination_dir, file_name) + + format = detect_format_from_url(url) + puts "format #{format}" + download_file(uri, archive_path) + + unless format + puts "case 1" + format = detect_format_from_headers(uri) + end + + unless format + puts "case 2" + format = detect_format_from_magic(archive_path) + end + + raise "Could not determine archive format" unless format + + extract_archive(archive_path, format) + end + + private + def self.detect_format_from_url(url) case File.extname(url) when '.gz', '.tgz' then 'gzip' @@ -61,33 +88,16 @@ module Archive when 'zstd' system("unzstd #{Shellwords.escape(file_path)}") when 'xz' - system("tar -xJf #{Shellwords.escape(file_path)}") + # if file_path.end_with?('.tar.xz') + if `file #{Shellwords.escape(file_path)}`.include?('tar archive') + system("tar -xJf #{Shellwords.escape(file_path)}") + else + system("xz -dk #{Shellwords.escape(file_path)}") + end else raise "Unsupported archive format: #{format}" end end - - def self.fetch_and_extract(url) - uri = URI.parse(url) - file_name = File.basename(uri.path) - tmp_path = "/tmp/#{file_name}" - - format = detect_format_from_url(url) - puts "format #{format}" - download_file(uri, tmp_path) - - unless format - format = detect_format_from_headers(uri) - end - - unless format - format = detect_format_from_magic(tmp_path) - end - - raise "Could not determine archive format" unless format - - extract_archive(tmp_path, format) - end end # Example usage: # fetch_and_extract("https://codeberg.org/forgejo/forgejo/releases/download/v12.0.1/forgejo-12.0.1-linux-amd64.xz") From 57cc223477ecb215dbd4c6614b2ac3d76eb5b242 Mon Sep 17 00:00:00 2001 From: Artur Gurgul Date: Tue, 5 Aug 2025 16:07:34 +0000 Subject: [PATCH 11/12] save --- lib/make.rb | 34 +++++++++++++++++++++++++++++++--- recipes/nginx/generate.rb | 34 ++++++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/lib/make.rb b/lib/make.rb index e36943f..1609f01 100644 --- a/lib/make.rb +++ b/lib/make.rb @@ -28,7 +28,7 @@ module Make class Context attr_accessor :name, :use_cache, :environment, :steps, :packages, :repository - attr_accessor :target + attr_accessor :target, :archive, :source_type def initialize(options: OpenStruct.new) @target = options.target || :user @@ -52,7 +52,21 @@ module Make # puts makefile @packages = makefile["packages"] || [] + + project_sources = { + repository: makefile["repository"] != nil, + archive: makefile["archive"] != nil + }.select { |_, v| v } + + if project_sources.size == 1 + @source_type = project_sources.keys.first + else + raise "Exactly one type of source: 'repository' or 'archive'" + end + puts @source_type + @repository = Make.rostruct(makefile["repository"] || OpenStruct.new) + @archive = Make.rostruct(makefile["archive"] || OpenStruct.new) @steps = makefile["steps"] || [] @environment = ENV.to_h.merge( @@ -147,7 +161,14 @@ module Make install @context.rpd do | path | @cwd = path - checkout + + case @context.source_type + when :repository + checkout + when :archive + download_and_extract + end + puts "path: #{path}" Dir.chdir(path) @@ -160,6 +181,13 @@ module Make end end end + + def download_and_extract + archive = @context.archive + + puts archive + exit -1 + end def checkout repo_path = @context.local_repo @@ -195,4 +223,4 @@ module Make builder = Builder.new(context) builder.build end -end \ No newline at end of file +end diff --git a/recipes/nginx/generate.rb b/recipes/nginx/generate.rb index 6f51fd4..cb9f0cc 100644 --- a/recipes/nginx/generate.rb +++ b/recipes/nginx/generate.rb @@ -3,27 +3,47 @@ require 'erb' class NGINXProxy class << self - attr_accessor :domain, :port, :service + attr_accessor :domain, :port, :service, :user def domain(value = nil) @domain = value unless value.nil? @domain end + def user(value = nil) + @user = value unless value.nil? + @user + end + def port(value = nil) @port = value unless value.nil? @port end - + + # This is name of the daemon that will be installed + # This is also master name user as user if not provided def service(value = nil) @service = value unless value.nil? @service end def generate - template = File.read("proxy.erb") - template = ERB.new(template) - template.result(binding) + template = File.read("proxy.erb") + template = ERB.new(template) + template.result(binding) + end + + def available_path + "/etc/nginx/sites-available/#{service}.#{domain}" + end + + def enabled_path + "/etc/nginx/sites-available/#{service}.#{domain}" + end + + def install + config = generate + File.write end end end @@ -31,7 +51,9 @@ end class ExampleProxy < NGINXProxy domain "gurgul.org" service "forgejo" + user "git" port 3000 end -puts ExampleProxy.generate \ No newline at end of file +puts ExampleProxy.generate +puts ExampleProxy.path From 7ab7d5529245ebe803c2a9b381e5cd8145913fe5 Mon Sep 17 00:00:00 2001 From: Artur Gurgul Date: Tue, 5 Aug 2025 18:09:06 +0200 Subject: [PATCH 12/12] save --- recipes/forgejo-recipe/debian.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 recipes/forgejo-recipe/debian.yml diff --git a/recipes/forgejo-recipe/debian.yml b/recipes/forgejo-recipe/debian.yml new file mode 100644 index 0000000..fb41220 --- /dev/null +++ b/recipes/forgejo-recipe/debian.yml @@ -0,0 +1,6 @@ + +archive: + url: https://codeberg.org/forgejo/forgejo/releases/download/v12.0.1/forgejo-12.0.1-linux-amd64.xz + +steps: + - echo "ls"