From edcc30164063def4aba5469f9a2c32fb81d65834 Mon Sep 17 00:00:00 2001 From: zawz Date: Fri, 7 Feb 2020 14:35:46 +0100 Subject: [PATCH] Complete impletation --- README.md | 40 ++++++++++++++++++++++++++++++++++++++ scripts/database_update.sh | 6 ++++++ scripts/gen_install.sh | 39 +++++++++++++++++++++++++++++++++++++ server_deploy.sh | 10 ++++++---- src/zpkg | 7 ++----- 5 files changed, 93 insertions(+), 9 deletions(-) create mode 100755 scripts/database_update.sh create mode 100755 scripts/gen_install.sh diff --git a/README.md b/README.md index 12740ca..e8a91be 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,42 @@ # zpkg + Simple and basic packaging system + +Designed to be used by anyone and deployed anywhere, +it is a very basic packaging system without much functionnality but very portable + +Official repo: `http://zawz.net/zpkg` + +## Use as user + +### Installing + +```shell +curl -SO http://zawz.net/zpkg/install.sh +sh install.sh +``` + +If you wish to use another repository, substitute `zawz.net/zpkg` for your desired target + +### Using + +See `zpkg help` + +## Deploy on a server + +### Requirements + +To deploy on a server you need: +- SSH server +- HTTP server +- dedicated zpkg user + +You need to be able to SSH to the zpkg user. SSH keys are recommended + +### Process + +1. Write the desired config in `.config`, see `.config.example` + +2. Run `server_deploy.sh` + +3. Make available the package directory to the HTTP server diff --git a/scripts/database_update.sh b/scripts/database_update.sh new file mode 100755 index 0000000..d99de07 --- /dev/null +++ b/scripts/database_update.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +. "$(pwd)/.config" + +cd "$HOME/$PKG_PATH" || exit $? +stat -c "%n %Y" ./*.tar.xz | sed 's|\.tar\.xz||g;s|^\./||g' > pkglist diff --git a/scripts/gen_install.sh b/scripts/gen_install.sh new file mode 100755 index 0000000..0dd2011 --- /dev/null +++ b/scripts/gen_install.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +. "$(pwd)/.config" + +# create install file +echo '#!/bin/sh +' > install.sh +grep -E "(^HTTP_)|(^PKG_PATH)" .config >> install.sh +echo ' + +# Generate conf file +mkdir -p /etc/zpkg || exit $? +{ + echo "SSH_ADDRESS=$SSH_USER@$SSH_ADDR" + echo "HTTP_ADDRESS=$HTTP_ADDR/$HTTP_PATH" + echo "PKG_PATH=pkg" +} > /etc/zpkg/zpkg.conf + +# download zpkg +mkdir -p tmp || exit $? +( + cd tmp || exit $? + if ! wget "$HTTP_ADDR/$HTTP_PATH/zpkg.tar.xz" -q -O "zpkg.tar.xz" + then + echo "Cannot reach $HTTP_ADDR/$HTTP_PATH" > /dev/stderr + exit 1 + fi + tar xf zpkg.tar.xz || exit $? + +# install zpkg package + usr/local/bin/zpkg install zpkg || exit $? +) + +# cleanup +rm -rd tmp || exit $? +zpkg update-database >/dev/null || exit $? + +' >> install.sh +mv install.sh "$HOME/$PKG_PATH" diff --git a/server_deploy.sh b/server_deploy.sh index bb88263..864e38a 100755 --- a/server_deploy.sh +++ b/server_deploy.sh @@ -17,10 +17,12 @@ mkdir -p "$DIR/$PKG$DEST" || exit $? mkdir -p "$DIR/$PKG$BASHDEST" || exit $? cp src/zpkg.bash "$ZPKG_PKG_PATH/$PKG$BASHDEST" || exit $? cp src/zpkg "$ZPKG_PKG_PATH/$PKG$DEST" || exit $? -cd pkg/zpkg || exit $? -tar -cvJf zpkg.tar.xz * || exit $? -# send package -scp zpkg.tar.xz "$ssh":~/"$PKG_PATH" || exit $? +( + cd pkg/zpkg || exit $? + tar -cvJf zpkg.tar.xz * || exit $? + # send package + scp zpkg.tar.xz "$ssh":~/"$PKG_PATH" || exit $? +) rm -rd "$DIR" # update database ssh "$ssh" sh database_update.sh || exit $? diff --git a/src/zpkg b/src/zpkg index db48bef..70a5c23 100755 --- a/src/zpkg +++ b/src/zpkg @@ -82,7 +82,7 @@ deploy_package () fetch_package () { - if ! wget "$HTTP_ADDRESS/zpkg/$1.tar.xz" -q --show-progress -O "$1.tar.xz" 2>&1 + if ! wget "$HTTP_ADDRESS/$1.tar.xz" -q --show-progress -O "$1.tar.xz" 2>&1 then echo "Package '$1' not found" > /dev/stderr return 1 @@ -105,7 +105,7 @@ fetch_pkglist () { cd "$config_path" mv pkglist pkglist_bak 2>/dev/null - if ! wget "$HTTP_ADDRESS/zpkg/pkglist" -q --show-progress -O pkglist 2>&1 + if ! wget "$HTTP_ADDRESS/pkglist" -q --show-progress -O pkglist 2>&1 then echo "Couldn't fetch server data" > /dev/stderr mv pkglist_bak pkglist 2>/dev/null @@ -216,9 +216,6 @@ fi . "$config_file" -#ssh_address=$(grep "SSH_ADDRESS=" "$config_file" | cut -d '=' -f2-) -#http_address=$(grep "HTTP_ADDRESS=" "$config_file" | cut -d '=' -f2-) -#pkg_path=$(grep "PKG_PATH=" "$config_file" | cut -d '=' -f2-) if [ "$(echo $PKG_PATH | cut -c1)" != "/" ] then PKG_PATH="$config_path/$PKG_PATH"