This commit is contained in:
Vomitblood 2024-03-25 15:35:00 +08:00
parent 315f968e6e
commit 518be21bef

View file

@ -1,31 +1,56 @@
#!/bin/sh
# TODO: check for rust dependency
# variables
PKG_NAME=rustmon
BUILD_DIR=build/debian
RELEASE_DIR=../../target/release
DEBIAN_DIR=$PKG_NAME/DEBIAN
BIN_DIR=$PKG_NAME/usr/bin
AUTO_INSTALL=${1:-"no"}
# create a directory structure that mirrors tha final structure of the installed package
mkdir -p rustmon/DEBIAN
mkdir -p rustmon/usr/bin
# check for rust
if ! command -v rustc &> /dev/null
then
if [ "$AUTO_INSTALL" = "-y" ]; then
echo "Rust is not installed. Auto-installing..."
sudo apt install rustc
source $HOME/.cargo/env
else
echo "Rust is not installed. Would you like to install it now? (yes/no)"
read answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
else
echo "Rust is required to continue. Exiting."
exit 1
fi
fi
fi
# build the executable
# create directory structure
mkdir -p $DEBIAN_DIR
mkdir -p $BIN_DIR
# Bbild the executable
cd ../..
cargo build --release
cd build/debian
cd $BUILD_DIR
# copy the executable
cp ../../target/release/rustmon rustmon/usr/bin/
cp $RELEASE_DIR/$PKG_NAME $BIN_DIR/
# create the control file
touch rustmon/DEBIAN/control
touch $DEBIAN_DIR/control
# edit the control file
echo "Package: rustmon
echo "Package: $PKG_NAME
Version: 1.0.0
Section: base
Priority: optional
Architecture: amd64
Maintainer: Vomitblood <tohyouxuan@gmail.com>
Description: "Pokemon Colorscripts written in Rust"" > rustmon/DEBIAN/control
Description: Pokemon Colorscripts written in Rust" > $DEBIAN_DIR/control
# actually build the thing
echo $(pwd)
dpkg-deb --build rustmon
# build the package
dpkg-deb --build $PKG_NAME