#!/bin/bash # I, Ian Kelling, follow the GNU license recommendations at # https://www.gnu.org/licenses/license-recommendations.en.html. They # recommend that small programs, < 300 lines, be licensed under the # Apache License 2.0. This file contains or is part of one or more small # programs. If a small program grows beyond 300 lines, I plan to switch # its license to GPL. # Copyright 2024 Ian Kelling # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. source /a/bin/bash-bear-trap/bash-bear if [[ -s ~/.bashrc ]]; then . ~/.bashrc; fi rebuild=false case $1 in -r) rebuild=true ;; esac # https://sw.kovidgoyal.net/kitty/build/ deps=( libdbus-1-dev libxcursor-dev libxrandr-dev libxi-dev libxinerama-dev libgl1-mesa-dev libxkbcommon-x11-dev libfontconfig-dev libx11-xcb-dev liblcms2-dev libpython3-dev librsync-dev ) pi ${deps[@]} last_build=/a/opt/kitty-build-info/last-build cd /a/opt/kitty rev=$(cat $last_build 2>/dev/null) ||: head=$(sudo -u zu git rev-parse HEAD) if ! $recompile && ! $bootstrap && [[ $rev == "$head" ]]; then : fi # built it on one machine, the others it dies with the error illegal # instruction. building is pretty quick, so just detect if our version # works, and if not, rebuild and install. # I had an idea to test the failure like so: # timeout 5 kitty /bin/true, but that doesn't work over ssh if ! $rebuild && ! /bin/true; then rebuild=true fi err-cleanup() { if mountpoint -q /usr/local/src/kitty; then s umount /usr/local/src/kitty fi } if $rebuild; then s mkdir -p /usr/local/src/kitty s mount -o bind /a/opt/kitty /usr/local/src/kitty s install -o zu -g zu -d /usr/local/src/kitty s chown -hR zu.zu /usr/local/src/kitty cd /usr/local/src/kitty # default plus go p=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/usr/local/go/bin gp=/usr/local/src/kitty/go m sudo -u zu bash -c 'PATH=$PATH:/usr/local/go/bin; export GOPATH=/usr/local/src/kitty/go; go mod download -x' m sudo -u zu firejail --read-write=/usr/local/src/kitty --profile=makekitty env PATH=$p make clean m sudo -u zu firejail --read-write=/usr/local/src/kitty --profile=makekitty env PATH=$p GOPATH=$gp make cd / s umount /usr/local/src/kitty s chown -hR iank.iank /a/opt/kitty fi cd /a/opt/kitty s rsync -ar --chown root:root --delete __main__.py kitty logo kittens /usr/local/src/kitty s rsync -ar --chown root:root ./terminfo/x/xterm-kitty /usr/share/terminfo/x/xterm-kitty s ln -sf -T /usr/local/src/kitty/kitty/launcher/kitty /usr/local/bin/kitty echo $head >$last_build