This commit is contained in:
Artur Gurgul 2025-08-01 12:52:57 +02:00
commit b3dba4542f
44 changed files with 1596 additions and 0 deletions

77
bin/dat Executable file
View file

@ -0,0 +1,77 @@
#!/usr/bin/env ruby
require 'optparse'
require 'ostruct'
# dat set private git://repo
# dat init private
# dat install
# dat reinstall
options = OpenStruct.new
# take the first so OptionParser will not see it
subcommand = ARGV.shift&.to_sym
OptionParser.new do |opt|
opt.on('-i', '--install', 'Install dat for the user') { |o| options.type = :install }
opt.on('-u', '--update', 'Update') do |o|
options.type = :update
end
opt.on('-n', '--name NAME', 'Make the recipe') do |o|
options.name = o
end
opt.on('--cache', 'Use cache') do |o|
options.use_cache = true
end
opt.on('-t', '--target TARGET', ['user', 'usr', 'package', 'pkg', 'system', 'sys'], 'Target type (user, package, system)') do |target|
normalized = case target.downcase
when 'user', 'usr'
:user
when 'package', 'pkg'
:package
when 'system', 'sys'
:system
end
options.target = normalized
end
end.parse!
case subcommand
when :install
puts "installing...."
require 'install'
Install.base_install
when :update
puts "updating...."
require 'install'
Install.base_update
when :make
puts "making..."
require 'make'
Make.command(options)
when :goto
Dir.chdir(ENV["DAT_ROOT"])
when :vm
puts 'vm command'
# dat vm --create name
# dat vm --run name --graphic (default no graphic)
# Idea ===========
# dat vm --pool --execute script.sh
else
puts "Error not found #{options.type}"
end
# install locally for the user
# dat install
# dat set git://repo
# dat init
# dat deinit
# dat reinstall

77
bin/img.create Executable file
View file

@ -0,0 +1,77 @@
#!/usr/bin/env ruby
require 'open-uri'
require 'zip' # gem install rubyzip
require 'stringio'
require 'fileutils'
require 'uri'
require 'xz' # gem install ruby-xz
url = 'https://artur.gurgul.pro/static/vms/debian.ext2.img.zip'
# 'https://artur.gurgul.pro/static/vms/linux-v1.zip'
# debian.ext2.img.zip debian.ext4.img.zip linux-v1.zip
# sudo fdisk -l debian.img
# [sudo] password for artur:
# Disk debian.img: 4 GiB, 4294967296 bytes, 8388608 sectors
# Units: sectors of 1 * 512 = 512 bytes
# Sector size (logical/physical): 512 bytes / 512 bytes
# I/O size (minimum/optimal): 512 bytes / 512 bytes
# Disklabel type: dos
# Disk identifier: 0x878d05dc
#
# Device Boot Start End Sectors Size Id Type
# debian.img1 * 2048 8386559 8384512 4G 83 Linux
# artur@gurgul.xyz ~/vm ➜ sudo mount -o loop,offset=1048576 debian.img /mnt
# 1048576 = 512 * 2048
# sudo tar --xattrs --acls --numeric-owner -cpf - -C /mnt/diskimg . | xz -T0 > disk-backup.tar.xz
# To preserve all metadata, ownership, permissions, symlinks, devices, etc., use tar with --xattrs, --numeric-owner
# -cpf - → write tar to stdout
# -C /mnt/diskimg . → change directory so root of the archive matches root of the image
# xz -T0 → compress using all CPU cores
# https://chatgpt.com/c/688b32da-5e14-8327-9abc-b83a44252c05
# compare for differences
# sudo diff -r /mnt/diskimg /tmp/old
# Determine file extension
ext = File.extname(URI.parse(url).path)
# Open remote stream
URI.open(url) do |remote_file|
case ext
when '.zip'
puts "Processing ZIP file..."
buffer = remote_file.read
Zip::File.open_buffer(StringIO.new(buffer)) do |zip_file|
zip_file.each do |entry|
puts "Extracting #{entry.name}..."
target_path = File.join(Dir.pwd, entry.name)
FileUtils.mkdir_p(File.dirname(target_path))
entry.extract(target_path) { true } # Overwrite if exists
end
end
when '.xz'
puts "Processing XZ file..."
# Use XZ::StreamReader to decompress on-the-fly
xz_reader = XZ::StreamReader.new(remote_file)
# Assume .xz contains a single file; decide on output name
output_filename = File.basename(url, '.xz')
output_path = File.join(Dir.pwd, output_filename)
File.open(output_path, 'wb') do |out|
IO.copy_stream(xz_reader, out)
end
puts "Decompressed to #{output_path}"
else
puts "Unsupported file extension: #{ext}"
end
end

73
bin/img.extend Executable file
View file

@ -0,0 +1,73 @@
#!/usr/bin/env ruby
# truncate -s +10G
# Usage: ruby extend_mbr.rb disk.img
SECTOR_SIZE = 512
MBR_SIZE = 512
PARTITION_ENTRY_OFFSET = 446
PARTITION_ENTRY_SIZE = 16
MAX_PARTITIONS = 4
if ARGV.length != 1
puts "Usage: #{$0} disk.img"
exit 1
end
image_path = ARGV[0]
# Read disk image and MBR
image_size = File.size(image_path)
total_sectors = image_size / SECTOR_SIZE
puts ">> Image size: #{image_size} bytes"
puts ">> Total sectors: #{total_sectors}"
File.open(image_path, 'rb+') do |f|
mbr = f.read(MBR_SIZE).dup
last_partition_index = nil
start_sector = nil
# Find last valid partition
MAX_PARTITIONS.times do |i|
offset = PARTITION_ENTRY_OFFSET + i * PARTITION_ENTRY_SIZE
part_type = mbr.getbyte(offset + 4)
if part_type != 0x00
last_partition_index = i
end
end
if last_partition_index.nil?
abort "!! No valid partitions found in MBR"
end
entry_offset = PARTITION_ENTRY_OFFSET + last_partition_index * PARTITION_ENTRY_SIZE
# Read start sector (little-endian uint32 at offset +8)
start_sector_bytes = mbr.byteslice(entry_offset + 8, 4)
start_sector = start_sector_bytes.unpack("V").first
new_size = total_sectors - start_sector
puts ">> Found partition ##{last_partition_index + 1}"
puts " Start sector: #{start_sector}"
puts " New size: #{new_size} sectors"
# Pack new size (little-endian uint32)
new_size_bytes = [new_size].pack("V")
mbr[entry_offset + 12, 4] = new_size_bytes
# Write back modified MBR
f.seek(0)
f.write(mbr)
puts "✅ MBR updated. Partition now fills remaining disk space."
end
# sudo e2fsck -f /dev/sda1
# sudo resize2fs /dev/sda1

13
bin/img.run Executable file
View file

@ -0,0 +1,13 @@
#!/usr/bin/bash
# mount -t 9p -o trans=virtio,version=9p2000.L host0 /root
qemu-system-x86_64 -append "root=/dev/sda1 console=ttyS0" \
-kernel "$HOME/Desktop/debian/vmlinuz-linux" \
-initrd "$HOME/Desktop/debian/initramfs-linux.img" \
-m 2048 \
-smp $(sysctl -n hw.logicalcpu) \
-cpu qemu64 \
-virtfs local,path=.,security_model=none,mount_tag=host0 \
-drive format=raw,file=debian.img \
-nographic

14
bin/makeshell Normal file
View file

@ -0,0 +1,14 @@
cp ./shell /usr/bin/shell
# append to /etc/shells
# /etc/shells
# useradd -mg users -s /usr/bin/shell user
# chsh -s /usr/bin/shell user
# For the cuurent user
#chsh -s /usr/bin/shell

3
bin/pclean Executable file
View file

@ -0,0 +1,3 @@
make clean
git clean -fdx

18
bin/server Executable file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env ruby
require 'server_manager'
# server application add file.yml
# ServerManager.init_sapplication("filename")
# server application remove name
# ServerManager.remove_application("service_name")
# server application passwd name
# ServerManager.application_passwd("service_name")
# server user add user-name
# server user remove user-name
# server user passwd user-name
# server install app-name

17
bin/shell Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
# Try to get home directory safely
USER_HOME=$(getent passwd "$USER" | cut -d: -f6)
MYZSH="$USER_HOME/.local/bin/zsh"
if [ -x "$MYZSH" ]; then
echo "user own shell"
exec "$MYZSH" -i
elif command -v zsh >/dev/null 2>&1; then
echo "system zsh shell"
exec "$(command -v zsh)"
else
echo "fallback, default bash"
exec bash
fi

6
bin/test-env Executable file
View file

@ -0,0 +1,6 @@
#!/usr/bin/bash
echo "Passed prefix: $PREFIX"
echo "Dat: $DAT_ROOT"
echo "test: ${TEST_ENV}"
echo "TT: $TT"

27
bin/vm Executable file
View file

@ -0,0 +1,27 @@
# mount -t 9p -o trans=virtio,version=9p2000.L share /home/user
# this add to brake and inspect /dev if /dev/sda1 not found
# -append "root=/dev/sda1 console=ttyS0 rd.break"
function run {
qemu-system-x86_64 -append "root=/dev/sda1 console=ttyS0 rd.break" \
-kernel "vmlinuz-linux" \
-initrd "initramfs-linux.img" \
-m 2048 \
-smp $(sysctl -n hw.logicalcpu) \
-cpu qemu64 \
-virtfs local,path=.,security_model=none,mount_tag=share \
-drive id=root-disk,if=none,format=raw,file=linux.img \
-device ide-hd,bus=ide.0,drive=root-disk \
-drive id=data-disk,if=none,format=qcow2,file=dat.qcow2 \
-device ide-hd,bus=ide.1,drive=data-disk \
-nographic
}
function reset {
qemu-img create -f qcow2 dat.qcow2 32G
}
$1

9
bin/zshrc/brew Normal file
View file

@ -0,0 +1,9 @@
if [[ "$OSTYPE" == "darwin"* ]]; then
ARCH=$(uname -m)
if [[ "$ARCH" == "arm64" ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
elif [[ "$ARCH" == "x86_64" ]]; then
eval "$(/usr/local/bin/brew shellenv)"
fi
fi

21
bin/zshrc/init Normal file
View file

@ -0,0 +1,21 @@
# sources that might alter the path
. $DAT_ROOT/bin/zshrc/brew
export PATH="$DAT_ROOT/bin:$HOME/.local/bin:$PATH"
export RUBYLIB="$DAT_ROOT/lib"
export PASSWORD_STORE_DIR=$HOME/.local/secure-vault/passwords
path=("$GEM_HOME/bin" $path)
alias gf='git log --all --oneline | fzf'
function cdd {
cd $DAT_ROOT
}
. $DAT_ROOT/bin/zshrc/prompt
. $DAT_ROOT/bin/zshrc/utils
bindkey '^e' edit-command-line

44
bin/zshrc/prompt Normal file
View file

@ -0,0 +1,44 @@
# Enable vcs_info
autoload -Uz vcs_info
autoload -Uz add-zsh-hook
# Colors
GRAY="%F{245}"
PURPLE="%F{141}"
RED="%F{red}"
RESET="%f"
zstyle ':vcs_info:git:*' formats '%b'
zstyle ':vcs_info:*' enable git
git_precmd() {
vcs_info
if [[ -n "${vcs_info_msg_0_}" ]]; then
GIT_PROMPT="${PURPLE}(${RED}${vcs_info_msg_0_}${PURPLE}) "
else
GIT_PROMPT=""
fi
PROMPT="${GRAY}%n@%M ${RESET}%~ ${GIT_PROMPT}${PURPLE}➜ ${RESET}"
}
add-zsh-hook precmd git_precmd
# Prompt
# PROMPT='${GRAY}%n@%m ${RESET}%~ ${PURPLE}(${RED}${vcs_info_msg_0_}${PURPLE}) ➜ ${RESET}'
#
# vcs_info
# PROMPT='${GRAY}%n@%m ${RESET}%~ ${GIT_PROMPT}${PURPLE}➜ ${RESET}'
# PROMPT="${GRAY}%n@%M ${RESET}%~ ${GIT_PROMPT}${PURPLE}➜ ${RESET}"
# Mac OS
# export HOST="gurgul.pro"
# sudo scutil --set HostName "Mac-mini"
# Linux
# sudo hostnamectl set-hostname
# hostnamectl

16
bin/zshrc/utils Normal file
View file

@ -0,0 +1,16 @@
export EDITOR='nvim'
export GIT_EDITOR='nvim'
# git config --global core.editor "nvim"
alias ddd='date +"%d-%m-%Y"'
alias v='nvim'
# should be for linux only
alias ip='ip -c'
alias hist='eval `history | fzf | cut -s -d " " -f4-`'
export LC_ALL=en_US.UTF-8
export HISTSIZE=100000000