summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkennycallado <kennycallado@gmail.com>2023-09-12 19:33:55 +0200
committerGitHub <noreply@github.com>2023-09-12 13:33:55 -0400
commitc2cc103a3df3c121cc5319990b184bf2916e1a14 (patch)
treed9e5bf910bc7c4e14e0ec344cdd7b10d22f964ae
parentbb1ca6d78227280a9d056575642962f98e131c72 (diff)
Script to install from the terminal (#427)
* update: move nix and docker to utils * feat: script to install from the terminal * doc: add some instructions to install from the terminal * strip the binary on release * udpate: - avoiding deprecated set-output - adds checksum files on release - remove strip step * update dockerignore * fix if checksum file exists --------- Co-authored-by: kennycallado <kennycallado@hotmail.com>
-rw-r--r--.Dockerignore6
-rw-r--r--.github/workflows/automated-build.yml76
-rw-r--r--Cargo.toml3
-rw-r--r--Dockerfile15
-rw-r--r--README.md36
-rw-r--r--utils/docker/Dockerfile19
-rw-r--r--utils/docker/builder.Dockerfile28
-rwxr-xr-xutils/install.sh138
-rw-r--r--utils/nix/default.nix (renamed from nix/default.nix)0
9 files changed, 265 insertions, 56 deletions
diff --git a/.Dockerignore b/.Dockerignore
index 5f6b81f..c21f84d 100644
--- a/.Dockerignore
+++ b/.Dockerignore
@@ -1,9 +1,11 @@
+.git
+.github
config
docs
target
+utils
Cargo.lock
-Docker*
+flake*
LICENSE
README.md
screenshot.png
-
diff --git a/.github/workflows/automated-build.yml b/.github/workflows/automated-build.yml
index 7be4129..b05bc87 100644
--- a/.github/workflows/automated-build.yml
+++ b/.github/workflows/automated-build.yml
@@ -1,3 +1,4 @@
+
name: Automated build
env:
CI_INTERMEDIATES_DIR: "_ci-intermediates"
@@ -17,9 +18,11 @@ jobs:
job:
- {os: ubuntu-20.04, target: arm-unknown-linux-gnueabihf, use-cross: true}
- {os: ubuntu-20.04, target: arm-unknown-linux-musleabihf, use-cross: true}
+ - {os: ubuntu-20.04, target: aarch64-unknown-linux-musl, use-cross: true}
- {os: ubuntu-20.04, target: aarch64-unknown-linux-gnu, use-cross: true}
- - {os: ubuntu-20.04, target: x86_64-unknown-linux-gnu}
- {os: ubuntu-20.04, target: x86_64-unknown-linux-musl, use-cross: true}
+ - {os: ubuntu-20.04, target: x86_64-unknown-linux-gnu}
+ - {os: macos-latest, target: aarch64-apple-darwin}
- {os: macos-13, target: x86_64-apple-darwin}
steps:
- name: Checkout source code
@@ -60,8 +63,8 @@ jobs:
use-cross: ${{ matrix.job.use-cross }}
command: build
args: --locked --release --target=${{ matrix.job.target }}
- - name: Strip debug information from executable
- id: strip
+ - name: Create tarball
+ id: package
shell: bash
run: |
# Figure out suffix of binary
@@ -70,45 +73,16 @@ jobs:
*-pc-windows-*) EXE_suffix=".exe" ;;
esac;
- # Figure out what strip tool to use if any
- STRIP="strip"
- case ${{ matrix.job.target }} in
- arm-unknown-linux-*) STRIP="arm-linux-gnueabihf-strip" ;;
- aarch64-unknown-linux-gnu) STRIP="aarch64-linux-gnu-strip" ;;
- *-pc-windows-msvc) STRIP="" ;;
- esac;
-
- # Setup paths
- BIN_DIR="${{ env.CI_INTERMEDIATES_DIR }}/stripped-release-bin/"
- mkdir -p "${BIN_DIR}"
BIN_NAME="${{ env.PROJECT_NAME }}${EXE_suffix}"
- BIN_PATH="${BIN_DIR}/${BIN_NAME}"
-
- # Copy the release build binary to the result location
- cp "target/${{ matrix.job.target }}/release/${BIN_NAME}" "${BIN_DIR}"
-
- # Also strip if possible
- if [ -n "${STRIP}" ]; then
- "${STRIP}" "${BIN_PATH}"
- fi
-
- # Let subsequent steps know where to find the (stripped) bin
- echo ::set-output name=BIN_PATH::${BIN_PATH}
- echo ::set-output name=BIN_NAME::${BIN_NAME}
- - name: Create tarball
- id: package
- shell: bash
- run: |
PKG_suffix=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_suffix=".zip" ;; esac;
PKG_BASENAME=${PROJECT_NAME}-v${PROJECT_VERSION}-${{ matrix.job.target }}
PKG_NAME=${PKG_BASENAME}${PKG_suffix}
- echo ::set-output name=PKG_NAME::${PKG_NAME}
PKG_STAGING="${{ env.CI_INTERMEDIATES_DIR }}/package"
ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/"
mkdir -p "${ARCHIVE_DIR}"
# Binary
- cp "${{ steps.strip.outputs.BIN_PATH }}" "$ARCHIVE_DIR"
+ cp "target/${{ matrix.job.target }}/release/${BIN_NAME}" "$ARCHIVE_DIR"
# base compressed package
pushd "${PKG_STAGING}/" >/dev/null
@@ -119,23 +93,47 @@ jobs:
popd >/dev/null
# Let subsequent steps know where to find the compressed package
- echo ::set-output name=PKG_PATH::"${PKG_STAGING}/${PKG_NAME}"
+ echo "PKG_PATH=${PKG_STAGING}/${PKG_NAME}" >> $GITHUB_ENV
+ echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_ENV
+ echo "PKG_STAGING=${PKG_STAGING}" >> $GITHUB_ENV
+ - name: "Generate checksum"
+ id: checksum
+ shell: bash
+ run: |
+ SUM_NAME=${{ env.PKG_NAME }}.sha256sum
+ SUM_PATH=${PKG_STAGING}/${SUM_NAME}
+ OS="$(uname -s)"
+
+ if [ "$OS" == "Linux" ]; then
+ sha256sum ${PKG_PATH} > ${SUM_PATH}
+ elif [ "$OS" == "Darwin" ]; then
+ shasum -a 256 ${PKG_PATH} > ${SUM_PATH}
+ fi
+
+ echo "SUM_NAME=${SUM_NAME}" >> $GITHUB_ENV
+ echo "SUM_PATH=${SUM_PATH}" >> $GITHUB_ENV
- name: "Artifact upload: tarball"
uses: actions/upload-artifact@master
with:
- name: ${{ steps.package.outputs.PKG_NAME }}
- path: ${{ steps.package.outputs.PKG_PATH }}
+ name: ${{ env.PKG_NAME }}
+ path: ${{ env.PKG_PATH }}
+ - name: "Artifact upload: checksum"
+ uses: actions/upload-artifact@master
+ with:
+ name: ${{ env.SUM_NAME }}
+ path: ${{ env.SUM_PATH }}
- name: Check for release
id: is-release
shell: bash
run: |
unset IS_RELEASE ; if [[ $GITHUB_REF =~ ^refs/tags/v[0-9].* ]]; then IS_RELEASE='true' ; fi
- echo ::set-output name=IS_RELEASE::${IS_RELEASE}
+ echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_ENV
- name: Publish archives and packages
uses: softprops/action-gh-release@v1
- if: steps.is-release.outputs.IS_RELEASE
+ if: env.IS_RELEASE
with:
files: |
- ${{ steps.package.outputs.PKG_PATH }}
+ ${{ env.PKG_PATH }}
+ ${{ env.SUM_PATH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/Cargo.toml b/Cargo.toml
index dbb3f16..92fd741 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,6 +10,9 @@ edition = "2021"
keywords = ["tui-rs", "ranger", "file_manager", "termion"]
categories = ['command-line-interface', 'command-line-utilities']
+[profile.release]
+strip = true
+
[dependencies]
alphanumeric-sort = "^1"
ansi-to-tui = { version = "^3.1.0", optional = true }
diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644
index c5251be..0000000
--- a/Dockerfile
+++ /dev/null
@@ -1,15 +0,0 @@
-FROM rust:latest AS builder
-
-COPY . /usr/src/joshuto
-
-WORKDIR /usr/src/joshuto
-
-RUN rustup target add x86_64-unknown-linux-musl \
- && cargo build --target x86_64-unknown-linux-musl --release
-
-FROM busybox:latest
-
-COPY --from=builder /usr/src/joshuto/target/x86_64-unknown-linux-musl/release/joshuto /bin/joshuto
-
-WORKDIR /root
-
diff --git a/README.md b/README.md
index 4e1cdc4..e512ef0 100644
--- a/README.md
+++ b/README.md
@@ -48,6 +48,42 @@ Also see [Cargo.toml](Cargo.toml)
~# cargo install --path=. --force --root=/usr/local # /usr also works
```
+#### From pre-compiled binary
+
+Dependencies:
+- curl
+- openssl
+
+##### Latest release
+
+Installs the latest version using the default installation path (_$HOME/.local/bin/_).
+
+``` bash
+~$ bash <(curl -s https://raw.githubusercontent.com/kamiyaa/joshuto/master/utils/install.sh)
+```
+
+##### Custom Installation path
+
+Allows you to install Joshuto to a custom directory by setting the INSTALL_PREFIX variable.
+
+``` bash
+~$ INSTALL_PREFIX="$HOME" bash <(curl -s https://raw.githubusercontent.com/kamiyaa/joshuto/master/utils/install.sh)
+```
+
+##### System wide
+
+``` bash
+~# INSTALL_PREFIX="/usr/local/bin" bash <(curl -s https://raw.githubusercontent.com/kamiyaa/joshuto/master/utils/install.sh)
+```
+
+##### Specific release
+
+Installs a specific release version of Joshuto by the desired version number.
+
+``` bash
+~$ RELEASE_VER='v0.9.4' bash <(curl -s https://raw.githubusercontent.com/kamiyaa/joshuto/master/utils/install.sh)
+```
+
#### Packaging status
##### Fedora ([COPR](https://copr.fedorainfracloud.org/coprs/atim/joshuto/))
diff --git a/utils/docker/Dockerfile b/utils/docker/Dockerfile
new file mode 100644
index 0000000..293f17a
--- /dev/null
+++ b/utils/docker/Dockerfile
@@ -0,0 +1,19 @@
+# For images like alpine, busybox, scratch with no libc you can use musl targets instead
+#
+# docker build -t joshuto:local-dev -f utils/docker/Dockerfile \
+# --build-arg TARGET="x86_64-unknown-linux-musl" \
+# --build-arg RELEASE_I="scratch" .
+
+ARG RELEASE_I="ubuntu:lunar"
+ARG TARGET
+
+FROM ${RELEASE_I}
+
+ARG TARGET
+
+COPY ./target/${TARGET}/release/joshuto /usr/local/bin/joshuto
+COPY ./config/ /root/.config/joshuto/
+
+WORKDIR /root
+
+ENTRYPOINT ["/usr/local/bin/joshuto"]
diff --git a/utils/docker/builder.Dockerfile b/utils/docker/builder.Dockerfile
new file mode 100644
index 0000000..4d27146
--- /dev/null
+++ b/utils/docker/builder.Dockerfile
@@ -0,0 +1,28 @@
+# docker build -t joshuto:local-dev -f utils/docker/builder.Dockerfile \
+# --build-arg TARGET="x86_64-unknown-linux-musl" \
+# --build-arg RELEASE_I="scratch" .
+
+ARG RELEASE_I="busybox:latest"
+ARG TARGET="x86_64-unknown-linux-musl"
+
+FROM rust:latest AS builder
+
+ARG TARGET
+
+COPY . /usr/src/joshuto
+
+WORKDIR /usr/src/joshuto
+
+RUN rustup target add ${TARGET} && rustup target add ${TARGET}
+RUN cargo build --target ${TARGET} --release
+
+FROM ${RELEASE_I} AS release
+
+ARG TARGET
+
+COPY --from=builder /usr/src/joshuto/target/${TARGET}/release/joshuto /usr/local/bin/joshuto
+COPY ./config/ /root/.config/joshuto/
+
+WORKDIR /root
+
+ENTRYPOINT ["/usr/local/bin/joshuto"]
diff --git a/utils/install.sh b/utils/install.sh
new file mode 100755
index 0000000..1ad59d8
--- /dev/null
+++ b/utils/install.sh
@@ -0,0 +1,138 @@
+#!/usr/bin/env sh
+
+# testing from fork:
+# REPO="kennycallado/joshuto" bash <(curl -s https://raw.githubusercontent.com/kennycallado/joshuto/master/utils/install.sh)
+
+set -eo pipefail
+
+# Check before starting the installation
+readonly INSTALL_PREFIX="${INSTALL_PREFIX:-"$HOME/.local/bin"}"
+if [ ! -d "$INSTALL_PREFIX" ];then echo "Error! $INSTALL_PREFIX does not exist"; exit 1 ;fi
+
+readonly GITHUB_API_URL="https://api.github.com/repos/kamiyaa/joshuto/releases"
+
+function get_latest_version() {
+ curl -Lfs "$GITHUB_API_URL" | \
+ grep '"tag_name":' | \
+ sed -E 's/.*"([^"]+)".*/\1/' | \
+ head -n 1
+}
+
+function get_release_body() {
+ curl -Lfs "$GITHUB_API_URL" | \
+ grep '"body":' | \
+ sed -E 's/.*"([^"]+)".*/\1/' | \
+ head -n 1
+}
+
+readonly OS="$(uname -s)"
+readonly ARCH="$(uname -m)"
+readonly REPO="${REPO:-"kamiyaa/joshuto"}"
+readonly LIBR="$(if [ -f /lib/libc.musl-x86_64.so.1 ];then echo "musl" ; else echo "gnu" ;fi)"
+
+readonly RELEASE_VER="${RELEASE_VER:-"$(get_latest_version)"}"
+readonly RELEASE_BODY="$(get_release_body)"
+
+if [ "$OS" == "Linux" ]; then
+ readonly ARCHIVE_NAME="joshuto-$RELEASE_VER-$ARCH-unknown-linux-$LIBR"
+elif [ "$OS" == "Darwin" ]; then
+ readonly ARCHIVE_NAME="joshuto-$RELEASE_VER-$ARCH-apple-darwin"
+else
+ echo
+ echo "$OS platform is not supported currently"
+ exit 1
+fi
+
+readonly ARCHIVE_URL="https://github.com/$REPO/releases/download/$RELEASE_VER/$ARCHIVE_NAME.tar.gz"
+readonly CHECKSUM_URL="$ARCHIVE_URL.sha256sum"
+
+readonly DOWNLOAD_DIR="$(mktemp -d)"
+readonly RELEASE_SHA="$(curl -Lfs "$CHECKSUM_URL" | awk '{print $1}')"
+
+function main() {
+ printf "$RELEASE_BODY\n\n"
+
+ printf '\e[1;32m%-6s\e[m' "===================="
+ printf '\e[1;34m%-6s\e[m' " Release notes  "
+ printf '\e[1;32m%-6s\e[m' "===================="
+
+ printf "\n\n";
+
+ download_archive
+ verify_archive
+ install_joshuto
+}
+
+function download_archive() {
+ echo "Downloading joshuto's binary from $RELEASE_VER release.."
+ if ! curl --progress-bar -Lf "$ARCHIVE_URL" -o "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz"; then
+ echo
+ echo "Download failed. Check that the release/filename are correct."
+ exit 1
+ fi
+ echo "Download complete!"
+}
+
+# Some releases don't have checksum file
+function checksum_file() {
+ local _return=$1
+
+ if [ -z "$RELEASE_SHA" ]; then
+ printf "\n"
+ printf '\e[1;33m%-6s\e[m' "Warning! "
+ printf '\e[1;0m%-6s\e[m' "release checksum file is not found."
+ printf "\n"
+
+ echo "Would you like to continue? [y/N]"
+ read -r answer
+ if [ "$answer" == "${answer#[Yy]}" ]; then
+ echo "Installation aborted."
+ exit 1
+ fi
+ fi
+
+ eval $_return="'$DOWNLOADED_SHA'"
+}
+
+function verify_archive() {
+ echo "Verifying the installation..."
+
+ DOWNLOADED_SHA="$(openssl dgst -sha256 "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz" | awk '{print $2}')"
+ checksum_file VERIFIED
+
+ if [ "$VERIFIED" != "$DOWNLOADED_SHA" ]; then
+ printf "\n"
+ printf '\e[1;31m%-6s\e[m' "Error! "
+ printf '\e[1;0m%-6s\e[m' "checksum mismatch."
+ printf "\n"
+
+ exit 1
+ fi
+ echo "Verification complete!"
+}
+
+function install_joshuto() {
+ echo "Installing joshuto..."
+
+ PWD="$(pwd)"
+ cd $DOWNLOAD_DIR
+ tar -xzf "$DOWNLOAD_DIR/$ARCHIVE_NAME.tar.gz"
+ cd $PWD
+
+ if [ ! -d "$DOWNLOAD_DIR/$ARCHIVE_NAME" ]; then
+ printf "\n"
+ printf '\e[1;31m%-6s\e[m' "Error! "
+ printf '\e[1;0m%-6s\e[m' "Archive does not contain a $ARCHIVE_NAME directory."
+ printf "\n"
+
+ exit 1
+ fi
+
+ cp -r "$DOWNLOAD_DIR/$ARCHIVE_NAME/joshuto" "$INSTALL_PREFIX/"
+ echo
+ echo "Installation complete!"
+ echo "======================"
+ echo "Now you can run $INSTALL_PREFIX/joshuto"
+}
+
+main "$@"
diff --git a/nix/default.nix b/utils/nix/default.nix
index ca449c8..ca449c8 100644
--- a/nix/default.nix
+++ b/utils/nix/default.nix