-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhx
executable file
·658 lines (455 loc) · 17.4 KB
/
hx
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
#!/bin/bash
#
#*************************************************************************************************
#
# 88 88
# 88 ""
# 88
# 88,dPPPba, ,adPPPba, 8b, ,d8 ,adPPPPba, ,adPPPb,d8 ,adPPPba, 8b,dPPPba, 88 8b, ,d8
# 88P' "88 a8P 88 `P8, ,8P' "" `P8 a8" `P88 a8" "8a 88P' `"88 88 `P8, ,8P'
# 88 88 8PP""""""" )888( ,adPPPPP88 8b 88 8b d8 88 88 88 )888(
# 88 88 "8b, ,aa ,d8" "8b, 88, ,88 "8a, ,d88 "8a, ,a8" 88 88 88 ,d8" "8b,
# 88 88 `"Pbbd8"' 8P' `P8 `"8bbdP"P8 `"PbbdP"P8 `"PbbdP"' 88 88 88 8P' `P8
# aa, ,88
# "P8bbdP"
#
# Sistema Operacional Hexagonix - Hexagonix Operating System
#
# Copyright (c) 2015-2025 Felipe Miguel Nery Lunkes
# Todos os direitos reservados - All rights reserved.
#
#*************************************************************************************************
#
# Português:
#
# O Hexagonix e seus componentes são licenciados sob licença BSD-3-Clause. Leia abaixo
# a licença que governa este arquivo e verifique a licença de cada repositório para
# obter mais informações sobre seus direitos e obrigações ao utilizar e reutilizar
# o código deste ou de outros arquivos.
#
# English:
#
# Hexagonix and its components are licensed under a BSD-3-Clause license. Read below
# the license that governs this file and check each repository's license for
# obtain more information about your rights and obligations when using and reusing
# the code of this or other files.
#
#*************************************************************************************************
#
# BSD 3-Clause License
#
# Copyright (c) 2015-2025, Felipe Miguel Nery Lunkes
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# $HexagonixOS$
# $PORTUGUÊS$
#
# Esse script deve ficar na raiz do projeto
#
# Esse script foi desenvolvido para rodar sobre o Linux e versão do QEMU para Linux.
# A versão atual é totalmente compatível com o ambiente WSL 2 (e apenas a versão 2).
# Aviso! Até o momento, o script não é compatível com a geração do sistema sobre o
# FreeBSD. Entretanto, já é compatível para a execução de máquinas virtuais. O suporte
# total ao FreeBSD está a caminho.
#
#
# $ENGLISH$
#
# This script must be in the root of the project
#
# This script was developed to run on Linux and the Linux version of QEMU.
# The current version is fully compatible with the WSL 2 environment (and version 2 only).
# Warning! At this time, the script does not support system generation over FreeBSD.
# However, it is already supported for running virtual machines. The full support to
# FreeBSD is on the way.
function main() {
# Let's configure the environment and start argument parsing
setupEnvironment
# Allow execution of any hx module
chmod +x $MOD_DIR/*.hx
# Perform the action determined by the given parameter
case $1 in
# Manage parameters starting with '-'
-v) manageVirtualMachines; exit;;
-i) manageBuild; exit;;
-h) showMainHelp; exit;;
-b) manageComponentBuild; exit;;
-br) callHXMod git infoRepo; exit;;
-u) callHXMod git updateRepositories; exit;;
-ui) callHXMod git updateDiskImages; exit;;
-un) callHXMod git switchBranchAndUpdateRepositories; exit;;
-m) callHXMod depend checkCloneDependencies; exit;;
-c) cleanObjectsInSourceTree; exit;;
# Manage parameters starting with '--'
--version) showVersion; exit;;
--depend) callHXMod depend installBuildDependencies; exit;;
--info) callHXMod buildInfo infoBuild; exit;;
--configure) startConfigureModule; exit;;
--indent) startIndentModule; exit;;
--stat) callHXMod stat displayStatistics; exit;;
--flags) callHXMod buildInfo showBuildFlags; exit;;
# Default function
*) parametersRequired; exit;;
esac
}
function setupEnvironment() {
# Let's configure environment and export constants
# Build step constants
export REMOTE="https://github.com/hexagonix"
export BUILD_ID=$(uuid -m -v 4)
export LOG="$(pwd)/log.log"
# Global configuration
# Constants for the system build and image creation steps.
# These are the default flags, and can be changed by parameters to change the behavior of
# the Hexagonix build or components.
# These variables MUST be exported. They must be accessible to child shell instances
export DISK_IMAGE_PATH="hexagonix/hexagonix.img" # Image filename with relative path
export IMAGE_PATH="hexagonix" # Image path
export COMMON_FLAGS="VERBOSE=YES -d LOGIN_STYLE=Hexagonix" # General build flags
export HEXAGON_FLAGS="VERBOSE=YES" # Hexagon build flags
export HBOOT_FLAGS="SOUND_THEME=Hexagonix" # HBoot build flags
export BUILD_DIRECTORY="$(pwd)/Build" # Location of executable images and generated static files
export IMAGE_FILENAME="hexagonix.img" # Final image name (without directory)
export MOUNT_POINT_DIRECTORY="$(pwd)/SystemBuild" # Disk image mount point for copying Hexagonix files
export ROOT_DIR="$(pwd)"
# Convert from command line to assembler for readable flags by removing parameters such as '-d'
export CONDENSED_HBOOT_FLAGS=$(tr ' ' '\n' <<< "$HBOOT_FLAGS" | grep -vf <(tr ' ' '\n' <<< "-d") | paste -sd ' ')
export CONDENSED_HEXAGON_FLAGS=$(tr ' ' '\n' <<< "$HEXAGON_FLAGS" | grep -vf <(tr ' ' '\n' <<< "-d") | paste -sd ' ')
export CONDENSED_COMMON_FLAGS=$(tr ' ' '\n' <<< "$COMMON_FLAGS" | grep -vf <(tr ' ' '\n' <<< "-d") | paste -sd ' ')
# Now, let's define where the libasm headers and libraries (necessary for fasm) are
# The variable MUST be exported. It needs to be accessible to child shell instances
export INCLUDE="$(pwd)/lib/fasm"
# Get information about the system build
getBuildInformation
# Get information from the branch used to build the system
#
# Notice! The information is obtained from the github.com/hexagonix/hexagonix repository only.
# It is not recommended to build the system using different branches, but to use all components
# coming from the same branch, such as CURRENT (main) or RELEASE.
# Mixing between the branches can cause various components to not work or work incorrectly.
# To sync all repositories with the same branch, use 'hx -un branch'.
if [ -e $DISK_IMAGE_PATH ] ; then
# Let's save each branch of the system components for later identification
# First, Andromeda-Apps and Unix-Apps
cd Apps/Andromeda
export ANDROMEDA_APPS_BRANCH=$(git branch --show-current)
cd ../Unix
export UNIX_APPS_BRANCH=$(git branch --show-current)
cd ../..
# Now HBoot and Saturno
cd "Boot/HBoot"
export HBOOT_BRANCH=$(git branch --show-current)
cd ../Saturno
export SATURNO_BRANCH=$(git branch --show-current)
cd ../..
cd Dist/etc
export ETC_BRANCH=$(git branch --show-current)
cd ../man
export MAN_BRANCH=$(git branch --show-current)
cd ../..
# Now fonts
cd Fonts
export FONT_BRANCH=$(git branch --show-current)
cd ..
# Now Hexagon
cd Hexagon
export HEXAGON_BRANCH=$(git branch --show-current)
cd ..
# Now libasm
cd lib
export LIBASM_BRANCH=$(git branch --show-current)
cd ..
# Now hx and hx modules
cd Scripts
export HX_BRANCH=$(git branch --show-current)
cd ..
# Main branch of everything, where the images will go
cd hexagonix
export MAIN_BRANCH=$(git branch --show-current)
cd ..
fi
}
function getBuildInformation() {
# Hexagonix version data
export HEXAGONIX_RELEASE_CHANNEL=$(cat Dist/etc/release.def)
export HEXAGONIX_CODENAME=$(cat Dist/etc/codename.def)
export HEXAGONIX_VERSION=$(cat Dist/etc/version.def)
}
#-------------------------------- Division --------------------------------#
# Help section and information about hx
function showMainHelp() {
case $PT2 in
-v) showVirtualMachineHelp; exit;;
-i) showBuildHelp; exit;;
esac
echo
echo -e "hx $HX_VERSION help:"
echo
echo -e "\e[1;94mMain\e[0m available parameters:"
echo
echo -e "\e[1;32m-v\e[0m - Start a virtual machine. \e[1;32mUse 'hx -h -v' to learn more\e[0m"
echo -e "\e[1;32m-i\e[0m - Build disk image. \e[1;32mUse 'hx -h -i' to learn more\e[0m"
echo -e "\e[1;32m-u\e[0m - Update all repositories with server (current branch)"
echo -e "\e[1;32m-un <branch>\e[0m - Switch branch to <branch> and update all repositories"
echo -e "\e[1;32m-ui\e[0m - Sync Hexagonix images with the official repository"
echo -e "\e[1;32m-br\e[0m - Get information about current used branch"
echo -e "\e[1;32m-m\e[0m - Clone repositories to location and configure build environment"
echo -e "\e[1;32m-c\e[0m - Clear system tree binary and configuration files"
echo
echo "See the complete documentation at: https://github.com/hexagonix/Doc"
echo
}
function showVirtualMachineHelp() {
echo
echo "hx $HX_VERSION help topics: running Hexagonix with virtual machone (qemu)"
echo
echo -e "Start a Hexagonix virtual machine. The available parameters are\e[1;31m (default hx)*\e[0m:"
echo -e "\e[1;32m hx\e[0m - Start virtual machine without sound"
echo -e "\e[1;32m hx.snd\e[0m - Start virtual machine with sound"
echo -e "\e[1;32m hx.serial\e[0m - Start virtual machine with no serial output"
echo -e "\e[1;32m hx.p3\e[0m - Start virtual machine with a legacy processor (Pentium III)"
echo -e "\e[1;32m hx.bsd\e[0m - Start BSD host compatible virtual machine"
echo -e "\e[1;31m* The 'hx' option will be selected if no parameter is passed after '-v'!\e[0m"
}
function showBuildHelp() {
echo
echo "hx $HX_VERSION help topics: building system disk"
echo
echo -e "Build disk image. The available parameters are\e[1;31m (default hx)*\e[0m:"
echo -e "\e[1;32m hx\e[0m - Build disk image with Hexagonix"
echo -e "\e[1;32m hx.test\e[0m - Build test disk image with Hexagonix"
echo -e "\e[1;31m* The 'hx' option will be selected if no parameter is passed after '-i'!\e[0m"
}
function showVersion() {
echo -e "hx: Hexagonix build utility, version $HX_VERSION"
echo
echo -e "\e[0mCopyright (c) 2015-2025 Felipe Miguel Nery Lunkes\e[0m"
echo -e "hx and hx modules are licensed under BSD-3-Clause and comes with no warranty."
}
function parametersRequired() {
echo
echo -e "You must provide at least one \e[1;94mvalid\e[0m parameter."
showMainHelp
}
#-------------------------------- Division --------------------------------#
# Collective build section of system components
function manageBuild() {
case $PT2 in
hx) setImageBuildOnLinux; exit;;
hx.test) setTestImageBuildOnLinux; exit;;
bsd) setImageBuildOnBSD; exit;;
UNIX) setImageBuildOnUNIXSolaris; exit;;
*) setImageBuildOnLinux; exit;; # Assume hx -i hx
esac
}
function manageComponentBuild() {
mkdir -p $BUILD_DIRECTORY
mkdir -p $BUILD_DIRECTORY/bin
mkdir -p $BUILD_DIRECTORY/etc
case $PT2 in
hexagon) callHXMod hexagon; exit;;
HBoot) callHXMod hboot; exit;;
saturno) callHXMod saturno; exit;;
unixland) callHXMod unix; exit;;
andromedaland) callHXMod andromeda; exit;;
hexagonix) hexagonix; exit;;
hx) buildAllComponents; exit;;
*) buildAllComponents; exit;;
esac
}
#-------------------------------- Division --------------------------------#
# Configuration section for build the system
function setImageBuildOnLinux() {
export HOST="LINUX"
checkStaticFiles
setReleaseBuild
buildHexagonix
}
function setImageBuildOnBSD() {
export HOST="BSD"
checkStaticFiles
setReleaseBuild
buildHexagonix
}
function setImageBuildOnUNIXSolaris() {
export HOST="UNIX"
checkStaticFiles
setReleaseBuild
buildHexagonix
}
function setTestImageBuildOnLinux() {
export HOST="LINUX"
checkStaticFiles
setTestBuild
buildHexagonix
}
#-------------------------------- Division --------------------------------#
function setTestBuild() {
# Here we will generate a small image, 2 Mb, smaller and just for testing.
# This image should not be used for the installation package.
# This image should be not compatible with virtual machines running with 2 virtual
# disk attached (system limitation).
export ISK_IMAGE_SIZE=2097012
export TEMP_IMAGE_SIZE=2048
}
function setReleaseBuild() {
# Here we will define an official size image, which takes longer to generate.
# This image is appropriate for the Hexagonix installation package and official releases.
export DISK_IMAGE_SIZE=47185920
export TEMP_IMAGE_SIZE=92160
}
#-------------------------------- Division --------------------------------#
function buildAllComponents() {
MSG="Building the Hexagonix"
clear
callHXMod common banner
callHXMod saturno
callHXMod hboot
callHXMod hexagon
callHXMod unix
callHXMod andromeda
callHXMod common finishStep
callHXMod common allDone
}
#-------------------------------- Division --------------------------------#
# System image build section
function buildHexagonix() {
callHXMod diskBuilder
}
#-------------------------------- Division --------------------------------#
# hx virtual machine management section
function manageVirtualMachines() {
callHXMod vm $PT2;
}
#-------------------------------- Division --------------------------------#
# hx utilities section
function cleanObjectsInSourceTree() {
clear
MSG="hx: clear system tree"
callHXMod common banner
echo "Performing system tree cleanup..."
echo -n " > Cleaning up generated components and system images..."
rm -rf $MOUNT_POINT_DIRECTORY $BUILD_DIRECTORY Hexagonix temp.img hexagonix.img
rm -rf log.log COM1.txt *.sis *.bin *.app Serial.txt
echo -e " [\e[32mOk\e[0m]"
echo -e " > \e[1;94mUse ./hx with parameters to regenerate these files.\e[0m"
echo -e " > For help on possible parameters, use ./hx -h."
echo -n " > Removing configuration files generated every build..."
rm -rf Dist/etc/*.unx Dist/etc/*.ocl Dist/etc/rc Dist/etc/passwd Dist/etc/shrc Dist/etc/host
echo -e " [\e[32mOk\e[0m]"
echo -e " > \e[1;94mUse ./configure.sh to regenerate these files.\e[0m"
callHXMod common allDone
echo
}
function startIndentModule() {
clear
if [ -e Scripts/indent.sh ] ; then
cp Scripts/indent.sh .
echo
echo -e "[\e[32mAllowing execution and starting indent.sh (using '-a' parameter)...\e[0m]"
# First, make sure the file can be executed
chmod +x indent.sh
./indent.sh -a
rm indent.sh
else
echo -e "[\e[31mError: indent.sh not found\e[0m]."
fi
callHXMod common finishStep
callHXMod common allDone
}
function startConfigureModule() {
clear
if [ -e configure.sh ] ; then
echo
echo -e "[\e[32mAllowing execution and starting configure.sh...\e[0m]"
# First, make sure the file can be executed
chmod +x configure.sh
./configure.sh
else
echo -e "[\e[31mError: configure.sh not found\e[0m]"
echo -e " > \e[1;31mYou CANNOT start building the system without this dependency\e[0m."
fi
callHXMod common finishStep
callHXMod common allDone
}
function checkStaticFiles() {
# Let's check if the essential static files have already been generated before.
# If not, we will generate them
if [ -e Dist/etc/base.ocl ] ; then
echo "Static files present."
else
clear
MSG="Building the Hexagonix"
callHXMod common banner
echo "The static files needed to build the system were not found."
echo "Build could not be started. To do so, hx will run ./configure.sh"
echo "to set up the build and generate the necessary files."
echo
echo "Press <ENTER> to continue or CTRL-C to cancel..."
read answer
./configure.sh
fi
}
function finish() {
exit
}
function tryWithSudo() {
clear
MSG="hx: you need to be root"
callHXMod common banner
echo -e "\e[1;94mYou must be a root user to perform the requested action ;D\e[0m"
echo
echo -e "\e[1;32mEnter your password below to change to the root user (root) an run hx again with\e[0m"
echo -e "\e[1;32mgiven parameters.\e[0m"
echo
sudo hx $PT1 $PT2 $PT3 $PT4 $PT5
exit
}
#-------------------------------- Division --------------------------------#
# Hx entry point, variable definition and parameter processing
#
#
# Copyright (c) 2015-2025 Felipe Miguel Nery Lunkes
# All rights reserved
# hx info
# These variables MUST be exported. They must be accessible to child shell instances
export HX_NAME=$0
export HX_VERSION="14.0.0-RELEASE"
# Modules directory
export MOD_DIR="$(pwd)/Scripts/modules"
# Imports
# Essential modules (macro to call other compatible modules)
. $MOD_DIR/macros.hx
# Export arguments
PT1=$1
PT2=$2
PT3=$3
PT4=$4
PT5=$5
PT6=$6
main $1