mirror of
https://github.com/pulb/mailnag.git
synced 2026-01-27 07:29:02 +01:00
use XDG dirs
This commit is contained in:
12
mailnag
12
mailnag
@@ -1,11 +1,17 @@
|
||||
#!/bin/bash
|
||||
CONFIG_HOME=$XDG_CONFIG_HOME
|
||||
if [ "$CONFIG_HOME" == "" ]; then
|
||||
CONFIG_HOME="$HOME/.config"
|
||||
fi
|
||||
config_dir="$CONFIG_HOME/mailnag"
|
||||
|
||||
main()
|
||||
{
|
||||
if [ -f ~/.mailnag/mailnag.log ]; then
|
||||
rm ~/.mailnag/mailnag.log
|
||||
if [ -f "$config_dir/mailnag.log" ]; then
|
||||
rm "$config_dir/mailnag.log"
|
||||
fi
|
||||
cd `dirname $0`
|
||||
python mailnag.py autostarted >> ~/.mailnag/mailnag.log 2>&1 &
|
||||
python mailnag.py autostarted >> "$config_dir/mailnag.log" 2>&1 &
|
||||
}
|
||||
|
||||
connection()
|
||||
|
||||
@@ -41,6 +41,7 @@ import gettext
|
||||
from mailnag_config import Keyring
|
||||
#import cairo
|
||||
import signal
|
||||
import xdg.BaseDirectory as bd
|
||||
|
||||
|
||||
gettext.bindtextdomain('mailnag', 'locale')
|
||||
@@ -431,14 +432,14 @@ def read_config(cfg_file): # read config file or create it
|
||||
|
||||
|
||||
def write_pid(): # write Mailnags's process id to file
|
||||
pid_file = user_path + 'mailnag.pid'
|
||||
pid_file = os.path.join(user_path, 'mailnag.pid')
|
||||
f = open(pid_file, 'w')
|
||||
f.write(str(os.getpid())) # get PID and write to file
|
||||
f.close()
|
||||
|
||||
|
||||
def delete_pid(): # delete file mailnag.pid
|
||||
pid_file = user_path + 'mailnag.pid'
|
||||
pid_file = os.path.join(user_path, 'mailnag.pid')
|
||||
if os.path.exists(pid_file):
|
||||
os.popen("rm " + pid_file) # delete it
|
||||
|
||||
@@ -1271,14 +1272,14 @@ def main():
|
||||
signal.signal(signal.SIGTERM, cleanup)
|
||||
|
||||
try:
|
||||
user_path = os.path.expanduser("~/.mailnag/") # set path to: "/home/user/.mailnag/"
|
||||
user_path = os.path.join(bd.xdg_config_home, "mailnag")
|
||||
autostarted = False # default setting for command line argument
|
||||
cmdline = sys.argv # get command line arguments
|
||||
if len(cmdline) > 1: # do we have something in command line?
|
||||
if cmdline[1] == 'autostarted':
|
||||
autostarted = True
|
||||
write_pid() # write Mailnag's process id to file
|
||||
cfg = read_config(user_path + 'mailnag.cfg') # get configuration from file
|
||||
cfg = read_config(os.path.join(user_path, 'mailnag.cfg')) # get configuration from file
|
||||
|
||||
accounts = Accounts() # create Accounts object
|
||||
if accounts.keyring_was_locked: firstcheck = False # required for correct sortorder in indi menu
|
||||
|
||||
@@ -1,21 +1,30 @@
|
||||
#!/bin/bash
|
||||
if [ ! -d ~/.mailnag ]; then
|
||||
mkdir ~/.mailnag
|
||||
CONFIG_HOME=$XDG_CONFIG_HOME
|
||||
if [ "$CONFIG_HOME" == "" ]; then
|
||||
CONFIG_HOME="$HOME/.config"
|
||||
fi
|
||||
if [ -f ~/.mailnag/mailnag_config.log ]; then
|
||||
rm ~/.mailnag/mailnag_config.log
|
||||
config_dir="$CONFIG_HOME/mailnag"
|
||||
|
||||
if [ ! -d "$config_dir" ]; then
|
||||
mkdir --parents "$config_dir"
|
||||
fi
|
||||
if [ -f "$config_dir/mailnag_config.log" ]; then
|
||||
rm "$config_dir/mailnag_config.log"
|
||||
fi
|
||||
|
||||
cd `dirname $0`
|
||||
python mailnag_config.py >> ~/.mailnag/mailnag_config.log 2>&1
|
||||
|
||||
python mailnag_config.py >> "$config_dir/mailnag_config.log" 2>&1
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
# Restart mailnag.py
|
||||
if [ -f ~/.mailnag/mailnag.pid ]; then
|
||||
kill $(cat ~/.mailnag/mailnag.pid)
|
||||
if [ -f "$config_dir/mailnag.pid" ]; then
|
||||
kill $(cat "$config_dir/mailnag.pid")
|
||||
fi
|
||||
if [ -f ~/.mailnag/mailnag.log ]; then
|
||||
rm ~/.mailnag/mailnag.log
|
||||
if [ -f "$config_dir/mailnag.log" ]; then
|
||||
rm "$config_dir/mailnag.log"
|
||||
fi
|
||||
python mailnag.py >> ~/.mailnag/mailnag.log 2>&1 &
|
||||
python mailnag.py >> "$config_dir/mailnag.log" 2>&1 &
|
||||
else
|
||||
echo mailnag-config discarded
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user