From ef4a8442334aee486001f0da51b38afe0fb00b91 Mon Sep 17 00:00:00 2001 From: Ade Date: Sat, 14 Nov 2015 16:02:31 +1300 Subject: [PATCH 1/2] rutracker fix --- headphones/rutracker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headphones/rutracker.py b/headphones/rutracker.py index 0b7959b9..f106e133 100644 --- a/headphones/rutracker.py +++ b/headphones/rutracker.py @@ -176,7 +176,7 @@ class Rutracker(object): cookie = {'bb_dl': torrent_id} try: headers = {'Referer': url} - r = self.session.get(url=downloadurl, cookies=cookie, headers=headers, timeout=self.timeout) + r = self.session.post(url=downloadurl, cookies=cookie, headers=headers, timeout=self.timeout) return r.content except Exception as e: logger.error('Error getting torrent: %s', e) From 4b445ca4dfbcfeb1e5486bd51294f9f83c0c7852 Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Fri, 27 Nov 2015 10:48:04 +0100 Subject: [PATCH 2/2] Make ShellCheck suggested changes --- init-scripts/init-alt.freebsd | 26 +++++++++++++------------- init-scripts/init.freebsd | 18 +++++++++--------- init-scripts/init.ubuntu | 30 +++++++++++++----------------- 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/init-scripts/init-alt.freebsd b/init-scripts/init-alt.freebsd index 16fd5f97..308b92d0 100644 --- a/init-scripts/init-alt.freebsd +++ b/init-scripts/init-alt.freebsd @@ -27,17 +27,17 @@ rcvar=${name}_enable load_rc_config ${name} -: ${headphones_enable:="NO"} -: ${headphones_user:="_sabnzbd"} -: ${headphones_dir:="/usr/local/headphones"} -: ${headphones_chdir:="${headphones_dir}"} -: ${headphones_pid:="${headphones_dir}/headphones.pid"} -: ${headphones_conf:="${headphones_dir}/config.ini"} +: "${headphones_enable:="NO"}" +: "${headphones_user:="_sabnzbd"}" +: "${headphones_dir:="/usr/local/headphones"}" +: "${headphones_chdir:="${headphones_dir}"}" +: "${headphones_pid:="${headphones_dir}/headphones.pid"}" +: "${headphones_conf:="${headphones_dir}/config.ini"}" WGET="/usr/local/bin/wget" # You need wget for this script to safely shutdown Headphones. if [ -e "${headphones_conf}" ]; then - HOST=`grep -A64 "\[General\]" "${headphones_conf}"|egrep "^http_host"|perl -wple 's/^http_host = (.*)$/$1/'` - PORT=`grep -A64 "\[General\]" "${headphones_conf}"|egrep "^http_port"|perl -wple 's/^http_port = (.*)$/$1/'` + HOST=$(grep -A64 "\[General\]" "${headphones_conf}"|egrep "^http_host"|perl -wple 's/^http_host = (.*)$/$1/') + PORT=$(grep -A64 "\[General\]" "${headphones_conf}"|egrep "^http_port"|perl -wple 's/^http_port = (.*)$/$1/') fi status_cmd="${name}_status" @@ -53,15 +53,15 @@ if [ ! -x "${WGET}" ]; then fi # Ensure user is root when running this script. -if [ `id -u` != "0" ]; then +if [ "$(id -u)" != "0" ]; then echo "Oops, you should be root before running this!" exit 1 fi verify_headphones_pid() { # Make sure the pid corresponds to the Headphones process. - pid=`cat ${headphones_pid} 2>/dev/null` - ps -p ${pid} | grep -q "python ${headphones_dir}/Headphones.py" + pid=$(cat "${headphones_pid}" 2>/dev/null) + pgrep -F "${headphones_pid}" -q "python ${headphones_dir}/Headphones.py" return $? } @@ -73,10 +73,10 @@ headphones_stop() { fi echo "Stopping $name" verify_headphones_pid - ${WGET} -O - -q --user=${SBUSR} --password=${SBPWD} "http://${HOST}:${PORT}/shutdown/" >/dev/null + ${WGET} -O - -q --user="${SBUSR}" --password="${SBPWD}" "http://${HOST}:${PORT}/shutdown/" >/dev/null if [ -n "${pid}" ]; then - wait_for_pids ${pid} + wait_for_pids "${pid}" echo "Stopped $name" fi } diff --git a/init-scripts/init.freebsd b/init-scripts/init.freebsd index 3d2ca978..85d2cf14 100755 --- a/init-scripts/init.freebsd +++ b/init-scripts/init.freebsd @@ -28,11 +28,11 @@ rcvar=${name}_enable load_rc_config ${name} -: ${headphones_enable:="NO"} -: ${headphones_user:="_sabnzbd"} -: ${headphones_dir:="/usr/local/headphones"} -: ${headphones_chdir:="${headphones_dir}"} -: ${headphones_pid:="${headphones_dir}/headphones.pid"} +: "${headphones_enable:="NO"}" +: "${headphones_user:="_sabnzbd"}" +: "${headphones_dir:="/usr/local/headphones"}" +: "${headphones_chdir:="${headphones_dir}"}" +: "${headphones_pid:="${headphones_dir}/headphones.pid"}" status_cmd="${name}_status" stop_cmd="${name}_stop" @@ -41,15 +41,15 @@ command="/usr/sbin/daemon" command_args="-f -p ${headphones_pid} python ${headphones_dir}/Headphones.py ${headphones_flags} --quiet --nolaunch" # Ensure user is root when running this script. -if [ `id -u` != "0" ]; then +if [ "$(id -u)" != "0" ]; then echo "Oops, you should be root before running this!" exit 1 fi verify_headphones_pid() { # Make sure the pid corresponds to the Headphones process. - pid=`cat ${headphones_pid} 2>/dev/null` - ps -p ${pid} | grep -q "python ${headphones_dir}/Headphones.py" + pid=$(cat "${headphones_pid}" 2>/dev/null) + pgrep -F "${headphones_pid}" -q "python ${headphones_dir}/Headphones.py" return $? } @@ -58,7 +58,7 @@ headphones_stop() { echo "Stopping $name" verify_headphones_pid if [ -n "${pid}" ]; then - wait_for_pids ${pid} + wait_for_pids "${pid}" echo "Stopped" fi } diff --git a/init-scripts/init.ubuntu b/init-scripts/init.ubuntu index 7578ecd1..991f8e0a 100755 --- a/init-scripts/init.ubuntu +++ b/init-scripts/init.ubuntu @@ -32,7 +32,6 @@ ## HP_PIDFILE= #$PID_FILE, the location of headphones.pid, the default is /var/run/headphones/headphones.pid ## PYTHON_BIN= #$DAEMON, the location of the python binary, the default is /usr/bin/python ## HP_OPTS= #$EXTRA_DAEMON_OPTS, extra cli option for headphones, i.e. " --config=/home/headphones/config.ini" -## SSD_OPTS= #$EXTRA_SSD_OPTS, extra start-stop-daemon option like " --group=users" ## HP_PORT= #$PORT_OPTS, hardcoded port for the webserver, overrides value in config.ini ## ## EXAMPLE if want to run as different user @@ -101,9 +100,6 @@ load_settings() { # Extra daemon option like: HP_OPTS=" --config=/home/headphones/config.ini" EXTRA_DAEMON_OPTS=${HP_OPTS-} - # Extra start-stop-daemon option like START_OPTS=" --group=users" - EXTRA_SSD_OPTS=${SSD_OPTS-} - # Hardcoded port to run on, overrides config.ini settings [ -n "$HP_PORT" ] && { PORT_OPTS=" --port=${HP_PORT} " @@ -114,7 +110,7 @@ load_settings() { SETTINGS_LOADED=TRUE fi - [ -x $DAEMON ] || { + [ -x "$DAEMON" ] || { log_warning_msg "$DESC: Can't execute daemon, aborting. See $DAEMON"; return 1;} @@ -125,8 +121,8 @@ load_settings || exit 0 is_running () { # returns 1 when running, else 0. - if [ -e $PID_FILE ]; then - PID=`cat $PID_FILE` + if [ -e "$PID_FILE" ]; then + PID=$(cat "$PID_FILE") RET=$? [ $RET -gt 1 ] && exit 1 || return $RET @@ -136,28 +132,28 @@ is_running () { } handle_pid () { - PID_PATH=`dirname $PID_FILE` - [ -d $PID_PATH ] || mkdir -p $PID_PATH && chown -R $RUN_AS $PID_PATH > /dev/null || { + PID_PATH=$(dirname "$PID_FILE") + [ -d "$PID_PATH" ] || mkdir -p "$PID_PATH" && chown -R "$RUN_AS" "$PID_PATH" > /dev/null || { log_warning_msg "$DESC: Could not create $PID_FILE, See $SETTINGS, aborting."; return 1;} - if [ -e $PID_FILE ]; then - PID=`cat $PID_FILE` - if ! kill -0 $PID > /dev/null 2>&1; then + if [ -e "$PID_FILE" ]; then + PID=$(cat "$PID_FILE") + if ! kill -0 "$PID" > /dev/null 2>&1; then log_warning_msg "Removing stale $PID_FILE" - rm $PID_FILE + rm "$PID_FILE" fi fi } handle_datadir () { - [ -d $DATA_DIR ] || mkdir -p $DATA_DIR && chown -R $RUN_AS $DATA_DIR > /dev/null || { + [ -d "$DATA_DIR" ] || mkdir -p "$DATA_DIR" && chown -R "$RUN_AS" "$DATA_DIR" > /dev/null || { log_warning_msg "$DESC: Could not create $DATA_DIR, See $SETTINGS, aborting."; return 1;} } handle_updates () { - chown -R $RUN_AS $APP_PATH > /dev/null || { + chown -R "$RUN_AS" "$APP_PATH" > /dev/null || { log_warning_msg "$DESC: $APP_PATH not writable by $RUN_AS for web-updates"; return 0; } } @@ -168,7 +164,7 @@ start_headphones () { handle_updates if ! is_running; then log_daemon_msg "Starting $DESC" - start-stop-daemon -o -d $APP_PATH -c $RUN_AS --start $EXTRA_SSD_OPTS --pidfile $PID_FILE --exec $DAEMON -- $DAEMON_OPTS + start-stop-daemon -o -d "$APP_PATH" -c "$RUN_AS" --start "$EXTRA_SSD"_OPTS --pidfile "$PID_FILE" --exec "$DAEMON" -- "$DAEMON_OPTS" check_retval else log_success_msg "$DESC: already running (pid $PID)" @@ -178,7 +174,7 @@ start_headphones () { stop_headphones () { if is_running; then log_daemon_msg "Stopping $DESC" - start-stop-daemon -o --stop --pidfile $PID_FILE --retry 15 + start-stop-daemon -o --stop --pidfile "$PID_FILE" --retry 15 check_retval else log_success_msg "$DESC: not running"