~mil/sxmo-build

sxmo-build/sxmo_build_all.sh -rwxr-xr-x 6.3 KiB
8861acadStacy Harper add bonsai 3 months ago
                                                                                
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/sh

mkdir -p build-sxmo-dev

cd build-sxmo-dev

set -e

hold_on() {
	if [ $INTERACTIVE -eq 1 ]; then
		read -p "Any key to continue..."
	fi
}

TARGET="wayland"
FORCE=0
INTERACTIVE=0
NOINSTALL=0
while [ $# -gt 0 ] ; do
	case $1 in
		-h | --help)
			echo "Usage: sxmo_build_all [options]">&2
			echo "Options: --force    Overwrite existing config.h">&2
			echo "         --interactive   Prompt">&2
			echo "         --noinstall    Do not actually install files">&2
			echo "         --x11          Build for X11">&2
			echo "         --wayland      Build for Wayland (default) ">&2
			echo "">&2
			echo "In case of failures, it may help to remove the">&2
			echo "entire build-sxmo-dev dir and rerun.">&2
			exit 0
			;;
		-f | --force)
			FORCE=1
			;;
		-i | --interactive)
			INTERACTIVE=1
			;;
		--noinstall)
			NOINSTALL=1
			;;
		--wayland)
			TARGET="wayland"
			;;
		--x11)
			TARGET="x11"
			;;
	esac
	shift
done

echo "Installing build dependencies (permanently, this may prompt for your sudo password)">&2
if [ -f /etc/os-release ]; then
	# freedesktop.org and systemd
	. /etc/os-release
	OS=$NAME
else
	OS="Unknown"
fi

hold_on

if ! which sudo > /dev/null 2>/dev/null; then
	if which doas > /dev/null 2>/dev/null; then
		#if the system has no sudo, but only doas, alias sudo to doas
		alias sudo=doas
	fi
fi

case $OS in
	"Arch Linux ARM")
		sudo pacman -Syu --needed libxft libx11 libxinerama webkit2gtk \
			xorgproto linux-headers fontconfig freetype2 libxext \
			libinput ncurses base-devel sdl2 nerd-fonts-fira-code noto-fonts-emoji \
			libpulse \
			opendoas cmake icu libphonenumber go meson ninja wayland #we need wayland headers also for x11 (lisgd needs it)
		[ "$TARGET" = "wayland" ] && sudo pacman -Syu --needed wayland libxkbcommon pango xorg-xwayland scdoc
		;;
	"Alpine Linux"|postmarketOS)
		sudo apk -ivt .makedepends-sxmo add libxft-dev libx11-dev libxinerama-dev \
			webkit2gtk-dev xproto linux-headers fontconfig-dev \
			freetype-dev libxext-dev libinput-dev eudev-dev \
			ncurses alpine-sdk coreutils linux-tools-iio sdl2 sdl2-dev vvmd scdoc \
			font-fira-mono-nerd cmake icu-dev libphonenumber-dev xdotool \
			mmsd-tng mmsd-tng-tools doas go wayland-dev tinydm tinydm-openrc light meson \
			pipewire wireplumber pipewire-pulse callaudiod pamixer pulseaudio-utils \
			ninja inotify-tools superd linux-tools-iio hare #(wayland-dev also needed for x11, for lisgd)
		if [ "$TARGET" = "wayland" ]; then
			sudo apk -iv add wayland xwayland pango-dev ncurses-dev wayland-protocols gojq sxmo-sway wl-clipboard swayidle mako wtype seatd wob
			sudo apk -iv add foot || printf "foot issue\n"
		fi
		if [ "$TARGET" = "x11" ]; then
			sudo apk -iv add conky dunst feh unclutter-xfixes xrandr xsetroot
		fi
		;;
	"Debian GNU/Linux")
		sudo apt install make gcc libxft-dev libx11-dev \
			libxinerama-dev libwebkit2gtk-4.0-dev x11proto-dev \
			libx11-xcb-dev libxcb-res0-dev libinput-dev \
			libsdl2-dev xdm fonts-firacode cmake libicu-dev \
			pulseaudio-utils \
			doas libphonenumber-dev golang meson ninja libwayland-dev
		[ "$TARGET" = "wayland" ] && sudo apt install xwayland libpango1.0-dev libxkbcommon-dev
		sudo sed -i '$ a svkbd-mobile-intl &' /etc/X11/xdm/Xsetup
		sudo sed -i '16 i pkill -f svkbd-mobile-intl' /etc/X11/xdm/Xstartup
		sudo sed -i 's/vt7.*/& -nocursor/' /etc/X11/xdm/Xservers
	;;
	*)
		echo "Unknown distribution! Exiting!"
		exit 1
		;;
esac

if [ "$TARGET" = "wayland" ]; then
	repos="~mil/sxmo-utils ~mil/lisgd jjsullivan5196/wvkbd ~proycon/clickclack ~proycon/wayout Orange-OpenSource/pn ~anjan/mnc ~stacyharper/bonsai"
else
	repos="~mil/sxmo-utils ~mil/sxmo-dwm ~mil/sxmo-dmenu ~mil/lisgd ~mil/sxmo-surf ~mil/sxmo-st ~proycon/svkbd ~proycon/clickclack Orange-OpenSource/pn ~anjan/mnc"
fi


for repo in $repos; do
	echo "------------------------">&2
	echo "Obtaining $repo...">&2
	echo "------------------------">&2
	hold_on
	repodir="$(basename "$repo")"
	if [ -d "$repodir" ]; then
		cd "$repodir"
		git pull --ff-only
	else
		first_char="$(echo "$repo" | cut -c1)"
		if [ "$first_char" = "~" ]; then
			#sourcehut namespaces start with ~
			git clone "https://git.sr.ht/$repo"
		else
			#assume github otherwise
			git clone "https://github.com/$repo"
		fi
		cd "$repodir"
	fi
	echo "------------------------">&2
	echo "Building $repo... (may request sudo password)">&2
	echo "------------------------">&2
	if [ -f config.def.h ]; then
		if [ $FORCE -eq 1 ] || [ ! -f config.h ]; then
			cp -f config.def.h config.h
		else
			echo "(leaving old config.h untouched, this could lead to errors: run sxmo_build_all.sh --force if you want to overwrite old config.h files)">&2
		fi
	fi
	git pull --tags
	git submodule update --init --recursive
	if [ "$repo" = "~anjan/mnc" ]; then
		go build mnc.go
		[ "$NOINSTALL" -eq 0 ] && sudo cp -f mnc /usr/bin
	elif [ -f CMakeLists.txt ]; then
		cmake -DCMAKE_INSTALL_PREFIX=/usr . && make .
	elif [ -f meson.build ]; then
		meson -Dprefix=/usr build
		ninja -C build
		[ "$NOINSTALL" -eq 0 ] && sudo ninja -C build install
	else
		make PREFIX=/usr
		[ "$NOINSTALL" -eq 0 ] && sudo make PREFIX=/usr install
		if [ "$repo" = "~jjsullivan5196/wvkbd" ]; then
    			[ "$NOINSTALL" -eq 0 ] && sudo ln -sf /usr/bin/wvkbd-mobintl /usr/bin/wvkbd
		fi
	fi
	cd ..
done

cd ..

hold_on

case $OS in
	"Arch Linux ARM")
		#TODO!
		;;
	"Alpine Linux"|postmarketOS)
		echo "Installing services (permanently)">&2
		if [ "$TARGET" = "wayland" ]; then
			[ "$NOINSTALL" -eq 0 ] && sudo tinydm-set-session -f -s /usr/share/wayland-sessions/swmo.desktop
		else
			[ "$NOINSTALL" -eq 0 ] && sudo tinydm-set-session -f -s /usr/share/xsessions/sxmo.desktop
		fi

		set +e

		[ "$NOINSTALL" -eq 0 ] && sudo rc-update add sxmo-setpermissions
		[ "$NOINSTALL" -eq 0 ] && sudo rc-update del xdm # To be compatible with older sxmo versions
		[ "$NOINSTALL" -eq 0 ] && sudo rc-update add tinydm
		if [ "$TARGET" = "wayland" ]; then
			[ "$NOINSTALL" -eq 0 ] && sudo rc-update add seatd
			[ "$NOINSTALL" -eq 0 ] && sudo usermod -aG seat $(id -un)
		fi
		;;
	"Debian GNU/Linux")
		#TODO!!
		;;
	*)
		echo "Unknown distribution! Exiting!"
		exit 1
		;;
esac

UID=$(id -u)
if [ "$UID" -ne 10000 ] && [ -f /etc/conf.d/tinydm ]; then
	echo "-------------------------------------"
	echo "IMPORTANT NOTE: You may need to add set your UID ($UID) in /etc/conf.d/tinydm , sxmo will not start otherwise!!"
	echo "-------------------------------------"
fi

set +e
echo "All done!"
exit 0