diff --git a/.gitignore b/.gitignore
index edc76b1..5e3dd63 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,3 @@
/.config
-/pkg
/Zmakefile
-/autodeploy.sh
-/.deploytime
/zpkg
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..5f70f28
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,8 @@
+
+
+deploy: build
+ scripts/server_deploy.sh
+
+build:
+ scripts/shcompile src/main.sh > zpkg && chmod +x zpkg
+
diff --git a/README.md b/README.md
index ca510d8..73a7a32 100644
--- a/README.md
+++ b/README.md
@@ -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
`
-> Target directories are structured as described above
+`zpkg deploy `
+> Target directories are structured as described above
> The name of the directory is the package name
+### Updating
+
+`git pull && make`
+
## Functionality
- Install/Remove/Update packages
diff --git a/compile.sh b/compile.sh
deleted file mode 100755
index 6989eae..0000000
--- a/compile.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/sh
-
-cd "$(dirname "$(readlink -f "$0")")"
-
-scripts/shcompile src/main.sh > zpkg
-chmod +x zpkg
diff --git a/server_deploy.sh b/scripts/server_deploy.sh
similarity index 82%
rename from server_deploy.sh
rename to scripts/server_deploy.sh
index a02fce3..b5e2491 100755
--- a/server_deploy.sh
+++ b/scripts/server_deploy.sh
@@ -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 $?
diff --git a/server_scripts/gen_install.sh b/server_scripts/gen_install.sh
index c1420e1..d9ac848 100755
--- a/server_scripts/gen_install.sh
+++ b/server_scripts/gen_install.sh
@@ -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)
diff --git a/src/config.sh b/src/config.sh
index 110bd86..9ae520b 100644
--- a/src/config.sh
+++ b/src/config.sh
@@ -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"
diff --git a/src/fetch.sh b/src/fetch.sh
index 7561597..08a0bcc 100644
--- a/src/fetch.sh
+++ b/src/fetch.sh
@@ -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
diff --git a/src/install.sh b/src/install.sh
index 38040ad..9996380 100644
--- a/src/install.sh
+++ b/src/install.sh
@@ -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
)
diff --git a/src/print.sh b/src/print.sh
index 2ee9522..1903c02 100644
--- a/src/print.sh
+++ b/src/print.sh
@@ -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() {
diff --git a/src/upgrade.sh b/src/upgrade.sh
index 00c53ef..da72672 100644
--- a/src/upgrade.sh
+++ b/src/upgrade.sh
@@ -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=$?