Last active
February 15, 2018 14:10
-
-
Save IGR2014/0a3b5f8a804f708885e98add289550d2 to your computer and use it in GitHub Desktop.
LTIB package automation tool v0.1 shell script
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
#!/bin/bash | |
# Main loop | |
while : | |
do | |
# Screen cleanup | |
clear | |
# Show menu | |
echo "LTIB package automation tool v0.2" | |
echo "=================================" | |
echo " Igor Baklykov (c) 2018" | |
echo | |
echo | |
echo "What action do you want to perform?" | |
echo | |
echo " [N] Create New Project" | |
echo | |
echo " [R] Rebuild Project Sources in test folder" | |
echo | |
echo " [D] Deploy Project to LTIB" | |
echo | |
echo " [B] Burn SD Card" | |
echo | |
echo " [I] Install to rootfs (Rebuild and Deploy)" | |
echo | |
echo " [F] Full cycle (Rebuild, Deploy and Burn)" | |
echo | |
echo " [E] Exit" | |
echo | |
echo | |
# Wait for input | |
read -p "Choosed option: " choise | |
# Cases for user input | |
case "$choise" in | |
# N, n or 1 | |
[nN1] ) | |
# Screen cleanup | |
clear | |
echo "Creating new project" | |
echo "--------------------" | |
echo | |
echo | |
# Go to Desktop folder | |
cd ~/Desktop | |
# Getting project name | |
read -p "Input project name: " projectName | |
# Getting project version | |
# Major part (wait for integer) | |
until [[ $projectVersionMajor =~ ^-?[0-9]+$ ]] | |
do | |
read -p "Input project major version: " projectVersionMajor | |
done | |
# Minor part (wait for integer) | |
until [[ $projectVersionMinor =~ ^-?[0-9]+$ ]] | |
do | |
read -p "Input project minor version: " projectVersionMinor | |
done | |
# Create new folder "projectName-projectVersionMajor.projectVersionMinor" | |
projectFolderName="$projectName-$projectVersionMajor.$projectVersionMinor" | |
echo "Folder name: $projectFolderName" | |
mkdir -p $projectFolderName | |
# Go to project folder | |
cd $projectFolderName | |
# Generate Makefile | |
echo "Generating Makefile..." | |
cat > Makefile <<EOF | |
# Compiller here (usualy gcc or g++) | |
CC = g++ | |
# Compiller flags (GCC) | |
CFLAGS = -I. -Wall -pedantic -Werror -O3 | |
# Linked libraries (empty in example) | |
LIBS = | |
# List of .o object files | |
OBJ = $projectName.o | |
# Name of built application | |
EXE = $projectName | |
# Folder to place program | |
prefix = /usr | |
# Empty - LTIB will do it for us | |
DESTDIR = | |
# Makes it easy for make | |
.PHONY: all clean install | |
# Building all .cpp files in current dir to .o files | |
%.o: %.cpp | |
\$(CC) -c -o \$@ \$< \$(CFLAGS) | |
# Linking all .o files into application | |
\$(EXE): \$(OBJ) | |
\$(CC) -o \$@ \$^ \$(CFLAGS) \$(LIBS) | |
# Dependencies for make | |
all: \$@ \$(EXE) | |
# Dependencies for make clean | |
clean: | |
# Remove .o files and application | |
rm -rf \$(OBJ) \$(EXE) | |
# Dependencies for make install | |
install : \$(DESTDIR)/\$(prefix)/bin | |
# Copy application to rootfs (folder /usr/bin) | |
cp -a \$(EXE) \$(DESTDIR)/\$(prefix)/bin/ | |
# Dependencies for install path | |
\$(DESTDIR)/\$(prefix)/bin: | |
# Create folder if needed (/usr/bin) | |
mkdir -p \$@ | |
EOF | |
# Generate simple $projectName.cpp | |
echo "Generating simple $projectName.cpp..." | |
cat > $projectName.cpp <<EOF | |
#include <iostream> | |
int main(int argc, char** argv) { | |
std::cout << "Hello from $projectName!" << std::endl; | |
return 0; | |
} | |
EOF | |
;; | |
# R, r or 2 | |
[rR2] ) | |
# Screen cleanup | |
clear | |
echo "Rebuilding project sources" | |
echo "--------------------------" | |
echo | |
echo | |
# Go to Desktop folder | |
cd ~/Desktop | |
# Getting project name | |
read -p "Input project name: " projectName | |
# Getting project version | |
# Major part (wait for integer) | |
until [[ $projectVersionMajor =~ ^-?[0-9]+$ ]] | |
do | |
read -p "Input project major version: " projectVersionMajor | |
done | |
# Minor part (wait for integer) | |
until [[ $projectVersionMinor =~ ^-?[0-9]+$ ]] | |
do | |
read -p "Input project minor version: " projectVersionMinor | |
done | |
# Go to folder "projectName-projectVersionMajor.projectVersionMinor" | |
projectFolderName="$projectName-$projectVersionMajor.$projectVersionMinor" | |
echo "Folder name: $projectFolderName" | |
cd $projectFolderName | |
# Make project | |
make | |
;; | |
# D, d or 3 | |
[dD3] ) | |
# Screen cleanup | |
clear | |
echo "Deploying project to LTIB" | |
echo "-------------------------" | |
echo | |
echo | |
# Go to Desktop folder | |
cd ~/Desktop | |
# Getting project name | |
read -p "Input project name: " projectName | |
# Getting project version | |
# Major part (wait for integer) | |
until [[ $projectVersionMajor =~ ^-?[0-9]+$ ]] | |
do | |
read -p "Input project major version: " projectVersionMajor | |
done | |
# Minor part (wait for integer) | |
until [[ $projectVersionMinor =~ ^-?[0-9]+$ ]] | |
do | |
read -p "Input project minor version: " projectVersionMinor | |
done | |
# Get folder "projectName-projectVersionMajor.projectVersionMinor" | |
projectFolderName="$projectName-$projectVersionMajor.$projectVersionMinor" | |
echo "Folder name: $projectFolderName" | |
# Packing project to tar.gz archive | |
tar -zcvf $projectFolderName.tar.gz $projectFolderName | |
# Move archive to LPP (Local Package Pool) | |
mv $projectFolderName.tar.gz /opt/ltib/pkgs/ | |
# Create project directory in /dist/lfs-5.1 folder | |
mkdir -p ~/logic/Logic_BSPs/Linux_3.0/1027480_LogicPD_Linux_BSP_2.4-4/dist/lfs-5.1/$projectName | |
# Go to created directory | |
cd ~/logic/Logic_BSPs/Linux_3.0/1027480_LogicPD_Linux_BSP_2.4-4/dist/lfs-5.1/$projectName | |
# Get project params | |
read -p "Project description/summary: " summary | |
read -p "Project creator (you): " packager | |
read -p "Project license: " license | |
read -p "Project vendor: " vendor | |
read -p "Project group: " group | |
until [[ $projectVersionRelease =~ ^-?[0-9]+$ ]] | |
do | |
read -p "Input project minor version: " projectVersionRelease | |
done | |
# Generate specifications | |
echo "Generating specifications file $projectName.spec..." | |
cat > $projectName.spec <<EOF | |
%define pfx /opt/freescale/rootfs/%{_target_cpu} | |
# Project description | |
Summary : $summary | |
# Project name (without version) | |
Name : $projectName | |
# Project version (same as at the end of package name) | |
Version : $projectVersionMajor.$projectVersionMinor | |
# Release number | |
Release : $projectVersionRelease | |
# License (usualy GPL or LGPL) | |
License : $license | |
# Vendor name | |
Vendor : $vendor | |
# Author name | |
Packager : $packager | |
# Group name | |
Group : $group | |
# Package name | |
Source : %{name}-%{version}.tar.gz | |
# Thouse are defaults | |
BuildRoot : %{_tmppath}/%{name} | |
Prefix : %{pfx} | |
%Description | |
%{summary} | |
%Prep | |
%setup | |
# Build actions | |
%Build | |
make | |
# Install actions | |
%Install | |
rm -rf \$RPM_BUILD_ROOT | |
make install DESTDIR=\$RPM_BUILD_ROOT/%{pfx} | |
# Clean-up actions | |
%Clean | |
rm -rf \$RPM_BUILD_ROOT | |
# File attributes (those are defaults) | |
%Files | |
%defattr(-,root,root) | |
%{pfx}/* | |
EOF | |
;; | |
# B, b or 4 | |
[bB4] ) | |
# Screen cleanup | |
clear | |
echo "Burning to SD card" | |
echo "------------------" | |
echo | |
echo | |
echo "Please, do not forget to insert SD card!" | |
echo | |
# Go to LTIB script burn directory | |
cd ~/logic/Logic_BSPs/Linux_3.0/1027480_LogicPD_Linux_BSP_2.4-4 | |
# Burn fatfs to SD card | |
./bin/mkLogicFATcard.sh -cy /dev/sdb | |
;; | |
# I, i or 5 | |
[iI5] ) | |
# Screen cleanup | |
clear | |
echo "Installing to rootfs (Rebuild and Deploy)" | |
echo "-----------------------------------------" | |
echo | |
echo | |
# Go to LTIB directory | |
cd ~/logic/Logic_BSPs/Linux_3.0/1027480_LogicPD_Linux_BSP_2.4-4 | |
# Getting project name | |
read -p "Input project name: " projectName | |
# Prepare package | |
./ltib -m prep -p $projectName.spec | |
# Build package | |
./ltib -m scbuild -p $projectName.spec | |
# Install package | |
./ltib -m scinstall -p $projectName.spec | |
# Deploy package | |
./ltib -m scdeploy -p $projectName.spec | |
;; | |
# F, f or 6 | |
[fF6] ) | |
# Screen cleanup | |
clear | |
echo "Full cycle (Rebuild, Deploy and Burn)" | |
echo "-------------------------------------" | |
echo | |
echo | |
echo "Please, do not forget to insert SD card!" | |
echo | |
# Go to LTIB directory | |
cd ~/logic/Logic_BSPs/Linux_3.0/1027480_LogicPD_Linux_BSP_2.4-4 | |
# Getting project name | |
read -p "Input project name: " projectName | |
# Prepare package | |
./ltib -m prep -p $projectName.spec | |
# Build package | |
./ltib -m scbuild -p $projectName.spec | |
# Install package | |
./ltib -m scinstall -p $projectName.spec | |
# Deploy package | |
./ltib -m scdeploy -p $projectName.spec | |
# Burn fatfs to SD card | |
./bin/mkLogicFATcard.sh -cy /dev/sdb | |
;; | |
# E, e, 7 or 0 | |
[eE70] ) | |
# Screen cleanup | |
clear | |
exit 0 | |
;; | |
# Other keys | |
* ) | |
# Screen cleanup | |
clear | |
echo "Wrong key! None of options was selected..." | |
echo | |
echo | |
;; | |
esac | |
# Wait for any key | |
echo | |
read -rsp $'Press any key to continue...\n' -n1 key | |
done | |
exit 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment