Skip to content

Instantly share code, notes, and snippets.

@snapo
Created March 2, 2016 14:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snapo/cb13052ccbd3a4ed56de to your computer and use it in GitHub Desktop.
Save snapo/cb13052ccbd3a4ed56de to your computer and use it in GitHub Desktop.
#!/bin/sh
# Author coreplayer2
# date 07/12/14
. /etc/init.d/tc-functions
# requires a connection to download advcomp.tcz if not found locally
################################################################
##draw at full screen width a line in blue ( use xy=(line#) for row position )
f_line() {
wide=`stty size | cut -d" " -f2`
printf "\033["$xy";0H${BLUE}"
printf '%*s\n' "$(( wide-1 ))" '' | tr ' ' =
printf "${NORMAL}"
}
f_cleanup() {
sudo rm -rf /tmp/core_extract
sudo rm -rf /tmp/core_package
}
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
}
f_chkconn(){
echo "${MAGENTA}Testing connection to server, please wait...${NORMAL}"
busybox wget -s -T 20 http://tinycorelinux.net/index.html
case $? in
0) echo "${GREEN}connection ok${NORMAL}"; cx=0;;
1) echo "${YELLOW}check internet connection, then try again${NORMAL}"; sleep 5; cx=1;;
esac
}
################################################################
##main script
trap 'f_cleanup ; trap 2 ; kill -2 $$' 1 2 3 13 15
##install advcomp dep
if [ ! -e /usr/local/tce.installed/advcomp ]; then
tce-load -i advcomp
fi
if [ ! -e /usr/local/tce.installed/advcomp ]; then
f_chkconn
if [ "x$cx" == x0 ]; then
echo -e " ${BLUE}fetching missing dependancy${NORMAL} "
tce-load -wil advcomp
fi
fi
if [ ! -e /usr/local/tce.installed/advcomp ]; then
echo -e " ${YELLOW}Dependancy not found, exiting...${NORMAL} "
sleep 5
exit
fi
clear
printf "\033[1;2H${MAGENTA}core.gz remaster${NORMAL} "
xy=2
f_line
cat <<-info
To extract then re-package core.gz,
core64.gz, module.gz or corepure64.gz
First copy core*.gz to /tmp directory then
To extract
Select "E" when prompted
To repackage
run this script again
Select "P" when prompted
Notes
1. When repackaging a x86_64 core/module.gz, use this script
on same architecture (booted to core64 or corepure64)
2. Extracting will remove any previously extracted
/tmp/core_extract working directories
info
read -p "${CYAN} Enter ${NORMAL}when ready to continue, or ${YELLOW}Ctrl+C ${NORMAL}to quit "
[ `/usr/bin/id -u` -ne 0 ] && user=sudo
if [ -e /tmp/core_package/*.gz ]; then
echo -e "\n ${YELLOW}re-packaged core/module.gz exists already, "
read -n1 -p " Delete and startover..? ${WHITE}(${MAGENTA}y${NORMAL}/${MAGENTA}n${WHITE}) " yn
case $yn in
[yY] ) f_cleanup;;
[nN] ) echo -e "\n exiting.."; sleep 2; exit;;
esac
fi
##test for 1 working archive in /tmp dir
archive=$(find /tmp -maxdepth 1 -name "*.gz" | wc -l)
if [ x"$archive" == x0 ]; then
clear
printf "\033[2;4H${MAGENTA}Archives found = ${YELLOW}$archive${NORMAL} "
xy=3
f_line
printf "\033[4;4H${YELLOW}Archive not found, \n ${NORMAL}Please copy core/module*.gz to /tmp directory and try again\n\n "
read -p " ${CYAN}Enter ${NORMAL}when ready to exit "
exit
elif [ x"$archive" != x0 -a x"$archive" != x1 ]; then
clear
printf "\033[2;4H${MAGENTA}Archives found = ${YELLOW}$archive${NORMAL}\n "
xy=3
f_line
printf "\033[4;4H${YELLOW}Only 1 expected\n ${NORMAL}Please remove unneeded core-module*.gz copies from /tmp directory and try again\n\n "
read -p " ${CYAN}Enter ${NORMAL}when ready to exit "
exit
fi
mycore=$($user find /tmp -maxdepth 1 -name "*.gz")
mycore=${mycore##*/}
##Extract or RePackage
if [ -d /tmp/core_extract ]; then
clear
printf "\033[2;4H${MAGENTA}Processing ${WHITE}$mycore${NORMAL} "
xy=3
f_line
## Extract or package choice
printf "\033[5;4H${BLUE}Choose ${WHITE}(${MAGENTA}P${NORMAL}/${MAGENTA}p${WHITE})${BLUE} to re-Package, or"
printf "\033[6;4HChoose ${WHITE}(${MAGENTA}E${NORMAL}/${MAGENTA}e${WHITE})${BLUE} to startover and Extract, or${NORMAL} "
printf "\033[7;4H${YELLOW}Ctrl+C ${NORMAL}to quit \n\n"
while [ "$ep" != [ep] ]; do
read -s -n1 -p "" ep
case $ep in
[Ee] )
echo -e "${BLUE} Extracting ${WHITE}$mycore${NORMAL} \n"
f_cleanup
set -x
f_extract
set +x
echo -e "\n${WHITE} $mycore ${BLUE}extract completed${NORMAL} \n\n when ready, run this script again with ${MAGENTA}P${NORMAL} option to re-Package \n"
read -p "${CYAN} Enter ${NORMAL}when ready to exit "
exit
;;
[Pp] )
if [ -d /tmp/core_extract ]; then
echo -e "${BLUE}RePacking ${WHITE}$mycore ${BLUE}please wait...${NORMAL} \n"
set -x
f_repack
set +x
echo -e "\n${WHITE} $mycore ${BLUE}repackage complete${NORMAL} "
sudo rm -rf /tmp/core_extract
echo -e "\n re-packaged $mycore can be found in /tmp/core_package/$mycore \n"
read -p "${CYAN} Enter ${NORMAL}when ready to exit "
exit
else
echo -e "\n${RED} Invalid option selected \n No working \"Extracted directory\" found, exiting... ${NORMAL} "
sleep 3
fi
;;
* )
echo -e "Key not supported, please try again "
;;
esac
done
else
clear
printf "\033[2;4H${MAGENTA}Processing ${WHITE}$mycore${NORMAL} "
xy=3
f_line
## Extract or package choice
printf "\033[5;4H${BLUE}Choose ${WHITE}(${MAGENTA}E${NORMAL}/${MAGENTA}e${WHITE})${BLUE} to Extract archive, or${NORMAL} "
printf "\033[6;4H${YELLOW}Ctrl+C ${NORMAL}to quit \n\n"
while [ "$e" != e ]; do
read -s -n1 -p "" e
case $e in
[Ee] )
echo -e "${BLUE} Extracting ${WHITE}$mycore${NORMAL} \n"
f_cleanup
set -x
f_extract
set +x
echo -e "\n${WHITE} $mycore ${BLUE}extract completed${NORMAL} \n\n when ready, run this script again with ${MAGENTA}P${NORMAL} option to re-Package \n"
read -p "${CYAN} Enter ${NORMAL}when ready to exit "
exit
;;
* )
echo -e "Key not supported, please try again "
;;
esac
done
fi
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment