aboutsummaryrefslogtreecommitdiffstats
path: root/install.sh
blob: 464bde9b055c213094bc034272a6d807909c35c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# sb-builder - install the GUI locally, or the helper on the VM
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#   ./install.sh            symlink the launcher into ~/bin (BINDIR overrides),
#                           create the GUI config from the example if missing
#   ./install.sh --remote   deploy remote/sbb-remote to the VM (SBB_TARGET,
#                           default buildsystem) and create its config if missing

set -euo pipefail
here=$(dirname "$(readlink -f "$0")")

if [[ ${1:-} == --remote ]]; then
    target=${SBB_TARGET:-buildsystem}
    read -rp "Deploy sbb-remote to $target:/usr/local/bin (config created only if missing)? [y/N] " a
    [[ $a =~ ^[Yy]$ ]] || exit 1
    scp -q "$here/remote/sbb-remote" "$target:/usr/local/bin/sbb-remote"
    scp -q "$here/remote/config.example.toml" "$target:/tmp/sbb-config.example.toml"
    ssh "$target" 'chmod 755 /usr/local/bin/sbb-remote &&
        mkdir -p /etc/sb-builder &&
        { [ -e /etc/sb-builder/config.toml ] || cp /tmp/sbb-config.example.toml /etc/sb-builder/config.toml; } &&
        rm -f /tmp/sbb-config.example.toml &&
        sbb-remote version'
    exit
fi

bindir=${BINDIR:-$HOME/bin}
cfgdir=${XDG_CONFIG_HOME:-$HOME/.config}/sb-builder
mkdir -p "$bindir" "$cfgdir"
ln -sfn "$here/sb-builder" "$bindir/sb-builder"
[[ -e $cfgdir/config.toml ]] || cp "$here/config.example.toml" "$cfgdir/config.toml"
echo "installed $bindir/sb-builder -> $here/sb-builder, config in $cfgdir/config.toml"