-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
larina3315
authored
Jan 14, 2024
1 parent
d9cbacf
commit 7989cc0
Showing
8 changed files
with
380 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
builds | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#variables | ||
FILE_DIR_OBK="$HOME/.obk-build/" | ||
DISTRO_COUNT=0 | ||
|
||
cleanup () { | ||
echo "Removing obk-toolbox containers..." | ||
for tbc in $(toolbox list | sed -n 's/.*\(obk-toolbox[^\ ]*\).*/\1/p'); do | ||
toolbox rm -f "$tbc" | ||
done | ||
echo "Cleaning build directory..." | ||
rm -rf "$FILE_DIR_OBK" > /dev/null 2>&1 | ||
} | ||
help () { | ||
echo "Usage: $0 [OPTIONS]" | ||
echo "Options:" | ||
echo " --ibus Compile IBus version" | ||
echo " --fcitx Compile Fcitx version (Doesn't work for OBK2 and earlier)" | ||
echo " --develop Compile from the develop branch" | ||
echo " --fedora <version> Compile for Fedora" | ||
echo " --debian <version> Compile for Debian" | ||
echo " --toolbox Compile inside of a toolbox" | ||
echo " --clean Clean \"$FILE_DIR_OBK\" directory and remove obk-toolbox-* containers" | ||
echo " --help Display this help message" | ||
echo " " | ||
echo " -> NOTE: User needs to specify the --toolbox flag to compile for multiple distros at the same time." | ||
echo " Otherwise, only one flag can be used at a time (e.g. --fedora and --debian can't be used together without --toolbox)" | ||
echo " -> NOTE: When compiling inside of a toolbox, an additional <version> must be specified for the distro flags." | ||
echo " (e.g. --fedora 37) This will generate packages for a specific version of a distro." | ||
echo "Example: " | ||
echo " $0 --ibus --fcitx --develop --fedora 37 --debian 11 --toolbox" | ||
echo " $0 --ibus --develop --debian" | ||
} | ||
add_config () { | ||
echo "$1" >> "$FILE_DIR_OBK"config.bash | ||
} | ||
#init FILE_DIR_OBK | ||
filedir_init () { | ||
mkdir "$FILE_DIR_OBK" > /dev/null 2>&1 | ||
rm -r "$FILE_DIR_OBK"config.bash > /dev/null 2>&1 | ||
touch "$FILE_DIR_OBK"config.bash > /dev/null 2>&1 | ||
add_config "START_DIR_OBK=$(pwd)" | ||
add_config 'add_config () { | ||
echo "$1" >> "$FILE_DIR_OBK"config.bash | ||
}' | ||
add_config 'log_debug () { | ||
if [[ "$DEBUG_OBK" = "YES" ]]; then | ||
set -x | ||
exec &> >(tee -a "$1.log") | ||
fi | ||
}' | ||
|
||
#rm -r "$FILE_DIR_OBK"distro.list > /dev/null 2>&1 | ||
#touch "$FILE_DIR_OBK"distro.list > /dev/null 2>&1 | ||
} | ||
parse_args () { | ||
for arg in "$@"; do | ||
case $arg in | ||
("--ibus") add_config 'IM_IBUS_OBK=YES' ;; | ||
("--fcitx") add_config 'IM_FCITX_OBK=YES' ;; | ||
("--develop") add_config 'BRANCH_OBK=develop' ;; | ||
("--toolbox") add_config 'TOOLBOX_ENABLE_OBK=YES' ;; | ||
("--fedora") | ||
add_config 'FEDORA_OBK=YES' | ||
add_config "FEDORA_VERSION_OBK=$(echo "$@" | sed -n 's/.*--fedora \([0-9]*\).*/\1/p')" | ||
((DISTRO_COUNT++)) ;; | ||
("--debian") | ||
add_config 'DEBIAN_OBK=YES' | ||
add_config "DEBIAN_VERSION_OBK=$(echo "$@" | sed -n 's/.*--debian \([0-9]*\).*/\1/p')" | ||
((DISTRO_COUNT++)) ;; | ||
("--clean") | ||
if [[ $(echo "$@" | wc -w) -gt 1 ]]; then | ||
echo 'Error: --clean cannot be used with other flags. Exiting...' | ||
exit 1 | ||
else | ||
cleanup | ||
exit 1 | ||
fi ;; | ||
("--help") help && exit 1 ;; | ||
(--*) | ||
echo "Unknown argument: $arg" | ||
help | ||
echo "Exiting..." | ||
exit 1 ;; | ||
esac | ||
done | ||
} | ||
toolbox_error () { | ||
echo "Error: toolbx had an issue. Exiting..." | ||
exit 1 | ||
} | ||
missing_version () { | ||
echo "Error: version for $1 missing. Exiting..." | ||
exit 1 | ||
} | ||
log_debug () { | ||
if [[ "$DEBUG_OBK" = 'YES' ]]; then | ||
set -x | ||
exec &> >(tee -a "$1.log") | ||
fi | ||
} | ||
|
||
# SOURCE FILES | ||
#function.bash : Contains initial variables and functions for use in make-pkgs.sh | ||
#config.bash : As toolbox containers donot inherit any environment variables, PERSISTENT variables are stored in here and loaded into other .sh files using source command | ||
|
||
# VARIABLES | ||
# YOU NEED TO LOAD config.bash TO HAVE PERSIST VARS AVAILABLE IN YOUR SHELL SCRIPTS | ||
#FILE_DIR_OBK (PERSIST) : General path where the scripts will store config data, git repos,build artifacts etc etc | ||
#START_DIR_OBK (PERSIST) : directory from where the script was called | ||
#DEBUG_OBK (PERSIST) : check if the debug flag is set | ||
#IM_*_OBK, TOOLBOX_ENABLE_OBK, <DISTRO>*_OBK, BRANCH_OBK (PERSIST) : self-explanatory | ||
#DISTRO_COUNT (TEMP) (make-pkgs.sh) : Counter to check if user tries to compile for multiple distros without --toolbox flag | ||
#PACKAGE_FORMAT, PACKAGE_FILE (TEMP) (make-build.sh) : stores which package format the compilation should use, and the path to the generated package file. | ||
|
||
# FUNCTIONS | ||
#add_config (1 args) (PERSIST) : takes one argument as input and appends it to config.bash | ||
#log_debug (1 args) (PERSIST) : takes one argument as the lof filename, checks if DEBUG_OBK is set, enables debugging. | ||
#filedir_init (noargs) (make-pkgs.sh) : cleans and creates config.bash, then adds the FILE_DIR_OBK, START_DIR_OBK, add_config, log_debug to that. | ||
#parse_args (1 args) (make-pkgs.sh) : parses arguments | ||
#cleanup (noargs) (make-pkgs.sh) : cleans FILE_DIR_OBK and removes obk-toolbox containers created by the script | ||
#help (noargs) (make_pkgs.sh) : shows helpinfo | ||
#toolbox_error (noargs) (make_pkgs.sh) : shows error on toolbox container error | ||
#missing_version (noargs) (make_pkgs.sh) : shows error on missing version with distro flag | ||
|
||
# STRUCTURE OF THE PROJECT | ||
# make-pkgs.sh | ||
# | | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# | | | | ||
# toolbox no toolbox (others?) | ||
# | | | | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# | | | | ||
# (fedora) (debian) (others) | ||
# | | | | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# | | ||
# make-build.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/bash | ||
|
||
|
||
# If insufficent args provided, exit | ||
if [[ -z "$1" || -z "$2" ]]; then | ||
echo "Insufficent arguments for this script, Exiting..." | ||
exit 1 | ||
fi | ||
|
||
FILE_DIR_OBK="$1" | ||
# shellcheck source=/dev/null | ||
source "$FILE_DIR_OBK"config.bash | ||
cd "$FILE_DIR_OBK" || { echo "Error entering FILE_DIR_OBK, Exiting..." && exit 1 ;} | ||
#DEBUG | ||
log_debug "$0" | ||
|
||
# This script takes the first argument as the "distro string", and that is used to name builddirs and determine the distro/version etc | ||
# The second argument points to FILE_DIR_OBK to load vars from | ||
|
||
#git clone obk, update if exists | ||
#THIS FILE NEEDS SINGLE BRACKETS | ||
{ | ||
if [ -d "$FILE_DIR_OBK"OpenBangla-Keyboard ]; then | ||
cd OpenBangla-Keyboard && git pull | ||
else | ||
( git clone --recursive https://github.com/OpenBangla/OpenBangla-Keyboard.git && cd OpenBangla-Keyboard ) || { echo "Error cloning git repo, Exiting..." && rm -rf "$FILE_DIR_OBK" && exit 1 ;} | ||
fi | ||
#determine branch | ||
if [[ "$BRANCH_OBK" = 'develop' ]]; then | ||
git checkout develop | ||
else | ||
git checkout master | ||
fi | ||
#update submodules | ||
git submodule update | ||
} || { echo "Error: there was an issue with git. Exiting..." && exit 1 ;} | ||
|
||
|
||
#determine packaging format | ||
case "$2" in | ||
(*fedora*) PACKAGE_FORMAT="RPM" ;; | ||
(*debian*) PACKAGE_FORMAT="DEB" ;; | ||
esac | ||
|
||
#compile for ibus and fcitx | ||
if [[ "$IM_IBUS_OBK" = 'YES' ]]; then | ||
mkdir build-ibus-"$2" | ||
cmake -Bbuild-ibus-"$2" -GNinja -DCPACK_GENERATOR="$PACKAGE_FORMAT" -DCMAKE_INSTALL_PREFIX="/usr" -DENABLE_IBUS=ON && ninja package -C build-ibus-"$2" | ||
fi | ||
if [[ "$IM_FCITX_OBK" = 'YES' ]]; then | ||
mkdir build-fcitx-"$2" | ||
cmake -Bbuild-fcitx-"$2" -GNinja -DCPACK_GENERATOR="$PACKAGE_FORMAT" -DCMAKE_INSTALL_PREFIX="/usr" -DENABLE_FCITX=ON && ninja package -C build-fcitx-"$2" | ||
fi | ||
|
||
|
||
#copying generated file to builds folder of make-pkgs.sh's location | ||
if [[ ! -d "$START_DIR_OBK/builds/" ]]; then | ||
( mkdir "$START_DIR_OBK/builds/" ) || { echo "Build was successful, but failed to copy files to $START_DIR_OBK, Exiting..." && exit 1 ;} | ||
fi | ||
|
||
find "$FILE_DIR_OBK" -type f -iname "*.$PACKAGE_FORMAT" -print0 | while IFS= read -r -d $'\0' PACKAGE_FILE; do | ||
# Copy each file to the destination directory | ||
cp "$PACKAGE_FILE" "$START_DIR_OBK/builds/" | ||
echo "Copied: $PACKAGE_FILE to $START_DIR_OBK/builds/" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
echo "Generating Debian packages..." | ||
|
||
# If insufficent args provided, exit | ||
if [[ -z "$1" ]]; then | ||
echo "Insufficent arguments for this script, Exiting..." | ||
exit 1 | ||
fi | ||
|
||
FILE_DIR_OBK="$1" | ||
# shellcheck source=/dev/null | ||
source "$FILE_DIR_OBK"config.bash > /dev/null 2>&1 | ||
#DEBUG | ||
log_debug "$0" | ||
|
||
#update the system and install builddeps | ||
{ | ||
sudo apt update -y && sudo apt upgrade -y | ||
sudo apt-get install -y build-essential file rustc cargo cmake meson ninja-build libibus-1.0-dev libfcitx5core-dev fcitx5 qtbase5-dev qtbase5-dev-tools libzstd-dev git | ||
} || { echo "Error: could not install packages. Exiting..." && exit 1 ;} | ||
|
||
#call buildscript | ||
chmod +x make-build.sh && ./make-build.sh "$FILE_DIR_OBK" debian-"$DEBIAN_VERSION_OBK" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
echo "Adding Fedora tweaks..." | ||
echo "max_parallel_downloads=19" | sudo tee -a /etc/dnf/dnf.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
echo "Generating Fedora packages..." | ||
|
||
# If insufficent args provided, exit | ||
if [[ -z "$1" ]]; then | ||
echo "Insufficent arguments for this script, Exiting..." | ||
exit 1 | ||
fi | ||
|
||
FILE_DIR_OBK="$1" | ||
# shellcheck source=/dev/null | ||
source "$FILE_DIR_OBK"config.bash > /dev/null 2>&1 | ||
#DEBUG | ||
log_debug "$0" | ||
|
||
#update the system and install builddeps | ||
{ | ||
sudo dnf -y update | ||
sudo dnf -y install @buildsys-build rust cargo cmake qt5-qtdeclarative-devel libzstd-devel fcitx5 fcitx5-devel ibus ibus-devel ninja-build curl meson git | ||
} || { echo "Error: could not install packages. Exiting..." && exit 1 ;} | ||
|
||
#call buildscript | ||
chmod +x make-build.sh && ./make-build.sh "$FILE_DIR_OBK" fedora-"$FEDORA_VERSION_OBK" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/bin/bash | ||
|
||
# Variable documentation -> see function.bash | ||
# Guide to add new distros | ||
# 1. add distro switch to parse_args function of function.bash of declare variables <DISTRO>_OBK and <DISTRO_VERSION>_OBK appropriately | ||
# 2. add appropriate make-<DISTRO>.sh file (optional but recommended) | ||
# 3. add appropriate distro-specific commands to #TOOLBOX USAGE section (use #fedora toolbox and #debian toolbox as templates) | ||
# 4. add appropriate distro-specific commands to #TOOLBOX NO USAGE section | ||
# 5. call make-build.sh with appropriate arguments | ||
|
||
#NOTE : | ||
# 1. All script files after make-pkgs.sh need to be passed FILE_DIR_OBK as their first argument | ||
# this needs to be done so the scripts know where to load config.bash from | ||
# 2. make-build.sh needs to be passed <distro name>-<DISTRO_VERSION_OBK> as 2nd argument | ||
# e.g. ./make-build.sh "$FILE_DIR_OBK" fedora-"$FEDORA_VERSION_OBK" | ||
|
||
#load functions and initial vars, setup filedir, handle args | ||
# shellcheck source=/dev/null | ||
source function.bash | ||
filedir_init | ||
#DEBUG | ||
[[ "$1" = '-v' ]] && { add_config 'DEBUG_OBK=YES' ;} | ||
parse_args "$@" | ||
|
||
#load vars from filedir | ||
# shellcheck source=/dev/null | ||
source "$FILE_DIR_OBK"config.bash | ||
#DEBUG | ||
log_debug "$0" | ||
#check what variables are loaded | ||
#cat "$FILE_DIR_OBK"config.bash | ||
|
||
#TOOLBOX USAGE | ||
if [[ "$TOOLBOX_ENABLE_OBK" = 'YES' ]]; then | ||
#create toolbox | ||
echo "Creating toolbox..." | ||
|
||
#fedora toolbox | ||
if [[ "$FEDORA_OBK" = 'YES' ]]; then | ||
chmod +x make-fedora.sh | ||
chmod +x make-fedora-tweaks.sh | ||
#check if version string exists | ||
[ -z "$FEDORA_VERSION_OBK" ] && missing_version "fedora" | ||
|
||
echo "Setting up Fedora toolbox..." | ||
{ | ||
toolbox create -y obk-toolbox-fedora-"$FEDORA_VERSION_OBK" -d fedora -r "$FEDORA_VERSION_OBK" | ||
#misc fedora tweaks | ||
toolbox run -c obk-toolbox-fedora-"$FEDORA_VERSION_OBK" ./make-fedora-tweaks.sh | ||
toolbox run -c obk-toolbox-fedora-"$FEDORA_VERSION_OBK" ./make-fedora.sh "$FILE_DIR_OBK" | ||
} || toolbox_error | ||
fi | ||
|
||
#debian toolbox | ||
if [[ "$DEBIAN_OBK" = 'YES' ]]; then | ||
chmod +x make-debian.sh | ||
#check if version string exists | ||
[ -z "$DEBIAN_VERSION_OBK" ] && missing_version "debian" | ||
|
||
echo "Setting up Debian toolbox..." | ||
( | ||
toolbox create -y obk-toolbox-debian-"$DEBIAN_VERSION_OBK" -i quay.io/toolbx-images/debian-toolbox:"$DEBIAN_VERSION_OBK" | ||
toolbox run -c obk-toolbox-debian-"$DEBIAN_VERSION_OBK" ./make-debian.sh "$FILE_DIR_OBK" | ||
) || toolbox_error | ||
fi | ||
|
||
#TOOLBOX NO USAGE | ||
elif [[ "$DISTRO_COUNT" -ne 1 ]]; then | ||
echo "Cannot use more than one distro without --toolbox flag." | ||
echo "Exiting..." | ||
exit 1 | ||
else | ||
if [[ "$FEDORA_OBK" = 'YES' ]]; then | ||
chmod +x make-fedora.sh | ||
./make-fedora.sh "$FILE_DIR_OBK" | ||
exit 1 | ||
fi | ||
if [[ "$DEBIAN_OBK" = 'YES' ]]; then | ||
chmod +x make-debian.sh | ||
./make-debian.sh "$FILE_DIR_OBK" | ||
exit 1 | ||
fi | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## make-pkgs | ||
|
||
**make-pkgs** is a collection of bash scripts, intended to make the experience of compiling and generating iBus/fcitx OBK packages for various distros simpler and user-friendly. | ||
This tool is primarily intended to be used by end users, with simple switches for operation. | ||
|
||
**NOTE** : It is **HIGHLY** recommended you have [toolbx](https://containertoolbx.org/) (`toolbox` package) installed in your system, it is required for the `--toolbox` flag to function. | ||
|
||
## The importance of toolbx containers | ||
|
||
[toolbx](https://containertoolbx.org/) is an user-friendly CLI utility for creating and entering "containers" for various linux distros, similar to Distrobox. | ||
toolbx is used in make-pkgs to compile and package OBK for distros other than your own. | ||
|
||
For example, If you are on Debian and you want to generate `.rpm`s specifically for Fedora 37. | ||
|
||
## How to use | ||
|
||
- (Optional) Copy this folder to a convenient location (e.g. ~/Scripts) | ||
- Make the make-pkgs.sh script executable by doing `chmod +x make-pkgs.sh` | ||
- Use the tool by running `./make-pkgs.sh --<flags>` | ||
|
||
For a list of commands, run `./make-pkgs.sh --help` | ||
\ | ||
Generated packages are stored inside the make-pkgs folder in a directory named "builds" | ||
|
||
## Examples | ||
|
||
Here are some examples and their explanation on how to use make-pkgs | ||
|
||
1. This command will compile and generate ibus OBK packages for Debian from the `develop` branch, development tools and libraries will be installed on your host system. | ||
``` | ||
./make-pkgs.sh --ibus --develop --debian` | ||
``` | ||
|
||
2. This command will compile and generate ibus and fcitx OBK packages for Debian 11 and Fedora 38 from the `develop` branch, development tools and libraries will be installed inside of toolbox containers, your host system will remain untouched. | ||
``` | ||
./make-pkgs.sh --ibus --fcitx --develop --debian 11 --fedora 38 --toolbox | ||
``` | ||
|
||
3. This command will remove all toolbox containers named "obk-toolbox-*" and clear the directory where the script stores it's files (by default in ~/.obk-build/) | ||
``` | ||
./make-pkgs.sh --clean | ||
``` |