Skip to content

Instantly share code, notes, and snippets.

@rwarren
Last active December 18, 2015 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwarren/5835600 to your computer and use it in GitHub Desktop.
Save rwarren/5835600 to your computer and use it in GitHub Desktop.
handy tinycore remastering script from coreplayer2 (see http://goo.gl/c6uQh). Takes the tedium out of it.
#!/bin/sh
. /etc/init.d/tc-functions
# Use this script to extract and re-package core.gz, core64.gz or corepure64.gz
#
# Note
# When repackaging a x86_64 core, use this script on same type system (core64 or corepure64)
#
# How to..
# Copy this script and core*.gz to /tmp directory then
# Run script once to extract, after making necessary changes
# run script again to repackage, when done
# look in /tmp/core_package for new file
################################################################
#cleanup, extract & repackage functions
f_cleanup() {
clear
$user rm -rf /tmp/core_extract
$user rm -rf /tmp/core_package
mycore=mycore
rm -f $mycore
}
f_extract() {
# prepare directories
mkdir -p /tmp/core_extract
mkdir -p /tmp/core_package
#extract core*.gz
cd /tmp/core_extract && zcat /tmp/$mycore | $user cpio -i -H newc -d
}
f_repack() {
cd /tmp/core_extract
#update modules list
$user depmod -a -b /tmp/core_extract `uname -r`
#re-package and compress new core*gz
$user find | $user cpio -o -H newc | $user gzip -2 > /tmp/core_package/$mycore
$user advdef -z4 /tmp/core_package/$mycore
}
################################################################
##main script
trap 'f_cleanup ; trap 2 ; kill -2 $$' 1 2 3 13 15
[ `/usr/bin/id -u` -ne 0 ] && user=sudo
if [ -e /tmp/core_package/core*.gz ]; then
echo "core.gz exists already,"
read -n1 -p "Continue..? (y/n)" yn
case $yn in
[yY] ) f_cleanup;;
[nN] ) echo -e "\nexit.."; exit;;
esac
fi
#mycore=`$user find /tmp -maxdepth 1 -name "core*.gz" | sed 's/\/tmp\///g'`
mycore=`$user find /tmp -maxdepth 1 -name "core*.gz" | cut -d/ -f3`
while [ "$ep" != [ep] ]; do
set +x
clear
if [ -n "$mycore" ]; then
printf "\033[2;4HProcessing $mycore"
else
printf "\033[2;4H${YELLOW}core*gz file not found${NORMAL}\n"
exit
fi
printf "\033[4;0HRun script once to extract, then \nRun script again to re-package"
## create choice
printf "\033[7;4H${BLUE}Choose ${WHITE}(${MAGENTA}E${NORMAL}/${MAGENTA}e${WHITE})${BLUE} to Extract or"
printf "\033[8;4HChoose ${WHITE}(${MAGENTA}P${NORMAL}/${MAGENTA}p${WHITE})${BLUE} to re-Package\n\n"
##print divider - full screen/terminal width
width=`stty size | cut -d" " -f2`
printf '%*s' "$(( width ))" '' | tr ' ' ~
printf "${NORMAL}\n\n"
read -s -n1 -p "" ep
set -x
case $ep in
[Ee] )
find /tmp -name core_extract | xargs $user rm -rf ;
set +x
echo -e "${WHITE}Extracting $mycore${NORMAL}"
set -x
f_extract
set +x
echo -e "\n${BLUE} $mycore extract completed${NORMAL} - when ready, run this script again with P option to repack\n"
exit
;;
[Pp] )
set +x
echo -e "${WHITE}RePacking $mycore please wait...${NORMAL}"
set -x
f_repack
set +x
echo -e "\n${BLUE} $mycore repackage complete${NORMAL}\n"
$user rm -rf /tmp/core_extract
exit
;;
* )
echo -e "Key not supported, please try again"
;;
esac
done
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment