diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5461348 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,92 @@ +name: build +on: + push: + tags: + - "[0-9]+.[0-9]+.[0-9]+" + +jobs: + build: + permissions: + contents: write + name: build + runs-on: ${{ matrix.os }} + strategy: + matrix: + build: [linux, macos, windows] + include: + - build: linux + os: ubuntu-latest + rust: nightly + target: x86_64-unknown-linux-musl + archive-name: airnc-linux.tar.gz + + - build: macos + os: macos-latest + rust: nightly + target: x86_64-apple-darwin + archive-name: airnc-macos.tar.gz + + - build: macos-aarch64 + os: macos-latest + rust: nightly + target: aarch64-apple-darwin + archive-name: airnc-macos-aarch64.tar.gz + + - build: windows + os: windows-2019 + rust: nightly-x86_64-msvc + target: x86_64-pc-windows-msvc + archive-name: airnc-windows.7z + fail-fast: false + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: true + target: ${{ matrix.target }} + + - name: Install musl(linux) + if: matrix.build == 'linux' + run: sudo apt-get install -y musl-tools + + - name: Build binary + run: cargo build --verbose --release --target ${{ matrix.target }} + env: + RUST_BACKTRACE: 1 + + - name: Strip binary (linux and macos) + if: matrix.build == 'linux' || matrix.build == 'macos' + run: | + strip "target/${{ matrix.target }}/release/airnc" + + - name: Build archive + shell: bash + run: | + mkdir archive + cp LICENSE README.md archive/ + cd archive + if [ "${{ matrix.build }}" = "windows" ]; then + cp "../target/${{ matrix.target }}/release/airnc.exe" ./ + 7z a "${{ matrix.archive-name }}" LICENSE README.md airnc.exe + else + cp "../target/${{ matrix.target }}/release/airnc" ./ + tar -czf "${{ matrix.archive-name }}" LICENSE README.md airnc + fi + + - name: Upload archive + uses: actions/upload-artifact@v1 + with: + name: ${{ matrix.archive-name }} + path: archive/${{ matrix.archive-name }} + + - name: Release + uses: softprops/action-gh-release@v1 + with: + draft: true + files: archive/${{ matrix.archive-name }} diff --git a/Cargo.lock b/Cargo.lock index 538f72f..7a8a9c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -220,15 +220,13 @@ dependencies = [ [[package]] name = "airnc" -version = "0.0.1" +version = "0.0.2" dependencies = [ "actix-web", "async-stream", "clap 4.4.13", "colored", - "futures", "image", - "lazy_static", "qrcode", "rand", "termimage", @@ -723,65 +721,12 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - [[package]] name = "futures-core" version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] - [[package]] name = "futures-sink" version = "0.3.30" @@ -800,16 +745,10 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ - "futures-channel", "futures-core", - "futures-io", - "futures-macro", - "futures-sink", "futures-task", - "memchr", "pin-project-lite", "pin-utils", - "slab", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a01db5b..99e3d32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,11 +2,16 @@ name = "airnc" version = "0.0.1" edition = "2021" +description = "A LAN transmission tool" +authors = ["fangyuan.leslie@gmail.com"] +keywords = ["cli", "file-transmission", "LAN"] +license = "MIT" +homepage = "https://github.com/zhazhazhu/airnc" +repository = "https://github.com/zhazhazhu/airnc" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -futures = "0.3" clap = { version = "4.4.13", features = ["derive"] } colored = "2.1.0" tokio = { version = "1.35.1", features = ["full"] } @@ -15,5 +20,4 @@ rand = "0.8.5" qrcode = "0.13" image = "0.24.7" termimage = "1.2.1" -lazy_static = "1.4.0" async-stream = "0.3.5" diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..d2beaaa --- /dev/null +++ b/install.sh @@ -0,0 +1,127 @@ +#!/bin/bash +OS_TYPE="$(uname)" +echo "Operating System: $OS_TYPE" + +if [[ "$OS_TYPE" == "Linux" ]]; then + FILENAME="airnc-linux.tar.gz" +elif [[ "$OS_TYPE" == "Darwin" ]]; then + ARCH="$(uname -m)" + if [[ "$ARCH" == "x86_64" ]]; then + FILENAME="airnc-macos.tar.gz" + elif [[ "$ARCH" == "arm64" ]]; then + FILENAME="airnc-macos-aarch64.tar.gz" + else + FILENAME="airnc-macos.tar.gz" + echo "Unknown macOS Architecture: $ARCH" + fi +elif [[ "$OS_TYPE" == "Windows_NT" ]]; then + FILENAME="airnc-windows.7z" +else + echo "Unknown Operating System: $OS_TYPE" + exit 1 +fi + +ARCHIVE_URL="https://github.com/zhazhazhu/airnc/releases/latest/download/$FILENAME" + +DOWNLOAD_DIR=$(mktemp -d) + +CURRENT_SHELL="$(basename "$SHELL")" + +TEMP_FILE="$DOWNLOAD_DIR/airnc.tar.gz" + +if [ -d "$HOME/.airnc" ]; then + INSTALL_DIR="$HOME/.airnc" +elif [ -n "$XDG_DATA_HOME" ]; then + INSTALL_DIR="$XDG_DATA_HOME/.airnc" +elif [ "$OS" = "Darwin" ]; then + INSTALL_DIR="$HOME/Library/Application Support/.airnc" +else + INSTALL_DIR="$HOME/.local/share/.airnc" +fi + +echo "CURRENT_SHELL is $CURRENT_SHELL" + +echo "INSTALL_DIR is $INSTALL_DIR" + +echo "DOWNLOAD_DIR is $DOWNLOAD_DIR" + +curl -L "$ARCHIVE_URL" -o "$TEMP_FILE" + +tar -xzvf "$TEMP_FILE" -C "$DOWNLOAD_DIR" + +if [ ! -d "$INSTALL_DIR" ]; then + mkdir "$INSTALL_DIR" +fi + +mv "$DOWNLOAD_DIR/airnc" "$INSTALL_DIR/airnc" + +rm -rf "$DOWNLOAD_DIR" + +ensure_containing_dir_exists() { + local CONTAINING_DIR + CONTAINING_DIR="$(dirname "$1")" + if [ ! -d "$CONTAINING_DIR" ]; then + echo " >> Creating directory $CONTAINING_DIR" + mkdir -p "$CONTAINING_DIR" + fi +} + +setup_shell() { + CURRENT_SHELL="$(basename "$SHELL")" + + if [ "$CURRENT_SHELL" = "zsh" ]; then + CONF_FILE=${ZDOTDIR:-$HOME}/.zshrc + ensure_containing_dir_exists "$CONF_FILE" + echo "Installing for Zsh. Appending the following to $CONF_FILE:" + echo "" + echo ' # airnc' + echo ' export PATH="'"$INSTALL_DIR"':$PATH"' + + echo '' >>$CONF_FILE + echo '# airnc' >>$CONF_FILE + echo 'export PATH="'$INSTALL_DIR':$PATH"' >>$CONF_FILE + + elif [ "$CURRENT_SHELL" = "fish" ]; then + CONF_FILE=$HOME/.config/fish/conf.d/airnc.fish + ensure_containing_dir_exists "$CONF_FILE" + echo "Installing for Fish. Appending the following to $CONF_FILE:" + echo "" + echo ' # airnc' + echo ' set PATH "'"$INSTALL_DIR"'" $PATH' + echo ' airnc env | source' + + echo '# airnc' >>$CONF_FILE + echo 'set PATH "'"$INSTALL_DIR"'" $PATH' >>$CONF_FILE + echo 'airnc env | source' >>$CONF_FILE + + elif [ "$CURRENT_SHELL" = "bash" ]; then + if [ "$OS" = "Darwin" ]; then + CONF_FILE=$HOME/.profile + else + CONF_FILE=$HOME/.bashrc + fi + ensure_containing_dir_exists "$CONF_FILE" + echo "Installing for Bash. Appending the following to $CONF_FILE:" + echo "" + echo ' # airnc' + echo ' export PATH="'"$INSTALL_DIR"':$PATH"' + + echo '' >>$CONF_FILE + echo '# airnc' >>$CONF_FILE + echo 'export PATH="'"$INSTALL_DIR"':$PATH"' >>$CONF_FILE + + else + echo "Could not infer shell type. Please set up manually." + exit 1 + fi + + echo '# airnc end' >>$CONF_FILE + echo "" + echo "In order to apply the changes, open a new terminal or run the following command:" + echo "" + echo " source $CONF_FILE" +} + +setup_shell + +echo "Installation completed successfully." \ No newline at end of file