Skip to content

Commit

Permalink
finalize initial version of sash-package, v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric committed Feb 23, 2019
1 parent 5a3c862 commit c8a27cb
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 16 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 1.X - Unreleased
## 1.2.0 - Unreleased

* Don't source `sash-parse.sh` before plugins load as plugins can overwrite that.
* Move `sash-parse.sh` into a `sash-libs` folder.
Expand All @@ -7,6 +7,8 @@
caused by error mode being active.
* Use traps to ensure IFS isn't left in a bad state for `sash-parse`/`sash-add`.
* `sash-parse` now depends on `sash-err-stack`
* Finalize `sash-package.sh` which allows you to package up a particular category, or subcategory
for distribution to others. Signs with keybase, otherwise you need to provide: "--unsafe-no-sign".

## 1.1.1 (November 5th, 2018)

Expand Down
89 changes: 74 additions & 15 deletions sash-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ _sash_package_category() {
return 0
}

__sash_append_to_root_of_tar_xz() {
__sash_guard_errors

local tarxz_file="$1"
local file="$2"

local my_dir="$(pwd)"
local temp_dir=$(mktemp -d "${TMPDIR:-/tmp}/sash-tmp-add-to-tar.XXXXXXXXXX")
tar xJf "$tarxz_file" -C "$temp_dir"
cp "$file" "$temp_dir"
(cd "$temp_dir" && tar cfJ "$my_dir/tmp.tar.xz" .)
rm "$tarxz_file"
mv "$my_dir/tmp.tar.xz" "$tarxz_file"
}

# sash_package(args: Array<String>) -> Int
#
# sash_package will package up a category, or sub category for you to distribute to your
Expand All @@ -129,17 +144,24 @@ sash_package() {
__sash_guard_errors

local arguments="${@}"
local flags=("package-without-checks" "c|category" "s|subcategory" "f|full-category")
local flags=("package-without-checks" "c|category" "s|subcategory" "f|full-category" "u|keybase-user" "unsafe-no-sign")

if ! __sash_parse_args "$arguments" "${flags[@]}" ; then
echo "Failed to parse arguments for sash_package" >&2
return 1
fi

if [[ "${__sash_parse_results[unsafe-no-sign]}" != "0" ]]; then
if ! hash keybase 2>/dev/null; then
die "Please install the Keybase CLI for generating packages."
fi
fi

local category=""
local subcategory=""
local is_full_category=""
local run_checks="1"
local final_result=""

if [[ "${__sash_parse_results[package-without-checks]}" == "0" ]]; then
run_checks="0"
Expand All @@ -154,26 +176,63 @@ sash_package() {
echo -e "${white}[${red}-${white}]${restore} Category: [$1] doesn't exist!"
fi

# TODO: Implement Signing + Versioning.

if [[ "$category" == "$HOME/.bash/plugins/post" ]]; then
echo "[+] Packaing Post Section..."
final_result="$(pwd)/${category##*/}.tar.xz"
_sash_package_subcategory "$category" "$run_checks"
return $?

if [[ "$?" != "0" ]]; then
die "Failed to package subcategory!"
fi
else
if [[ "${__sash_parse_results[full-category]}" == "0" ]]; then
echo "[+] Packaging Category: $category..."
final_result="$(pwd)/${category##*/}.tar.xz"
_sash_package_category "$category" "$run_checks"

if [[ "$?" != "0" ]]; then
die "Failed to package subcategory!"
fi
else
if [[ "x${__sash_parse_results[subcategory]}" == "x" ]]; then
echo "[/] Please Choose a Subcategory to Package: "
subcategory="$(cd "$category" && _sash_choose_a_directory ".")"
else
subcategory="${__sash_parse_results[subcategory]}"
fi

local tmp_cat_subcat="$category/$subcategory"
echo "Packaging Subcategory: $tmp_cat_subcat"
final_result="$(pwd)/${tmp_cat_subcat##*/}.tar.xz"
_sash_package_subcategory "$tmp_cat_subcat" "$run_checks"

if [[ "$?" != "0" ]]; then
die "Failed to package!"
fi
fi
fi
if [[ "${__sash_parse_results[full-category]}" == "0" ]]; then
echo "[+] Packaging Category: $category..."
_sash_package_category "$category" "$run_checks"
return $?

if [[ "${__sash_parse_results[unsafe-no-sign]}" == "0" ]]; then
echo "[+] Generated unsafe, non signed package."
return 0
fi

if [[ "x${__sash_parse_results[subcategory]}" == "x" ]]; then
echo "[/] Please Choose a Subcategory to Package: "
subcategory="$(cd "$category" && _sash_choose_a_directory ".")"
if [[ "x${__sash_parse_results[keybase-user]}" != "x" ]]; then
local user="${__sash_parse_results[keybase-user]}"
echo "[+] Ensuring keybase user exists before signing."
keybase id "$user"
echo "[+] PGP Encrypting for user."
keybase pgp encrypt "$user" -i "$final_result" -o "${final_result}.asc"
rm "$final_result"
echo "[+] Encrypted. Encrypted tar.xz is at: ${final_result}.asc"
return 0
else
subcategory="${__sash_parse_results[subcategory]}"
echo "[+] Creating signature file for package."
keybase pgp sign -i "$final_result" --detached > "sig.asc"
__sash_append_to_root_of_tar_xz "$final_result" "sig.asc"
rm "sig.asc"
keybase id 2>&1 | head -n1 | awk '{ print $NF }' | sed 's/\x1B\[[0-9;]\+[A-Za-z]//g' > "sig.usr"
__sash_append_to_root_of_tar_xz "$final_result" "sig.usr"
rm "sig.usr"
fi
echo "Packaging Subcategory: $category/$subcategory"
_sash_package_subcategory "$category/$subcategory" "$run_checks"
return $?
}

0 comments on commit c8a27cb

Please sign in to comment.