slackbuilds/xap/rkvm/SlackBuild
2023-08-16 12:23:26 +02:00

175 lines
4.3 KiB
Bash
Executable file

#!/bin/bash
# variables
#GITHUB_REPO=leonardolang/rkvm
GITHUB_REPO=htrefil/rkvm
VERSION=${VERSION:-latest}
BUILD=${BUILD:-1}
TAG=gwh
TMP=/tmp/$TAG
CWD=$(pwd)
PRGNAM=$(basename $CWD)
PKG=$TMP/pkg-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}
ARCH=${ARCH:-$(uname -m)}
REPOSITORY=${REPOSITORY:-/home/installs/SlackBuilds/_repositories/$PRGNAM}
PREFIX=${PREFIX:-/usr}
# nettoyage préalable
rm -fr $PKG $TMP/$PRGNAM
mkdir -p $PKG
# mise en place
cd $TMP
[ ! -e $REPOSITORY ] && git clone https://github.com/${GITHUB_REPO}.git $REPOSITORY
cd $REPOSITORY
git pull --all
cp -R $REPOSITORY $TMP/
cd $TMP/$PRGNAM
[ "x$VERSION" == "xlatest" ] && VERSION=$(git describe --tags --abbrev=0)
[ "x$VERSION" == "x" ] && VERSION=trunk
[ "x$VERSION" == "xtrunk" ] && VERSION="git_r$(git rev-list --count HEAD)_$(git log -1 --format=%h)" || git checkout $VERSION
cargo build --release
mkdir -p $PKG$PREFIX/bin
find target/release/ -type f -executable -maxdepth 1 -exec cp {} $PKG$PREFIX/bin/ \;
chmod 755 $PKG$PREFIX/bin/*
(cd $PKG$PREFIX/bin/
for i in *; do
mv $i rkvm-$i;
done
)
# move doc/ to the appropriate location
mkdir -p $PKG$PREFIX/doc/$PRGNAM
cp -R example/ LICENSE *.md $PKG$PREFIX/doc/$PRGNAM
cat <<EOF > $PKG$PREFIX/doc/$PRGNAM/setup-keys.sh
#!/bin/bash
$PREFIX/bin/rkvm-certificate-gen /etc/rkvm/identity.p12.new /etc/rkvm/certificate.pem.new /etc/rkvm/key.pem.new -i \$(hostname -I | cut -d\\ -f1)
EOF
chmod +x $PKG$PREFIX/doc/$PRGNAM/setup-keys.sh
mkdir -p $PKG/etc/rc.d
cat <<EOF > $PKG/etc/rc.d/rc.rkvm-server
#!/bin/bash
start() {
echo "Starting rkvm server..."
/usr/bin/rkvm-server /etc/rkvm/server.toml &
[ \$? -ne 0 ] && echo "Could not start rkvm-server."
}
stop() {
killall rkvm-server
}
case \$1 in
start )
start
;;
stop )
stop
;;
restart )
stop
sleep 1
start
;;
* )
echo "Unrecognized command: \$1"
echo "Try one of the following: (start|stop|restart)"
;;
esac
EOF
cat <<EOF > $PKG/etc/rc.d/rc.rkvm-client
#!/bin/bash
start() {
echo "Starting rkvm client..."
/usr/bin/rkvm-client /etc/rkvm/client.toml &
[ \$? -ne 0 ] && echo "Could not start rkvm-client."
}
stop() {
killall rkvm-client
}
case \$1 in
start )
start
;;
stop )
stop
;;
restart )
stop
sleep 1
start
;;
* )
echo "Unrecognized command: \$1"
echo "Try one of the following: (start|stop|restart)"
;;
esac
EOF
mkdir -p $PKG/etc/rkvm
cat <<EOF > $PKG/etc/rkvm/server.toml.new
listen-address = "0.0.0.0:5258"
# Switch to next client by pressing the right alt key.
switch-keys = ["RightAlt"]
identity-path = "/etc/rkvm/identity.p12"
# Leave unset if no password is set.
#identity-password = "123456789"
EOF
cat <<EOF > $PKG/etc/rkvm/client.toml.new
server = "$(hostname -I | cut -d\ -f1):5258"
certificate-path = "/etc/rkvm/certificate.pem"
EOF
# correction
cd $PKG
chown -R root:root *
[ -d $PKG$PREFIX/man ] && find $PKG$PREFIX/man -type f -not -name \*.gz -exec gzip -9 {} \;
# embaumement
mkdir -p $PKG/install
cat <<EOF > $PKG/install/slack-desc
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in. You must
# make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':'.
|-----handy-ruler------------------------------------------------------|
$PRGNAM: $PRGNAM ( Virtual KVM switch for Linux machines )
$PRGNAM:
$PRGNAM: rkvm is a tool for sharing keyboard and mouse across multiple Linux
$PRGNAM: and Windows machines. It is based on a client/server architecture,
$PRGNAM: where server is the machine controlling mouse and keyboard and relays
$PRGNAM: events (mouse move, key presses, ...) to clients.
$PRGNAM: Switching between different clients is done by a configurable keyboard
$PRGNAM: shortcut.
$PRGNAM:
$PRGNAM: (use $PREFIX/doc/$PRGNAM/gen-keys.sh)
$PRGNAM: https://github.com/${GITHUB_REPO}
EOF
# empaquetage
rm -f $PKG/{,usr/}lib$(uname -m | grep -o 64)/*.la
/sbin/makepkg --linkadd y --chown n --prepend $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.txz