You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1 KiB

  1. #!/bin/sh
  2. set -e
  3. # POSIX-compliant maint function recommend by devref
  4. # to check for the existence of a command
  5. # https://www.debian.org/doc/manuals/developers-reference/ch06.html#bpp-debian-maint-scripts
  6. pathfind() {
  7. OLDIFS="$IFS"
  8. IFS=:
  9. for p in $PATH; do
  10. if [ -x "$p/$*" ]; then
  11. IFS="$OLDIFS"
  12. return 0
  13. fi
  14. done
  15. IFS="$OLDIFS"
  16. return 1
  17. }
  18. case "$1" in
  19. configure|reconfigure)
  20. pathfind setcap && setcap \
  21. cap_net_bind_service+ep /usr/bin/ss-local \
  22. cap_net_bind_service,cap_net_admin+ep /usr/bin/ss-redir \
  23. cap_net_bind_service+ep /usr/bin/ss-server \
  24. cap_net_bind_service+ep /usr/bin/ss-tunnel
  25. if [ ! -f /etc/shadowsocks-libev/config.json ]; then
  26. pathfind apg
  27. if [ $? -eq 0 ]; then
  28. passwd=$(apg -n 1 -M ncl)
  29. else
  30. passwd=$(pwgen 12 1)
  31. fi
  32. mkdir -p /etc/shadowsocks-libev
  33. sed "s/barfoo!/$passwd/" /usr/share/shadowsocks-libev/config.json \
  34. > /etc/shadowsocks-libev/config.json
  35. fi
  36. ;;
  37. abort-upgrade|abort-remove|abort-deconfigure)
  38. exit 0
  39. ;;
  40. *)
  41. echo "postinst called with unknown argument \`$1'" >&2
  42. exit 0
  43. ;;
  44. esac
  45. #DEBHELPER#
  46. exit 0