overdue commit lots of changes
[buildscripts] / kitty
1 #!/bin/bash
2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
7 # its license to GPL.
8
9 # Copyright 2024 Ian Kelling
10
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
14
15 # http://www.apache.org/licenses/LICENSE-2.0
16
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
22
23
24 source /a/bin/bash-bear-trap/bash-bear
25
26 if [[ -s ~/.bashrc ]]; then . ~/.bashrc; fi
27
28 rebuild=false
29 case $1 in
30 -r) rebuild=true ;;
31 esac
32
33 # https://sw.kovidgoyal.net/kitty/build/
34 deps=(
35 libdbus-1-dev
36 libxcursor-dev
37 libxrandr-dev
38 libxi-dev
39 libxinerama-dev
40 libgl1-mesa-dev
41 libxkbcommon-x11-dev
42 libfontconfig-dev
43 libx11-xcb-dev
44 liblcms2-dev
45 libpython3-dev
46 librsync-dev
47 )
48
49 pi ${deps[@]}
50
51 last_build=/a/opt/kitty-build-info/last-build
52 cd /a/opt/kitty
53 rev=$(cat $last_build 2>/dev/null) ||:
54 head=$(sudo -u zu git rev-parse HEAD)
55 if ! $recompile && ! $bootstrap && [[ $rev == "$head" ]]; then
56 :
57 fi
58
59
60 # built it on one machine, the others it dies with the error illegal
61 # instruction. building is pretty quick, so just detect if our version
62 # works, and if not, rebuild and install.
63 # I had an idea to test the failure like so:
64 # timeout 5 kitty /bin/true, but that doesn't work over ssh
65 if ! $rebuild && ! /bin/true; then
66 rebuild=true
67 fi
68
69 err-cleanup() {
70 if mountpoint -q /usr/local/src/kitty; then
71 s umount /usr/local/src/kitty
72 fi
73 }
74
75 if $rebuild; then
76 s mkdir -p /usr/local/src/kitty
77 s mount -o bind /a/opt/kitty /usr/local/src/kitty
78
79 s install -o zu -g zu -d /usr/local/src/kitty
80 s chown -hR zu.zu /usr/local/src/kitty
81 cd /usr/local/src/kitty
82 # default plus go
83 p=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/usr/local/go/bin
84 gp=/usr/local/src/kitty/go
85 m sudo -u zu bash -c 'PATH=$PATH:/usr/local/go/bin; export GOPATH=/usr/local/src/kitty/go; go mod download -x'
86 m sudo -u zu firejail --read-write=/usr/local/src/kitty --profile=makekitty env PATH=$p make clean
87 m sudo -u zu firejail --read-write=/usr/local/src/kitty --profile=makekitty env PATH=$p GOPATH=$gp make
88 cd /
89 s umount /usr/local/src/kitty
90 s chown -hR iank.iank /a/opt/kitty
91 fi
92
93 cd /a/opt/kitty
94 s rsync -ar --chown root:root --delete __main__.py kitty logo kittens /usr/local/src/kitty
95 s rsync -ar --chown root:root ./terminfo/x/xterm-kitty /usr/share/terminfo/x/xterm-kitty
96 s ln -sf -T /usr/local/src/kitty/kitty/launcher/kitty /usr/local/bin/kitty
97
98 echo $head >$last_build