Commit ed4a0a35 authored by PoroCYon's avatar PoroCYon
Browse files

added 'install'

parent 019f3ad6
...@@ -3,25 +3,32 @@ ...@@ -3,25 +3,32 @@
*samselplatro* -- A semidecent 'package manager' meant for installing and *samselplatro* -- A semidecent 'package manager' meant for installing and
updating the upstream version of a program. It does ***NOT*** try to be a updating the upstream version of a program. It does ***NOT*** try to be a
full-fledged package manager for systemwide use. It does ***NOT*** keep full-fledged package manager for systemwide use. It does ***NOT*** keep
track of dependencies. track of dependencies, files owned by multiple packages, etc.
Packages are installed per-users, and there is currently no way to install
them globally (aside from using sspt to invoke the system package manager).
I made this because I thought `ls | xargs "!f() { pushd $1 && git pull && make && make install && popd }; f"` I made this because I thought `ls | xargs "!f() { pushd $1 && git pull && make && make install && popd }; f"`
is only slightly too hacky. `sspt` is a slightly nicer way for doing this. is only slightly too hacky. `sspt` is a slightly nicer way for doing this.
I suggest you don't use this on systems where you don't want broken
packages to happen.
## Dependencies ## Dependencies
* `coreutils` * `coreutils`
* `bash` * `bash`
* `strace`
### Optional ### Optional
* `git`, `hg`, `svn`, `cvs`, `bzr`, `mtn`, `darcs`, `curl`/`wget`, * `git`, `hg`, `svn`, `cvs`, `bzr`, `mtn`, `darcs`, `curl`/`wget`,
`rsync`: for support for the respecitve VCS (or 'VCS') types. `unar` `rsync`: for support for the respecitve VCS (or 'VCS') types. `unar`
is required for `curl`/`wget` and `rsync`. is required for `curl`/`wget` and `rsync`.
* `npm`, `cargo`, `setuptools`, `idris`, `xbuild`, `stack`, `cabal`, * `pacman`/`alpm`, `apk-tools`, `npm`, `cargo`, `setuptools`, `idris`,
`scons`, `gradle`, `sbt`, `bazel`, `meson`, `ninja`, `ant`, `maven`, `xbuild`, `stack`, `cabal`, `scons`, `gradle`, `sbt`, `bazel`, `meson`,
`cmake`, `qmake`, `autoconf`/`autotools`, `make`: for support for the `ninja`, `ant`, `maven`, `cmake`, `qmake`, `autoconf`/`autotools`,
respective build system types. `make`: for support for the respective build system types.
## Installation ## Installation
...@@ -29,7 +36,8 @@ is only slightly too hacky. `sspt` is a slightly nicer way for doing this. ...@@ -29,7 +36,8 @@ is only slightly too hacky. `sspt` is a slightly nicer way for doing this.
./sspt-bootstrap ./sspt-bootstrap
``` ```
**NOTE: this currently does not work, as `install` isn't implemented yet.** ***NOTE***: this currently does not work, as there is no `.sspt` file
yet for sspt itself...
## Usage ## Usage
...@@ -42,11 +50,13 @@ The default location of the configuration file is ...@@ -42,11 +50,13 @@ The default location of the configuration file is
these four environment variables: these four environment variables:
* `SSPT_DEST_DIR`: The directory where packages should be installed in * `SSPT_DEST_DIR`: The directory where packages should be installed in
(think Makefile `PREFIX`). (think Makefile `PREFIX`). This defaults to `$HOME/.local`
* `SSPT_SUB_DIR`: The directory where the subcommands reside. * `SSPT_SUB_DIR`: The directory where the subcommands reside. This
defaults to `$HOME/.local/libexec/sspt`.
* `SSPT_DB_DIR`: The directory where the sspt database of pulled and * `SSPT_DB_DIR`: The directory where the sspt database of pulled and
installed packages resides. installed packages resides. This defaults to `$HOME/.local/share/sspt`.
* `SSPT_DL_DIR`: The directory where sspt downloads the repositories to. * `SSPT_DL_DIR`: The directory where sspt downloads the repositories to.
This defaults to `$HOME/src/sspt`
The location of the config file can be specified using the `-c` flag. The location of the config file can be specified using the `-c` flag.
...@@ -98,19 +108,22 @@ This currently requires the package to be pulled. ...@@ -98,19 +108,22 @@ This currently requires the package to be pulled.
sspt build sspt sspt build sspt
``` ```
NOTE: currently, it doesn't automatically configure the package. NOTE: currently, it doesn't automatically configure the package. You
might want to run `sspt configure sspt` first.
### Installing a package ### Installing a package
This currently requires the package to be pulled (And probably built 'Installing' simply means executing 'make install' or its equivalent,
as well, when this is implemented). no fancy package management stuff is done, aside from keeping track of
which files have been installed. sspt does not check whether a file is
owned by multiple packages.
This currently requires the package to be pulled and compiled.
``` ```
sspt install sspt sspt install sspt
``` ```
**NOTE: This is not yet implemented.**
You can use `sspt pkgcmd install sspt` to directly install the package, You can use `sspt pkgcmd install sspt` to directly install the package,
but this doesn't take care of: but this doesn't take care of:
...@@ -158,14 +171,17 @@ and `./testenv.sh` to execute other commands in it. ...@@ -158,14 +171,17 @@ and `./testenv.sh` to execute other commands in it.
I'm open to making it more portable (by using less linuxisms and bashisms). I'm open to making it more portable (by using less linuxisms and bashisms).
I'm open to adding support for more VCSes and build system types (and
-- *especially* -- making that part more modular).
I'm ***NOT*** open to making it into a proper package manager à la I'm ***NOT*** open to making it into a proper package manager à la
`pacman` or `xbps`, let alone `nix` or `guix`. `pacman` or `xbps`, let alone `nix` or `guix`.
I'm ***NOT*** open to adding dependency management. I'm ***NOT*** open to adding dependency management and other fancy stuff.
I'm ***NOT*** open to rewriting it in `<insert language here>` because I'm ***NOT*** open to rewriting it in `<insert language here>` because
shell scritps are slow/ugly/not even a real language/... sspt isn't meant shell scritps are slow/ugly/not even a real language/... . sspt isn't meant
to be professional. to be professional, or look like something 'real'.
## License ## License
......
#!/usr/bin/env bash #!/usr/bin/env bash
THISSCRIPT=$(realpath $0) export SSPT_THISSCRIPT=$(realpath "$0")
RUNDIR=$(dirname $THISSCRIPT) export SSPT_RUNDIR=$(dirname "$SSPT_THISSCRIPT")
ALL_ARGS=("$@") ALL_ARGS=("$@")
ARG_COUNT=$# ARG_COUNT=$#
...@@ -22,6 +22,9 @@ exit_cleanup() { ...@@ -22,6 +22,9 @@ exit_cleanup() {
unset SSPT_BIN_DB_FILE unset SSPT_BIN_DB_FILE
unset SSPT_BIN_DB_DIR unset SSPT_BIN_DB_DIR
unset SSPT_THISSCRIPT
unset SSPT_RUNDIR
exit $@ exit $@
} }
...@@ -30,7 +33,7 @@ escape_string() { ...@@ -30,7 +33,7 @@ escape_string() {
} }
export -f escape_string export -f escape_string
temp_filename() { temp_filename() {
echo "/tmp/ssbt-$(cat /dev/urandom | head -c 4 | base64)" echo "/tmp/sspt-$(cat /dev/urandom | head -c 4 | base32)"
} }
export -f temp_filename export -f temp_filename
file_exists_glob() { file_exists_glob() {
...@@ -48,7 +51,7 @@ print_version() { ...@@ -48,7 +51,7 @@ print_version() {
} }
print_help() { print_help() {
print_version #print_version
(>&2 cat <<EOF (>&2 cat <<EOF
sspt - manage upstream repositories sspt - manage upstream repositories
Usage: $0 [-h|-?|--help] Usage: $0 [-h|-?|--help]
......
...@@ -154,7 +154,44 @@ autogen_buildsys() { ...@@ -154,7 +154,44 @@ autogen_buildsys() {
RELI_DIR="../" RELI_DIR="../"
fi fi
if [ -f "package.json" ]; then if [ -f "PKGBUILD" ]; then
cat >> "$SSPT_FILE" <<EOF
sspt_config() {
makepkg -o
}
sspt_build() {
makepkg -e
}
sspt_install() {
makepkg -e -o -i
}
sspt_clean() {
makepkg -c -e -o
}
sspt_clean_config() {
true
}
EOF
elif [ -f "APKBUILD" ]; then
cat >> "$SSPT_FILE" <<EOF
sspt_config() {
abuild prepare
}
sspt_build() {
abuild build
}
sspt_install() {
abuild package -i
}
sspt_clean() {
abuild clean
}
sspt_clean_config() {
abuild clean
abuild cleancache
}
EOF
elif [ -f "package.json" ]; then
cat >> "$SSPT_FILE" <<EOF cat >> "$SSPT_FILE" <<EOF
sspt_config() { sspt_config() {
(>&2 echo "NOTE: npm doesn't honor \$SSPT_DEST_DIR") (>&2 echo "NOTE: npm doesn't honor \$SSPT_DEST_DIR")
...@@ -209,25 +246,6 @@ sspt_clean() { ...@@ -209,25 +246,6 @@ sspt_clean() {
sspt_clean_config() { sspt_clean_config() {
"$REL_DIR/setup.py" clean -a "$REL_DIR/setup.py" clean -a
} }
EOF
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() {
(>&2 echo "NOTE: idris doesn't honor \$SSPT_DEST_DIR")
}
sspt_build() {
idris --build "$REL_DIR/$IPKG_FILE"
}
sspt_install() {
idris --install "$REL_DIR/$IPKG_FILE" && idris --installdoc "$REL_DIR/$IPKG_FILE"
}
sspt_clean() {
idris --clean "$REL_DIR/$IPKG_FILE"
}
sspt_clean_config() {
true
}
EOF EOF
elif file_exists_glob *.sln; then elif file_exists_glob *.sln; then
local SLN_FILE=$(ls *.sln | head -1) local SLN_FILE=$(ls *.sln | head -1)
...@@ -518,6 +536,25 @@ sspt_clean() { ...@@ -518,6 +536,25 @@ sspt_clean() {
sspt_clean_config() { sspt_clean_config() {
true true
} }
EOF
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() {
(>&2 echo "NOTE: idris doesn't honor \$SSPT_DEST_DIR")
}
sspt_build() {
idris --build "$REL_DIR/$IPKG_FILE"
}
sspt_install() {
idris --install "$REL_DIR/$IPKG_FILE" && idris --installdoc "$REL_DIR/$IPKG_FILE"
}
sspt_clean() {
idris --clean "$REL_DIR/$IPKG_FILE"
}
sspt_clean_config() {
true
}
EOF EOF
elif ! [ -z "$CHANGED_DIR" ]; then elif ! [ -z "$CHANGED_DIR" ]; then
# try top directory instead # try top directory instead
......
...@@ -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 " < "$SSPT_BIN_DB_FILE" egrep -q -e "^$ESCAPED_PKG$" < "$SSPT_BIN_DB_FILE"
return $? return $?
;; ;;
reg|register) reg|register)
...@@ -36,16 +36,15 @@ main() { ...@@ -36,16 +36,15 @@ 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 " < "$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"
cp "$3" "$SSPT_BIN_DB_DIR/$ESCAPED_PKG" cp "$3" "$SSPT_BIN_DB_DIR/$ESCAPED_PKG"
else else
# update path # update 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 " < "$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,13 +53,13 @@ main() { ...@@ -54,13 +53,13 @@ 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 " < "$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" < "$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 -f "$SSPT_BIN_DB_DIR/$ESCAPED_PKG"
else else
(>&2 echo "Package doesn't exist.") (>&2 echo "Package doesn't exist.")
fi fi
......
#!/usr/bin/env bash
print_help() {
(>&2 cat <<EOF
Install a package's binary files.
Usage: $0 [-h|-?|--help]
Print this help text and exit.
- $0 <package-name>
Install the binary files of this package.
EOF
)
}
main() {
case $1 in
-h|-?|--help)
print_help
;;
*)
# TODO: other stuff
exec_subcommand strace "$1"
;;
esac
}
if [ $? -eq 0 ]; then
print_help
exit
fi
main $@
...@@ -12,12 +12,7 @@ EOF ...@@ -12,12 +12,7 @@ EOF
} }
main() { main() {
local ESCAPED_PKG=`escape_string $2` local ESCAPED_PKG=`escape_string $1`
if [ -z "$2" ]; then
print_help
exit
fi
case $1 in case $1 in
-h|-?|--help) -h|-?|--help)
......
#!/usr/bin/env bash
print_help() {
(>&2 cat <<EOF
Use strace to record which files are installed by a 'make install'
command (or something similar).
Usage: $0 [-h|-?-|--help]
Print this help text and exit.
- $0 <package name>
Runs strace on \`pkgcmd install <package name>\`.
NOTE: this subcommand is supposed to be used only by ssbt internally.
Proceed with caution.
NOTE: THIS SUBCOMMAND IS A HUGE HACK. STAY AWAY FROM IT AS FAR AS POSSIBLE.
EOF
# ^ is right. close this file now.
)
}
OUTFILE=""
# TODO: ktrace/kdump support (and whatever freebsd/... use)
run_strace() {
# not using -e trace=%file because I don't care about eg. the stat syscalls
local SYSCALLS="open,openat,creat,link,linkat,mkdir,mkdirat,rename,renameat,renameat2,rmdir,symlink,symlinkat" # ,unlink,unlinkat
local STRACE_OUT="$(temp_filename)"
local GREP_OUT="$(temp_filename)"
# v only interested in paths, not any other kind of string
strace -f -a 80 -s 0 -qq -o "$STRACE_OUT" -e trace="$SYSCALLS" \
bash -c "'$SSPT_THISSCRIPT' pkgcmd install '$1'"
# 1. select only files that are written to
# 2,3. but also add stuff that doesn't use these flags
# 4. filter out uninteresting places
# 5. filter out local stuff & db operations
# 6. throw away PID & retval (it'd be much cleaner if it wouldn't
# pretty-print errors)
< "$STRACE_OUT" grep -e O_RDWR -e O_WRONLY \
-e creat -e link -e linkat -e mkdir -e mkdirat -e rename \
-e renameat2 -e renameat2 -e rmdir -e symlink -e symlinkat \
| egrep -v -e "\(\"\/dev\/" -e "\(\"\/tmp\/" -e "\(\"[^\/]" -e "\(\"\/home\"" \
| grep -v -e "$SSPT_DL_DIR" -e "$SSPT_DB_DIR" \
| sed -E -e 's/^[0-9]* *//' -e 's/\) *=.*/\)/' \
> "$GREP_OUT" # I told you, this is total madness
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/\)$//')
IFS=', '
read -ra allargs <<< "$alargs_"
unset IFS
local outfile=""
case "$syscall" in
open|creat|mkdir|rmdir|symlink)
outfile="${allargs[0]}"
;;
openat|link|mkdirat|rename)
outfile="${allargs[1]}"
;;
symlinkat)
outfile="${allargs[2]}"
;;
linkat|renameat|renameat2)
outfile="${allargs[3]}"
;;
*)
(>&2 echo "Unexpeted strace output '$line'!")
unset OUTFILE
exit 1
;;
esac
echo "$outfile" >> "$STRACE_OUT" # reuse the file
done < "$GREP_OUT"
rm "$GREP_OUT"
OUTFILE="$STRACE_OUT"
}
main() {
case $1 in
-h|-?|--help)
print_help
exit
;;
*)
exec_subcommand src-db exists "$1"
if [ $? -ne 0 ]; then
(>&2 echo "This package doesn't exist.")
unset OUTFILE
exit 1
fi
run_strace $@
exec_subcommand bin-db reg "$1" "$OUTFILE"
rm "$OUTFILE"
;;
esac
}
if [ $# -eq 0 ]; then
print_help
unset OUTFILE
exit
fi
main $@
unset OUTFILE
...@@ -2,23 +2,35 @@ ...@@ -2,23 +2,35 @@
print_help() { print_help() {
(>&2 cat <<EOF (>&2 cat <<EOF
Delete a package's installed binaries and its source code. Delete a package's installed binaries.
Usage: $0 [-h|-?|--help] Usage: $0 [-h|-?|--help]
Print this help text and exit. Print this help text and exit.
- $0 <package-name> - $0 <package-name>
Purge the package. Uninstall the package.
EOF EOF
) )
} }
main() { remove_empty_dir_rec() {
local ESCAPED_PKG=`escape_string $2` # ensure it stops somehwere - who knows / might be empty (somehow)
if [ "$1" == "/" ]; then
return
fi
if [ -z "$2" ]; then echo "trying $1"
print_help if ! file_exists_glob "$1/"*; then
exit echo "removing $1"
rm -rf "$1"
else
return
fi fi
remove_empty_dir_rec "$(dirname "$1")"
}
main() {
local ESCAPED_PKG=`escape_string $1`
case $1 in case $1 in
-h|-?|--help) -h|-?|--help)
print_help print_help
...@@ -31,7 +43,17 @@ main() { ...@@ -31,7 +43,17 @@ main() {
fi fi
# 1. delete all files # 1. delete all files
cat "$SSPT_BIN_DB_DIR/$ESCAPED_PKG" | xargs rm while read -r line; do
# unescape
local lin_=$(echo "$line" | sed -E 's/\\(.)/\1/g')
lin_="${lin_%\"}"
lin_="${lin_#\"}"
rm -rf "$lin_"
# if dir is empty, remove it
remove_empty_dir_rec "$(dirname "$lin_")"
done < "$SSPT_BIN_DB_DIR/$ESCAPED_PKG"
# 2. remove from the db # 2. remove from the db
exec_subcommand bin-db unreg "$1" exec_subcommand bin-db unreg "$1"
......
* install!!! * install!!!
* PKGBUILD/APKBUILD/xbps support
* aliases (sspt rm foo) * aliases (sspt rm foo)