Commit 94a9ce7a authored by PoroCYon's avatar PoroCYon
Browse files

pull, pkgcmd

parent 1959af92
......@@ -2,6 +2,22 @@
samselplatro -- semidecent 'package manager' that handles upstream repos
## Dependencies
* `coreutils`
* `bash`
### Optional
* `git`, `hg`, `svn`, `cvs`, `bzr`, `mtn`, `darcs`, `curl`/`wget`,
`rsync`: for support for the respecitve VCS (or 'VCS') types. `unar`
is required for `curl`/`wget` and `rsync`.
* `npm`, `cargo`, `setuptools`, `idris`, `xbuild`, `stack`, `cabal`,
`scons`, `gradle`, `sbt`, `bazel`, `meson`, `ninja`, `ant`, `maven`,
`cmake`, `qmake`, `autoconf`, `makefile`: for support for the
respective build system types.
## Usage
TODO
......@@ -2,10 +2,15 @@
print_help() {
(>&2 cat <<EOF
Usage: $0 [-h|-?|--help]
Print this help text and exit.
- $0 <package-name>
Generate the .sspt file for this package.
Autogenerate an .sspt file for a package.
Usage: $0 [-h|-?|--help]
Print this help text and exit.
- $0 <package-name>
Generate the .sspt file for this package.
Supported VCSes: git, hg, svn, cvs, bzr, mtn, darcs
Supported build systems: npm, cargo, setuptools, idris, xbuild, stack,
cabal, scons, gradle, sbt, bazel, meson, ninja, ant, mvn, cmake,
qmake, autoconf, makefile
EOF
)
}
......@@ -81,6 +86,7 @@ autogen_mtn() {
cat >> ".sspt" <<EOF
sspt_pull() {
mtn pull
mtn update
}
sspt_version() {
mtn log --last=1 --no-graph | grep "Revision" | egrep -o "[A-Za-z0-9]$"
......@@ -119,6 +125,8 @@ autogen_vcs() {
elif [ -d "_darcs/" ]; then
autogen_darcs
else
(>&2 echo "NOTE: could not detect repository type, add the .sspt" \
"file to make updating this pacakge possible.")
# no upstream?
cat >> ".sspt" <<EOF
sspt_pull() {
......@@ -223,7 +231,7 @@ sspt_clean_config() {
EOF
elif ! [ -z "$(ls *.sln)" ]; then
local SLN_FILE=$(ls *.sln | head -1)
local PROBABLE_PROJECT_NAME=${SLN_FILE##*/}
local PROBABLE_PROJECT_NAME=${SLN_FILE%.*}
cat >> "$SSPT_FILE" <<EOF
sspt_config() {
(>&2 echo "NOTE: the \`install' command for xbuild projects is extremely hacky, you might want to tweak it.")
......
......@@ -2,18 +2,19 @@
print_help() {
(>&2 cat <<EOF
NOTE: this subcommand is supposed to be used only by ssbt internally.
Proceed with caution.
Usage: $0 -h|-?|--help
Print this help text and exit.
- $0 exists <package-name>
Check whether the package has been installed. The exit code
is set to 0 if the package exists, and 1 otherwise.
- $0 reg(ister) <package-name> <file containing the list of files the package owns>
Add the package to the list of registered packages.
Use \`sspt add\` to actually install the package.
- $0 unreg(ister) <package-name>
Remove the package from the list of registered packages.
Modify the database of installed binaries.
Usage: $0 -h|-?|--help
Print this help text and exit.
- $0 exists <package-name>
Check whether the package has been installed. The exit code
is set to 0 if the package exists, and 1 otherwise.
- $0 reg(ister) <package-name> <file containing the list of files the package owns>
Add the package to the list of registered packages.
Use \`sspt add\` to actually install the package.
- $0 unreg(ister) <package-name>
Remove the package from the list of registered packages.
NOTE: this subcommand is supposed to be used only by ssbt internally.
Proceed with caution.
EOF
)
}
......
......@@ -2,10 +2,11 @@
print_help() {
(>&2 cat <<EOF
Usage: $0 [-h|-?|--help]
Print this help text and edit.
- $0 <package-name>
Edit the build script of the package using \$EDITOR.
Edit the .sspt file of a package.
Usage: $0 [-h|-?|--help]
Print this help text and edit.
- $0 <package-name>
Edit the .sspt file of the package using \$EDITOR.
EOF
)
}
......@@ -26,7 +27,11 @@ main() {
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]$")
$EDITOR "$PACKAGE_DIR/.sspt"
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
;;
esac
}
......
#!/usr/bin/env bash
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.
- $0 <command> <package-name>
Run <command> on the specified package.
NOTE: this subcommand is supposed to be used only by ssbt internally.
Proceed with caution.
EOF
)
}
main() {
local ESCAPED_PKG=`escape_string $2`
if [ -z "$2" ]; then
print_help
exit
fi
case $1 in
-h|-?|--help)
print_help
;;
*)
pushd "$SSPT_DL_DIR/$ESCAPED_PKG" >/dev/null
bash -c "source \".sspt\" && \"$1\""
local RETVAL=$?
popd >/dev/null
exit $RETVAL
;;
esac
}
if [ $# -eq 0 ]; then
print_help
exit
fi
main $@
#!/usr/bin/env bash
print_help() {
(>&2 cat <<EOF
Pull the source code of a package from a remote location.
Usage: $0 [-h|-?|--help]
Print this help text and exit.
- $0 {--<vcs>} <repo url>
Add the repo to the database and download the source code.
Optionally, the VCS type can be specified.
Supported VCSes: git, hg, svn, cvs, bzr, mtn, darcs, http(s), rsync
(Those last two aren't VCSes, but you can get tarballs over them.)
EOF
)
}
pull_with_vcs() {
local PKG_NAME="$(basename $2)"
if [ "$1" == "git" ] && [[ "$PKG_NAME" == *".git" ]]; then
PKG_NAME=${PKG_NAME%.*}
fi
exec_subcommand src-db exists "$PKG_NAME"
if [ $? -eq 0 ]; then
(>&2 echo "Package '$PKG_NAME' is already pulled.")
return
fi
case $1 in
git)
git clone --recursive "$2" "$SSPT_DL_DIR/$PKG_NAME"
;;
hg)
hg clone "$2" "$SSPT_DL_DIR/$PKG_NAME"
;;
svn)
svn co "$2" "$SSPT_DL_DIR/$PKG_NAME"
;;
cvs)
cvs -z3 -d"$2" co "$SSPT_DL_DIR/$PKG_NAME"
;;
bzr)
bzr branch "$2" "$SSPT_DL_DIR/$PKG_NAME"
;;
mtn)
mtn --db=mtn.db clone "$2" -b "$PKG_NAME" "${PKG_NAME##*.}"
;;
darcs)
darcs clone "$2" "$SSPT_DL_DIR/$PKG_NAME"
;;
http)
if command -v "wget" >/dev/null 2>&1; then
wget "$2" -q -O "/tmp/$PKG_NAME"
elif command -v "curl" >/dev/null 2>&1; then
curl "$2" -S -o "/tmp/$PKG_NAME"
else
(>&2 echo "wget nor curl are installed, but they are" \
"required to fetch data over HTTP(S).")
exit 1
fi
if ! [ -d "$SSPT_DL_DIR/$PKG_NAME" ]; then
mkdir -p "$SSPT_DL_DIR/$PKG_NAME"
fi
unar -D "/tmp/$PKG_NAME" -o "$SSPT_DL_DIR/$PKG_NAME"
rm "/tmp/$PKG_NAME"
;;
rsync)
rsync "$1" "/tmp/$PKG_NAME"
if ! [ -d "$SSPT_DL_DIR/$PKG_NAME" ]; then
mkdir -p "$SSPT_DL_DIR/$PKG_NAME"
fi
unar -D "/tmp/$PKG_NAME" -o "$SSPT_DL_DIR/$PKG_NAME"
rm "/tmp/$PKG_NAME"
;;
esac
}
main() {
case $1 in
-h|-?|--help)
print_help
;;
--*)
pull_with_vcs "${1:2}" "$2"
;;
git*|*.git|*github*|*gitlab*|*git.savannah*|*gogs*|://git.*|:git.*)
pull_with_vcs git "$1"
;;
hg*|*hg.savannah*|://hg.*|://mercurial.*|:hg.*|:mercurial.*)
pull_with_vcs hg "$1"
;;
svn*|*svn.savannah*|://svn.*|:svn.*)
pull_with_vcs svn "$1"
;;
cvs*|*cvs.savannah*|://cvs.*|:cvs.*)
pull_with_vcs cvs "$1"
;;
bzr*|*bzr.savannah*|://bzr.*|:bzr.*)
pull_with_vcs bzr "$1"
;;
mtn*|://mtn.*|:mtn.*)
pull_with_vcs mtn "$1"
;;
darcs*|*hub.darcs*|://darcs.*|:darcs.*)
pull_with_vcs darcs "$1"
;;
http*.tar|http*.tar.*|http*.zip|http*.7z)
pull_with_vcs http "$1"
;;
rsync:*)
pull_with_vcs rsync "$1"
;;
*)
(>&2 echo "Could not detect VCS type, please use the --<vcs> switch.")
exit 1
;;
esac
exec_subcommand src-db reg "$PKG_NAME"
exec_subcommand autogen "$PKG_NAME"
if [ $? -ne 0 ]; then
exec_subcommand edit "$PKG_NAME"
fi
}
if [ $# -eq 0 ]; then
print_help
exit
fi
main $@
......@@ -2,18 +2,19 @@
print_help() {
(>&2 cat <<EOF
NOTE: this subcommand is supposed to be used only by ssbt internally.
Proceed with caution.
Usage: $0 -h|-?|--help
Print this help text and exit.
- $0 exists <package-name>
Check whether the package has been pulled. The exit code
is set to 0 if the package exists, and 1 otherwise.
- $0 reg(ister) <package-name> <source directory> <current commit id>
Add the package to the list of registered packages.
Use \`sspt pull\` to actually download the package.
- $0 unreg(ister) <package-name>
Remove the package from the list of registered packages.
Modify the database of pulled source code.
Usage: $0 -h|-?|--help
Print this help text and exit.
- $0 exists <package-name>
Check whether the package has been pulled. The exit code
is set to 0 if the package exists, and 1 otherwise.
- $0 reg(ister) <package-name> <current commit id>
Add the package to the list of registered packages.
Use \`sspt pull\` to actually download the package.
- $0 unreg(ister) <package-name>
Remove the package from the list of registered packages.
NOTE: this subcommand is supposed to be used only by ssbt internally.
Proceed with caution.
EOF
)
}
......@@ -39,14 +40,14 @@ main() {
# check whether package exists
egrep -q -e "^$ESCAPED_PKG " -f "$SSPT_SRC_DB_FILE"
if [ $? -ne 0 ]; then
echo "$2 $3 $4" >> "$SSPT_SRC_DB_FILE"
echo "$2 $3" >> "$SSPT_SRC_DB_FILE"
else
# update path
(>&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"
echo "$2 $3 $4" >> "$TMPFILE"
echo "$2 $3" >> "$TMPFILE"
mv "$TMPFILE" "$SSPT_SRC_DB_FILE"
fi
;;
......@@ -70,6 +71,7 @@ if [ $# -eq 0 ]; then
exit
fi
touch "$SSPT_SRC_DB_FILE"
main $@
exit $?
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