当前位置:   article > 正文

Let'sEncrypt免费域名申请一键式脚本-目前最简单的脚本_letsencrypt 自动 脚本

letsencrypt 自动 脚本

注: 该脚本为开源组织提供

里面的所有东西都不要改,  复制下来,放到文本里,  放到linux下, 执行就好了.

网络上很多各种各样的教程形式, 我也在网络上查询了很长时间, 发现公司线上服务器上有个脚本,,不知道是不是公司人写的, 拿第一句话,到百度上一搜索, 发现第一个链接点击去, 就是脚本开源组织提供的地址.

    步骤:

       1. 桌面创建文本: certbot-auto   //注意去掉txt后缀

       2. 复制以下内容到文本里

  1. #!/bin/sh
  2. #
  3. # Download and run the latest release version of the Certbot client.
  4. #
  5. # NOTE: THIS SCRIPT IS AUTO-GENERATED AND SELF-UPDATING
  6. #
  7. # IF YOU WANT TO EDIT IT LOCALLY, *ALWAYS* RUN YOUR COPY WITH THE
  8. # "--no-self-upgrade" FLAG
  9. #
  10. # IF YOU WANT TO SEND PULL REQUESTS, THE REAL SOURCE FOR THIS FILE IS
  11. # letsencrypt-auto-source/letsencrypt-auto.template AND
  12. # letsencrypt-auto-source/pieces/bootstrappers/*
  13. set -e # Work even if somebody does "sh thisscript.sh".
  14. # Note: you can set XDG_DATA_HOME or VENV_PATH before running this script,
  15. # if you want to change where the virtual environment will be installed
  16. # HOME might not be defined when being run through something like systemd
  17. if [ -z "$HOME" ]; then
  18. HOME=~root
  19. fi
  20. if [ -z "$XDG_DATA_HOME" ]; then
  21. XDG_DATA_HOME=~/.local/share
  22. fi
  23. if [ -z "$VENV_PATH" ]; then
  24. # We export these values so they are preserved properly if this script is
  25. # rerun with sudo/su where $HOME/$XDG_DATA_HOME may have a different value.
  26. export OLD_VENV_PATH="$XDG_DATA_HOME/letsencrypt"
  27. export VENV_PATH="/opt/eff.org/certbot/venv"
  28. fi
  29. VENV_BIN="$VENV_PATH/bin"
  30. BOOTSTRAP_VERSION_PATH="$VENV_PATH/certbot-auto-bootstrap-version.txt"
  31. LE_AUTO_VERSION="0.37.2"
  32. BASENAME=$(basename $0)
  33. USAGE="Usage: $BASENAME [OPTIONS]
  34. A self-updating wrapper script for the Certbot ACME client. When run, updates
  35. to both this script and certbot will be downloaded and installed. After
  36. ensuring you have the latest versions installed, certbot will be invoked with
  37. all arguments you have provided.
  38. Help for certbot itself cannot be provided until it is installed.
  39. --debug attempt experimental installation
  40. -h, --help print this help
  41. -n, --non-interactive, --noninteractive run without asking for user input
  42. --no-bootstrap do not install OS dependencies
  43. --no-permissions-check do not warn about file system permissions
  44. --no-self-upgrade do not download updates
  45. --os-packages-only install OS dependencies and exit
  46. --install-only install certbot, upgrade if needed, and exit
  47. -v, --verbose provide more output
  48. -q, --quiet provide only update/error output;
  49. implies --non-interactive
  50. All arguments are accepted and forwarded to the Certbot client when run."
  51. export CERTBOT_AUTO="$0"
  52. for arg in "$@" ; do
  53. case "$arg" in
  54. --debug)
  55. DEBUG=1;;
  56. --os-packages-only)
  57. OS_PACKAGES_ONLY=1;;
  58. --install-only)
  59. INSTALL_ONLY=1;;
  60. --no-self-upgrade)
  61. # Do not upgrade this script (also prevents client upgrades, because each
  62. # copy of the script pins a hash of the python client)
  63. NO_SELF_UPGRADE=1;;
  64. --no-permissions-check)
  65. NO_PERMISSIONS_CHECK=1;;
  66. --no-bootstrap)
  67. NO_BOOTSTRAP=1;;
  68. --help)
  69. HELP=1;;
  70. --noninteractive|--non-interactive)
  71. NONINTERACTIVE=1;;
  72. --quiet)
  73. QUIET=1;;
  74. renew)
  75. ASSUME_YES=1;;
  76. --verbose)
  77. VERBOSE=1;;
  78. -[!-]*)
  79. OPTIND=1
  80. while getopts ":hnvq" short_arg $arg; do
  81. case "$short_arg" in
  82. h)
  83. HELP=1;;
  84. n)
  85. NONINTERACTIVE=1;;
  86. q)
  87. QUIET=1;;
  88. v)
  89. VERBOSE=1;;
  90. esac
  91. done;;
  92. esac
  93. done
  94. if [ $BASENAME = "letsencrypt-auto" ]; then
  95. # letsencrypt-auto does not respect --help or --yes for backwards compatibility
  96. NONINTERACTIVE=1
  97. HELP=0
  98. fi
  99. # Set ASSUME_YES to 1 if QUIET or NONINTERACTIVE
  100. if [ "$QUIET" = 1 -o "$NONINTERACTIVE" = 1 ]; then
  101. ASSUME_YES=1
  102. fi
  103. say() {
  104. if [ "$QUIET" != 1 ]; then
  105. echo "$@"
  106. fi
  107. }
  108. error() {
  109. echo "$@"
  110. }
  111. # Support for busybox and others where there is no "command",
  112. # but "which" instead
  113. if command -v command > /dev/null 2>&1 ; then
  114. export EXISTS="command -v"
  115. elif which which > /dev/null 2>&1 ; then
  116. export EXISTS="which"
  117. else
  118. error "Cannot find command nor which... please install one!"
  119. exit 1
  120. fi
  121. # Certbot itself needs root access for almost all modes of operation.
  122. # certbot-auto needs root access to bootstrap OS dependencies and install
  123. # Certbot at a protected path so it can be safely run as root. To accomplish
  124. # this, this script will attempt to run itself as root if it doesn't have the
  125. # necessary privileges by using `sudo` or falling back to `su` if it is not
  126. # available. The mechanism used to obtain root access can be set explicitly by
  127. # setting the environment variable LE_AUTO_SUDO to 'sudo', 'su', 'su_sudo',
  128. # 'SuSudo', or '' as used below.
  129. # Because the parameters in `su -c` has to be a string,
  130. # we need to properly escape it.
  131. SuSudo() {
  132. args=""
  133. # This `while` loop iterates over all parameters given to this function.
  134. # For each parameter, all `'` will be replace by `'"'"'`, and the escaped string
  135. # will be wrapped in a pair of `'`, then appended to `$args` string
  136. # For example, `echo "It's only 1\$\!"` will be escaped to:
  137. # 'echo' 'It'"'"'s only 1$!'
  138. # │ │└┼┘│
  139. # │ │ │ └── `'s only 1$!'` the literal string
  140. # │ │ └── `\"'\"` is a single quote (as a string)
  141. # │ └── `'It'`, to be concatenated with the strings following it
  142. # └── `echo` wrapped in a pair of `'`, it's totally fine for the shell command itself
  143. while [ $# -ne 0 ]; do
  144. args="$args'$(printf "%s" "$1" | sed -e "s/'/'\"'\"'/g")' "
  145. shift
  146. done
  147. su root -c "$args"
  148. }
  149. # Sets the environment variable SUDO to be the name of the program or function
  150. # to call to get root access. If this script already has root privleges, SUDO
  151. # is set to an empty string. The value in SUDO should be run with the command
  152. # to called with root privileges as arguments.
  153. SetRootAuthMechanism() {
  154. SUDO=""
  155. if [ -n "${LE_AUTO_SUDO+x}" ]; then
  156. case "$LE_AUTO_SUDO" in
  157. SuSudo|su_sudo|su)
  158. SUDO=SuSudo
  159. ;;
  160. sudo)
  161. SUDO="sudo -E"
  162. ;;
  163. '')
  164. # If we're not running with root, don't check that this script can only
  165. # be modified by system users and groups.
  166. NO_PERMISSIONS_CHECK=1
  167. ;;
  168. *)
  169. error "Error: unknown root authorization mechanism '$LE_AUTO_SUDO'."
  170. exit 1
  171. esac
  172. say "Using preset root authorization mechanism '$LE_AUTO_SUDO'."
  173. else
  174. if test "`id -u`" -ne "0" ; then
  175. if $EXISTS sudo 1>/dev/null 2>&1; then
  176. SUDO="sudo -E"
  177. else
  178. say \"sudo\" is not available, will use \"su\" for installation steps...
  179. SUDO=SuSudo
  180. fi
  181. fi
  182. fi
  183. }
  184. if [ "$1" = "--cb-auto-has-root" ]; then
  185. shift 1
  186. else
  187. SetRootAuthMechanism
  188. if [ -n "$SUDO" ]; then
  189. say "Requesting to rerun $0 with root privileges..."
  190. $SUDO "$0" --cb-auto-has-root "$@"
  191. exit 0
  192. fi
  193. fi
  194. # Runs this script again with the given arguments. --cb-auto-has-root is added
  195. # to the command line arguments to ensure we don't try to acquire root a
  196. # second time. After the script is rerun, we exit the current script.
  197. RerunWithArgs() {
  198. "$0" --cb-auto-has-root "$@"
  199. exit 0
  200. }
  201. BootstrapMessage() {
  202. # Arguments: Platform name
  203. say "Bootstrapping dependencies for $1... (you can skip this with --no-bootstrap)"
  204. }
  205. ExperimentalBootstrap() {
  206. # Arguments: Platform name, bootstrap function name
  207. if [ "$DEBUG" = 1 ]; then
  208. if [ "$2" != "" ]; then
  209. BootstrapMessage $1
  210. $2
  211. fi
  212. else
  213. error "FATAL: $1 support is very experimental at present..."
  214. error "if you would like to work on improving it, please ensure you have backups"
  215. error "and then run this script again with the --debug flag!"
  216. error "Alternatively, you can install OS dependencies yourself and run this script"
  217. error "again with --no-bootstrap."
  218. exit 1
  219. fi
  220. }
  221. DeprecationBootstrap() {
  222. # Arguments: Platform name, bootstrap function name
  223. if [ "$DEBUG" = 1 ]; then
  224. if [ "$2" != "" ]; then
  225. BootstrapMessage $1
  226. $2
  227. fi
  228. else
  229. error "WARNING: certbot-auto support for this $1 is DEPRECATED!"
  230. error "Please visit certbot.eff.org to learn how to download a version of"
  231. error "Certbot that is packaged for your system. While an existing version"
  232. error "of certbot-auto may work currently, we have stopped supporting updating"
  233. error "system packages for your system. Please switch to a packaged version"
  234. error "as soon as possible."
  235. exit 1
  236. fi
  237. }
  238. MIN_PYTHON_VERSION="2.7"
  239. MIN_PYVER=$(echo "$MIN_PYTHON_VERSION" | sed 's/\.//')
  240. # Sets LE_PYTHON to Python version string and PYVER to the first two
  241. # digits of the python version
  242. DeterminePythonVersion() {
  243. # Arguments: "NOCRASH" if we shouldn't crash if we don't find a good python
  244. #
  245. # If no Python is found, PYVER is set to 0.
  246. if [ "$USE_PYTHON_3" = 1 ]; then
  247. for LE_PYTHON in "$LE_PYTHON" python3; do
  248. # Break (while keeping the LE_PYTHON value) if found.
  249. $EXISTS "$LE_PYTHON" > /dev/null && break
  250. done
  251. else
  252. for LE_PYTHON in "$LE_PYTHON" python2.7 python27 python2 python; do
  253. # Break (while keeping the LE_PYTHON value) if found.
  254. $EXISTS "$LE_PYTHON" > /dev/null && break
  255. done
  256. fi
  257. if [ "$?" != "0" ]; then
  258. if [ "$1" != "NOCRASH" ]; then
  259. error "Cannot find any Pythons; please install one!"
  260. exit 1
  261. else
  262. PYVER=0
  263. return 0
  264. fi
  265. fi
  266. PYVER=`"$LE_PYTHON" -V 2>&1 | cut -d" " -f 2 | cut -d. -f1,2 | sed 's/\.//'`
  267. if [ "$PYVER" -lt "$MIN_PYVER" ]; then
  268. if [ "$1" != "NOCRASH" ]; then
  269. error "You have an ancient version of Python entombed in your operating system..."
  270. error "This isn't going to work; you'll need at least version $MIN_PYTHON_VERSION."
  271. exit 1
  272. fi
  273. fi
  274. }
  275. # If new packages are installed by BootstrapDebCommon below, this version
  276. # number must be increased.
  277. BOOTSTRAP_DEB_COMMON_VERSION=1
  278. BootstrapDebCommon() {
  279. # Current version tested with:
  280. #
  281. # - Ubuntu
  282. # - 14.04 (x64)
  283. # - 15.04 (x64)
  284. # - Debian
  285. # - 7.9 "wheezy" (x64)
  286. # - sid (2015-10-21) (x64)
  287. # Past versions tested with:
  288. #
  289. # - Debian 8.0 "jessie" (x64)
  290. # - Raspbian 7.8 (armhf)
  291. # Believed not to work:
  292. #
  293. # - Debian 6.0.10 "squeeze" (x64)
  294. if [ "$QUIET" = 1 ]; then
  295. QUIET_FLAG='-qq'
  296. fi
  297. apt-get $QUIET_FLAG update || error apt-get update hit problems but continuing anyway...
  298. # virtualenv binary can be found in different packages depending on
  299. # distro version (#346)
  300. virtualenv=
  301. # virtual env is known to apt and is installable
  302. if apt-cache show virtualenv > /dev/null 2>&1 ; then
  303. if ! LC_ALL=C apt-cache --quiet=0 show virtualenv 2>&1 | grep -q 'No packages found'; then
  304. virtualenv="virtualenv"
  305. fi
  306. fi
  307. if apt-cache show python-virtualenv > /dev/null 2>&1; then
  308. virtualenv="$virtualenv python-virtualenv"
  309. fi
  310. augeas_pkg="libaugeas0 augeas-lenses"
  311. if [ "$ASSUME_YES" = 1 ]; then
  312. YES_FLAG="-y"
  313. fi
  314. apt-get install $QUIET_FLAG $YES_FLAG --no-install-recommends \
  315. python \
  316. python-dev \
  317. $virtualenv \
  318. gcc \
  319. $augeas_pkg \
  320. libssl-dev \
  321. openssl \
  322. libffi-dev \
  323. ca-certificates \
  324. if ! $EXISTS virtualenv > /dev/null ; then
  325. error Failed to install a working \"virtualenv\" command, exiting
  326. exit 1
  327. fi
  328. }
  329. # If new packages are installed by BootstrapRpmCommonBase below, version
  330. # numbers in rpm_common.sh and rpm_python3.sh must be increased.
  331. # Sets TOOL to the name of the package manager
  332. # Sets appropriate values for YES_FLAG and QUIET_FLAG based on $ASSUME_YES and $QUIET_FLAG.
  333. # Enables EPEL if applicable and possible.
  334. InitializeRPMCommonBase() {
  335. if type dnf 2>/dev/null
  336. then
  337. TOOL=dnf
  338. elif type yum 2>/dev/null
  339. then
  340. TOOL=yum
  341. else
  342. error "Neither yum nor dnf found. Aborting bootstrap!"
  343. exit 1
  344. fi
  345. if [ "$ASSUME_YES" = 1 ]; then
  346. YES_FLAG="-y"
  347. fi
  348. if [ "$QUIET" = 1 ]; then
  349. QUIET_FLAG='--quiet'
  350. fi
  351. if ! $TOOL list *virtualenv >/dev/null 2>&1; then
  352. echo "To use Certbot, packages from the EPEL repository need to be installed."
  353. if ! $TOOL list epel-release >/dev/null 2>&1; then
  354. error "Enable the EPEL repository and try running Certbot again."
  355. exit 1
  356. fi
  357. if [ "$ASSUME_YES" = 1 ]; then
  358. /bin/echo -n "Enabling the EPEL repository in 3 seconds..."
  359. sleep 1s
  360. /bin/echo -ne "\e[0K\rEnabling the EPEL repository in 2 seconds..."
  361. sleep 1s
  362. /bin/echo -e "\e[0K\rEnabling the EPEL repository in 1 second..."
  363. sleep 1s
  364. fi
  365. if ! $TOOL install $YES_FLAG $QUIET_FLAG epel-release; then
  366. error "Could not enable EPEL. Aborting bootstrap!"
  367. exit 1
  368. fi
  369. fi
  370. }
  371. BootstrapRpmCommonBase() {
  372. # Arguments: whitespace-delimited python packages to install
  373. InitializeRPMCommonBase # This call is superfluous in practice
  374. pkgs="
  375. gcc
  376. augeas-libs
  377. openssl
  378. openssl-devel
  379. libffi-devel
  380. redhat-rpm-config
  381. ca-certificates
  382. "
  383. # Add the python packages
  384. pkgs="$pkgs
  385. $1
  386. "
  387. if $TOOL list installed "httpd" >/dev/null 2>&1; then
  388. pkgs="$pkgs
  389. mod_ssl
  390. "
  391. fi
  392. if ! $TOOL install $YES_FLAG $QUIET_FLAG $pkgs; then
  393. error "Could not install OS dependencies. Aborting bootstrap!"
  394. exit 1
  395. fi
  396. }
  397. # If new packages are installed by BootstrapRpmCommon below, this version
  398. # number must be increased.
  399. BOOTSTRAP_RPM_COMMON_VERSION=1
  400. Bootst
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/387647
推荐阅读
相关标签
  

闽ICP备14008679号