| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #!/bin/bash
- # SlackPkg Pre-install Hook for snap-slack
- # Place this in /etc/slackpkg/hooks/pre-install.sh
- # Configuration
- SNAP_SLACK=/usr/bin/snap-slack
- ENABLE_AUTO_SNAPSHOTS=1 # Set to 0 to disable automatic snapshots
- MAX_PACKAGE_COUNT=100 # Maximum number of packages to include in snapshot name
- # Check if snap-slack is installed
- if [ ! -x "$SNAP_SLACK" ]; then
- echo "WARNING: snap-slack not found at $SNAP_SLACK, skipping pre-install snapshot"
- exit 0
- fi
- # Check if auto snapshots are enabled
- if [ "$ENABLE_AUTO_SNAPSHOTS" != "1" ]; then
- echo "INFO: Automatic snapshots are disabled in slackpkg hook"
- exit 0
- fi
- # Function to create a snapshot
- create_snapshot() {
- local desc="$1"
- echo "Creating snapshot before package operations: $desc"
- $SNAP_SLACK create --description "$desc"
- }
- # Get the operation being performed
- OPERATION="$1"
- shift
- PACKAGES="$@"
- # Create appropriate snapshot based on operation
- case "$OPERATION" in
- upgrade-all)
- create_snapshot "pre-upgrade-all"
- ;;
- install|upgrade)
- # Limit the number of packages in the snapshot name for readability
- if [ "$(echo $PACKAGES | wc -w)" -gt $MAX_PACKAGE_COUNT ]; then
- PKG_COUNT=$(echo $PACKAGES | wc -w)
- create_snapshot "pre-$OPERATION-$PKG_COUNT-packages"
- else
- create_snapshot "pre-$OPERATION-$(echo $PACKAGES | tr ' ' '-')"
- fi
- ;;
- remove)
- if [ "$(echo $PACKAGES | wc -w)" -gt $MAX_PACKAGE_COUNT ]; then
- PKG_COUNT=$(echo $PACKAGES | wc -w)
- create_snapshot "pre-remove-$PKG_COUNT-packages"
- else
- create_snapshot "pre-remove-$(echo $PACKAGES | tr ' ' '-')"
- fi
- ;;
- *)
- # For other operations, create a generic snapshot
- create_snapshot "pre-slackpkg-operation"
- ;;
- esac
- exit 0
|