+ Add direct env config

+ Add makefile
+ Add special umask patches
This commit is contained in:
zawz 2020-08-11 15:55:53 +02:00
parent 30f089d3ca
commit 269a2786f3
11 changed files with 62 additions and 36 deletions

3
.gitignore vendored
View file

@ -1,6 +1,3 @@
/.config
/pkg
/Zmakefile
/autodeploy.sh
/.deploytime
/zpkg

8
Makefile Normal file
View file

@ -0,0 +1,8 @@
deploy: build
scripts/server_deploy.sh
build:
scripts/shcompile src/main.sh > zpkg && chmod +x zpkg

View file

@ -57,9 +57,9 @@ You need to be able to SSH to the zpkg user, SSH keys are recommended
1. Write the desired config in `.config`, see `.config.example`
2. Run `server_deploy.sh`
2. Run `make`
3. Make available the package directory to the HTTP server
3. Expose the package directory to the HTTP server
### Package architecture
@ -72,17 +72,21 @@ You need to be able to SSH to the zpkg user, SSH keys are recommended
+-- HOME
+-- ~
```
- The ROOT directory represents the root filesystem
- The HOME directory represents the home directory of the user
- The ROOT directory represents the root filesystem
- The HOME directory represents the home directory of the user
- The DEPS file contains dependency packages separated by spaces or newlines. Dependencies are package names from the repository
- The DESC file contains the description of the package
### Deploying packages
`zpkg deploy <dir...>`
> Target directories are structured as described above
`zpkg deploy <dir...>`
> Target directories are structured as described above <br>
> The name of the directory is the package name
### Updating
`git pull && make`
## Functionality
- Install/Remove/Update packages

View file

@ -1,6 +0,0 @@
#!/bin/sh
cd "$(dirname "$(readlink -f "$0")")"
scripts/shcompile src/main.sh > zpkg
chmod +x zpkg

View file

@ -4,7 +4,7 @@
[ -z "$TMPDIR" ] && TMPDIR=/tmp
[ -z "$COMPRESSION" ] && COMPRESSION="xz:xz:pixz"
[ -z "$COMPRESSION" ] && COMPRESSION="xz:xz:pixz:-6"
extension=$(echo "$COMPRESSION" | cut -d':' -f1)
compress=$(echo "$COMPRESSION" | cut -d':' -f2)
pcompress=$(echo "$COMPRESSION" | cut -d':' -f3)
@ -17,33 +17,36 @@ random_string()
tr -cd '[:alnum:]' < /dev/urandom | head -c$1
}
# build
./compile.sh || exit $?
# add sources to server
ssh "$SSH_ADDRESS" mkdir -p "$PKG_PATH" || exit $?
scp .config server_scripts/* "$SSH_ADDRESS":~/ || exit $?
## zpkg package
# env
PKG=zpkg
DEST=/usr/bin
BASHDEST=/etc/bash_completion.d
tmpdir="$TMPDIR/zpkg$(random_string 5)"
fullpath="$tmpdir/$PKG/ROOT"
# setup package sources
mkdir -p "$fullpath$DEST" || exit $?
mkdir -p "$fullpath$BASHDEST" || exit $?
cp completion/zpkg.bash "$fullpath$BASHDEST" || exit $?
mv zpkg "$fullpath$DEST" || exit $?
# create and send package
(
cd "$tmpdir/$PKG" || exit $?
tar -cf - * | $pcompress > zpkg.tar.$extension || exit $?
# send package
scp zpkg.tar.$extension "$SSH_ADDRESS":~/"$PKG_PATH" || exit $?
)
) || ret=$?
# cleanup
rm -rd "$tmpdir"
# update database
ssh "$SSH_ADDRESS" sh database_update.sh zpkg || exit $?
# generate install script
ssh "$SSH_ADDRESS" sh gen_install.sh || exit $?
rm -r "$tmpdir"
[ -n "$ret" ] && exit $ret
# generate server data
ssh "$SSH_ADDRESS" sh database_update.sh zpkg '&&' sh gen_install.sh || exit $?

View file

@ -77,7 +77,9 @@ UPDATE_REMOVE=true\" > zpkg.conf"
# install config file
$sudo mkdir -p "$config_path" || exit $?
$sudo chmod a+rx "$config_path" 2>/dev/null
$sudo mv zpkg.conf "$config_path" || exit $?
$sudo chmod a+r "$config_path/zpkg.conf" 2>/dev/null
# download zpkg
tmpdir=$TMPDIR/zpkg$(tr -cd "[:alnum:]" < /dev/urandom | head -c5)

View file

@ -22,16 +22,25 @@ if ! root_check ; then
fi
[ ! -d "$config_path" ] && { $sudo mkdir -p "$config_path" 2>/dev/null || exit $?; }
[ ! -f "$config_file" ] && echo "Error: no config file '$config_file'" >&2 && exit 1
[ ! -f "$config_file" ] && echo "WARN: no config file '$config_file'" >&2
. "$config_file"
[ -f "$config_file" ] && . "$config_file"
[ -n "$ZPKG_SSH_ADDRESS" ] && SSH_ADDRESS=$ZPKG_SSH_ADDRESS
[ -n "$ZPKG_HTTP_ADDRESS" ] && HTTP_ADDRESS=$ZPKG_HTTP_ADDRESS
[ -n "$ZPKG_COMPRESSION" ] && COMPRESSION=$ZPKG_COMPRESSION
[ -n "$ZPKG_ALLOW_ROOT" ] && ALLOW_ROOT=$ZPKG_ALLOW_ROOT
[ -n "$ZPKG_UPDATE_REMOVE" ] && UPDATE_REMOVE=$ZPKG_UPDATE_REMOVE
# resolve relative pkg_path
PKG_PATH="$(resolve_path "$PKG_PATH" "$config_path")"
if [ -n "$ZPKG_PKG_PATH" ]
then PKG_PATH="$(resolve_path "$ZPKG_PKG_PATH" "$(pwd)")"
else PKG_PATH="$(resolve_path "$PKG_PATH" "$config_path")"
fi
root_check && [ -z "$opt_f" ] && [ "$ALLOW_ROOT" != "true" ] && echo "Cannot run as root" >&2 && exit 10
[ ! -d "$PKG_PATH" ] && $sudo mkdir -p "$PKG_PATH"
[ ! -d "$PKG_PATH" ] && $sudo mkdir -p "$PKG_PATH" && $sudo chmod a+rx "$PKG_PATH"
# resolve compression
[ -z "$COMPRESSION" ] && COMPRESSION="xz:xz:pixz"

View file

@ -12,7 +12,7 @@ fetch_package()
fetch_pkglist()
{
(
cd "$PKG_PATH"
cd "$PKG_PATH" || exit $?
$1 mv pkglist pkglist_bak 2>/dev/null
if ! $1 wget "$HTTP_ADDRESS/pkglist" -q --show-progress -O pkglist 2>&1
then
@ -20,6 +20,7 @@ fetch_pkglist()
$1 mv pkglist_bak pkglist 2>/dev/null
return 1
else
$1 chmod a+r pkglist
$1 rm pkglist_bak 2>/dev/null
return 0
fi

View file

@ -1,5 +1,6 @@
#!/bin/sh
# $1 = file , $2 = prefix
unpack()
{
echo "Unpacking $1"
@ -16,11 +17,12 @@ add_package_entry()
$2 sed "s|$1 .*\$|$1 $(date +%s)|g" -i installed
else
$2 sh -c "echo '$1 $(date +%s)' >> installed"
$2 chmod a+r installed
fi
)
}
# $1 = source_dir, $2 = dest_dir, $3 = prefix for exec
# $1 = source_dir , $2 = dest_dir , $3 = prefix
copy_files() {
$3 cp -r "$1/." "$2"
}
@ -33,11 +35,15 @@ install_package()
tmpdir="$TMPDIR/zpkg_$(random_string 5)"
mkdir -p "$tmpdir"
(
cd "$tmpdir"
cd "$tmpdir" || exit $?
fetch_package "$1" || { echo "Package '$1' not found" >&2 && return 1; }
$2 cp "$1.tar.$extension" "$PKG_PATH"
unpack "$1.tar.$extension" || return $?
copy_files ROOT / $2 2>/dev/null
$2 chmod a+r "$PKG_PATH/$1.tar.$extension"
(
umask a+rx
unpack "$1.tar.$extension" $2 || return $?
copy_files ROOT / $2 o+rx 2>/dev/null || return $?
) || return $?
copy_files HOME "$HOME" 2>/dev/null
add_package_entry "$1" $2
)

View file

@ -26,13 +26,14 @@ Options:
-f Force running when root
-R Don't do self-update mitigation
Config (zpkg.conf):
Config file (zpkg.conf):
SSH_ADDRESS SSH access for deploy
HTTP_ADDRESS HTTP address for downloading packages
PKG_PATH Path to the local package database
COMPRESSION Compression configuration, extension:binary:parallel_binary:options
ALLOW_ROOT Set to true to allow running as root without -f. Default: false
UPDATE_REMOVE Remove packages on update. Default: true"
UPDATE_REMOVE Remove packages on update. Default: true
Config can be overwritten by environment by appending 'ZPKG_' to the corresponding variable"
}
error() {

View file

@ -31,6 +31,7 @@ upgrade_package()
copy_files ROOT / $2 2>/dev/null
copy_files HOME "$HOME" 2>/dev/null
$2 cp "$1.tar.$extension" "$PKG_PATH"
$2 chmod a+r "$PKG_PATH/$1.tar.$extension"
add_package_entry "$1" $2
)
ret=$?