sulinstrapt 4.25 KB
Newer Older
1
#!/bin/bash
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
set -e
umask 022
curdir=$(pwd)
packages=(baselayout bash bzip2 ca-certificates    \
          coreutils cracklib curl expat gdbm       \
          gettext glib2 glibc gmp libcap libffi    \
          libgcc libgomp libidn2 libpcre libssh2   \
          libunistring libxml2 ncurses openssl     \
          pam python3 python3-psutil sed busybox   \
          python3-pycurl readline run-parts libpsl \
          sqlite timezone unzip xz zlib acl attr)

repo="https://osdn.net/frs/redir.php?m=dotsrc&f=storage/g/s/su/sulinos/SulinRepository/inary-index.xml.xz"
help_msg(){
    echo "Usage: sulinstrapt [options] destdir"
    echo "  -r   : repository url"
    echo "  -b   : install boot packages"
    echo "  -x   : install x11 packages"
    echo "  -d   : install devel packages"
    echo "  -n   : install network packages"
    echo "  -a   : install additional packages"
    exit $1
}
get_path(){
    name=$1
    grep "${name:0:0}\/$name/$name-[0-9][0-9.]*[a-f,-\.]" "$sulin/tmp/repo" | sed "s/.*<PackageURI>//g" | sed "s/<\/.*//g" | sort -V | head -n 1
}
clean_tmp(){
    rm -rf "$sulin"/tmp/install.tar.* 
    rm -rf "$sulin"/tmp/*.xml 
    rm -rf "$sulin"/tmp/*.py
    rm -rf "$sulin"/tmp/scom
}
if [[ "$1" == ""  ||  "$1" == "-*" ]] ; then
ğ's avatar
ğ committed
36
	help_msg
37
	exit 0
38
elif [[ $UID -ne 0 ]] ; then
39 40
	echo "You must be root!"
	exit 1
Ali Rıza Keskin's avatar
Ali Rıza Keskin committed
41
fi
Ali Rıza KESKİN's avatar
Ali Rıza KESKİN committed
42 43
if [[ -d "$1" ]] ; then
  echo "$1 already exist"
44
  exit 1
Ali Rıza KESKİN's avatar
Ali Rıza KESKİN committed
45 46
elif [[ -f "$1" ]] ; then
  echo "$1 is a file. You must delete or move."
Ali Rıza Keskin's avatar
Ali Rıza Keskin committed
47 48
  exit 1
fi
Ali Rıza KESKİN's avatar
Ali Rıza KESKİN committed
49
mkdir -p "$1"
50 51 52 53 54 55 56 57 58 59 60 61 62 63

while getopts -- ':r' OPTION; do
  if [[ "$OPTION" == "r" ]] ; then
      repo="${OPTARG[@]}"
   fi
done
sulin=$(realpath "$1")
mkdir -p "$sulin/tmp"
if [[ ! -f "$sulin/tmp/repo" ]] ; then
    wget -c "$repo" -O "$sulin/tmp/repo"
    if LANG=C file "$sulin/tmp/repo" | grep "XZ" &>/dev/null ; then
        mv "$sulin/tmp/repo" "$sulin/tmp/repo.xz"
        xz -d "$sulin/tmp/repo.xz"
    fi
64
fi
65 66 67 68 69 70 71 72 73 74 75 76 77
i=0
total=${#packages[@]}
cd $sulin/
for pkg in ${packages[@]} ; do
    URI=$(dirname "$repo")/$(get_path $pkg)
    echo -e "\033[32;1m[$i/$total] Install: \033[0m$pkg"
    if [[ ! -f "$sulin/tmp/$pkg.zip" ]] ; then
        wget -c "$URI" -O "$sulin/tmp/$pkg.zip"
        cd tmp ; unzip -o $sulin/tmp/$pkg.zip >/dev/null ; cd ..
        tar --overwrite -xf tmp/install.tar.*
        clean_tmp
    fi
    i=$(($i+1))
Your Name's avatar
Your Name committed
78
done
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
echo -e "\033[32;1m[$i/$total] Install: \033[0minary-develop"
if [[ ! -f "$sulin/tmp/inary-develop.zip" ]] ; then
    wget https://gitlab.com/sulinos/devel/inary/-/archive/develop/inary-develop.zip -O "$sulin/tmp/inary-develop.zip"
    cd tmp ; unzip -o $sulin/tmp/inary-develop.zip >/dev/null
    mkdir -p "$sulin/usr/lib/sulin/inary"
    cp -prf inary-develop/inary/* "$sulin/usr/lib/sulin/inary"
    cp -pf inary-develop/inary-cli "$sulin/usr/bin/inary-cli"
    ln -s inary-cli "$sulin/usr/bin/inary"
    rm -rf inary-develop
    clean_tmp
fi
for i in $(chroot "$sulin" busybox --list)
    do
	if chroot "$sulin" busybox which $i &>/dev/null ; then
		true
	else
		chroot "$sulin" ln -s $(chroot "$sulin" busybox which busybox) /usr/bin/$i
	fi
    done
for dir in dev sys proc run ; do
    [[ -d "$sulin/$dir" ]] || mkdir -p "$sulin/$dir"
    while umount -f "$sulin/dev" 2>/dev/null ; do true; done
    mount --bind /run "$sulin/$dir"
done
cat /etc/resolv.conf > "$sulin/etc/resolv.conf"
chroot "$sulin" update-ca-certificates --fresh >/dev/null
chroot "$sulin" inary ar sulin "$repo" || true
chroot "$sulin" inary ur sulin -y
chroot "$sulin" inary it baselayout --ignore-dep --ignore-safety -y --ignore-configure
chroot "$sulin" inary it -c system.base -y --ignore-configure
Your Name's avatar
Your Name committed
109
chroot $sulin inary cp busybox
110
chroot $sulin inary cp baselayout
Your Name's avatar
Your Name committed
111
chroot $sulin inary cp
112 113 114 115 116 117 118 119 120 121 122
if echo "$2" | grep "^-" &>/dev/null ; then
	echo $2 | grep "b" && chroot "$sulin" inary it -c system.boot toybox btrfs-progs linux linux-firmware -y --ignore-configure
	echo $2 | grep "x" && chroot "$sulin" inary it -c x11 -y --ignore-configure
	echo $2 | grep "d" && chroot "$sulin" inary it -c system.devel -y --ignore-configure
	echo $2 | grep "n" && chroot "$sulin" inary it NetworkManager -y --ignore-configure
	echo $2 | grep "a" && chroot "$sulin" inary it nano wget vim strace ntfsprogs tree dialog pfork scom htop -y --ignore-configure
fi
rm -rf "$sulin"/tmp*
for dir in dev sys proc run ; do
    while umount -f "$sulin/$dir" 2>/dev/null ; do true; done
done