WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: alternative to upgrade_tce.sh  (Read 4533 times)

Offline SvOlli

  • Full Member
  • ***
  • Posts: 193
  • Linux Developer
alternative to upgrade_tce.sh
« on: July 10, 2009, 01:44:56 PM »
Hello,

I've hacked up an alternative to the upgrade_tce.sh script that takes a slightly different approach.

Instead of booting in a "failsafe" mode, I just upgrade the files in the tce directory, so the updated packages will be loaded only after a reboot.

I hope, it's useful for someone here. It's also attached for easier downloading.

Greetings,
SvOlli

Code: (update-tce.sh) [Select]
#!/bin/sh

tmpdir=/tmp/update.tce
tcedir="$(cat /opt/.tce_dir)"
export $(sed 's/: /=/' </opt/.tcrc)
baseurl="${Protocol}://${Mirror}"

. /etc/init.d/tc-functions

check()
{
  p=${4%.md5.txt}
  wget -q -c ${2}/${3}/${4} 2>/dev/null
  if [ ! -f ${4} ]; then
    echo ${1}/${p} ${RED}not found${NORMAL}
    return
  fi
  if cmp -s ${1}/${4} ${4}; then
    echo ${1}/${p} ${GREEN}current${NORMAL}
  else
    wget -c ${2}/${3}/${p}
    rm ${1}/${p} ${1}/${4}
    mv ${p} ${4} ${1}
    echo ${1}/${p} ${YELLOW}updated${NORMAL}
  fi
}

tceget()
{
for i in $(cd ${1};echo *.md5.txt); do
  case ${i} in
    *.tce*) check ${1} ${baseurl} tce ${i} ;;
    *.tcz*) check ${1} ${baseurl} tcz ${i} ;;
    *) echo ${RED}${i} unknown${NORMAL};;
  esac
done
}

mkdir -p ${tmpdir}
cd ${tmpdir}
[ -d ${tcedir} ] && tceget ${tcedir}
[ -d ${tcedir}/optional ] && tceget ${tcedir}/optional
cd ..
rm -r ${tmpdir}

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: alternative to upgrade_tce.sh
« Reply #1 on: July 10, 2009, 01:57:34 PM »
This should only be used for TCE type packages. Even though overwriting a mounted file should be safe, it's really bad practise to do.
The only barriers that can stop you are the ones you create yourself.

Offline SvOlli

  • Full Member
  • ***
  • Posts: 193
  • Linux Developer
Re: alternative to upgrade_tce.sh
« Reply #2 on: July 10, 2009, 02:44:00 PM »
It is intended for updating .tce and .tcz. By removing the .tcz (or .tce) first it is made sure, that the new .tcz is a different file. Once the old one's been unmounted, the memory is freed as well. So the main topic here is that the storage consumption using .tcz's is old.tcz + new.tcz instead of just new.tcz. I think it's a better way to go instead of trying to unmount an .tcz that might have open filedescriptors itself. Also a reboot is assumed afterwards, which should do the cleanup anyway.