Commit a7388635 authored by PoroCYon's avatar PoroCYon
Browse files

more cleanup stuff

parent 0cf5de32
......@@ -3,8 +3,6 @@
export SSPT_THISSCRIPT=$(realpath "$0")
export SSPT_RUNDIR=$(dirname "$SSPT_THISSCRIPT")
ALL_ARGS=("$@")
exit_cleanup() {
unset -f escape_string
unset -f temp_filename
......@@ -123,12 +121,12 @@ exec_subcommand () {
if ! [ -d "$SSPT_BIN_DB_DIR" ]; then mkdir -p "$SSPT_BIN_DB_DIR"; fi
local SUB_FILE="$SSPT_SUB_DIR/sspt-$1"
local ALL_ARGS_=("$@")
local ALL_ARGS=("$@")
command -v "$SUB_FILE" >/dev/null 2>&1 || exec_sub_rip "$SUB_FILE" "$1"
#(>&2 echo "execing $1 : ${ALL_ARGS_[@]:1}")
"$SUB_FILE" "${ALL_ARGS_[@]:1}"
#(>&2 echo "execing $1 : ${ALL_ARGS[@]:1}")
"$SUB_FILE" "${ALL_ARGS[@]:1}"
return $?
}
export -f exec_subcommand
......@@ -192,6 +190,7 @@ main() {
local RETVAL=$?
if [ $RETVAL -gt 0 ] && [ -z "$ISSUBCMD" ]; then
# TODO: make this work with s/2/\$RETVAL/
local ALL_ARGS=("$@")
local NEW_ARGS=(${ALL_ARGS[@]:2})
if [ ${#NEW_ARGS[@]} -eq 0 ]; then
print_help
......
......@@ -24,9 +24,6 @@ main() {
fi
# assume it is already configured
exec_subcommand pkgcmd build "$1"
# now update the 'known latest version'
#exec_subcommand src-db reg "$1" $(exec_subcommand pkgcmd version "$1")
;;
esac
}
......
......@@ -24,7 +24,7 @@ main() {
exit 1
fi
local PACKAGE_DIR="$SSPT_DL_DIR/$ESCAPED_PKG"
local PACKAGE_DIR="${SSPT_DL_DIR:?}/$ESCAPED_PKG"
command -v "$EDITOR" >/dev/null 2>&1 && "$EDITOR" "$PACKAGE_DIR/.sspt" && return
command -v "nano" >/dev/null 2>&1 && "nano" "$PACKAGE_DIR/.sspt" && return
......
......@@ -15,24 +15,24 @@ EOF
main() {
case "$1" in
-i|--installed-only|--only-installed)
while read -r pkg; do
local ESCAPED_PKG=$(escape_string "$pkg")
local ver=$(grep -E "^$ESCAPED_PKG " < "$SSPT_SRC_DB_FILE" | grep -E -o "[A-Za-z0-9_\-\.]$")
while read -r PKG; do
local ESCAPED_PKG=$(escape_string "$PKG")
local VER=$(grep -E "^$ESCAPED_PKG " < "$SSPT_SRC_DB_FILE" | grep -E -o "[A-Za-z0-9_\-\.]$")
echo "$pkg $ver"
echo "$PKG $VER"
done < "$SSPT_BIN_DB_FILE"
;;
*)
while read -r pkg_and_ver; do
local pkg=$(echo "$pkg_and_ver" | grep -E -o "^[A-Za-z0-9_\-\.]")
local ver=$(echo "$pkg_and_ver" | grep -E -o "[A-Za-z0-9_\-\.]$")
while read -r PKG_AND_VER; do
local PKG=$(echo "$PKG_AND_VER" | grep -E -o "^[A-Za-z0-9_\-\.]")
local VER=$(echo "$PKG_AND_VER" | grep -E -o "[A-Za-z0-9_\-\.]$")
local inst=" "
if exec_subcommand bin-db exists "$pkg"; then
inst="*"
local INST=" "
if exec_subcommand bin-db exists "$PKG"; then
INST="*"
fi
echo "$inst $pkg $ver"
echo "$INST $PKG $VER"
done < "$SSPT_SRC_DB_FILE"
;;
esac
......
......@@ -44,34 +44,34 @@ run_strace() {
rm "$STRACE_OUT"
while read -r line; do
local syscall=$(echo "$line" | sed -E -e 's/\(.*$//')
local alargs_=$(echo "$line" | sed -E -e 's/^.*?\(//' -e 's/\)$//')
while read -r LINE; do
local SYSCALL=$(echo "$LINE" | sed -E -e 's/\(.*$//')
local ALLARG_=$(echo "$LINE" | sed -E -e 's/^.*?\(//' -e 's/\)$//')
IFS=', '
read -ra allargs <<< "$alargs_"
read -ra ALLARGS <<< "$ALLARG_"
unset IFS
local outfile=""
case "$syscall" in
local OUTFIL=""
case "$SYSCALL" in
open|creat|mkdir|rmdir|symlink)
outfile="${allargs[0]}"
OUTFIL="${ALLARGS[0]}"
;;
openat|link|mkdirat|rename)
outfile="${allargs[1]}"
OUTFIL="${ALLARGS[1]}"
;;
symlinkat)
outfile="${allargs[2]}"
OUTFIL="${ALLARGS[2]}"
;;
linkat|renameat|renameat2)
outfile="${allargs[3]}"
OUTFIL="${ALLARGS[3]}"
;;
*)
(>&2 echo "Unexpeted strace output '$line'!")
(>&2 echo "Unexpeted strace output '$LINE'!")
unset OUTFILE
exit 1
;;
esac
echo "$outfile" >> "$STRACE_OUT" # reuse the file
echo "$OUTFIL" >> "$STRACE_OUT" # reuse the file
done < "$GREP_OUT"
rm "$GREP_OUT"
......
......@@ -42,17 +42,17 @@ main() {
fi
# 1. delete all files
while read -r line; do
while read -r LINE; do
# unescape
local lin_=$(echo "$line" | sed -E 's/\\(.)/\1/g')
lin_="${lin_%\"}"
lin_="${lin_#\"}"
local LIN_=$(echo "$LINE" | sed -E 's/\\(.)/\1/g')
LIN_="${LIN_%\"}"
LIN_="${LIN_#\"}"
rm -rf "$lin_"
rm -rf "$LIN_"
# if dir is empty, remove it
remove_empty_dir_rec "$(dirname "$lin_")"
done < "$SSPT_BIN_DB_DIR/$ESCAPED_PKG"
remove_empty_dir_rec "$(dirname "$LIN_")"
done < "${SSPT_BIN_DB_DIR:?}/$ESCAPED_PKG"
# 2. remove from the db
exec_subcommand bin-db unreg "$1"
......
......@@ -14,17 +14,18 @@ EOF
}
update_package() {
local pkg="$1"
local before="$2"
if [ -z "$before" ]; then
local epkg=$(escape_string "$pkg")
before=$(< "$SSPT_SRC_DB_FILE" grep -E "^$pkg " | grep -E -v -o "^$epkg ")
local PKG="$1"
local BEFORE="$2"
if [ -z "$BEFORE" ]; then
# TODO: src-db getver $pkg?
local EPKG=$(escape_string "$PKG")
BEFORE=$(< "$SSPT_SRC_DB_FILE" grep -E "^$EPKG " | grep -E -v -o "^$EPKG ")
fi
exec_subcommand pkgcmd pull "$pkg"
local after=$(exec_subcommand pkgcmd version "$pkg")
exec_subcommand pkgcmd pull "$PKG"
local AFTER=$(exec_subcommand pkgcmd version "$PKG")
if [ "$before" != "$after" ]; then
exec_subcommand src-db reg "$pkg" "$after"
if [ "$BEFORE" != "$AFTER" ]; then
exec_subcommand src-db reg "$PKG" "$AFTER"
return 1
fi
......@@ -37,8 +38,8 @@ upgrade_package() {
exec_subcommand install "$1"
}
upgrade_pkgs() {
while read -r pkg; do
upgrade_package "$pkg"
while read -r PKG; do
upgrade_package "$PKG"
done < "/tmp/upgrade_list"
rm /tmp/upgrade_list
}
......@@ -46,10 +47,10 @@ upgrade_pkgs() {
update_selection() {
touch /tmp/upgrade-list
local allargs=("$@")
for pkg in "${allargs[@]}"; do
if ! update_package "$pkg" ""; then
echo "$pkg" >> /tmp/upgrade_list
local ALLARGS=("$@")
for pkg in "${ALLARGS[@]}"; do
if ! update_package "$PKG" ""; then
echo "$PKG" >> /tmp/upgrade_list
fi
done
......@@ -59,12 +60,12 @@ update_selection() {
update_all() {
touch /tmp/upgrade-list
while read -r pkg_and_ver; do
local pkg=$(echo "$pkg_and_ver" | grep -E -o "^[A-Za-z0-9_\-\.]")
local before=$(echo "$pkg_and_ver" | grep -E -o "[A-Za-z0-9_\-\.]$")
while read -r PKG_AND_VER; do
local PKG=$(echo "$PKG_AND_VER" | grep -E -o "^[A-Za-z0-9_\-\.]")
local BEFORE=$(echo "$PKG_AND_VER" | grep -E -o "[A-Za-z0-9_\-\.]$")
if ! update_package "$pkg" "$before"; then
echo "$pkg" >> /tmp/upgrade_list
if ! update_package "$PKG" "$BEFORE"; then
echo "$PKG" >> /tmp/upgrade_list
fi
done < "$SSPT_SRC_DB_FILE"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment