Αποστολέας Θέμα: SBKS (Slack-Build-Kernel-Script)  (Αναγνώστηκε 596 φορές)

r-tz

  • Newbie
  • *
  • Μηνύματα: 10
  • /etc/rc.d/rc.virtuallife-autoservice
    • Προφίλ
SBKS (Slack-Build-Kernel-Script)
« στις: Δεκεμβρίου 18, 2022, 09:24:11 μμ »
Σας παρουσιάζω το SBKS
Για την ώρα είναι ένα απλό script στο μέλλον ίσως αποκτίσει και ένα desktop endry...
To SBKS το τρέχεις ως root και

  • Κατεβάζει τον linux-kernel που το έχεις πει
  • Τσεκάρει τα κλειδιά με gpg2
  • Χτίζει kernel, modules,κάνει εγκατάσταση χωρίς να διαγράφει παλιούς πυρήνες
  • τρέχει το mkinitrd και φτιάχνει generic πυρηνα
  • κάνει update-grub
    • ελέγχει αν οι modules έχουν εγκατασταθεί στο σωστό μέρος

    Με λίγα λογια απλά βάζεις ποιον πυρηνα θέλει και τα κάνει όλα αυτόματα εσύ μόνο reboot πρέπει να κάνεις για να μπεις με το νέο σου πυρηνα...
    Βασική και μοναδική προυπόθεση να έχεις grub για bootloader. ΑΝ έχεις elilo το script απλά θα κάνει exit.

Κώδικας
#!/bin/bash

# Slackware bash script named SBKS (Slack-Build-Kernel-Script)

# Anagnostakis Ioannis 12/2022 GR (Crete) and there is NOT a copyright!
# Plz make it better and share it to SlackWorld :)
#
#
#   
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


# next 3 lines need edit every time you update/rebuild a new linux kernel
# kernel.org branch url and target files
KERNEL_URL=https://cdn.kernel.org/pub/linux/kernel/v6.x
KERNEL_VERSION=6.1
VERSION2=6.1.0

# Normal dont need edit next lines exept if you want to use "make menuconfig"
KERNEL_TAR=linux-$KERNEL_VERSION.tar.xz
KERNEL_SIGN=linux-$KERNEL_VERSION.tar.sign
PRGNAM=linux
GPG=gpg2
AWK=awk
WGET=wget
JOBS=${JOBS:-" -j$(expr $(getconf _NPROCESSORS_ONLN) \* 2 ) "}

# you must be root
if [ "$EUID" -ne 0 ];then
    echo "Please run this script as root"
    exit 1
fi

# Check if BOTH kernel version AND signature file exist
$WGET -c --spider $KERNEL_URL/linux-$KERNEL_VERSION.tar.{sign,xz}
if [ $? ]
then
# Download kernel AND signature
  $WGET -c $KERNEL_URL/linux-$KERNEL_VERSION.tar.{sign,xz}
fi

# Using GnuPG to verify kernel signatures
# Not working with all kernels every time,sorry , thats why set -e starting after this step.
unxz linux-$KERNEL_VERSION.tar.xz
$GPG --verify linux-$KERNEL_VERSION.tar.sign
xz -cd $KERNEL_VERSION.tar.xz | gpg2 --verify linux-$KERNEL_VERSION.tar.sign -
echo "---------------CHECK IF KEYS ARE THE SAME. IF YES hit 'y' ---"
echo "################ IF ARE NOT THE SAME hit 'n' ###############"
while true; do

read -p "Do you want to proceed? (y/n) " yn

case $yn in
[yY] ) echo ok, we will proceed;
break;;
[nN] ) echo exiting...;
exit;;
* ) echo invalid response;;
esac

done

echo doing stuff...

# «κάλλιο γαϊδουρόδενε, παρά γαϊδουρογύρευε» <--Ancient Greek adage from my Grand, grand, grand ...father. The founder of "set -e" 3679 BC
set -e

# script check if Grub is installed to your system, if not exit...
if [ /boot/grub/grub.cfg ]
then 
    echo " OK you have grub as bootloader"
else
    exit 0
fi


# create and direcory, put kernel tarbal there for the rest of the work
mkdir -p kernel-$KERNEL_VERSION
cp $PRGNAM-$KERNEL_VERSION.tar kernel-$KERNEL_VERSION/
cd kernel-$KERNEL_VERSION/
echo "untar Linux-kernel "
sleep 3
tar xvpf $PRGNAM-$KERNEL_VERSION.tar
echo "cd to Linux-kernel package and make oldconfig"
# My old .config I use has commended
# CONFIG_SYSTEM_TRUSTED_KEYS
# CONFIG_SYSTEM_TRUSTED_KEYRING
sleep 3
cd $PRGNAM-$KERNEL_VERSION/
zcat /proc/config.gz > .config 
make oldconfig
# uncomend next line if you want make menuconfig
# make menuconfig
echo 'Lets Burn Out CPU!!!!! AND BUILD THE UNIVERSE'
sleep 3
make $JOBS
make modules_install
echo "finish build and install"
sleep 2

# cp vnlinuz and ln System.map etc. Some things are optional but just in case...not hurt.
cp arch/x86_64/boot/bzImage /boot/vmlinuz-$VERSION2
cp System.map /boot/System.map-$VERSION2
cd /boot
rm System.map
ln -s System.map-$VERSION2 System.map

# I prefer this type of kernel in my Slackware systems
/usr/share/mkinitrd/mkinitrd_command_generator.sh -k $VERSION2 > mymkinitrd.sh
sh mymkinitrd.sh

# update-grub
grub-mkconfig -o /boot/grub/grub.cfg
echo 'YOU NEVER CAN BE SURE WITH GRUB!!!'
echo "update-grub again"
grub-mkconfig -o /boot/grub/grub.cfg
sleep 3

# Just be sure that modules are on the right place
echo 'modules where are you?'
ls /lib/modules/
sleep 3
echo 'Did you saw them?'
sleep 2

# I m really sorry but, I never wrote a serious script in my life, its a tradition to add bullshits inside.
# Although I use Gnome beacause it buggy and always I have something to fix.
# Assume that you have KDE in your full Slackware installation...
/usr/bin/mplayer /usr/share/sounds/KDE-KStars-Alert.ogg &
curl -s "wttr.in/$1?m1"
echo 'Is that a snowflake or the Sun?'
sleep 4
exit 0
« Τελευταία τροποποίηση: Δεκεμβρίου 18, 2022, 11:47:46 μμ από r-tz »
friendly
0
funny
0
informative
0
agree
0
disagree
0
pwnt
0
like
3
dislike
0
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
Members reacted like:
tkor,linuxer,rhtoras,
No reactions
#mkdir human

tkor

  • Author
  • *****
  • Μηνύματα: 19
    • Προφίλ
Απ: SBKS (Slack-Build-Kernel-Script)
« Απάντηση #1 στις: Δεκεμβρίου 18, 2022, 09:39:42 μμ »
Το δοκιμάζω τώρα...
friendly
0
funny
0
informative
0
agree
0
disagree
0
pwnt
0
like
0
dislike
0
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions

r-tz

  • Newbie
  • *
  • Μηνύματα: 10
  • /etc/rc.d/rc.virtuallife-autoservice
    • Προφίλ
Απ: SBKS (Slack-Build-Kernel-Script)
« Απάντηση #2 στις: Δεκεμβρίου 18, 2022, 10:54:43 μμ »
προσθεσε στο σκριπτ
JOBS=${JOBS:-" -j$(expr $(getconf _NPROCESSORS_ONLN) \* 2 ) "}
γιατι τι ξεχασα ή ξανα κατεβασε το το εκανα edit

yg. αν σε καποιο σημειο σταματησει πες μου. στο λαπτοπ ετρεξε κανονικα στο desktop σταματησε μετα το install modules
« Τελευταία τροποποίηση: Δεκεμβρίου 18, 2022, 10:56:15 μμ από r-tz »
friendly
0
funny
0
informative
0
agree
0
disagree
0
pwnt
0
like
0
dislike
0
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
#mkdir human

r-tz

  • Newbie
  • *
  • Μηνύματα: 10
  • /etc/rc.d/rc.virtuallife-autoservice
    • Προφίλ
Απ: SBKS (Slack-Build-Kernel-Script)
« Απάντηση #3 στις: Δεκεμβρίου 19, 2022, 10:54:38 μμ »
Σας ανεβαζω εδώ ενα κομψοτεχνιμα που το δικό μου script δεν πιάνει μία μπροστα του.

Κώδικας
#!/bin/bash

set -e
set -x

CWD=$(pwd)
THIS_HOST=${THIS_HOST:-$(hostname -s)}
PRGNAM=$(basename $CWD)-$THIS_HOST
BUILD=${BUILD:-5}
BRANCH=${BRANCH:-mainline}        # stable ; mainline
ARCH=$(uname -m)

TAG=gwh
TMP=/tmp/$TAG
PKG=$TMP/pkg-$PRGNAM
OUTPUT=/tmp

NUMJOBS=${NUMJOBS:-" -j$(nproc)"}

ANEW=${ANEW:-true}

rm -fr $PKG

VERSION=${VERSION:-$(curl https://www.kernel.org/feeds/kdist.xml | grep -o "[0-9.rc-]*: $BRANCH" | head -n1 | cut -d: -f1)}

mkdir -p $PKG/usr/src/
if [ -e /usr/src/linux-$VERSION ] && [[ "$ANEW" != "true" ]]; then
    cp -a /usr/src/linux-$VERSION $PKG/usr/src/
else
    if [ $BRANCH == "stable" ]; then
        SRC_URL="https://cdn.kernel.org/pub/linux/kernel/v$(echo $VERSION | cut -d. -f1).x"
    else
        SRC_URL="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/snapshot"
    fi

    [ ! -e $CWD/linux-$VERSION.tar.?z* ] && wget -c "$SRC_URL/linux-$VERSION.tar.gz" -O $CWD/linux-$VERSION.tar.gz
    tar xf $CWD/linux-$VERSION.tar.gz -C $PKG/usr/src/
fi

cd $PKG/usr/src/
ln -s linux-$VERSION linux
cd linux-$VERSION

if [ -e $CWD/config-$THIS_HOST-$VERSION ] ; then
    cp $CWD/config-$THIS_HOST-$VERSION .config
else
    if [ -e $CWD/config-$THIS_HOST ] ; then
        cp $CWD/config-$THIS_HOST .config
    else
        zcat /proc/config.gz > .config
    fi
fi

make oldconfig $*

make $NUMJOBS
make modules $NUMJOBS
make modules_install INSTALL_MOD_PATH=$PKG

if [ -z "${HEADERS_ARCH}" ]; then
    case "$(uname -m)" in
    i?86) HEADERS_ARCH=x86 ;;
    x86_64) HEADERS_ARCH=x86 ;;
    aarch64) HEADERS_ARCH=arm64 ;;
    # Use uname -m for all other archs:
    *) HEADERS_ARCH=$(uname -m) ;;
  esac
fi
# Generate the kernel headers and clean them up:
( echo "Generating headers from the Linux kernel source tree in ${KERNEL_SOURCE}:"
  make headers_install ARCH=${HEADERS_ARCH} INSTALL_HDR_PATH=$PKG/usr
  cd $PKG/usr/include
  # You won't want these files. The ones in libdrm work better.
  rm -rf drm
  # This next part seems pretty much cosmetic, but since we've been doing this
  # for a long time (and others also do), we'll stick with it:
  mv asm asm-${HEADERS_ARCH}
  ln -sf asm-${HEADERS_ARCH} asm
  # Remove unneeded dotfiles:
  find . -name ".??*" -exec rm -f {} \+
)

VERSION=$(basename $(ls $PKG/lib/modules/ | head -n1))

mkdir -p $PKG/boot/
cp System.map $PKG/boot/System.map-gwh-$VERSION
cp .config $PKG/boot/config-gwh-$VERSION
cp arch/${ARCH}/boot/bzImage $PKG/boot/vmlinuz-gwh-$VERSION

make clean

cd $PKG/boot/
ln -s vmlinuz-gwh-$VERSION vmlinuz-gwh
ln -s config-gwh-$VERSION config-gwh
ln -s System.map-gwh-$VERSION System.map-gwh

mkdir -p $PKG/install
cat <<EOF > $PKG/install/doinst.sh
echo -n "updating grub... "
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=grub
echo OK

echo -n "building initrd… "
eval \$(/usr/share/mkinitrd/mkinitrd_command_generator.sh -k $VERSION -r | sed "s|/boot/initrd.gz|/boot/initrd-gwh-${VERSION}.gz|")
echo "OK"

[ -L /boot/initrd-gwh.gz ] && rm /boot/initrd-gwh.gz
ln -s /boot/initrd-gwh-${VERSION}.gz /boot/initrd-gwh.gz

grub-mkconfig -o /boot/grub/grub.cfg
EOF

cat <<EOF > $PKG/install/slack-desc
$PRGNAM: $PRGNAM (kernel)
$PRGNAM:
$PRGNAM: Linux is a clone of the operating system Unix, written from scratch by
$PRGNAM: Linus Torvalds with assistance from a loosely-knit team of hackers
$PRGNAM: across the Net. It aims towards POSIX and Single UNIX Specification
$PRGNAM: compliance.
$PRGNAM:
$PRGNAM: It has all the features you would expect in a modern fully-fledged Unix
$PRGNAM:
$PRGNAM: http://www.kernel.org
$PRGNAM:
EOF

cd $PKG
rm -f $PKG/{,usr/}lib$(uname -m | grep -o 64)/*.la
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$(echo $VERSION | tr - _)-$ARCH-$BUILD$TAG.txz

άλλα πράγματα...επαγγελματίας developer
friendly
0
funny
0
informative
0
agree
0
disagree
0
pwnt
0
like
0
dislike
0
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
#mkdir human

r-tz

  • Newbie
  • *
  • Μηνύματα: 10
  • /etc/rc.d/rc.virtuallife-autoservice
    • Προφίλ
Απ: SBKS (Slack-Build-Kernel-Script)
« Απάντηση #4 στις: Ιανουαρίου 27, 2023, 10:11:19 μμ »


English subtitles
SBKS if out with zenity dialogs... Τα έχει όλα και συμφέρει!   ;)
https://github.com/rizitis/SBKS
friendly
0
funny
0
informative
0
agree
0
disagree
0
pwnt
0
like
0
dislike
0
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
No reactions
#mkdir human

Tags: