Commit 8d074540 authored by PoroCYon's avatar PoroCYon
Browse files

bugfixes, but still no 'install'

parent 6a554259
sources/*
local/lib/*
local/share/* local/share/*
*~ *~
......
...@@ -11,6 +11,7 @@ exit_cleanup() { ...@@ -11,6 +11,7 @@ exit_cleanup() {
unset -f temp_filename unset -f temp_filename
unset -f load_config unset -f load_config
unset -f exec_subcommand unset -f exec_subcommand
unset -f file_exists_glob
unset SSPT_DEST_DIR unset SSPT_DEST_DIR
unset SSPT_DB_DIR unset SSPT_DB_DIR
...@@ -29,9 +30,18 @@ escape_string() { ...@@ -29,9 +30,18 @@ escape_string() {
} }
export -f escape_string export -f escape_string
temp_filename() { temp_filename() {
echo "/tmp/ssbt-$(cat /dev/urando | head -c 4 | base64)" echo "/tmp/ssbt-$(cat /dev/urandom | head -c 4 | base64)"
} }
export -f temp_filename export -f temp_filename
file_exists_glob() {
for f in $1; do
[ -e "$f" ] && return 0 || return 1
break
done
return 1
}
export -f file_exists_glob
print_version() { print_version() {
(>&2 echo "sspt v0.0.0") (>&2 echo "sspt v0.0.0")
...@@ -51,7 +61,7 @@ Usage: $0 [-h|-?|--help] ...@@ -51,7 +61,7 @@ Usage: $0 [-h|-?|--help]
- $0 --mk-default-config - $0 --mk-default-config
Create a default config file. The file is placed in Create a default config file. The file is placed in
\$XDG_CONFIG_HOME/sspt.conf , unless --config was specified. \$XDG_CONFIG_HOME/sspt.conf , unless --config was specified.
- $0 --list-subcommands - $0 [-L|--list|--list-subcommands]
List all available subcommands. Subcommands work like they List all available subcommands. Subcommands work like they
do in git, one can define them by creating a sspt-<subcommand> do in git, one can define them by creating a sspt-<subcommand>
and placing it in \$SSPT_SUB_DIR (defined in the sspt config and placing it in \$SSPT_SUB_DIR (defined in the sspt config
...@@ -85,6 +95,10 @@ load_config() { ...@@ -85,6 +95,10 @@ load_config() {
} }
export -f load_config export -f load_config
exec_sub_rip() {
(>&2 echo "File '$1' does not exist, cannot execute subcommand '$2'.")
exit_cleanup 1
}
exec_subcommand () { exec_subcommand () {
if [ -z "$SSPT_DEST_DIR" ] || [ -z "$SSPT_DB_DIR" ] || [ -z "$SSPT_SUB_DIR" ] || [ -z "$SSPT_DL_DIR" ]; then 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.") (>&2 echo "\$SSPT_DEST_DIR or \$SSPT_DB_DIR or \$SSPT_SUB_DIR or \$SSPT_DL_DIR not defined.")
...@@ -104,9 +118,10 @@ exec_subcommand () { ...@@ -104,9 +118,10 @@ exec_subcommand () {
local SUB_FILE="$SSPT_SUB_DIR/sspt-$1" local SUB_FILE="$SSPT_SUB_DIR/sspt-$1"
local ALL_ARGS_=("$@") local ALL_ARGS_=("$@")
command -v "$SUB_FILE" >/dev/null 2>&1 || { (>&2 echo "File '$SUB_FILE' does not exist, cannot execute subcommand '$1'.") } && exit_cleanup 1 command -v "$SUB_FILE" >/dev/null 2>&1 || exec_sub_rip "$SUB_FILE" "$1"
exec $SUB_FILE "${ALL_ARGS_[@]:1}" #(>&2 echo "execing $1 : ${ALL_ARGS_[@]:1}")
"$SUB_FILE" "${ALL_ARGS_[@]:1}"
return $? return $?
} }
export -f exec_subcommand export -f exec_subcommand
...@@ -130,10 +145,11 @@ parse_arg() { ...@@ -130,10 +145,11 @@ parse_arg() {
-V|--version) -V|--version)
print_version print_version
;; ;;
--list-subcommands) --list-subcommands|--list|-L)
# I'm lazy
load_config load_config
find -type f -name "sspt-*" "$SSPT_SUB_DIR/" for sc in $(find "$SSPT_SUB_DIR/" -type f -name "sspt-*"); do
echo "$(basename "$sc")"
done
;; ;;
--mk-default-config) --mk-default-config)
if ! [ -d "$CONFIG_PATH" ]; then if ! [ -d "$CONFIG_PATH" ]; then
......
...@@ -210,7 +210,7 @@ sspt_clean_config() { ...@@ -210,7 +210,7 @@ sspt_clean_config() {
"$REL_DIR/setup.py" clean -a "$REL_DIR/setup.py" clean -a
} }
EOF EOF
elif ! [ -z "$(ls *.ipkg)" ]; then elif file_exists_glob *.ipkg; then
local IPKG_FILE=$(ls *.ipkg | head -1) # ensure it's only 1 file local IPKG_FILE=$(ls *.ipkg | head -1) # ensure it's only 1 file
cat >> "$SSPT_FILE" <<EOF cat >> "$SSPT_FILE" <<EOF
sspt_config() { sspt_config() {
...@@ -229,7 +229,7 @@ sspt_clean_config() { ...@@ -229,7 +229,7 @@ sspt_clean_config() {
true true
} }
EOF EOF
elif ! [ -z "$(ls *.sln)" ]; then elif file_exists_glob *.sln; then
local SLN_FILE=$(ls *.sln | head -1) local SLN_FILE=$(ls *.sln | head -1)
local PROBABLE_PROJECT_NAME=${SLN_FILE%.*} local PROBABLE_PROJECT_NAME=${SLN_FILE%.*}
cat >> "$SSPT_FILE" <<EOF cat >> "$SSPT_FILE" <<EOF
...@@ -271,7 +271,7 @@ sspt_clean_config() { ...@@ -271,7 +271,7 @@ sspt_clean_config() {
stack clean --full stack clean --full
} }
EOF EOF
elif ! [ -z "$(ls *.cabal)" ]; then elif file_exists_glob *.cabal; then
cat >> "$SSPT_FILE" <<EOF cat >> "$SSPT_FILE" <<EOF
sspt_config() { sspt_config() {
cabal configure -O2 --user --prefix=\$SSPT_DEST_DIR --ghc-option=-j$(nproc) cabal configure -O2 --user --prefix=\$SSPT_DEST_DIR --ghc-option=-j$(nproc)
...@@ -325,7 +325,7 @@ sspt_clean_config() { ...@@ -325,7 +325,7 @@ sspt_clean_config() {
true true
} }
EOF EOF
elif ! [ -z "$(ls *.sbt)" ]; then elif file_exists_glob *.sbt; then
cat >> "$SSPT_FILE" <<EOF cat >> "$SSPT_FILE" <<EOF
sspt_config() { sspt_config() {
(>&2 echo "NOTE: sbt cannot install packages.") (>&2 echo "NOTE: sbt cannot install packages.")
...@@ -463,7 +463,7 @@ sspt_clean_config() { ...@@ -463,7 +463,7 @@ sspt_clean_config() {
rm -rf "$REL_DIR/cmake-build" rm -rf "$REL_DIR/cmake-build"
} }
EOF EOF
elif ! [ -z "$(ls *.pro)" ]; then elif file_exists_glob *.pro; then
local PRO_FILE="$(ls *.pro | head -1)" local PRO_FILE="$(ls *.pro | head -1)"
cat >> "$SSPT_FILE" <<EOF cat >> "$SSPT_FILE" <<EOF
...@@ -529,7 +529,7 @@ EOF ...@@ -529,7 +529,7 @@ EOF
return 1 return 1
fi fi
if ! [ -z "$CHANGED_DIR" ]; if ! [ -z "$CHANGED_DIR" ]; then
popd >/dev/null popd >/dev/null
fi fi
} }
...@@ -550,14 +550,13 @@ main() { ...@@ -550,14 +550,13 @@ main() {
print_help print_help
;; ;;
*) *)
egrep -q -e "^$ESCAPED_PKG " -f "$SSPT_SRC_DB_FILE" exec_subcommand src-db exists "$1"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
(>&2 echo "Package '$1' doesn't exist.") (>&2 echo "Package '$1' doesn't exist.")
exit 1 exit 1
fi fi
local PACKAGE_DIR=$(egrep -e "^$ESCAPED_PKG " -f "$SSPT_SRC_DB_FILE" \ local PACKAGE_DIR="$SSPT_DL_DIR/$ESCAPED_PKG"
| egrep -v -o -e "^[A-Za-z0-9_\-\.]* " | egrep -v -o -e " [A-Za-z0-9]$")
pushd "$PACKAGE_DIR" >/dev/null pushd "$PACKAGE_DIR" >/dev/null
autogen_cwd autogen_cwd
......
...@@ -28,7 +28,7 @@ main() { ...@@ -28,7 +28,7 @@ main() {
;; ;;
exists) exists)
if [ $# -lt 2 ]; then print_help; exit 1; fi if [ $# -lt 2 ]; then print_help; exit 1; fi
egrep -q -e "^$ESCAPED_PKG " -f "$SSPT_BIN_DB_FILE" egrep -q -e "^$ESCAPED_PKG " < "$SSPT_BIN_DB_FILE"
return $? return $?
;; ;;
reg|register) reg|register)
...@@ -36,7 +36,7 @@ main() { ...@@ -36,7 +36,7 @@ main() {
if ! [ -f "$3" ]; then print_help; exit 1; fi if ! [ -f "$3" ]; then print_help; exit 1; fi
# check whether package exists # check whether package exists
egrep -q -e "^$ESCAPED_PKG " -f "$SSPT_BIN_DB_FILE" egrep -q -e "^$ESCAPED_PKG " < "$SSPT_BIN_DB_FILE"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
# doesn't exist # doesn't exist
echo "$2" >> "$SSPT_BIN_DB_FILE" echo "$2" >> "$SSPT_BIN_DB_FILE"
...@@ -45,7 +45,7 @@ main() { ...@@ -45,7 +45,7 @@ main() {
# update path # update path
(>&2 echo "WARNING: This package is already registered, updating its path...") (>&2 echo "WARNING: This package is already registered, updating its path...")
local TMPFILE="$(temp_filename)" local TMPFILE="$(temp_filename)"
egrep -v -e "^$ESCAPED_PKG " -f "$SSPT_BIN_DB_FILE" > "$TMPFILE" egrep -v -e "^$ESCAPED_PKG " < "$SSPT_BIN_DB_FILE" > "$TMPFILE"
echo "$2" >> "$TMPFILE" echo "$2" >> "$TMPFILE"
mv "$TMPFILE" "$SSPT_BIN_DB_FILE" mv "$TMPFILE" "$SSPT_BIN_DB_FILE"
cp "$3" "$SSPT_BIN_DB_DIR/$ESCAPED_PKG" cp "$3" "$SSPT_BIN_DB_DIR/$ESCAPED_PKG"
...@@ -54,11 +54,11 @@ main() { ...@@ -54,11 +54,11 @@ main() {
unreg|unregister) unreg|unregister)
if [ $# -lt 2 ]; then print_help; exit 1; fi if [ $# -lt 2 ]; then print_help; exit 1; fi
egrep -q -e "^$ESCAPED_PKG " -f "$SSPT_BIN_DB_FILE" egrep -q -e "^$ESCAPED_PKG " < "$SSPT_BIN_DB_FILE"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
# exists # exists
local TMPFILE="$(temp_filename)" local TMPFILE="$(temp_filename)"
egrep -v -e "^$ESCAPED_PKG" -f "$SSPT_BIN_DB_FILE" > "$TMPFILE" egrep -v -e "^$ESCAPED_PKG" < "$SSPT_BIN_DB_FILE" > "$TMPFILE"
mv "$TMPFILE" "$SSPT_BIN_DB_FILE" mv "$TMPFILE" "$SSPT_BIN_DB_FILE"
rm "$SSPT_BIN_DB_DIR/$ESCAPED_PKG" rm "$SSPT_BIN_DB_DIR/$ESCAPED_PKG"
else else
......
...@@ -27,7 +27,7 @@ main() { ...@@ -27,7 +27,7 @@ main() {
exec_subcommand pkgcmd build "$1" exec_subcommand pkgcmd build "$1"
# now update the 'known latest version' # now update the 'known latest version'
exec_subcommand src-db reg "$1" $(exec_subcommand pkgcmd version "$1") #exec_subcommand src-db reg "$1" $(exec_subcommand pkgcmd version "$1")
;; ;;
esac esac
} }
......
...@@ -23,7 +23,7 @@ main() { ...@@ -23,7 +23,7 @@ main() {
(>&2 echo "This package doesn't exist.") (>&2 echo "This package doesn't exist.")
exit 1 exit 1
fi fi
exec_subcommand pkgcmd configure "$1" exec_subcommand pkgcmd config "$1"
;; ;;
esac esac
} }
......
...@@ -137,5 +137,3 @@ fi ...@@ -137,5 +137,3 @@ fi
main $@ main $@
...@@ -31,22 +31,22 @@ main() { ...@@ -31,22 +31,22 @@ main() {
;; ;;
exists) exists)
if [ $# -lt 2 ]; then print_help; exit 1; fi if [ $# -lt 2 ]; then print_help; exit 1; fi
egrep -q -e "^$ESCAPED_PKG " -f "$SSPT_SRC_DB_FILE" egrep -q -e "^$ESCAPED_PKG " < "$SSPT_SRC_DB_FILE"
return $? return $?
;; ;;
reg|register) reg|register)
if [ $# -lt 4 ]; then print_help; exit 1; fi if [ $# -lt 3 ]; then print_help; exit 1; fi
# check whether package exists # check whether package exists
egrep -q -e "^$ESCAPED_PKG " -f "$SSPT_SRC_DB_FILE" egrep -q -e "^$ESCAPED_PKG " < "$SSPT_SRC_DB_FILE"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "$2 $3" >> "$SSPT_SRC_DB_FILE" echo "$2 $3" >> "$SSPT_SRC_DB_FILE"
else else
# update path # update rev
(>&2 echo "WARNING: Package '$2' is already registered, updating its path...") #(>&2 echo "WARNING: Package '$2' is already registered, updating its path...")
local TMPFILE="$(temp_filename)" local TMPFILE="$(temp_filename)"
# grep can bork when the intput and output files are the same # grep can bork when the intput and output files are the same
egrep -v -e "^$ESCAPED_PKG " -f "$SSPT_SRC_DB_FILE" > "$TMPFILE" egrep -v -e "^$ESCAPED_PKG " < "$SSPT_SRC_DB_FILE" > "$TMPFILE"
echo "$2 $3" >> "$TMPFILE" echo "$2 $3" >> "$TMPFILE"
mv "$TMPFILE" "$SSPT_SRC_DB_FILE" mv "$TMPFILE" "$SSPT_SRC_DB_FILE"
fi fi
...@@ -54,10 +54,10 @@ main() { ...@@ -54,10 +54,10 @@ main() {
unreg|unregister) unreg|unregister)
if [ $# -lt 2 ]; then print_help; exit 1; fi if [ $# -lt 2 ]; then print_help; exit 1; fi
egrep -q -e "^$ESCAPED_PKG " -f "$SSPT_SRC_DB_FILE" egrep -q -e "^$ESCAPED_PKG " < "$SSPT_SRC_DB_FILE"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
local TMPFILE="$(temp_filename)" local TMPFILE="$(temp_filename)"
egrep -v -e "^$ESCAPED_PKG" -f "$SSPT_SRC_DB_FILE" > "$TMPFILE" egrep -v -e "^$ESCAPED_PKG" < "$SSPT_SRC_DB_FILE" > "$TMPFILE"
mv "$TMPFILE" "$SSPT_SRC_DB_FILE" mv "$TMPFILE" "$SSPT_SRC_DB_FILE"
else else
(>&2 echo "Package '$2' doesn't exist.") (>&2 echo "Package '$2' doesn't exist.")
......
#!/usr/bin/env bash
cwd=$(pwd)
if [ $# -eq 0 ]; then
MANPATH="$cwd/local/share/man:$MANPATH" \
LD_LIBRARY_PATH="$cwd/local/lib:$LD_LIBRARY_PATH" \
PATH="$cwd/local/bin:$PATH" \
bash
else
MANPATH="$cwd/local/share/man:$MANPATH" \
LD_LIBRARY_PATH="$cwd/local/lib:$LD_LIBRARY_PATH" \
PATH="$cwd/local/bin:$PATH" \
$@
fi
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