snap-slack.SlackBuild 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. # Slackware build script for snap-slack
  3. # Set up variables
  4. PRGNAM=snap-slack
  5. VERSION=1.0
  6. BUILD=${BUILD:-1}
  7. TAG=${TAG:-_SBo}
  8. CWD=$(pwd)
  9. TMP=${TMP:-/tmp/SBo}
  10. PKG=${TMP}/package-${PRGNAM}
  11. OUTPUT=${OUTPUT:-/tmp}
  12. # Determine architecture (noarch for Python script)
  13. ARCH=noarch
  14. # Create directories
  15. rm -rf $PKG
  16. mkdir -p $PKG/usr/bin
  17. mkdir -p $PKG/usr/share/$PRGNAM/hooks
  18. mkdir -p $PKG/etc/$PRGNAM
  19. mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION/examples
  20. mkdir -p $PKG/var/log
  21. mkdir -p $PKG/install
  22. # Copy program files
  23. cp $CWD/src/snap-slack.py $PKG/usr/bin/snap-slack
  24. chmod 0755 $PKG/usr/bin/snap-slack
  25. # Copy hook files
  26. cp $CWD/hooks/install-hooks.sh $PKG/usr/share/$PRGNAM/hooks/
  27. cp $CWD/hooks/pre-install.sh $PKG/usr/share/$PRGNAM/hooks/
  28. cp $CWD/hooks/post-install.sh $PKG/usr/share/$PRGNAM/hooks/
  29. chmod 0755 $PKG/usr/share/$PRGNAM/hooks/*.sh
  30. # Copy configuration file as a .new file to prevent overwriting user's config
  31. cp $CWD/config.toml $PKG/etc/$PRGNAM/config.toml.new
  32. chmod 0644 $PKG/etc/$PRGNAM/config.toml.new
  33. # Copy example configuration files
  34. cp $CWD/docs/config-examples/config-*.toml $PKG/usr/doc/$PRGNAM-$VERSION/examples/
  35. chmod 0644 $PKG/usr/doc/$PRGNAM-$VERSION/examples/*
  36. # Create an empty log file
  37. touch $PKG/var/log/snap-slack.log.new
  38. chmod 0644 $PKG/var/log/snap-slack.log.new
  39. # Copy documentation
  40. cp $CWD/docs/README.md $PKG/usr/doc/$PRGNAM-$VERSION/
  41. cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
  42. # Create doinst.sh for handling .new files and running post-install actions
  43. cat > $PKG/install/doinst.sh << EOF
  44. config() {
  45. NEW="\$1"
  46. OLD="\$(dirname \$NEW)/\$(basename \$NEW .new)"
  47. # If there's no config file by that name, mv it over:
  48. if [ ! -r \$OLD ]; then
  49. mv \$NEW \$OLD
  50. elif [ "\$(cat \$OLD | md5sum)" = "\$(cat \$NEW | md5sum)" ]; then
  51. # toss the redundant copy
  52. rm \$NEW
  53. fi
  54. # Otherwise, we leave the .new copy for the admin to consider...
  55. }
  56. # Handle config files
  57. config etc/$PRGNAM/config.toml.new
  58. config var/log/snap-slack.log.new
  59. # Suggest installing hooks
  60. echo ""
  61. echo "To install SlackPkg hooks for automatic snapshots, run:"
  62. echo " snap-slack install-hooks"
  63. echo ""
  64. EOF
  65. # Create the Slackware package description
  66. cat << EOF > $PKG/install/slack-desc
  67. # HOW TO EDIT THIS FILE:
  68. # The "handy ruler" below makes it easier to edit a package description.
  69. # Line up the first '|' above the ':' following the base package name, and
  70. # the '|' on the right side marks the last column you can put a character in.
  71. # You must make exactly 11 lines for the formatting to be correct. It's also
  72. # customary to leave one space after the ':' except on otherwise blank lines.
  73. |-----handy-ruler------------------------------------------------------|
  74. $PRGNAM: $PRGNAM (BTRFS snapshot manager with bootloader integration)
  75. $PRGNAM:
  76. $PRGNAM: Snap-Slack is a comprehensive utility for managing Btrfs snapshots on
  77. $PRGNAM: Slackware Linux. It provides functionality to create snapshots, manage
  78. $PRGNAM: existing snapshots, clean up old snapshots, and adopt snapshots as the
  79. $PRGNAM: new root subvolume. The tool also integrates with ELILO and GRUB
  80. $PRGNAM: bootloaders, supports encrypted volumes, and has hibernation support.
  81. $PRGNAM: It can also automatically create snapshots before package operations.
  82. $PRGNAM:
  83. $PRGNAM: Version: $VERSION
  84. $PRGNAM: Homepage: https://git.bernardomagri.eu/bernardo/snap-slack/
  85. EOF
  86. # Build the package
  87. cd $PKG
  88. /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.txz