Commit 3a194444 authored by PoroCYon's avatar PoroCYon
Browse files

almost everything

parent 94a9ce7a
local/share/*
*~
# temporary files which can be created if a process still has a handle open of a deleted file
......
......@@ -6,12 +6,32 @@ RUNDIR=$(dirname $THISSCRIPT)
ALL_ARGS=("$@")
ARG_COUNT=$#
exit_cleanup() {
unset -f escape_string
unset -f temp_filename
unset -f load_config
unset -f exec_subcommand
unset SSPT_DEST_DIR
unset SSPT_DB_DIR
unset SSPT_SUB_DIR
unset SSPT_DL_DIR
unset SSPT_SRC_DB_FILE
unset SSPT_BIN_DB_FILE
unset SSPT_BIN_DB_DIR
exit $@
}
escape_string() {
printf '%s' "$@" | sed 's/[.[\*^$()+?{|]/\\&/g'
}
export -f escape_string
temp_filename() {
echo "/tmp/ssbt-$(cat /dev/urando | head -c 4 | base64)"
}
export -f temp_filename
print_version() {
(>&2 echo "sspt v0.0.0")
......@@ -20,33 +40,33 @@ print_version() {
print_help() {
print_version
(>&2 cat <<EOF
Usage: $0 [-h|-?|--help]
Print this help text and exit.
- $0 [-V|--version]
Print the version of sspt and exit.
- $0 [-c|--config] <file>
Use the specified file as configuration, instead of
\$XDG_CONFIG_HOME/sspt.conf
- $0 --mk-default-config
Create a default config file. The file is placed in
\$XDG_CONFIG_HOME/sspt.conf , unless --config was specified.
- $0 --list-subcommands
List all available subcommands. Subcommands work like
they do in git, one can define them by creating a
sspt-<subcommand> and placing it in \$SSPT_SUB_DIR
(defined in the sspt config file). Note that calling the
subcommand files directly is a bad idea as the main ssbt
script sets up the environment.
- $0 <subcommand> <options...>
Execute a subcommand. Use \`$0 <subcommand> --help\' for
more information about a particular subcommand.
sspt - manage upstream repositories
Usage: $0 [-h|-?|--help]
Print this help text and exit.
- $0 [-V|--version]
Print the version of sspt and exit.
- $0 [-c|--config] <file>
Use the specified file as configuration, instead of
\$XDG_CONFIG_HOME/sspt.conf
- $0 --mk-default-config
Create a default config file. The file is placed in
\$XDG_CONFIG_HOME/sspt.conf , unless --config was specified.
- $0 --list-subcommands
List all available subcommands. Subcommands work like they
do in git, one can define them by creating a sspt-<subcommand>
and placing it in \$SSPT_SUB_DIR (defined in the sspt config
file). Note that calling the subcommand files directly is a
bad idea as the main ssbt script sets up the environment.
- $0 <subcommand> <options...>
Execute a subcommand. Use \`$0 <subcommand> --help\' for more
information about a particular subcommand.
EOF
)
}
if [ $# -eq 0 ]; then
print_help
exit
exit_cleanup
fi
CONFIG_PATH="$XDG_CONFIG_HOME"
......@@ -58,36 +78,38 @@ CONFIG_FILE="$CONFIG_PATH/sspt.conf"
load_config() {
if ! [ -f "$CONFIG_FILE" ]; then
(>&2 echo "Config file '$CONFIG_FILE' does not exist!")
exit 1
exit_cleanup 1
fi
source "$CONFIG_FILE"
}
export -f load_config
exec_subcommand () {
if [ -z "$SSPT_DEST_DIR" ] || [ -z "$SSPT_DB_DIR" ] || [ -z "$SSPT_SUB_DIR" ] || [ -z "$SSPT_DL_DIR" ]; then
(>&2 echo "\$SSPT_DEST_DIR or \$SSPT_DB_DIR or \$SSPT_SUB_DIR or \$SSPT_DL_DIR not defined.")
exit 1
exit_cleanup 1
fi
SSPT_SRC_DB_FILE="$SSPT_DB_DIR/sources"
SSPT_BIN_DB_FILE="$SSPT_DB_DIR/installs"
export SSPT_SRC_DB_FILE="$SSPT_DB_DIR/sources"
export SSPT_BIN_DB_FILE="$SSPT_DB_DIR/installs"
if ! [ -f "$SSPT_SRC_DB_FILE" ]; then touch "$SSPT_SRC_DB_FILE"; fi
if ! [ -f "$SSPT_BIN_DB_FILE" ]; then touch "$SSPT_BIN_DB_FILE"; fi
SSPT_BIN_DB_DIR="$SSPT_DB_DIR/files"
export SSPT_BIN_DB_DIR="$SSPT_DB_DIR/files"
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_=("$@")
command -v "$SUB_FILE" >/dev/null 2>&1 || { (>&2 echo "File '$SUB_FILE' does not exist, cannot execute subcommand '$1'.") } && exit 1
command -v "$SUB_FILE" >/dev/null 2>&1 || { (>&2 echo "File '$SUB_FILE' does not exist, cannot execute subcommand '$1'.") } && exit_cleanup 1
exec $SUB_FILE "${ALL_ARGS_[@]:1}"
return $?
}
export -f exec_subcommand
ISSUBCMD=""
parse_arg() {
......@@ -95,7 +117,7 @@ parse_arg() {
-c|--config)
if [ $# -lt 2 ]; then
(>&2 echo "No config file path given.")
exit 1
exit_cleanup 1
fi
CONFIG_FILE="$2"
......@@ -111,18 +133,22 @@ parse_arg() {
--list-subcommands)
# I'm lazy
load_config
ls $SSPT_SUB_DIR/sspt-*
find -type f -name "sspt-*" "$SSPT_SUB_DIR/"
;;
--mk-default-config)
if ! [ -d "$CONFIG_PATH" ]; then
mkdir -p "$CONFIG_PATH"
fi
cat > "$CONFIG_FILE" <<EOF
# SSPT_DEST_DIR controls e.g. the PREFIX variable in makefile builds.
# NOTE: This variable is used when configuring packages. If you change
# this, it will not have any effect unless you reconfigure all packages.
export SSPT_DEST_DIR="\$HOME/.local"
export SSPT_SUB_DIR="\$HOME/.local/libexec/sspt"
export SSPT_DB_DIR="\$HOME/.local/share/sspt"
export SSPT_DEST_DIR="\$XDG_CONFIG_HOME"
# This directory contains all the subcommand scripts.
export SSPT_SUB_DIR="\$XDG_CONFIG_HOME/libexec/sspt"
# This directory contains all the database files.
export SSPT_DB_DIR="\$XDG_CONFIG_HOME/share/sspt"
# This is where sspt stores the source code of all pacakges.
# You might want to change this.
export SSPT_DL_DIR="\$HOME/src/sspt"
EOF
......@@ -146,7 +172,7 @@ main() {
local NEW_ARGS="${ALL_ARGS[@]:2}"
if [ ${#NEW_ARGS[@]} -eq 0 ]; then
print_help
exit
exit_cleanup
fi
parse_arg ${NEW_ARGS[@]}
......
......@@ -20,10 +20,7 @@ EOF
}
main() {
local ESCAPED_PKG=
if ! [ -z "$2" ]; then
ESCAPED_PKG=`escape_string $2`
fi
local ESCAPED_PKG=`escape_string $2`
case $1 in
-h|-?|--help)
......@@ -43,7 +40,7 @@ main() {
if [ $? -ne 0 ]; then
# doesn't exist
echo "$2" >> "$SSPT_BIN_DB_FILE"
cp "$3" "$SSPT_BIN_DB_DIR/$2"
cp "$3" "$SSPT_BIN_DB_DIR/$ESCAPED_PKG"
else
# update path
(>&2 echo "WARNING: This package is already registered, updating its path...")
......@@ -51,7 +48,7 @@ main() {
egrep -v -e "^$ESCAPED_PKG " -f "$SSPT_BIN_DB_FILE" > "$TMPFILE"
echo "$2" >> "$TMPFILE"
mv "$TMPFILE" "$SSPT_BIN_DB_FILE"
cp "$3" "$SSPT_BIN_DB_DIR/$2"
cp "$3" "$SSPT_BIN_DB_DIR/$ESCAPED_PKG"
fi
;;
unreg|unregister)
......@@ -63,6 +60,7 @@ main() {
local TMPFILE="$(temp_filename)"
egrep -v -e "^$ESCAPED_PKG" -f "$SSPT_BIN_DB_FILE" > "$TMPFILE"
mv "$TMPFILE" "$SSPT_BIN_DB_FILE"
rm "$SSPT_BIN_DB_DIR/$ESCAPED_PKG"
else
(>&2 echo "Package doesn't exist.")
fi
......
#!/usr/bin/env bash
print_help() {
(>&2 cat <<EOF
Build a package.
Usage: $0 [-h|-?|--help]
Print this help text and exit.
- $0 <package-name>
Build the package.
EOF
)
}
main() {
case $1 in
-h|-?|--help)
print_help
;;
*)
exec_subcommand src-db exists "$1"
if [ $? -ne 0 ]; then
# TODO: download if URL specified
(>&2 echo "This package doesn't exist.")
exit 1
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
}
if [ $# -eq 0 ]; then
print_help
exit
fi
main $@
#!/usr/bin/env bash
print_help() {
(>&2 cat <<EOF
Clean a package.
Usage: $0 [-h|-?|--help]
Print this help text and exit.
- $0 <package-name>
Clean the package.
EOF
)
}
main() {
case $1 in
-h|-?|--help)
print_help
;;
*)
exec_subcommand src-db exists "$1"
if [ $? -ne 0 ]; then
(>&2 echo "This package doesn't exist.")
exit 1
fi
exec_subcommand pkgcmd clean "$1"
;;
esac
}
if [ $# -eq 0 ]; then
print_help
exit
fi
main $@
#!/usr/bin/env bash
print_help() {
(>&2 cat <<EOF
Clean a package, including all configuration files.
Usage: $0 [-h|-?|--help]
Print this help text and exit.
- $0 <package-name>
Clean the package.
EOF
)
}
main() {
case $1 in
-h|-?|--help)
print_help
;;
*)
exec_subcommand src-db exists "$1"
if [ $? -ne 0 ]; then
(>&2 echo "This package doesn't exist.")
exit 1
fi
exec_subcommand pkgcmd clean_config "$1"
;;
esac
}
if [ $# -eq 0 ]; then
print_help
exit
fi
main $@
#!/usr/bin/env bash
print_help() {
(>&2 cat <<EOF
Configure a pacakge.
Usage: $0 [-h|-?|--help]
Print this help text and exit.
- $0 <package-name>
Configure the package.
EOF
)
}
main() {
case $1 in
-h|-?|--help)
print_help
;;
*)
exec_subcommand src-db exists "$1"
if [ $? -ne 0 ]; then
# TODO: download if URL specified
(>&2 echo "This package doesn't exist.")
exit 1
fi
exec_subcommand pkgcmd configure "$1"
;;
esac
}
if [ $# -eq 0 ]; then
print_help
exit
fi
main $@
......@@ -4,7 +4,7 @@ print_help() {
(>&2 cat <<EOF
Edit the .sspt file of a package.
Usage: $0 [-h|-?|--help]
Print this help text and edit.
Print this help text and exit.
- $0 <package-name>
Edit the .sspt file of the package using \$EDITOR.
EOF
......@@ -19,19 +19,20 @@ main() {
print_help
;;
*)
egrep -q -e "^$ESCAPED_PKG " -f "$SSPT_SRC_DB_FILE"
exec_subcommand src-db exists "$1"
if [ $? -ne 0 ]; then
(>&2 echo "Package '$1' doesn't exist.")
exit 1
fi
local PACKAGE_DIR=$(egrep -e "^$ESCAPED_PKG " -f "$SSPT_SRC_DB_FILE" \
| egrep -v -o -e "^[A-Za-z0-9_\-\.]* " | egrep -v -o -e " [A-Za-z0-9]$")
| egrep -v -o -e "^[A-Za-z0-9_\-\.]* " | egrep -v -o -e " [A-Za-z0-9_\-\.]$")
command -v "$EDITOR" >/dev/null 2>&1 && "$EDITOR" "$PACKAGE_DIR/.sspt" && return
command -v "nano" >/dev/null 2>&1 && "nano" "$PACKAGE_DIR/.sspt" && return
command -v "nvim" >/dev/null 2>&1 && "nvim" "$PACKAGE_DIR/.sspt" && return
command -v "vim" >/dev/null 2>&1 && "vim" "$PACKAGE_DIR/.sspt" && return
command -v "vi" >/dev/null 2>&1 && "vi" "$PACKAGE_DIR/.sspt" && return
;;
esac
}
......
......@@ -4,7 +4,7 @@ print_help() {
(>&2 cat <<EOF
Directly execute a command from a package's .sspt file.
Usage: $0 [-h|-?|--help]
Print this help text and edit.
Print this help text and exit.
- $0 <command> <package-name>
Run <command> on the specified package.
NOTE: this subcommand is supposed to be used only by ssbt internally.
......@@ -14,20 +14,26 @@ EOF
}
main() {
local ESCAPED_PKG=`escape_string $2`
if [ -z "$2" ]; then
print_help
exit
fi
local ESCAPED_PKG=`escape_string $2`
case $1 in
-h|-?|--help)
print_help
;;
*)
exec_subcommand src-db exists "$2"
if [ $? -ne 0 ]; then
(>&2 echo "This package doesn't exist.")
exit 1
fi
pushd "$SSPT_DL_DIR/$ESCAPED_PKG" >/dev/null
bash -c "source \".sspt\" && \"$1\""
bash -c "source \".sspt\" && \"sspt_$1\""
local RETVAL=$?
popd >/dev/null
exit $RETVAL
......
......@@ -14,8 +14,10 @@ EOF
)
}
PKG_NAME=
pull_with_vcs() {
local PKG_NAME="$(basename $2)"
PKG_NAME="$(basename $2)"
if [ "$1" == "git" ] && [[ "$PKG_NAME" == *".git" ]]; then
PKG_NAME=${PKG_NAME%.*}
......@@ -117,11 +119,15 @@ main() {
;;
esac
exec_subcommand src-db reg "$PKG_NAME"
# need to register it before we can autogen the .sspt file
exec_subcommand src-db reg "$PKG_NAME" dummy_revision
exec_subcommand autogen "$PKG_NAME"
if [ $? -ne 0 ]; then
if [ $? -ne 0 ]; then # autogen failed -> resorting to manual edit
exec_subcommand edit "$PKG_NAME"
fi
# now set the version of the package in the DB
# (this is only possible because the .sspt file is generated)
exec_subcommand src-db reg "$PKG_NAME" $(exec_subcommand pkgcmd version "$PKG_NAME")
}
if [ $# -eq 0 ]; then
......@@ -131,3 +137,5 @@ fi
main $@
#!/usr/bin/env bash
print_help() {
(>&2 cat <<EOF
Delete a package's installed binaries and its source code.
Usage: $0 [-h|-?|--help]
Print this help text and exit.
- $0 <package-name>
Purge the package.
EOF
)
}
main() {
local ESCAPED_PKG=`escape_string $2`
if [ -z "$2" ]; then
print_help
exit
fi
case $1 in
-h|-?|--help)
print_help
;;
*)
exec_subcommand src-db exists "$1"
if [ $? -ne 0 ]; then
(>&2 echo "This package doesn't exist.")
exit 1
fi
# 1. uninstall (does a bin-db unreg)
exec_subcommand bin-db exists "$1"
if [ $? -eq 0 ]; then
exec_subcommand pkgcmd uninstall "$1"
fi
# 2. unregister
exec_subcommand src-db unreg "$1"
# 3. nuke
rm -rf "$SSPT_DL_DIR/$ESCAPED_PKG"
;;
esac
}
if [ $# -eq 0 ]; then
print_help
exit
fi
main $@
#!/usr/bin/env bash
print_help() {
(>&2 cat <<EOF
Delete a package's installed binaries and its source code.
Usage: $0 [-h|-?|--help]
Print this help text and exit.
- $0 <package-name>
Purge the package.
EOF
)
}
main() {
local ESCAPED_PKG=`escape_string $2`
if [ -z "$2" ]; then
print_help
exit
fi
case $1 in
-h|-?|--help)
print_help
;;
*)
exec_subcommand src-db exists "$1"
if [ $? -ne 0 ]; then
(>&2 echo "This package doesn't exist.")
exit 1
fi
# 1. delete all files
cat "$SSPT_BIN_DB_DIR/$ESCAPED_PKG" | xargs rm
# 2. remove from the db
exec_subcommand bin-db unreg "$1"
;;
esac
}
if [ $# -eq 0 ]; then
print_help
exit
fi
main $@
#!/usr/bin/env bash
print_help() {
(>&2 cat <<EOF
Update packages.
Usage: $0 [-h|-?|--help]
Print this help text and exit.
- $0 <package-name...>
Update the selected packages.
- $0
Update all packages.
EOF
)
}
update_package() {
local pkg="$1"
local before="$2"
if [ -z "$before" ]; then
local epkg=$(escape_string "$pkg")
before=$(cat "$SSPT_SRC_DB_FILE" | egrep "^$pkg " | egrep -v -o "^$epkg ")
fi
exec_subcommand pkgcmd pull "$pkg"
local after=$(exec_subcommand pkgcmd vesion "$pkg")
if [ "$before" != "$after" ]; then
exec_subcommand src-db reg "$pkg" "$after"
return 1
fi
return 0
}
upgrade_package() {
exec_subcommand configure "$1"
exec_subcommand build "$1"
exec_subcommand install "$1"
}
upgrade_pkgs() {
for pkg in $(cat /tmp/upgrade_list); do
upgrade_package "$pkg"
done
rm /tmp/upgrade_list
}
update_selection() {
touch /tmp/upgrade-list
for pkg in "${@[@]}"; do