Created
March 20, 2014 21:06
-
-
Save ruario/9673819 to your computer and use it in GitHub Desktop.
Converts Opera Linux Generic (cross distro) tar packages into the Slackware package format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# op2slk Version 0.9.15 | |
# | |
# This is a script to convert Opera Linux Generic (cross distro) tar | |
# packages into the Slackware package format. | |
# | |
# Use as follows: 'op2slk operapackage' | |
# | |
# Recent stable and beta versions of Opera can be downloaded from: | |
# http://www.opera.com/browser/download/ | |
# | |
# Recent alpha/development versions of Opera can be downloaded from: | |
# http://my.opera.com/desktopteam/blog/ | |
# | |
# Special versions are sometimes made available here: | |
# http://labs.opera.com/ | |
# | |
# More information on repackaging Opera can be found here: | |
# http://my.opera.com/ruario/blog/2010/12/20/repackaging-opera-for-linux-or-freebsd-and-variants | |
# | |
# For information on this script, see: | |
# http://my.opera.com/ruario/blog/2010/12/26/automatic-conversion-of-opera-generic-linux-packages-into-slackware-format | |
# Set user defined options | |
# To include the distro name within the User Agent String, remove # | |
# from '#opdistro=Slackware' in the line below. This will cause the | |
# value to be inserted into the UA string. Be aware this change will | |
# only happen if you start Opera with a clean profile or you are | |
# upgrading from a build with a lower version and/or build number. | |
# Alternatively this string can be manually set via | |
# opera:config#ISP|Id within Opera itself. | |
#opdistro=Slackware | |
available() | |
{ | |
command -v $1 >/dev/null 2>&1 | |
} | |
# Before proceeding, check that an Opera package was specified or is | |
# available in the current working directory | |
if [ -z "${1}" ]; then | |
srcpkg=$(echo * | tr " " "\n" | grep -E "^(opera|opera-next|opera-labs-[-a-z0-9]+)-[0-9][0-9]\.[0-9][0-9]-[0-9]+\.(i386|x86_64)\.linux\.tar\.(gz|bz2|xz)$" | tail -n1) | |
if [ -z "${srcpkg}" ]; then | |
echo "There are no Opera tar packages in this directory. Either place one" | |
echo "in this directory or specify the file to convert on the command line" | |
echo "as follows:" | |
echo "\$ ${0} [somepath/]operapackage" | |
exit 1 | |
fi | |
else | |
srcpkg=${1} | |
if [ ! -e "${srcpkg}" ]; then | |
echo "You did not specify a valid file to convert. The correct usage is:" | |
echo "\$ ${0} [somepath/]operapackage" | |
exit 1 | |
fi | |
if ! echo ${srcpkg} | grep -Eq "(opera|opera-next|opera-labs-[-a-z0-9]+)-[0-9][0-9]\.[0-9][0-9]-[0-9]+\.(i386|x86_64)\.linux\.tar\.(gz|bz2|xz)$"; then | |
echo "${srcpkg} is not named like an Opera tar package, aborting" | |
exit 1 | |
fi | |
fi | |
# Automatically set main variables | |
opname=$(echo ${srcpkg} | sed -r "s/.*((opera|opera-next|opera-labs-[-a-z0-9]+))-[0-9][0-9]\.[0-9][0-9]-[0-9]+\.(i386|x86_64)\.linux\.tar\.(gz|bz2|xz)$/\1/") | |
opvernr=$(echo ${srcpkg} | sed -r "s/.*-([0-9][0-9]\.[0-9][0-9])-[0-9]+\.(i386|x86_64)\.linux\.tar\.(gz|bz2|xz)$/\1/") | |
opbldnr=$(echo ${srcpkg} | sed -r "s/.*-([0-9]+)\.(i386|x86_64)\.linux\.tar\.(gz|bz2|xz)$/\1/") | |
oparch=$(echo ${srcpkg} | sed -r "s/.*((i386|x86_64))\.linux\.tar\.(gz|bz2|xz)$/\1/") | |
if [ "$oparch" = "i386" ]; then | |
sarch=i686 | |
else | |
sarch=$oparch | |
fi | |
pkgver=1ro | |
if available xz; then | |
compress="xz -c" | |
compext=txz | |
else | |
compress="gzip -9c" | |
compext=tgz | |
fi | |
slkpkg=${opname}-${opvernr}.${opbldnr}-${sarch}-${pkgver}.${compext} | |
rpkdir=$(mktemp -d -t repack_${opname}-${opvernr}-${opbldnr}-${sarch}.XXXXXX) | |
opackage=${rpkdir}/pkg | |
osource=${rpkdir}/src | |
startdir=$(pwd) | |
# Extract Opera into $osource | |
mkdir -p "${opackage}/install" "${osource}" | |
echo ": Extracting '${srcpkg}' to '${rpkdir}/'" | |
tar -xf "${srcpkg}" -C "${osource}" || exit 1 | |
# Install Opera into $opackage | |
echo ": Calling Opera install script to check files and do initial file setup" | |
"${osource}/${opname}-${opvernr}-${opbldnr}.${oparch}.linux/install" --prefix /usr --repackage "${opackage}/usr" || exit 1 | |
# Place a copy of this 'build script' in the doc directory | |
install -m 644 "${0}" "${opackage}/usr/share/doc/${opname}/${0/*\//}" | |
# Switch into the $opackage directory to do some cleanup | |
cd "${opackage}" | |
echo " " | |
echo ": Re-organising some files to be more Slackware compliant" | |
# Move man and doc to the standard Slackware locations | |
mv usr/share/{man,doc} usr/ | |
mv usr/doc/${opname} usr/doc/${opname}-${opvernr}.${opbldnr} | |
# If the LICENSE is in the doc directory, move it to Opera's share | |
# directory so that it can be found by Opera in first startup | |
if [ -f "usr/doc/${opname}-${opvernr}.${opbldnr}/LICENSE" ]; then | |
find usr/share/${opname}/{defaults,locale/en*} -name license.txt -type l -delete | |
mv usr/doc/${opname}-${opvernr}.${opbldnr}/LICENSE usr/share/${opname}/defaults/license.txt | |
( cd usr/doc/${opname}-${opvernr}.${opbldnr}/ ; ln -s ../../share/${opname}/defaults/license.txt LICENSE ) | |
fi | |
# Set library directory to /usr/lib64 if converting a 64bit package | |
if [ "${oparch}" = "x86_64" ]; then | |
mv usr/lib usr/lib64 | |
sed -e "s,/lib/,/lib64/," -i usr/bin/${opname} | |
fi | |
# Make Slackware description file | |
if [ "${opname}" = "opera-next" ]; then | |
cat <<EODN > install/slack-desc | |
${opname}: ${opname} (Fast and secure web browser and Internet suite) | |
${opname}: | |
${opname}: Opera Next is a line of bleeding-edge releases of the Opera browser, | |
${opname}: including alpha and beta versions in addition to final releases. | |
${opname}: | |
${opname}: | |
${opname}: http://my.opera.com/desktopteam/blog/ | |
${opname}: | |
${opname}: | |
${opname}: Note: This package was converted to Slackware format using the file | |
${opname}: ${srcpkg/*\//} as a source. | |
EODN | |
elif [[ "${opname}" = opera-labs-* ]]; then | |
cat <<EODL > install/slack-desc | |
${opname}: ${opname} (web browser and Internet suite) | |
${opname}: | |
${opname}: Opera Labs is an experimental release of the Opera browser, | |
${opname}: to showcase a feature in development. | |
${opname}: | |
${opname}: http://labs.opera.com/ | |
${opname}: | |
${opname}: | |
${opname}: Note: This package was converted to Slackware format using the | |
${opname}: following file as a source: | |
${opname}: ${srcpkg/*\//} | |
EODL | |
else | |
cat <<EODO > install/slack-desc | |
${opname}: ${opname} (Fast and secure web browser and Internet suite) | |
${opname}: | |
${opname}: Opera is a small, fast, customizable, powerful and user-friendly web | |
${opname}: browser, as well as an Internet suite, including an email client, an | |
${opname}: IRC client, web developer tools (Opera Dragonfly), and a personal web | |
${opname}: server (Opera Unite). | |
${opname}: | |
${opname}: http://www.opera.com/browser/ | |
${opname}: | |
${opname}: Note: This package was converted to Slackware format using the file | |
${opname}: ${srcpkg/*\//} as a source. | |
EODO | |
fi | |
# Change symlinks into shell script code in the post install | |
find * -type l -printf '( cd %h ; rm -rf %f )\n( cd %h ; ln -sf %l %f )\n' > install/doinst.sh | |
find . -type l -delete | |
# Ensure the desktop environment updates in Slackware post install | |
cat <<EOS >> "${opackage}/install/doinst.sh" | |
available() | |
{ | |
command -v \$1 >/dev/null 2>&1 | |
} | |
# Setup menu entries | |
if available update-desktop-database; then | |
update-desktop-database -q usr/share/applications | |
fi | |
# Setup MIME associations | |
if available update-mime-database; then | |
mkdir -p usr/share/mime/packages | |
update-mime-database usr/share/mime >/dev/null | |
fi | |
# Setup icons | |
touch -c usr/share/icons/hicolor | |
if available gtk-update-icon-cache; then | |
gtk-update-icon-cache -tq usr/share/icons/hicolor | |
fi | |
EOS | |
# Edit the Opera user agent string to include $opdistro if it is set | |
if [ -n "${opdistro}" ]; then | |
mkdir -p usr/share/${opname}/custom/defaults | |
echo "[ISP]" > usr/share/${opname}/custom/defaults/operaprefs.ini | |
echo "Id=${opdistro}" >> usr/share/${opname}/custom/defaults/operaprefs.ini | |
fi | |
# Ensure permissions are correctly set | |
chmod -R u+w,go+r-w . | |
# Compress files into a Slackware package | |
echo ": Compressing files and creating Slackware Package" | |
if available tar-1.13; then | |
tar-1.13 --owner 0 --group 0 -cf- . | ${compress} > "${startdir}/${slkpkg}" | |
else | |
find ./ -print | sed "s,^\./\(.\),\1," | tar --owner 0 --group 0 --no-recursion -T- -cf- | ${compress} > "${startdir}/${slkpkg}" | |
fi | |
cd "${startdir}" | |
# Remove staging directory as it is no longer needed | |
if [ -d "${rpkdir}" ]; then | |
echo ": Removing '${rpkdir}/', as it is no longer needed" | |
rm -fr "${rpkdir}" | |
echo ": The Slackware package './${slkpkg}' was created" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment