Skip to content

Instantly share code, notes, and snippets.

@TaivasJumala
Created May 29, 2023 06:58
Show Gist options
  • Save TaivasJumala/436d1707f3655435fe824ce542fdc53c to your computer and use it in GitHub Desktop.
Save TaivasJumala/436d1707f3655435fe824ce542fdc53c to your computer and use it in GitHub Desktop.
I'm going to use this to update changes in linux-surface to my kernel-source package in Open Build Service.
#!/bin/bash
# @description: This script is used to update the linux-surface kernel built on
# Open Build Service.
# https://build.opensuse.org/package/show/home:TaivasJumala:Surface/kernel-source
# @date: 2023-05-29
# @author: TaivasJumala
# @last_modified: 2023-05-29T14:55:59+08:00
# git and osc should be properly configed
CURRENT_WORING_DIRECTORY=$(pwd)
# get latest linux-surface source code
if [ -d linux-surface/.git ]; then
cd linux-surface || exit
git pull
else
git clone https://github.com/linux-surface/linux-surface.git
fi
cd "$CURRENT_WORING_DIRECTORY" || exit
# get latest kernel-source source code
if [ -d home:TaivasJumala:Surface ]; then
cd home:TaivasJumala:Surface || exit
if [ -d "kernel-source" ]; then
cd kernel-source || exit
osc update
else
osc checkout kernel-source
fi
else
mkdir home:TaivasJumala:Surface
cd home:TaivasJumala:Surface || exit
osc checkout kernel-source
fi
cd "$CURRENT_WORING_DIRECTORY" || exit
# tar patches
cd ./home:TaivasJumala:Surface/kernel-source/ || exit
rm ./patches.addon.tar.bz2
if [ ! -d ./patches.addon ]; then
mkdir ./patches.addon
fi
cd "$CURRENT_WORING_DIRECTORY" || exit
cd ./linux-surface || exit
cd ./patches || exit
# get latest patches
max_version=""
for dir in "."/*/; do
version=$(basename "$dir")
if [[ $version > $max_version ]]; then
max_version=$version
max_version_dir=$dir
fi
ehco "$version"
done
cp "$max_version_dir/*" \
"$CURRENT_WORING_DIRECTORY/home:TaivasJumala:Surface/kernel-source/patches.addon/"
cd "$CURRENT_WORING_DIRECTORY/home:TaivasJumala:Surface/kernel-source" || exit
tar -cvjf ./patches.addon.tar.bz2 ./patches.addon/*
rm config.addon.tar.bz2
if [ ! -d ./config.addon ]; then
mkdir ./confg.addon
cd config.addon || exit
mkdir x86_64
else
cd config.addon || exit
if [ ! -d ./x86_64 ]; then
mkdir x86_64
fi
fi
# tar new config.addon
cd "$CURRENT_WORING_DIRECTORY" || exit
cp "./linux-surface/configs/surface-$max_version.config" \
"./home:TaivasJumala:Surface/kernel-source/config.addon/x86_64/default"
cd ./home:TaivasJumala:Surface/kernel-source/config.addon/x86_64 || exit
cp default debug
cp default source
cd ../.. || exit
tar -cvjf config.addon.tar.bz2 ./config.addon
# update series.conf file
# Find the line number of the first occurrence of 'patches.addon'
line_number=$(grep -n 'patches.addon' "series.conf" | head -n 1 | cut -d ':' -f 1)
if [ -n "$line_number" ]; then
# Delete the line and everything following it using sed
sed -i "${line_number},\$d" "series.conf"
fi
for filename in "$CURRENT_WORING_DIRECTORY/linux-surface/patches/$max_version"/*; do
# Append the filename to the end of the file
echo -e "\tpatches.addon/$(basename "$filename")" >> "series.conf"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment