add elf_package "manager"
This commit is contained in:
3
private_dot_config/env/run_after_all.sh
vendored
Normal file
3
private_dot_config/env/run_after_all.sh
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
update_env
|
||||||
@@ -17,11 +17,8 @@ export ANSIBLE_GALAXY_CACHE_DIR="$XDG_CACHE_HOME/ansible/galaxy_cache"
|
|||||||
#NOTE: for the tmp dir on remotes sould be configuard in ansible.cfg
|
#NOTE: for the tmp dir on remotes sould be configuard in ansible.cfg
|
||||||
|
|
||||||
# fix rust dirs
|
# fix rust dirs
|
||||||
export RUSTUP_HOME="$HOME/.local/rust/rustup"
|
|
||||||
export CARGO_HOME="$HOME/.local/rust/cargo"
|
|
||||||
|
|
||||||
# fix discord dirs
|
# fix discord dirs
|
||||||
# export DISCORD_USER_DATA_DIR="$XDG_DATA_HOME"
|
export DISCORD_USER_DATA_DIR="$XDG_DATA_HOME"
|
||||||
|
|
||||||
# fix docker dirs
|
# fix docker dirs
|
||||||
export DOCKER_CONFIG="$XDG_CONFIG_HOME/docker"
|
export DOCKER_CONFIG="$XDG_CONFIG_HOME/docker"
|
||||||
@@ -48,8 +45,3 @@ export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME/npm/npmrc"
|
|||||||
|
|
||||||
# fix java dirs
|
# fix java dirs
|
||||||
export _JAVA_OPTIONS="-Djava.util.prefs.userRoot=$XDG_CONFIG_HOME/java"
|
export _JAVA_OPTIONS="-Djava.util.prefs.userRoot=$XDG_CONFIG_HOME/java"
|
||||||
|
|
||||||
|
|
||||||
# pico SDK
|
|
||||||
export PICO_SDK_PATH="$HOME/.local/rpi/pico-sdk"
|
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
source "$HOME/.config/env"
|
source "$HOME/.config/env/all"
|
||||||
|
|
||||||
if status is-interactive
|
if status is-interactive
|
||||||
|
|
||||||
@@ -9,8 +9,6 @@ if status is-interactive
|
|||||||
|
|
||||||
export EDITOR=vim
|
export EDITOR=vim
|
||||||
|
|
||||||
# TODO: ssh-agent
|
|
||||||
|
|
||||||
# fuzzy find
|
# fuzzy find
|
||||||
export FZF_CTRL_T_OPTS="
|
export FZF_CTRL_T_OPTS="
|
||||||
--walker-skip .git,node_modules,target,.var
|
--walker-skip .git,node_modules,target,.var
|
||||||
|
|||||||
104
private_dot_local/bin/executable_elf_packages
Normal file
104
private_dot_local/bin/executable_elf_packages
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
SCRIPTS_DIR="$HOME/.local/share/elfos"
|
||||||
|
|
||||||
|
function print_help() {
|
||||||
|
echo "usage: elf_packages <ACTION>"
|
||||||
|
echo
|
||||||
|
echo "ACTION:"
|
||||||
|
echo " list list available scripts"
|
||||||
|
echo " install <script> execute install script"
|
||||||
|
echo " uninstall <script> execute remove script"
|
||||||
|
echo " help display this help"
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_if_script_exists() {
|
||||||
|
script="$1"
|
||||||
|
|
||||||
|
if [[ ! -f "$SCRIPTS_DIR/$script.sh" ]]
|
||||||
|
then
|
||||||
|
echo "ERROR: $script does not exists"
|
||||||
|
print_help
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_pacman_deps() {
|
||||||
|
deps="$1"
|
||||||
|
|
||||||
|
pacman -Sy --noconfirm $deps
|
||||||
|
}
|
||||||
|
|
||||||
|
function update() {
|
||||||
|
script="$1"
|
||||||
|
|
||||||
|
check_if_script_exists "$script" || return 1
|
||||||
|
|
||||||
|
. "$SCRIPTS_DIR/$script.sh"
|
||||||
|
|
||||||
|
if package_check_installed
|
||||||
|
then
|
||||||
|
package_update
|
||||||
|
else
|
||||||
|
echo "package not installed"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function uninstall() {
|
||||||
|
script="$1"
|
||||||
|
|
||||||
|
check_if_script_exists "$script" || return 1
|
||||||
|
|
||||||
|
. "$SCRIPTS_DIR/$script.sh"
|
||||||
|
|
||||||
|
if package_check_installed
|
||||||
|
then
|
||||||
|
package_remove
|
||||||
|
else
|
||||||
|
echo "package not installed"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function update() {
|
||||||
|
script="$1"
|
||||||
|
|
||||||
|
check_if_script_exists "$script" && return 1
|
||||||
|
|
||||||
|
. "$SCRIPTS_DIR/$script"
|
||||||
|
package_update
|
||||||
|
}
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
list)
|
||||||
|
find "$SCRIPTS_DIR" -maxdepth 1 -name '*.sh' \
|
||||||
|
-exec basename "{}" ';' \
|
||||||
|
| sed -e 's/\.sh$//'
|
||||||
|
;;
|
||||||
|
install)
|
||||||
|
shift
|
||||||
|
install $*
|
||||||
|
;;
|
||||||
|
uninstall)
|
||||||
|
shift
|
||||||
|
uninstall $*
|
||||||
|
;;
|
||||||
|
update)
|
||||||
|
shift
|
||||||
|
update $*
|
||||||
|
;;
|
||||||
|
help)
|
||||||
|
print_help
|
||||||
|
;;
|
||||||
|
"--help")
|
||||||
|
print_help
|
||||||
|
;;
|
||||||
|
"-h")
|
||||||
|
print_help
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "ERROR: invalid action $1"
|
||||||
|
print_help
|
||||||
|
;;
|
||||||
|
esac
|
||||||
@@ -1,4 +1,11 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
cat "$1"/* | sed -e 's|//.*$||' -e 's|^[ \t]*||' | grep -v '^[ \t]*$' | awk '/\/\*/ {s=1} /\*\// && s==1 {s=0} !s' | grep -v '^.$' | grep -v '^..$' | grep -v '^...$' | wc -l
|
cat "$1"/* \
|
||||||
|
| sed -e 's|//.*$||' -e 's|^[ \t]*||' \
|
||||||
|
| grep -v '^[ \t]*$' \
|
||||||
|
| awk '/\/\*/ {s=1} /\*\// && s==1 {s=0} !s' \
|
||||||
|
| grep -v '^.$' \
|
||||||
|
| grep -v '^..$' \
|
||||||
|
| grep -v '^...$' \
|
||||||
|
| wc -l
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ function pick_song() {
|
|||||||
playlist_path="$PLAYLIST_DIR/$playlist.pls"
|
playlist_path="$PLAYLIST_DIR/$playlist.pls"
|
||||||
if [[ ! -f "$playlist_path" ]]
|
if [[ ! -f "$playlist_path" ]]
|
||||||
then
|
then
|
||||||
echo "error: playlist $playlist not found"
|
echo "ERROR: playlist $playlist not found" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
4
private_dot_local/bin/executable_update_env
Normal file
4
private_dot_local/bin/executable_update_env
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
cat "$(find "$HOME/.config/env" -name '*.env' -type f)" \
|
||||||
|
>"$HOME/.config/env/all"
|
||||||
195
private_dot_local/share/elfos/common/block_in_file.sh
Normal file
195
private_dot_local/share/elfos/common/block_in_file.sh
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
|
||||||
|
function __block_in_file__help() {
|
||||||
|
local func="$1"
|
||||||
|
if [[ "$func" = "update" ]]
|
||||||
|
then
|
||||||
|
echo "block_in_file [<OPTIONS>] <FILE> <ID> <BLOCK>"
|
||||||
|
else
|
||||||
|
echo "block_in_file_remove [<OPTIONS>] <FILE> <ID>"
|
||||||
|
fi
|
||||||
|
echo "$func [<OPTIONS>] <FILE> <ID> <BLOCK>"
|
||||||
|
echo
|
||||||
|
echo "OPTIONS:"
|
||||||
|
if [[ "$func" = "update" ]]
|
||||||
|
then
|
||||||
|
echo " --before <MATCH> insert block before matched line"
|
||||||
|
echo " --after <MATCH> insert block after matched line"
|
||||||
|
fi
|
||||||
|
echo " --id-start-pre <str> set id-start-pre to str"
|
||||||
|
echo " --id-start-post <str> set id-start-post to str"
|
||||||
|
echo " --id-end-pre <str> set id-end-pre to str"
|
||||||
|
echo " --id-end-post <str> set id-end-post to str"
|
||||||
|
echo
|
||||||
|
echo "ID:"
|
||||||
|
echo " an identifier string to regonise the block."
|
||||||
|
if [[ "$func" = "update" ]]
|
||||||
|
then
|
||||||
|
echo
|
||||||
|
echo "MATCH:"
|
||||||
|
echo " line search/match string in grep format"
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
echo "block fomat:"
|
||||||
|
echo " <id-start-pre><id><id-start-post>"
|
||||||
|
echo " <block>"
|
||||||
|
echo " <id-end-pre><id><id-end-post>"
|
||||||
|
}
|
||||||
|
|
||||||
|
function block_in_file() {
|
||||||
|
__block_in_file__inner "update" $*
|
||||||
|
}
|
||||||
|
|
||||||
|
function block_in_file_remove() {
|
||||||
|
__block_in_file__inner "remove" $*
|
||||||
|
}
|
||||||
|
|
||||||
|
function __block_in_file__inner() {
|
||||||
|
local FN="$1"
|
||||||
|
local BEFORE="EOF"
|
||||||
|
local AFTER="SOF"
|
||||||
|
local ID_START_PRE="#START manged by elf_packages: "
|
||||||
|
local ID_START_POST=""
|
||||||
|
local ID_END_PRE="#END "
|
||||||
|
local ID_END_POST=""
|
||||||
|
while [[ $1 == \-* ]]
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
"--before")
|
||||||
|
if [[ "$FN" = "update" ]]
|
||||||
|
then
|
||||||
|
shift
|
||||||
|
BEFORE="$1"
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
echo "ERROR: invalid options $1"
|
||||||
|
__block_in_file__help "$FN"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"--after")
|
||||||
|
if [[ "$FN" = "update" ]]
|
||||||
|
then
|
||||||
|
shift
|
||||||
|
AFTER="$1"
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
echo "ERROR: invalid options $1"
|
||||||
|
__block_in_file__help "$FN"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"--id-start-pre")
|
||||||
|
shift
|
||||||
|
ID_START_PRE="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"--id-start-post")
|
||||||
|
shift
|
||||||
|
ID_START_POST="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"--id-end-pre")
|
||||||
|
shift
|
||||||
|
ID_END_PRE="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"--id-end-post")
|
||||||
|
shift
|
||||||
|
ID_END_POST="$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"--")
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "ERROR: invalid options $1"
|
||||||
|
__block_in_file__help "$FN"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
local FILE="$1"
|
||||||
|
local ID="$2"
|
||||||
|
local BLOCK="$3"
|
||||||
|
|
||||||
|
if [[ ! -f "$FILE" ]]
|
||||||
|
then
|
||||||
|
echo "ERROR: file not found: $FILE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local id_start_line="${ID_START_PRE}${ID}${ID_START_POST}"
|
||||||
|
local id_end_line="${ID_END_PRE}${ID}${ID_END_POST}"
|
||||||
|
|
||||||
|
if [[ "$func" = "update" ]]
|
||||||
|
then
|
||||||
|
block_in_file "$FILE" "$id_start_line" "$id_end_line" "$BEFORE" "$AFTER" "$BLOCK"
|
||||||
|
else
|
||||||
|
block_in_file_remove "$FILE" "$id_start_line" "$id_end_line" "$BLOCK"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function __block_in_file__inner_update() {
|
||||||
|
local file="$1"
|
||||||
|
local id_start_line="$2"
|
||||||
|
local id_end_line="$3"
|
||||||
|
local before="$4"
|
||||||
|
local after="$5"
|
||||||
|
local block="$6"
|
||||||
|
|
||||||
|
if [[ -z "$(grep "^$id_start_line\$" "$file")" ]]
|
||||||
|
then
|
||||||
|
# no existing block. add a new one
|
||||||
|
if [ "$before" == "EOF" ]
|
||||||
|
then
|
||||||
|
before="$(($(cat "$file" | wc --lines) + 1))"
|
||||||
|
else
|
||||||
|
before="$(grep --line-number -e "$before" "$file" | head --lines=1 | awk -F: '{{print $1}}')"
|
||||||
|
fi
|
||||||
|
if [ "$after" == "SOF" ]
|
||||||
|
then
|
||||||
|
after="0"
|
||||||
|
else
|
||||||
|
after="$(grep --line-number -e "$after" "$file" | head --lines=1 | awk -F: '{{print $1}}')"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $after > $before ]]; then
|
||||||
|
echo "ERROR: after is bigger than before, no place to put the block"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
tmp_file=$(mktemp)
|
||||||
|
head --lines=$AFTER "$file" >"$tmp_file"
|
||||||
|
echo "$id_start_line" >>"$tmp_file"
|
||||||
|
echo "$block" >>"$tmp_file"
|
||||||
|
echo "$id_end_line" >>"$tmp_file"
|
||||||
|
tail --lines=+$(($AFTER + 1)) "$file" >>"$tmp_file"
|
||||||
|
mv "$tmp_file" "$file"
|
||||||
|
else
|
||||||
|
# update existing block
|
||||||
|
local start="$(grep --line-number -e "^$id_start_line\$" "$file" | head --lines=1 | awk -F: '{{print $1}}')"
|
||||||
|
local end="$(grep --line-number -e "^$id_end_line\$" "$file" | head --lines=1 | awk -F: '{{print $1}}')"
|
||||||
|
|
||||||
|
local tmp_file=$(mktemp)
|
||||||
|
head --lines=$start "$file" >"$tmp_file"
|
||||||
|
echo "$block" >>"$tmp_file"
|
||||||
|
tail --lines=+$end "$file" >>"$tmp_file"
|
||||||
|
mv "$tmp_file" "$file"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function __block_in_file__inner_remove() {
|
||||||
|
local file="$1"
|
||||||
|
local id_start_line="$2"
|
||||||
|
local id_end_line="$3"
|
||||||
|
local block="$4"
|
||||||
|
|
||||||
|
local start="$(grep --line-number -e "^$id_start_line\$" "$file" | head --lines=1 | awk -F: '{{print $1}}')"
|
||||||
|
local end="$(grep --line-number -e "^$id_end_line\$" "$file" | head --lines=1 | awk -F: '{{print $1}}')"
|
||||||
|
|
||||||
|
local tmp_file=$(mktemp)
|
||||||
|
head --lines=$(($start - 1)) "$file" >"$tmp_file"
|
||||||
|
tail --lines=+$(($start + 1)) "$file" >>"$tmp_file"
|
||||||
|
mv "$tmp_file" "$file"
|
||||||
|
}
|
||||||
38
private_dot_local/share/elfos/esp-idf.sh
Normal file
38
private_dot_local/share/elfos/esp-idf.sh
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
export PACKAGE_DEPS_PACMAN="flex bison gperf ninja ccache libffi dfu-util libusb"
|
||||||
|
|
||||||
|
function package_install() {
|
||||||
|
mkdir -p "$XDG_DATA_HOME/espressif"
|
||||||
|
git clone --recursive --depth=1 https://github.com/espressif/esp-idf.git \
|
||||||
|
"$XDG_DATA_HOME/espressif/esp-idf"
|
||||||
|
git clone --recursive --depth=1 https://github.com/espressif/idf-extra-components.git \
|
||||||
|
"$XDG_DATA_HOME/espressif/idf-extra-components"
|
||||||
|
git clone --recursive --depth=1 https://github.com/espressif/esp-protocols.git \
|
||||||
|
"$XDG_DATA_HOME/espressif/esp-protocols"
|
||||||
|
git clone --recursive --depth=1 https://github.com/espressif/esp-zigbee-sdk.git \
|
||||||
|
"$XDG_DATA_HOME/espressif/esp-zigbee-sdk"
|
||||||
|
|
||||||
|
echo 'export IDF_TOOLS_PATH="$XDG_DATA_HOME/espressif"' \
|
||||||
|
>"$XDG_CONFIG_HOME/env/esp-idf.env"
|
||||||
|
update_env
|
||||||
|
. "$SESSION_ENV_FILE"
|
||||||
|
|
||||||
|
"$XDG_DATA_HOME/espressif/esp-idf/install.sh" all
|
||||||
|
}
|
||||||
|
|
||||||
|
function package_update() {
|
||||||
|
git -C "$XDG_DATA_HOME/espressif/esp-idf" pull
|
||||||
|
git -C "$XDG_DATA_HOME/espressif/idf-extra-components" pull
|
||||||
|
git -C "$XDG_DATA_HOME/espressif/esp-protocols" pull
|
||||||
|
git -C "$XDG_DATA_HOME/espressif/esp-zigbee-sdk" pull
|
||||||
|
}
|
||||||
|
|
||||||
|
function package_remove() {
|
||||||
|
rm -rf "$XDG_DATA_HOME/espressif"
|
||||||
|
rm "$XDG_CONFIG_HOME/env/esp-idf.env"
|
||||||
|
}
|
||||||
|
|
||||||
|
function package_check_installed() {
|
||||||
|
[[ -d "$XDG_DATA_HOME/espressif" ]]
|
||||||
|
}
|
||||||
17
private_dot_local/share/elfos/oh-my-posh.sh
Normal file
17
private_dot_local/share/elfos/oh-my-posh.sh
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
function package_install() {
|
||||||
|
curl -s https://ohmyposh.dev/install.sh | bash -s
|
||||||
|
}
|
||||||
|
|
||||||
|
function package_update() {
|
||||||
|
#TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
function package_remove() {
|
||||||
|
#TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
function package_check_installed() {
|
||||||
|
#TODO
|
||||||
|
}
|
||||||
19
private_dot_local/share/elfos/py-glob.sh
Normal file
19
private_dot_local/share/elfos/py-glob.sh
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
function package_install() {
|
||||||
|
mkdir -p $HOME/.local/py-glob
|
||||||
|
python3 -m venv $HOME/.local/py-glob
|
||||||
|
}
|
||||||
|
|
||||||
|
function package_update() {
|
||||||
|
#TODO
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
function package_remove() {
|
||||||
|
rm -rf "$HOME/.local/py-glob"
|
||||||
|
}
|
||||||
|
|
||||||
|
function package_check_installed() {
|
||||||
|
[[ -d "$HOME/.local/py-glob" ]]
|
||||||
|
}
|
||||||
27
private_dot_local/share/elfos/rustup.sh
Normal file
27
private_dot_local/share/elfos/rustup.sh
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
function package_install() {
|
||||||
|
echo 'export RUSTUP_HOME="$XDG_DATA_HOME/rustup"' >"$XDG_CONFIG_HOME/env/rustup.env"
|
||||||
|
echo 'export CARGO_HOME="$XDG_DATA_HOME/cargo"' >>"$XDG_CONFIG_HOME/env/rustup.env"
|
||||||
|
|
||||||
|
. "$SESSION_ENV_FILE"
|
||||||
|
|
||||||
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs >/tmp/rustup.sh
|
||||||
|
sh /tmp/rustup.sh -y
|
||||||
|
rm /tmp/rustup.sh
|
||||||
|
}
|
||||||
|
|
||||||
|
function package_update() {
|
||||||
|
#TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
function package_remove() {
|
||||||
|
#TODO
|
||||||
|
|
||||||
|
rm "$XDG_CONFIG_HOME/env/rustup.env"
|
||||||
|
}
|
||||||
|
|
||||||
|
function package_check_installed() {
|
||||||
|
#TODO
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user