Change server config

This commit is contained in:
zawz 2020-05-28 19:34:52 +02:00
parent 572ca12e64
commit 8ea223fe93
3 changed files with 18 additions and 27 deletions

View file

@ -1,16 +1,14 @@
# zpkg server config
# address of the SSH server
SSH_ADDR=example.com
# user for the SSH server
SSH_USER=zpkg
# path to packages for the zpkg user
PKG_PATH=pkg
# public address of the HTTP server
HTTP_ADDR=example.com
# path on server
HTTP_PATH=zpkg
HTTP_ADDRESS=http://example.com
# address of the SSH server
SSH_ADDRESS=user@example.com
# path to packages for the zpkg user
# this is the target folder available at the HTTP_ADDRESS
PKG_PATH=pkg
# Compression to use for packages
# format:

View file

@ -2,8 +2,6 @@
. "$(pwd)/.config"
ssh="$SSH_USER@$SSH_ADDR"
[ -z "$COMPRESSION" ] && COMPRESSION="xz:xz:pxz"
extension=$(echo "$COMPRESSION" | cut -d':' -f1)
compress=$(echo "$COMPRESSION" | cut -d':' -f2)
@ -21,8 +19,8 @@ random_string()
./compile.sh || exit $?
# add sources to server
ssh "$ssh" mkdir -p "$PKG_PATH" || exit $?
scp .config server_scripts/* "$ssh":~/ || exit $?
ssh "$SSH_ADDRESS" mkdir -p "$PKG_PATH" || exit $?
scp .config server_scripts/* "$SSH_ADDRESS":~/ || exit $?
PKG=zpkg
DEST=/usr/local/bin
@ -39,11 +37,11 @@ mv zpkg "$fullpath$DEST" || exit $?
cd "$tmpdir/$PKG" || exit $?
tar -cf - * | $pcompress > zpkg.tar.$extension || exit $?
# send package
scp zpkg.tar.$extension "$ssh":~/"$PKG_PATH" || exit $?
scp zpkg.tar.$extension "$SSH_ADDRESS":~/"$PKG_PATH" || exit $?
)
# cleanup
rm -rd "$tmpdir"
# update database
ssh "$ssh" sh database_update.sh zpkg || exit $?
ssh "$SSH_ADDRESS" sh database_update.sh zpkg || exit $?
# generate install script
ssh "$ssh" sh gen_install.sh || exit $?
ssh "$SSH_ADDRESS" sh gen_install.sh || exit $?

View file

@ -29,11 +29,6 @@ Options:
-c <path> Use this path as config"
}
random_string()
{
tr -cd '[:alnum:]' < /dev/urandom | head -c$1
}
config_path=/etc/zpkg
while getopts ":hc:" opt;
@ -71,8 +66,8 @@ fi
# Generate conf file
$sudo sh -c "{
echo SSH_ADDRESS=$SSH_USER@$SSH_ADDR
echo HTTP_ADDRESS=$HTTP_ADDR/$HTTP_PATH
echo SSH_ADDRESS=$SSH_ADDRESS
echo HTTP_ADDRESS=$HTTP_ADDRESS
echo COMPRESSION=$COMPRESSION
echo PKG_PATH=pkg
} > zpkg.conf"
@ -82,13 +77,13 @@ $sudo mkdir -p "$config_path" || exit $?
$sudo mv zpkg.conf "$config_path" || exit $?
# download zpkg
tmpdir=/tmp/zpkg$(random_string 5)
tmpdir=/tmp/zpkg$(tr -cd "[:alnum:]" < /dev/urandom | head -c5)
mkdir -p "$tmpdir" || exit $?
(
cd "$tmpdir" || exit $?
if ! wget "$HTTP_ADDR/$HTTP_PATH/zpkg.tar.$extension" -q -O "zpkg.tar.$extension"
if ! wget "$HTTP_ADDRESS/zpkg.tar.$extension" -q -O "zpkg.tar.$extension"
then
echo "Cannot reach $HTTP_ADDR/$HTTP_PATH" > /dev/stderr
echo "Cannot reach $HTTP_ADDRESS" > /dev/stderr
exit 1
fi
$pcompress -dc "zpkg.tar.$extension" | tar -xf - || exit $?