move scripts to own dir

This commit is contained in:
Ella-0 2021-07-31 11:58:05 +00:00
parent c5bca6fe45
commit f18677f304
10 changed files with 33 additions and 22 deletions

27
scripts/build_utils Executable file
View file

@ -0,0 +1,27 @@
cp_packages (){
#IMPORTANT: must be run from the folder where the iglunix repo is.
#NOTE: this will assume that there always is a '*-dev'/'*-doc' package,\n this is not true.
# That's why the errors are shown to some one who cares.
echo "Hello this is build-utils"
for pkg in ${packages[@]}
do
if [ ! -d pkgs/${pkg}/out ]; then
echo "NOTE: ${pkg} was not yet build, building it now"
cd pkgs/${pkg}/
../../iglupkg.sh
cd ../..
fi
echo "Going to copy: $pkg to $1"
tar -xf pkgs/${pkg}/out/${pkg}.*.tar.zst -I zstd -C $1
tar -xf pkgs/${pkg}/out/${pkg}-dev.*.tar.zst -I zstd -C $1 2> /dev/null
tar -xf pkgs/${pkg}/out/${pkg}-doc.*.tar.zst -I zstd -C $1 2> /dev/null
done
}

92
scripts/createimg.sh Executable file
View file

@ -0,0 +1,92 @@
#!/bin/sh
echo "Createimg.sh"
rm iglunix.img
dd if=/tiny-linux-bootloader/disk of=iglunix.img
source build_utils
FILE_SIZE=$(stat -c %s iglunix.img)
echo "FILE_SIZE=${FILE_SIZE}"
PARTITION_START=$(($FILE_SIZE / 512))
PARTITION_START=$(($PARTITION_START + 1))
echo "PARTITION_START=${PARTITION_START}"
#create room for a partition
ls -al iglunix.img -h
dd if=/dev/zero bs=1 count=0 seek=2560M of=iglunix.img
ls -al iglunix.img -h
echo "n
p
1
${PARTITION_START}
w
" | fdisk iglunix.img
PARTITION_START2=$((${PARTITION_START} * 512))
echo "PARTITION_START2: ${PARTITION_START2}"
LOOPBACK=$(losetup -o ${PARTITION_START2} -s -f iglunix.img)
echo "loopback interface: ${LOOPBACK}"
#ERROR IF NO LOOPBACK
[ -z "$LOOPBACK" ] && echo "loopback creation failed!" && exit -1
mke2fs -t ext4 -L "__IGLUNIX_ROOT" ${LOOPBACK}
ROOT=/mnt/__IGLUNIX_ROOT
umount ${ROOT}
rm -rf ${ROOT}
mkdir -p ${ROOT}
mount ${LOOPBACK} ${ROOT}
packages=(musl mksh bmake gmake llvm libressl mandoc cmake curl rsync reflex byacc om4 zlib samurai libffi python ca-certificates zlib expat gettext-tiny git kati netbsd-curses kakoune iglunix rust toybox busybox less pci-ids e2fsprogs util-linux linux-pam kbd)
cp_packages ${ROOT}
echo "Linked ld.lld (from llvm) to ld"
ln -s ${ROOT}/usr/bin/ld.lld ${ROOT}/usr/bin/ld
echo "Copying misc files & creating misc dirs for live-usb"
mkdir ${ROOT}/proc/
mkdir ${ROOT}/dev/
mkdir ${ROOT}/tmp/
mkdir ${ROOT}/sys/
mkdir ${ROOT}/mnt/
mkdir ${ROOT}/etc/
mkdir ${ROOT}/root/
cp ./pkgs/tiny-linux-bootloader/fstab ${ROOT}/etc/fstab
cp ./etc/hostname ${ROOT}/etc/hostname
cp ./etc/passwd ${ROOT}/etc/passwd
cp ./etc/group ${ROOT}/etc/group
touch ${ROOT}/etc/shadow
echo "Using the host keymap"
cp /etc/vconsole.conf ${ROOT}/etc/vconsole.conf
#TODO: this is a systemd file,
# use udev/kbd
echo "Copying init.d files& inittab"
mkdir ${ROOT}/etc/init.d/
cp -r ./init/init.d ${ROOT}/etc/
cp ./init/inittab ${ROOT}/etc/
echo "Unmounting & closing loopback"
#umount ${ROOT}
#losetup -d ${LOOPBACK}
#zstd iglunix.img --ultra -22 -T
exit
# losetup -o 32256 /dev/loop0 iglunix.img
# mkfs.vfat /dev/loop0
# mount /dev/loop0 ./isoroot
# #rm -r isoroot/*
# #cp -r isoout/* isoroot
# umount ./isoroot

137
scripts/geninitrd.sh Executable file
View file

@ -0,0 +1,137 @@
#!/bin/mksh
#
# Creates an ISO from the following built packages.
# mksh bmake gmake libressl cmake curl rsync linux flex
# byacc om4 zlib samurai libffi python ca-certificates
# zlib expat gettext-tiny git kati netbsd-curses kakoune
# iglunix llvm musl
#
# This should be enough to completely rebuild Iglunix from Source
#
# Create the root fs dir
echo "geninitrd.sh"
source build_utils
rm -rf isoout isoroot
mkdir isoroot
mkdir isoout
# This should be a minimal number of packages, if we want fast boot times.
# The remaining packages are in createimg.sh
#packages=(musl mksh bmake gmake libressl cmake curl rsync linux flex byacc om4 zlib samurai libffi python ca-certificates zlib expat gettext-tiny git kati netbsd-curses kakoune iglunix)
packages=(musl linux mksh busybox toybox iglunix)
cp_packages ./isoroot
cat >isoroot/init << EOF
#!/bin/sh
exec /sbin/init
EOF
rm isoroot/sbin/init
cat >isoroot/sbin/init << 'EOF'
#!/bin/sh
export PATH=/usr/sbin:/usr/bin:/sbin:/bin
mkdir /proc
mkdir /sys
mkdir /tmp
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t tmpfs tmpfs /tmp
busybox mdev -s
busybox mdev -d
mkdir /mnt
while ! mount $(findfs LABEL=__IGLUNIX_ROOT) /mnt; do
echo "Failed to mount boot disk"
echo "Retrying"
sleep 0.5
done
echo "Starting switch_root"
#exec switch_root /mnt /etc/init.d/rcS
exec switch_root /mnt /sbin/init
EOF
chmod +x isoroot/init
chmod +x isoroot/sbin/init
# mkdir -p isoroot/etc/init.d/
# cat >isoroot/etc/init.d/rcS << EOF
# #!/bin/sh
# export PATH=/usr/sbin:/usr/bin:/sbin:/bin
# mkdir /proc
# mkdir /sys
# mkdir /tmp
# mount -t proc proc /proc
# mount -t sysfs sysfs /sys
# mount -t tmpfs tmpfs /tmp
# echo 0 > /proc/sys/kernel/printk
# ln -s /proc/self/fd/0 /dev/stdin
# ln -s /proc/self/fd/1 /dev/stdout
# ln -s /proc/self/fd/2 /dev/stderr
# busybox mdev -s
# busybox mdev -d
# mkdir -p /dev/pts
# mount -t devpts devpts /dev/pts
# hostname -F /etc/hostname
# mount -a
# #busybox modprobe broadcom
# #busybox modprobe tg3
# #ifconfig eth0 192.168.2.16
# #busybox route add default gw 192.168.2.1
# #busybox modprobe radeon
# #busybox telnetd
# #clear
# EOF
# chmod +x isoroot/etc/init.d/rcS
# cp /etc/inittab isoroot/etc/
cp /etc/hostname ./isoroot/hostname
cd isoroot
find . | cpio -ov | gzip -9 >../isoout/initramfs.img
cp boot/vmlinuz ../isoout/vmlinuz
# cd ../isoout
# mkdir -p EFI/BOOT
# cp ~/Shell.efi EFI/BOOT/BOOTX64.EFI
# cat >startup.nsh << EOF
# \vmlinuz initrd=\initramfs.img console=ttyS0 console=tty0
# EOF
exit
dd if=/dev/zero of=iglunix.img count=524288
fdisk iglunix.img
#losetup -o 32256 /dev/loop0 iglunix.img
mount /dev/loop0 ./isoroot
rm -r isoroot/*
cp -r isoout/* isoroot
umount ./isoroot

6
scripts/gentar.sh Normal file
View file

@ -0,0 +1,6 @@
#!/bin/sh
. ./build_utils
packages=(musl mksh bmake gmake llvm libressl mandoc cmake curl reflex byacc om4 zlib samurai libffi python ca-certificates zlib expat gettext-tiny git kati netbsd-curses kakoune iglunix rust toybox busybox less pci-ids libexecinfo)
cp_packages $(pwd)/_pi_install

242
scripts/iglu.sh Executable file
View file

@ -0,0 +1,242 @@
#!/bin/sh
HELP="
-h This help window
--help alias to \`-h\`
-i install
-u uninstall
-l outputs the license
-f lists installed files
-d list dependencies
-iu install update or install upgrade
-ui alias to \`-iu\`
These needs iglunix-dev (iglupkg) installed
-b build
-bi build and install the current package
-biu build and install update the current package
-bui alias to \`-iu\`
NOT IMPLEMENTED:
-o root"
usage() {
echo usage: $(basename "$0") '[-biu|-l|-f|-d|-h]' '[target]' "${HELP}" 1>&2
exit 1
}
error_usage() {
echo $(basename "$0"): ERROR: "$@" 1>&2
usage
}
tar_fail() {
echo "Failed to extract tar"
exit 1
}
stat_fail() {
echo "Not a valid package"
echo "Missing package meta file"
exit 1
}
find_fail() {
echo "Package not installed"
exit 1
}
continue_interactive() {
printf '%s' "Do you wish to proceed?: "
read yn
case $yn in
[Yy]* ) echo "Proceeding";;
[Nn]* ) exit;;
* ) exit;;
esac
}
already_exists() {
echo "Package already installed"
echo "pass -u and -i to upgrade"
exit 1
}
dep_not_found() {
echo "Missing dep: $1"
exit 1
}
iglupkg_check() {
if ! command -v iglupkg > /dev/null 2>&1; then
echo "iglupkg from iglunix-dev needs to be installed"
exit 1
fi
}
b= bi= i= u= l= f= o= d= iu=
# Handle commandline arguments.
case "$1" in
-i) i=1;;
-u) u=1;;
-l) l=1;;
-f) f=1;;
-d) d=1;;
-iu) iu=1;;
-ui) iu=1;;
-b) b=1;;
-bi) bi=1;;
-biu) biu=1;;
-bui) biu=1;;
-h) usage;;
--help) usage;;
*) error_usage "bad argument $i";;
esac
shift
while :
do
case "$1" in
-o) shift; o="$1";;
--) shift; break;;
-*) usage "bad argument $1";;
*) break;;
esac
shift
done
if [ "$d" = "1" ]; then
#LIST DEPS
stat /usr/share/iglupkg/$1 > /dev/null 2> /dev/null || find_fail
grep deps /usr/share/iglupkg/$1 | tr '=' '\n' | grep -v deps | tr ':' '\n'
elif [ "$iu" = "1" ]; then
#INSTALL & UPDATE
# Setup names
bname_we=$(basename "$1")
bname=$(echo "$bname_we" | cut -f 1 -d '.')
# locate installed package
stat /usr/share/iglupkg/$bname > /dev/null 2> /dev/null || find_fail
echo "Upgrading $bname_we"
continue_interactive
# Extract new package and verify
mkdir -p /tmp/iglunix/$bname_we || exit 1
tar -I zstd -xf $1 -C /tmp/iglunix/$bname_we || tar_fail
stat /tmp/iglunix/$bname_we/usr/share/iglupkg/$bname >/dev/null || stat_fail
# Check deps
deps=$(grep deps /tmp/iglunix/$bname_we/usr/share/iglupkg/$bname | tr '=' '\n' | grep -v deps | tr ':' '\n')
for dep in $deps; do
stat /usr/share/iglupkg/$dep > /dev/null 2> /dev/null || dep_not_found $dep
done
# Grab a list of old files and new files to install
OFILES=$(sed -n '/\[fs\]/,$p' /usr/share/iglupkg/$bname |
grep -v "\[fs\]" | awk '{print length, $0}' | sort -rn | cut -d " " -f2-)
NFILES=$(sed -n '/\[fs\]/,$p' /tmp/iglunix/$bname_we/usr/share/iglupkg/$bname |
grep -v "\[fs\]" | awk '{print length, $0}' | sort -rn | cut -d " " -f2-)
# Extract tar
tar -I zstd -xf $1 -C /
rm -r /tmp/iglunix/$bname_we
# Remove old files (don't know if this works yet)
for file in $OFILES; do
if echo $NFILES | grep -q $file; then
echo "not removing $file"
else
echo "attempting to remove $file"
case $(stat -c "%F" /$file) in
directory) rmdir 2>/dev/null /$file;;
"regular file") rm /$file;;
"regular empty file") rm /$file;;
"symbolic link") rm /$file;;
*) break;;
esac
fi
done
echo $OFILES
echo $NFILES
elif [ "$i" = "1" ]; then
#INSTALL
bname_we=$(basename "$1")
bname=$(echo "$bname_we" | cut -f 1 -d '.')
stat /usr/share/iglupkg/$bname > /dev/null 2> /dev/null && already_exists
echo "Installing $bname_we"
continue_interactive
mkdir -p /tmp/iglunix/$bname_we || exit 1
tar -I zstd -xf $1 -C /tmp/iglunix/$bname_we || tar_fail
stat /tmp/iglunix/$bname_we/usr/share/iglupkg/$bname >/dev/null || stat_fail
deps=$(grep deps /tmp/iglunix/$bname_we/usr/share/iglupkg/$bname | tr '=' '\n' | grep -v deps | tr ':' '\n')
for dep in $deps; do
stat /usr/share/iglupkg/$dep > /dev/null 2> /dev/null || dep_not_found $dep
done
tar -I zstd -xf $1 -C /
rm -r /tmp/iglunix/$bname_we
elif [ "$f" = "1" ]; then
#LIST INSTALLED FILES
stat /usr/share/iglupkg/$1 > /dev/null 2> /dev/null || find_fail
sed -n '/\[fs\]/,$p' /usr/share/iglupkg/$1 | grep -v "\[fs\]"
elif [ "$l" = "1" ]; then
#LICENSE
stat /usr/share/iglupkg/$1 > /dev/null 2> /dev/null || find_fail
sed -n '/\[license\]/,/\[fs\]/{/\[license\]\|\[fs\]/!p}' /usr/share/iglupkg/$1
elif [ "$u" = "1" ]; then
#UNINSTALL
stat /usr/share/iglupkg/$1 > /dev/null 2> /dev/null || find_fail
FILES=$(sed -n '/\[fs\]/,$p' /usr/share/iglupkg/$1 | grep -v "\[fs\]" | awk '{print length, $0}' | sort -rn | cut -d " " -f2-)
echo "Uninstalling $1"
continue_interactive
for file in $FILES; do
case $(stat -c "%F" /$file) in
directory) rmdir 2>/dev/null /$file;;
"regular file") rm /$file;;
"regular empty file") rm /$file;;
"symbolic link") rm /$file;;
*) echo "can't remove /$file";;
esac
done
elif [ "$b" = "1" ]; then
#BUILD
iglupkg_check
iglupkg || exit 1
elif [ "$bi" = "1" ]; then
#BUILD INSTALL
iglupkg_check
iglupkg || exit 1
cd out/
for pkg in *.tar.xz; do
iglu -i "$pkg"
done
elif [ "$biu" = "1" ]; then
#BUILD INSTALL UPDATE
iglupkg_check
iglupkg || exit 1
cd out/
for pkg in *.tar.xz; do
iglu -iu "$pkg"
done
fi

112
scripts/iglupkg.sh Executable file
View file

@ -0,0 +1,112 @@
#!/bin/sh
export JOBS="$(nproc)"
#export RUSTFLAGS="-C target-cpu=native"
export CC=clang
export CXX=clang++
export ARCH=$(uname -m)
export KERN=linux
export ABI=musl
export TRIPLE=$ARCH-unknown-$KERN-$ABI
#export CFLAGS="-march=native"
#export CXXFLAGS="-march=native"
stat /etc/iglupkg.conf > /dev/null 2> /dev/null && . /etc/iglupkg.conf
export SAMUFLAGS=-j$JOBS
. ./build.sh
dir=$(pwd)
stat out > /dev/null && rm -rf out
mkdir out
function do_fetch() {
mkdir -p src
cd src
srcdir=$(pwd) fetch
}
srcdir=$(pwd)/src
stat src > /dev/null 2>/dev/null || do_fetch
stat src > /dev/null 2>/dev/null && echo '=========================================='
stat src > /dev/null 2>/dev/null && echo 'Warning: `./src/` found: not running fetch'
stat src > /dev/null 2>/dev/null && echo '=========================================='
cd $srcdir
MAKEFLAGS=-j$JOBS build
cd $srcdir
echo "
. $dir/build.sh
mkdir -p $dir/out/$pkgname
pkgdir=$dir/out/$pkgname package
mkdir -p $dir/out/$pkgname/usr/share/iglupkg
cat > $dir/out/$pkgname/usr/share/iglupkg/$pkgname << EOF
[pkg]
name=$pkgname
ver=$pkgver
deps=$deps
[license]
EOF
chmod 644 $dir/out/$pkgname/usr/share/iglupkg/$pkgname
cd $srcdir
license >> $dir/out/$pkgname/usr/share/iglupkg/$pkgname
echo >> $dir/out/$pkgname/usr/share/iglupkg/$pkgname
echo [fs] >> $dir/out/$pkgname/usr/share/iglupkg/$pkgname
cd $dir/out/$pkgname/
find * >> $dir/out/$pkgname/usr/share/iglupkg/$pkgname
cd $dir/out/$pkgname
tar -I zstd -cf ../$pkgname.$pkgver.tar.zst *
if [ $ext ]; then
echo $ext | tr ':' '\n' | while read e; do
echo \$e
cd $srcdir
mkdir -p $dir/out/$pkgname-\$e
pkgdir=$dir/out/$pkgname-\$e
package_\$(echo \$e | tr '-' '_')
mkdir -p $dir/out/$pkgname-\$e/usr/share/iglupkg
cat > $dir/out/$pkgname-\$e/usr/share/iglupkg/$pkgname-\$e << EOF
[pkg]
name=$pkgname-\$e
ver=$pkgver
deps=$pkgname
[license]
EOF
chmod 644 $dir/out/$pkgname-\$e/usr/share/iglupkg/$pkgname-\$e
cd $srcdir
license >> $dir/out/$pkgname-\$e/usr/share/iglupkg/$pkgname-\$e
echo >> $dir/out/$pkgname-\$e/usr/share/iglupkg/$pkgname-\$e
echo [fs] >> $dir/out/$pkgname-\$e/usr/share/iglupkg/$pkgname-\$e
cd $dir/out/$pkgname-\$e
find * >> $dir/out/$pkgname-\$e/usr/share/iglupkg/$pkgname-\$e
cd $dir/out/$pkgname-\$e
tar -I zstd -cf ../$pkgname-\$e.$pkgver.tar.zst *
done
fi
" | sh
cd $dir

5
scripts/install.sh Normal file
View file

@ -0,0 +1,5 @@
#!/bin/sh
. ./build_utils
packages=(musl mksh bmake gmake llvm libressl cmake curl rsync flex byacc om4 zlib samurai libffi python ca-certificates expat gettext-tiny git kati netbsd-curses kakoune iglunix rust toybox busybox less pci-ids heirloom-doctools)
cp_packages /mnt

16
scripts/repover.sh Executable file
View file

@ -0,0 +1,16 @@
#!/bin/sh
REPO_VER=$(curl "https://repology.org/project/$1/history" 2>/dev/null | grep "version-newest" | tr '>' ' ' | tr '<' ' ' | awk '{ print $5; }' | head -n1)
REPO_MAJOR=$(echo $REPO_VER | tr '.' ' ' | awk '{ print $1; }')
REPO_MINOR=$(echo $REPO_VER | tr '.' ' ' | awk '{ print $2; }')
REPO_MICRO=$(echo $REPO_VER | tr '.' ' ' | awk '{ print $3; }')
LOCAL_VER=$(cat pkgs/$1/build.sh | grep 'pkgver=' | tr '=' ' ' | awk '{ print $2; }')
LOCAL_MAJOR=$(echo $LOCAL_VER | tr '.' ' ' | awk '{ print $1; }')
LOCAL_MINOR=$(echo $LOCAL_VER | tr '.' ' ' | awk '{ print $2; }')
LOCAL_MICRO=$(echo $LOCAL_VER | tr '.' ' ' | awk '{ print $3; }')
echo "Remote Version:" $REPO_VER >&2
echo "Local Version:" $LOCAL_VER >&2
echo $REPO_VER

5
scripts/updatever.sh Executable file
View file

@ -0,0 +1,5 @@
#!/bin/sh
NVER=$(./repover.sh $1)
TMP=$(mktemp)
sed 's/pkgver=.*/pkgver='$NVER'/g' pkgs/$1/build.sh > $TMP
mv $TMP pkgs/$1/build.sh