Merge branch 'main' of ssh://gurgul.pro/artur/environment
This commit is contained in:
commit
5ef0ee912f
17 changed files with 426 additions and 16 deletions
28
bin/apas
Executable file
28
bin/apas
Executable file
|
@ -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
|
98
bin/cht
Executable file
98
bin/cht
Executable file
|
@ -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)
|
||||
}
|
57
bin/get
Executable file
57
bin/get
Executable file
|
@ -0,0 +1,57 @@
|
|||
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
|
||||
|
||||
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
|
||||
|
||||
# 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
|
16
bin/index
Executable file
16
bin/index
Executable file
|
@ -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"
|
16
bin/macos-config/macos-dock.sh
Normal file
16
bin/macos-config/macos-dock.sh
Normal file
|
@ -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
|
24
bin/macos-config/macos-settings.sh
Normal file
24
bin/macos-config/macos-settings.sh
Normal file
|
@ -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'
|
1
bin/macos-config/readme.md
Normal file
1
bin/macos-config/readme.md
Normal file
|
@ -0,0 +1 @@
|
|||
# Reinstall macOS
|
|
@ -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
|
|
@ -3,9 +3,13 @@
|
|||
|
||||
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/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)
|
||||
|
||||
|
@ -18,4 +22,6 @@ function cdd {
|
|||
. $DAT_ROOT/bin/zshrc/prompt
|
||||
. $DAT_ROOT/bin/zshrc/utils
|
||||
|
||||
bindkey '^e' edit-command-line
|
||||
bindkey '^e' edit-command-line
|
||||
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
|
|
103
lib/archive.rb
Normal file
103
lib/archive.rb
Normal file
|
@ -0,0 +1,103 @@
|
|||
require 'net/http'
|
||||
require 'uri'
|
||||
require 'open3'
|
||||
require 'fileutils'
|
||||
require 'open-uri'
|
||||
require 'shellwords'
|
||||
|
||||
module Archive
|
||||
MAGIC_NUMBERS = {
|
||||
"\x1F\x8B" => 'gzip',
|
||||
"\x50\x4B\x03\x04" => 'zip',
|
||||
"\x28\xB5\x2F\xFD" => 'zstd',
|
||||
"\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'
|
||||
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'
|
||||
# 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
|
||||
end
|
||||
# Example usage:
|
||||
# fetch_and_extract("https://codeberg.org/forgejo/forgejo/releases/download/v12.0.1/forgejo-12.0.1-linux-amd64.xz")
|
34
lib/make.rb
34
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
|
||||
end
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
6
recipes/forgejo-recipe/debian.yml
Normal file
6
recipes/forgejo-recipe/debian.yml
Normal file
|
@ -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"
|
|
@ -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
|
||||
puts ExampleProxy.generate
|
||||
puts ExampleProxy.path
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
- make install
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue