Skip to content

Instantly share code, notes, and snippets.

@Mr-Kumar-Abhishek
Last active December 30, 2015 03:35
Show Gist options
  • Save Mr-Kumar-Abhishek/637734769a3fdb8526a2 to your computer and use it in GitHub Desktop.
Save Mr-Kumar-Abhishek/637734769a3fdb8526a2 to your computer and use it in GitHub Desktop.
Woof CE patch generator by @mavrothal
#!/bin/bash
# A script to generate woof-CE patches against a running puppy (run without
# any arguments) or the puppy.sfs (run with the 'sfs' argument).
Version=0.7
. /etc/DISTRO_SPECS
. /etc/rc.d/PUPSTATE
# Check if we are good to run
if [ "$(which git)" = "" ]; then
Xdialog --title "Error" --msgbox \
"Please install the devx sfs or just git from the repo." 0 0
exit 1
fi
WDIR=$(pwd) # Should be just above your freshly cloned woof-CE git
if [ ! -d $WDIR/woof-CE ]; then
Xdialog --title "Error" --msgbox \
"This script should be in the same folder as the woof-CE git folder" 0 0
exit 1
fi
GIT_BRANCH=$(cut -f3 -d'/' $WDIR/woof-CE/.git/HEAD)
if [ ! "$GIT_BRANCH" ]; then
Xdialog --title "Error" --msgbox \
"The woof-CE folder is not a git repo. Please clone the woof-CE git" 0 0
exit 1
fi
if [ "$GIT_BRANCH" != "testing" ]; then
Xdialog --title "Error" --msgbox \
"Your woof-CE repo is not in the testing branch. Please run 'git checkout testing'" 0 0
exit 1
fi
GIT_HEAD=$(cut -c 1-6 $WDIR/woof-CE/.git/refs/heads/testing)
REMOTE_HEAD=$(git ls-remote https://github.com/puppylinux-woof-CE/woof-CE.git |
grep 'refs/heads/testing' | cut -c 1-6)
if [ "$REMOTE_HEAD" != "$GIT_HEAD" ]; then
Xdialog --title "Error" --msgbox \
"Your local repo is not in sysnc with the remote. Please run 'git pull --all'" 0 0
exit 1
fi
if [ "$1" = "sfs" -a "$PUPMODE" = "2" ]; then
Xdialog --title "Error" --msgbox \
"There is no pup.sfs in full installs. Please run without the 'sfs' argument" 0 0
exit 1
fi
# Make the patches
[ "$BUILD_FROM_WOOF" ] && FROMWOOF=_$(echo $BUILD_FROM_WOOF | cut -f 2 -d ';' | cut -c 1-6)
case "$1" in
sfs) COMP_DIR=/initrd/pup_ro2
PATCHES=woof_"$GIT_BRANCH""$GIT_HEAD"_patches_to_"$DISTRO_FILE_PREFIX"-"$DISTRO_VERSION"_sfs"$FROMWOOF"
;;
*) COMP_DIR=
PATCHES=woof_"$GIT_BRANCH""$GIT_HEAD"_patches_to_"$DISTRO_FILE_PREFIX"-"$DISTRO_VERSION""$FROMWOOF"
;;
esac
mkdir -p $WDIR/$PATCHES
rm -rf $WDIR/$PATCHES/*
DIRS=rootfs-skeleton
for i in $(ls woof-CE/woof-code/rootfs-packages/)
do
DIRS="$DIRS rootfs-packages/$i"
done
for D in $DIRS
do
FOLDER=woof-CE/woof-code/$D
cd $WDIR/$FOLDER
for f in $(find ./ -type f)
do
[ -f $COMP_DIR/$f ] && [ "$(diff -u -N $f $COMP_DIR/$f)" != "" ] \
&& diff -u -N $f $COMP_DIR/$f > $WDIR/$PATCHES/$(basename $f).patch
done
#exit 0 #Uncomment to check if compared correctly
cd $WDIR/$PATCHES
DS="$(echo $D | sed 's/\//\\\//')"
sed -i "s/\-\-\-\ \.\//\-\-\-\ a\/woof\-code\/$DS\//" *
if [ "$1" = "sfs" ]; then
sed -i "s/\+\+\+\ \/initrd\/pup_ro2\/\.\//\+\+\+\ b\/woof\-code\/$DS\//" *
else
sed -i "s/\+\+\+\ \/\.\//\+\+\+\ b\/woof\-code\/$DS\//" *
fi
done
# check init
INITPATH=$(echo "$PUPSFS" | cut -f 2 -d '/' | grep -v sfs)
mkdir -p /tmp/initfs
cd /tmp/initfs
gunzip -c /mnt/home/$INITPATH/initrd.gz | cpio -i
cd $WDIR/woof-CE/woof-code
HUGEINIT=$(ls /mnt/home/$INITPATH/*.sfs | grep -s zdrv)
if [ "$HUGEINIT" != "" ]; then
diff -u huge_extras/init /tmp/initfs/init > $WDIR/$PATCHES/init.patch
sed -i "s/\-\-\-\ /\-\-\-\ a\/\woof\-code\//" $WDIR/$PATCHES/init.patch
sed -i "s/\+\+\+\ \/tmp\/initfs/\+\+\+\ b\/woof\-code\/huge_extras/" $WDIR/$PATCHES/init.patch
else
diff -u boot/initrd-tree/init /tmp/initfs/init > $WDIR/$PATCHES/init.patch
sed -i "s/\-\-\-\ /\-\-\-\ \woof\-code\//" $WDIR/$PATCHES/init.patch
sed -i "s/\+\+\+\ \/tmp\/initfs/\+\+\+\ b\/woof\-code\/boot\/initrd\-tree0/" $WDIR/$PATCHES/init.patch
fi
rm -rf /tmp/initfs
# Move some patches to folders for easy reviewing
cd $WDIR/$PATCHES
mkdir binary_files SVGs defaults docs running desktop
for f in $( grep ^Binary * | cut -f 1 -d':')
do
mv $f binary_files/
done
mv *.svg.patch SVGs/
mv default*.patch defaults/
mv *.rules.patch running/
mv {PUPSTATE,BOOTCONFIG,clock,current_month,issue,hosts,hostname,ld.so.conf,resolv.conf,profile}.patch running/
mv *.{htm,html,css,txt}.patch docs/
mv *.html.*.patch docs/
mv *.desktop.patch desktop/
rm -f messages.patch
cd $WDIR
# exit 0 #Uncomment to review if patches are OK FOR woof-CE
rm -f $WDIR/$PATCHES.tar.gz
tar cvzf $PATCHES.tar.gz $PATCHES/
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment