do not write /usr/loca/bin/ anymore. install to home.

This commit is contained in:
neil 2016-01-31 17:15:02 +08:00
parent a925dd56b7
commit 525997ee04

162
le.sh
View File

@ -163,8 +163,8 @@ _send_signed_request() {
_debug url $url _debug url $url
_debug payload "$payload" _debug payload "$payload"
CURL_HEADER="$WORKING_DIR/curl.header" CURL_HEADER="$LE_WORKING_DIR/curl.header"
dp="$WORKING_DIR/curl.dump" dp="$LE_WORKING_DIR/curl.dump"
CURL="curl --silent --dump-header $CURL_HEADER " CURL="curl --silent --dump-header $CURL_HEADER "
if [ "$DEBUG" ] ; then if [ "$DEBUG" ] ; then
CURL="$CURL --trace-ascii $dp " CURL="$CURL --trace-ascii $dp "
@ -303,8 +303,8 @@ _initpath() {
fi fi
fi fi
if [ -z "$WORKING_DIR" ]; then if [ -z "$LE_WORKING_DIR" ]; then
WORKING_DIR=$HOME/.le LE_WORKING_DIR=$HOME/.le
fi fi
if [ -z "$ACME_DIR" ] ; then if [ -z "$ACME_DIR" ] ; then
@ -312,18 +312,18 @@ _initpath() {
fi fi
if [ -z "$APACHE_CONF_BACKUP_DIR" ] ; then if [ -z "$APACHE_CONF_BACKUP_DIR" ] ; then
APACHE_CONF_BACKUP_DIR="$WORKING_DIR/" APACHE_CONF_BACKUP_DIR="$LE_WORKING_DIR/"
fi fi
domain="$1" domain="$1"
mkdir -p "$WORKING_DIR" mkdir -p "$LE_WORKING_DIR"
if [ -z "$ACCOUNT_KEY_PATH" ] ; then if [ -z "$ACCOUNT_KEY_PATH" ] ; then
ACCOUNT_KEY_PATH="$WORKING_DIR/account.key" ACCOUNT_KEY_PATH="$LE_WORKING_DIR/account.key"
fi fi
if [ -z "$ACCOUNT_CONF_PATH" ] ; then if [ -z "$ACCOUNT_CONF_PATH" ] ; then
ACCOUNT_CONF_PATH="$WORKING_DIR/account.conf" ACCOUNT_CONF_PATH="$LE_WORKING_DIR/account.conf"
fi fi
if [ -f "$ACCOUNT_CONF_PATH" ] ; then if [ -f "$ACCOUNT_CONF_PATH" ] ; then
@ -334,22 +334,22 @@ _initpath() {
return 0 return 0
fi fi
mkdir -p "$WORKING_DIR/$domain" mkdir -p "$LE_WORKING_DIR/$domain"
if [ -z "$DOMAIN_CONF" ] ; then if [ -z "$DOMAIN_CONF" ] ; then
DOMAIN_CONF="$WORKING_DIR/$domain/$Le_Domain.conf" DOMAIN_CONF="$LE_WORKING_DIR/$domain/$Le_Domain.conf"
fi fi
if [ -z "$CSR_PATH" ] ; then if [ -z "$CSR_PATH" ] ; then
CSR_PATH="$WORKING_DIR/$domain/$domain.csr" CSR_PATH="$LE_WORKING_DIR/$domain/$domain.csr"
fi fi
if [ -z "$CERT_KEY_PATH" ] ; then if [ -z "$CERT_KEY_PATH" ] ; then
CERT_KEY_PATH="$WORKING_DIR/$domain/$domain.key" CERT_KEY_PATH="$LE_WORKING_DIR/$domain/$domain.key"
fi fi
if [ -z "$CERT_PATH" ] ; then if [ -z "$CERT_PATH" ] ; then
CERT_PATH="$WORKING_DIR/$domain/$domain.cer" CERT_PATH="$LE_WORKING_DIR/$domain/$domain.cer"
fi fi
if [ -z "$CA_CERT_PATH" ] ; then if [ -z "$CA_CERT_PATH" ] ; then
CA_CERT_PATH="$WORKING_DIR/$domain/ca.cer" CA_CERT_PATH="$LE_WORKING_DIR/$domain/ca.cer"
fi fi
} }
@ -584,7 +584,7 @@ issue() {
if [ "$code" == "" ] || [ "$code" == '201' ] ; then if [ "$code" == "" ] || [ "$code" == '201' ] ; then
_info "Registered" _info "Registered"
echo $response > $WORKING_DIR/account.json echo $response > $LE_WORKING_DIR/account.json
elif [ "$code" == '409' ] ; then elif [ "$code" == '409' ] ; then
_info "Already registered" _info "Already registered"
else else
@ -650,18 +650,18 @@ issue() {
#dns #dns
#1. check use api #1. check use api
d_api="" d_api=""
if [ -f "$WORKING_DIR/$d/$Le_Webroot" ] ; then if [ -f "$LE_WORKING_DIR/$d/$Le_Webroot" ] ; then
d_api="$WORKING_DIR/$d/$Le_Webroot" d_api="$LE_WORKING_DIR/$d/$Le_Webroot"
elif [ -f "$WORKING_DIR/$d/$Le_Webroot.sh" ] ; then elif [ -f "$LE_WORKING_DIR/$d/$Le_Webroot.sh" ] ; then
d_api="$WORKING_DIR/$d/$Le_Webroot.sh" d_api="$LE_WORKING_DIR/$d/$Le_Webroot.sh"
elif [ -f "$WORKING_DIR/$Le_Webroot" ] ; then elif [ -f "$LE_WORKING_DIR/$Le_Webroot" ] ; then
d_api="$WORKING_DIR/$Le_Webroot" d_api="$LE_WORKING_DIR/$Le_Webroot"
elif [ -f "$WORKING_DIR/$Le_Webroot.sh" ] ; then elif [ -f "$LE_WORKING_DIR/$Le_Webroot.sh" ] ; then
d_api="$WORKING_DIR/$Le_Webroot.sh" d_api="$LE_WORKING_DIR/$Le_Webroot.sh"
elif [ -f "$WORKING_DIR/dnsapi/$Le_Webroot" ] ; then elif [ -f "$LE_WORKING_DIR/dnsapi/$Le_Webroot" ] ; then
d_api="$WORKING_DIR/dnsapi/$Le_Webroot" d_api="$LE_WORKING_DIR/dnsapi/$Le_Webroot"
elif [ -f "$WORKING_DIR/dnsapi/$Le_Webroot.sh" ] ; then elif [ -f "$LE_WORKING_DIR/dnsapi/$Le_Webroot.sh" ] ; then
d_api="$WORKING_DIR/dnsapi/$Le_Webroot.sh" d_api="$LE_WORKING_DIR/dnsapi/$Le_Webroot.sh"
fi fi
_debug d_api "$d_api" _debug d_api "$d_api"
@ -897,7 +897,7 @@ renewAll() {
_initpath _initpath
_info "renewAll" _info "renewAll"
for d in $(ls -F $WORKING_DIR | grep '/$') ; do for d in $(ls -F $LE_WORKING_DIR | grep '/$') ; do
d=$(echo $d | cut -d '/' -f 1) d=$(echo $d | cut -d '/' -f 1)
_info "renew $d" _info "renew $d"
@ -992,13 +992,13 @@ installcronjob() {
_initpath _initpath
_info "Installing cron job" _info "Installing cron job"
if ! crontab -l | grep 'le.sh cron' ; then if ! crontab -l | grep 'le.sh cron' ; then
if [ -f "$WORKING_DIR/le.sh" ] ; then if [ -f "$LE_WORKING_DIR/le.sh" ] ; then
lesh="\"$WORKING_DIR\"/le.sh" lesh="\"$LE_WORKING_DIR\"/le.sh"
else else
_err "Can not install cronjob, le.sh not found." _err "Can not install cronjob, le.sh not found."
return 1 return 1
fi fi
crontab -l | { cat; echo "0 0 * * * $SUDO WORKING_DIR=\"$WORKING_DIR\" $lesh cron > /dev/null"; } | crontab - crontab -l | { cat; echo "0 0 * * * $SUDO LE_WORKING_DIR=\"$LE_WORKING_DIR\" $lesh cron > /dev/null"; } | crontab -
fi fi
return 0 return 0
} }
@ -1008,13 +1008,53 @@ uninstallcronjob() {
cr="$(crontab -l | grep 'le.sh cron')" cr="$(crontab -l | grep 'le.sh cron')"
if [ "$cr" ] ; then if [ "$cr" ] ; then
crontab -l | sed "/le.sh cron/d" | crontab - crontab -l | sed "/le.sh cron/d" | crontab -
WORKING_DIR="$(echo "$cr" | cut -d ' ' -f 7 | cut -d '=' -f 2 | tr -d '"')" LE_WORKING_DIR="$(echo "$cr" | cut -d ' ' -f 7 | cut -d '=' -f 2 | tr -d '"')"
_info WORKING_DIR "$WORKING_DIR" _info LE_WORKING_DIR "$LE_WORKING_DIR"
fi fi
_initpath _initpath
} }
# Detect profile file if not specified as environment variable
_detect_profile() {
if [ -n "$PROFILE" -a -f "$PROFILE" ]; then
echo "$PROFILE"
return
fi
local DETECTED_PROFILE
DETECTED_PROFILE=''
local SHELLTYPE
SHELLTYPE="$(basename "/$SHELL")"
if [ "$SHELLTYPE" = "bash" ]; then
if [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
fi
elif [ "$SHELLTYPE" = "zsh" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
fi
if [ -z "$DETECTED_PROFILE" ]; then
if [ -f "$HOME/.profile" ]; then
DETECTED_PROFILE="$HOME/.profile"
elif [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
elif [ -f "$HOME/.zshrc" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
fi
fi
if [ ! -z "$DETECTED_PROFILE" ]; then
echo "$DETECTED_PROFILE"
fi
}
install() { install() {
_initpath _initpath
@ -1047,33 +1087,33 @@ install() {
return 1 return 1
fi fi
_info "Installing to $WORKING_DIR" _info "Installing to $LE_WORKING_DIR"
_info "Installed to $LE_WORKING_DIR/le.sh"
cp le.sh $LE_WORKING_DIR/
chmod +x $LE_WORKING_DIR/le.sh
_profile="$(_detect_profile)"
if [ "$_profile" ] ; then
_debug "Found profile: $_profile"
echo "LE_WORKING_DIR=$LE_WORKING_DIR
alias le=\"$LE_WORKING_DIR/le.sh\"
alias le.sh=\"$LE_WORKING_DIR/le.sh\"
" > "$LE_WORKING_DIR/le.env"
_setopt "$_profile" "source \"$LE_WORKING_DIR/le.env\""
#try install to /bin if is root
if [ ! -f /usr/local/bin/le.sh ] ; then
#if root
if $SUDO cp le.sh /usr/local/bin/le.sh > /dev/null 2>&1; then
$SUDO chmod 755 /usr/local/bin/le.sh
$SUDO ln -s "/usr/local/bin/le.sh" /usr/local/bin/le
rm -f $WORKING_DIR/le.sh
$SUDO ln -s /usr/local/bin/le.sh $WORKING_DIR/le.sh
_info "Installed to /usr/local/bin/le"
else else
#install to home, for non root user _info "No profile is found, you will need to go into $LE_WORKING_DIR to use le.sh"
cp le.sh $WORKING_DIR/
chmod +x $WORKING_DIR/le.sh
_info "Installed to $WORKING_DIR/le.sh"
fi fi
fi
rm -f $WORKING_DIR/le
ln -s $WORKING_DIR/le.sh $WORKING_DIR/le
mkdir -p $WORKING_DIR/dnsapi mkdir -p $LE_WORKING_DIR/dnsapi
cp dnsapi/* $WORKING_DIR/dnsapi/ cp dnsapi/* $LE_WORKING_DIR/dnsapi/
#to keep compatible mv the .acc file to .key file #to keep compatible mv the .acc file to .key file
if [ -f "$WORKING_DIR/account.acc" ] ; then if [ -f "$LE_WORKING_DIR/account.acc" ] ; then
mv "$WORKING_DIR/account.acc" "$WORKING_DIR/account.key" mv "$LE_WORKING_DIR/account.acc" "$LE_WORKING_DIR/account.key"
fi fi
installcronjob installcronjob
@ -1085,15 +1125,13 @@ uninstall() {
uninstallcronjob uninstallcronjob
_initpath _initpath
if [ -f "/usr/local/bin/le.sh" ] ; then _profile="$(_detect_profile)"
_info "Removing /usr/local/bin/le.sh" if [ "$_profile" ] ; then
if $SUDO rm -f /usr/local/bin/le.sh ; then sed -i "/source \"$LE_WORKING_DIR/le.env\"/d" "$_profile"
$SUDO rm -f /usr/local/bin/le
fi fi
fi
rm -f $WORKING_DIR/le rm -f $LE_WORKING_DIR/le.sh
rm -f $WORKING_DIR/le.sh _info "The keys and certs are in $LE_WORKING_DIR, you can remove them by yourself."
_info "The keys and certs are in $WORKING_DIR, you can remove them by yourself."
} }