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

bugfixes, but still no 'install'

parent 6a554259
sources/*
local/lib/*
local/share/*
*~
......
......@@ -11,6 +11,7 @@ exit_cleanup() {
unset -f temp_filename
unset -f load_config
unset -f exec_subcommand
unset -f file_exists_glob
unset SSPT_DEST_DIR
unset SSPT_DB_DIR
......@@ -29,9 +30,18 @@ escape_string() {
}
export -f escape_string
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
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() {
(>&2 echo "sspt v0.0.0")
......@@ -51,7 +61,7 @@ Usage: $0 [-h|-?|--help]
- $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
- $0 [-L|--list|--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
......@@ -85,6 +95,10 @@ 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 () {
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.")
......@@ -104,9 +118,10 @@ exec_subcommand () {
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_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 $?
}
export -f exec_subcommand
......@@ -130,10 +145,11 @@ parse_arg() {
-V|--version)
print_version
;;
--list-subcommands)
# I'm lazy
--list-subcommands|--list|-L)
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)
if ! [ -d "$CONFIG_PATH" ]; then
......
......@@ -210,7 +210,7 @@ sspt_clean_config() {
"$REL_DIR/setup.py" clean -a
}
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
cat >> "$SSPT_FILE" <<EOF
sspt_config() {
......@@ -229,7 +229,7 @@ sspt_clean_config() {
true
}
EOF
elif ! [ -z "$(ls *.sln)" ]; then
elif file_exists_glob *.sln; then
local SLN_FILE=$(ls *.sln | head -1)
local PROBABLE_PROJECT_NAME=${SLN_FILE%.*}
cat >> "$SSPT_FILE" <<EOF
......@@ -271,7 +271,7 @@ sspt_clean_config() {
stack clean --full
}
EOF
elif ! [ -z "$(ls *.cabal)" ]; then
elif file_exists_glob *.cabal; then
cat >> "$SSPT_FILE" <<EOF
sspt_config() {
cabal configure -O2 --user --prefix=\$SSPT_DEST_DIR --ghc-option=-j$(nproc)
......@@ -325,7 +325,7 @@ sspt_clean_config() {
true
}
EOF
elif ! [ -z "$(ls *.sbt)" ]; then
elif file_exists_glob *.sbt; then
cat >> "$SSPT_FILE" <<EOF
sspt_config() {
(>&2 echo "NOTE: sbt cannot install packages.")
......@@ -463,7 +463,7 @@ sspt_clean_config() {
rm -rf "$REL_DIR/cmake-build"
}
EOF
elif ! [ -z "$(ls *.pro)" ]; then
elif file_exists_glob *.pro; then
local PRO_FILE="$(ls *.pro | head -1)"
cat >> "$SSPT_FILE" <<EOF
......@@ -529,7 +529,7 @@ EOF
return 1
fi
if ! [ -z "$CHANGED_DIR" ];
if ! [ -z "$CHANGED_DIR" ]; then
popd >/dev/null
fi
}
......@@ -550,14 +550,13 @@ 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]$")
local PACKAGE_DIR="$SSPT_DL_DIR/$ESCAPED_PKG"
pushd "$PACKAGE_DIR" >/dev/null
autogen_cwd
......
......@@ -28,7 +28,7 @@ main() {
;;
exists)
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 $?
;;
reg|register)
......@@ -36,7 +36,7 @@ main() {
if ! [ -f "$3" ]; then print_help; exit 1; fi
# 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
# doesn't exist
echo "$2" >> "$SSPT_BIN_DB_FILE"
......@@ -45,7 +45,7 @@ main() {
# update path
(>&2 echo "WARNING: This package is already registered, updating its path...")
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"
mv "$TMPFILE" "$SSPT_BIN_DB_FILE"
cp "$3" "$SSPT_BIN_DB_DIR/$ESCAPED_PKG"
......@@ -54,11 +54,11 @@ main() {
unreg|unregister)
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
# exists
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"
rm "$SSPT_BIN_DB_DIR/$ESCAPED_PKG"
else
......
......@@ -27,7 +27,7 @@ main() {
exec_subcommand pkgcmd build "$1"
# 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
}
......
......@@ -23,7 +23,7 @@ main() {
(>&2 echo "This package doesn't exist.")
exit 1
fi
exec_subcommand pkgcmd configure "$1"
exec_subcommand pkgcmd config "$1"
;;
esac
}
......
......@@ -137,5 +137,3 @@ fi
main $@
......@@ -31,22 +31,22 @@ main() {
;;
exists)
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 $?
;;
reg|register)
if [ $# -lt 4 ]; then print_help; exit 1; fi
if [ $# -lt 3 ]; then print_help; exit 1; fi
# 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
echo "$2 $3" >> "$SSPT_SRC_DB_FILE"
else
# update path
(>&2 echo "WARNING: Package '$2' is already registered, updating its path...")
# update rev
#(>&2 echo "WARNING: Package '$2' is already registered, updating its path...")
local TMPFILE="$(temp_filename)"
# 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"
mv "$TMPFILE" "$SSPT_SRC_DB_FILE"
fi
......@@ -54,10 +54,10 @@ main() {
unreg|unregister)
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
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"
else
(>&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