copy-smartdns.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/sh
  2. CURR_DIR=$(cd $(dirname $0);pwd)
  3. WORKDIR=$CURR_DIR/target
  4. CODE_DIR="$CURR_DIR/.."
  5. SMARTDNS_STATIC_DIR="$WORKDIR/smartdns-static"
  6. main() {
  7. TARGET_DIR=$1
  8. PREFIX=$2
  9. if [ -z "$TARGET_DIR" ]; then
  10. echo "Usage: $0 <target_directory> [prefix_directory]"
  11. exit 1
  12. fi
  13. if [ ! -d "$TARGET_DIR" ]; then
  14. echo "Target directory $TARGET_DIR does not exist."
  15. exit 1
  16. fi
  17. if [ ! -f "$SMARTDNS_STATIC_DIR/smartdns" ]; then
  18. cp "$CODE_DIR/src/smartdns" "$TARGET_DIR$PREFIX/usr/sbin/smartdns"
  19. if [ $? -ne 0 ]; then
  20. echo "Failed to copy smartdns binary to $TARGET_DIR/usr/sbin."
  21. return 1
  22. fi
  23. chmod +x "$TARGET_DIR/usr/sbin/smartdns"
  24. return 0
  25. fi
  26. if [ ! -f "$SMARTDNS_STATIC_DIR/smartdns" ]; then
  27. echo "SmartDNS binary not found in $SMARTDNS_STATIC_DIR."
  28. return 1
  29. fi
  30. mkdir -p "$TARGET_DIR/usr/local/lib/smartdns"
  31. if [ $? -ne 0 ]; then
  32. echo "Failed to create directory $TARGET_DIR/usr/local/lib/smartdns."
  33. return 1
  34. fi
  35. cp $SMARTDNS_STATIC_DIR/* $TARGET_DIR/usr/local/lib/smartdns/ -a
  36. if [ $? -ne 0 ]; then
  37. echo "Failed to copy smartdns static files to $TARGET_DIR/usr/local/lib/smartdns."
  38. return 1
  39. fi
  40. ln -f -s "$PREFIX/usr/local/lib/smartdns/run-smartdns" "$TARGET_DIR/usr/sbin/smartdns"
  41. if [ $? -ne 0 ]; then
  42. echo "Failed to create symlink for smartdns in $TARGET_DIR/usr/sbin."
  43. return 1
  44. fi
  45. chmod +x "$TARGET_DIR/usr/local/lib/smartdns/run-smartdns"
  46. echo "SmartDNS files copied successfully to $TARGET_DIR."
  47. return 0
  48. }
  49. main $@