diff --git a/.gitignore b/.gitignore index 0bf0468..b446cb9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /husarion_motd nimcache/ +package_dir +husarion-motd-* +.vscode \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..adcf963 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# husarion-motd + +Welcome message for Linux-based Husarion devices + +## Building + +To build the package you need `nim`: + +``` +sudo apt install nim +``` + +You can use `build.sh` script to preapare `.deb` package: + +``` +./build.sh +``` + +Script will create a `.deb` package named according to pattern: `husarion-motd-VERSION-ARCH.deb` + +Install it with: + +``` +sudo dpkg -i husarion-motd-VERSION-ARCH.deb +``` + diff --git a/build.sh b/build.sh old mode 100644 new mode 100755 index e69de29..e5e823f --- a/build.sh +++ b/build.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +ARCHITECTURE=$(uname -m) +VERSION='1.0.2' + +if [ $ARCHITECTURE = "x86_64" ] +then + ARCH='amd64' +elif [[ $ARCHITECTURE = 'armv7l' ]] +then + ARCH='armhf' +else + echo 'Unsupported architecture' + exit 1 +fi + +rm -rf package_dir +mkdir package_dir +mkdir package_dir/DEBIAN +mkdir package_dir/etc +mkdir package_dir/etc/profile.d/ +mkdir package_dir/usr +mkdir package_dir/usr/bin + +echo "Package: husarion-motd +Version: $VERSION +Section: custom +Priority: optional +Architecture: $ARCH +Essential: no +Installed-Size: 1024 +Maintainer: Husarion +Description: Welcome message for Linux-based Husarion devices" > package_dir/DEBIAN/control + +echo "#!/bin/sh +set -e +if [ -e /etc/motd -a ! -e /etc/motd.old ]; then + mv /etc/motd /etc/motd.old + touch /etc/motd +fi +chmod -x /etc/update-motd.d/*" > package_dir/DEBIAN/postinst +chmod a+x package_dir/DEBIAN/postinst + +cp -a husarion-motd.sh package_dir/etc/profile.d/husarion-motd.sh + + +if [ $ARCH = 'amd64' ] +then + nim compile --define:pro husarion_motd.nim +elif [ $ARCH = 'armhf' ] +then + nim compile husarion_motd.nim +fi + +mv husarion_motd package_dir/usr/bin/husarion-motd + +dpkg-deb --build package_dir husarion-motd-$VERSION-$ARCH.deb \ No newline at end of file diff --git a/husarion_motd.nim b/husarion_motd.nim index 60c2f7a..c6eb7dc 100644 --- a/husarion_motd.nim +++ b/husarion_motd.nim @@ -28,18 +28,29 @@ const logo = """ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%""" -const title = """ - _____ ____ _____ ______ ___ _____ ____ _____ - / ____/ __ \| __ \| ____|__ \ | __ \ / __ \ / ____| - | | | | | | |__) | |__ ) |_____| |__) | | | | (___ - | | | | | | _ /| __| / /______| _ /| | | |\___ \ - | |___| |__| | | \ \| |____ / /_ | | \ \| |__| |____) | - \_____\____/|_| \_\______|____| |_| \_\\____/|_____/ +when not defined(pro): + const title = """ + _____ ____ _____ _ _ ___ ___ +| __ \ / __ \ / ____|| | | | |__ \ / _ \ +| |__) || | | || (___ | |__ ___ | |_ ) | | | | | +| _ / | | | | \___ \ | '_ \ / _ \ | __| / / | | | | +| | \ \ | |__| | ____) || |_) || (_) || |_ / /_ _| |_| | +|_| \_\ \____/ |_____/ |_.__/ \___/ \__| |____|(_)\___/ """ -const baseInfoText = """Documentation: https://docs.husarion.com -Remote access: https://cloud.husarion.com""" +when defined(pro): + const title = """ + _____ ____ _____ _ _ ___ ___ _____ _____ ____ +| __ \ / __ \ / ____|| | | | |__ \ / _ \ | __ \ | __ \ / __ \ +| |__) || | | || (___ | |__ ___ | |_ ) | | | | | | |__) || |__) || | | | +| _ / | | | | \___ \ | '_ \ / _ \ | __| / / | | | | | ___/ | _ / | | | | +| | \ \ | |__| | ____) || |_) || (_) || |_ / /_ _| |_| | | | | | \ \ | |__| | +|_| \_\ \____/ |_____/ |_.__/ \___/ \__| |____|(_)\___/ |_| |_| \_\ \____/ + +""" + +const baseInfoText = """Documentation: https://husarion.com/manuals/""" const redFont = "\x1b[31m"