+ 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 /.config
/pkg
/Zmakefile /Zmakefile
/autodeploy.sh
/.deploytime
/zpkg /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` 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 ### Package architecture
@ -72,17 +72,21 @@ You need to be able to SSH to the zpkg user, SSH keys are recommended
+-- HOME +-- HOME
+-- ~ +-- ~
``` ```
- The ROOT directory represents the root filesystem - The ROOT directory represents the root filesystem
- The HOME directory represents the home directory of the user - 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 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 - The DESC file contains the description of the package
### Deploying packages ### Deploying packages
`zpkg deploy <dir...>` `zpkg deploy <dir...>`
> Target directories are structured as described above > Target directories are structured as described above <br>
> The name of the directory is the package name > The name of the directory is the package name
### Updating
`git pull && make`
## Functionality ## Functionality
- Install/Remove/Update packages - 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 "$TMPDIR" ] && TMPDIR=/tmp
[ -z "$COMPRESSION" ] && COMPRESSION="xz:xz:pixz" [ -z "$COMPRESSION" ] && COMPRESSION="xz:xz:pixz:-6"
extension=$(echo "$COMPRESSION" | cut -d':' -f1) extension=$(echo "$COMPRESSION" | cut -d':' -f1)
compress=$(echo "$COMPRESSION" | cut -d':' -f2) compress=$(echo "$COMPRESSION" | cut -d':' -f2)
pcompress=$(echo "$COMPRESSION" | cut -d':' -f3) pcompress=$(echo "$COMPRESSION" | cut -d':' -f3)
@ -17,33 +17,36 @@ random_string()
tr -cd '[:alnum:]' < /dev/urandom | head -c$1 tr -cd '[:alnum:]' < /dev/urandom | head -c$1
} }
# build
./compile.sh || exit $?
# add sources to server # add sources to server
ssh "$SSH_ADDRESS" mkdir -p "$PKG_PATH" || exit $? ssh "$SSH_ADDRESS" mkdir -p "$PKG_PATH" || exit $?
scp .config server_scripts/* "$SSH_ADDRESS":~/ || exit $? scp .config server_scripts/* "$SSH_ADDRESS":~/ || exit $?
## zpkg package
# env
PKG=zpkg PKG=zpkg
DEST=/usr/bin DEST=/usr/bin
BASHDEST=/etc/bash_completion.d BASHDEST=/etc/bash_completion.d
tmpdir="$TMPDIR/zpkg$(random_string 5)" tmpdir="$TMPDIR/zpkg$(random_string 5)"
fullpath="$tmpdir/$PKG/ROOT" fullpath="$tmpdir/$PKG/ROOT"
# setup package sources # setup package sources
mkdir -p "$fullpath$DEST" || exit $? mkdir -p "$fullpath$DEST" || exit $?
mkdir -p "$fullpath$BASHDEST" || exit $? mkdir -p "$fullpath$BASHDEST" || exit $?
cp completion/zpkg.bash "$fullpath$BASHDEST" || exit $? cp completion/zpkg.bash "$fullpath$BASHDEST" || exit $?
mv zpkg "$fullpath$DEST" || exit $? mv zpkg "$fullpath$DEST" || exit $?
# create and send package # create and send package
( (
cd "$tmpdir/$PKG" || exit $? cd "$tmpdir/$PKG" || exit $?
tar -cf - * | $pcompress > zpkg.tar.$extension || exit $? tar -cf - * | $pcompress > zpkg.tar.$extension || exit $?
# send package # send package
scp zpkg.tar.$extension "$SSH_ADDRESS":~/"$PKG_PATH" || exit $? scp zpkg.tar.$extension "$SSH_ADDRESS":~/"$PKG_PATH" || exit $?
) ) || ret=$?
# cleanup # cleanup
rm -rd "$tmpdir" rm -r "$tmpdir"
# update database [ -n "$ret" ] && exit $ret
ssh "$SSH_ADDRESS" sh database_update.sh zpkg || exit $?
# generate install script # generate server data
ssh "$SSH_ADDRESS" sh gen_install.sh || exit $? 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 # install config file
$sudo mkdir -p "$config_path" || exit $? $sudo mkdir -p "$config_path" || exit $?
$sudo chmod a+rx "$config_path" 2>/dev/null
$sudo mv zpkg.conf "$config_path" || exit $? $sudo mv zpkg.conf "$config_path" || exit $?
$sudo chmod a+r "$config_path/zpkg.conf" 2>/dev/null
# download zpkg # download zpkg
tmpdir=$TMPDIR/zpkg$(tr -cd "[:alnum:]" < /dev/urandom | head -c5) tmpdir=$TMPDIR/zpkg$(tr -cd "[:alnum:]" < /dev/urandom | head -c5)

View file

@ -22,16 +22,25 @@ if ! root_check ; then
fi fi
[ ! -d "$config_path" ] && { $sudo mkdir -p "$config_path" 2>/dev/null || exit $?; } [ ! -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 # 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 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 # resolve compression
[ -z "$COMPRESSION" ] && COMPRESSION="xz:xz:pixz" [ -z "$COMPRESSION" ] && COMPRESSION="xz:xz:pixz"

View file

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

View file

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

View file

@ -26,13 +26,14 @@ Options:
-f Force running when root -f Force running when root
-R Don't do self-update mitigation -R Don't do self-update mitigation
Config (zpkg.conf): Config file (zpkg.conf):
SSH_ADDRESS SSH access for deploy SSH_ADDRESS SSH access for deploy
HTTP_ADDRESS HTTP address for downloading packages HTTP_ADDRESS HTTP address for downloading packages
PKG_PATH Path to the local package database PKG_PATH Path to the local package database
COMPRESSION Compression configuration, extension:binary:parallel_binary:options COMPRESSION Compression configuration, extension:binary:parallel_binary:options
ALLOW_ROOT Set to true to allow running as root without -f. Default: false 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() { error() {

View file

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