Add -i option to create config files (includimg vdirsyncer config)
Add -l / -r options to specify local/remote vdirsyncer storage names.
This commit is contained in:
parent
71d4229b59
commit
e564188289
172
t.sh
172
t.sh
|
@ -57,8 +57,10 @@ function usage() {
|
|||
format="%22s %-40s %s\n"
|
||||
echo "usage: $0 COMMAND [OPTIONS] [commandopts]"
|
||||
echo
|
||||
echo " -s Auto-sync with server when complete."
|
||||
echo " -f Assume 'yes' to all questions."
|
||||
echo " -l xx Specify name of local vdirsyncer storage name (default: $DEFAULT_VDS_LOCAL)"
|
||||
echo " -r xx Specify name of remote vdirsyncer storage name (default: $DEFAULT_VDS_REMOTE)"
|
||||
echo " -s Auto-sync with server when complete."
|
||||
echo
|
||||
printf "$format" "COMMAND" "DESCRIPTION" "SYNONYMS"
|
||||
for x in $valid_modes; do
|
||||
|
@ -246,6 +248,10 @@ function action() {
|
|||
echo -e "$BOLD$GREEN* $PLAIN$GREEN$*$PLAIN"
|
||||
}
|
||||
|
||||
function warn() {
|
||||
echo -e "$BOLD${YELLOW}WARNING: $PLAIN$YELLOW$*$PLAIN" >/dev/stderr
|
||||
}
|
||||
|
||||
function error() {
|
||||
echo -e "$BOLD${RED}ERROR: $PLAIN$RED$*$PLAIN" >/dev/stderr
|
||||
}
|
||||
|
@ -1097,6 +1103,142 @@ function getchildren() {
|
|||
return 0
|
||||
}
|
||||
|
||||
function init() {
|
||||
local gotvdconf=0 d url count cals cals_arr thiscal selcal
|
||||
action "Initialising configration"
|
||||
|
||||
if ! which -s vdirsyncer; then
|
||||
error "Can't find ${BOLD}vdirsyncer${PLAIN}${RED} - please install it."
|
||||
return 1
|
||||
fi
|
||||
if [[ -e $vdirsyncconfig ]]; then
|
||||
confirm "Use existing vdirsyncer config in ${BOLD}$vdirsyncconfig${PLAIN}${MAGENTA}"
|
||||
if [[ $? -eq 0 ]]; then
|
||||
gotvdconf=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $gotvdconf -ne 1 ]]; then
|
||||
for d in "$vdirsyncdir" "$vdircaldir" "$vdirstatdir"; do
|
||||
if [[ -d "$d" ]]; then
|
||||
info "Directory $d already exists"
|
||||
else
|
||||
mkdir -p "$vdirsyncdir"
|
||||
if [[ $? -eq 0 ]]; then
|
||||
action "Created directory ${BOLD}$d${PLAIN}"
|
||||
else
|
||||
error "Couldn't mkdir ${BOLD}$d${PLAIN}${RED}"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
echo -e "${MAGENTA}Please provide the URL of your caldav server.${PLAIN}"
|
||||
echo -en "${BOLD}${MAGENTA}==> ${PLAIN}"
|
||||
read url
|
||||
if [[ ! $url =~ ^http.* ]]; then
|
||||
error "Provided URL 'url' appears invalid."
|
||||
return 1
|
||||
fi
|
||||
echo -en "${BOLD}${MAGENTA}Caldav username: ${PLAIN}"
|
||||
read u
|
||||
echo -en "${BOLD}${MAGENTA}Caldav password: ${PLAIN}"
|
||||
read -s p
|
||||
|
||||
cat >"${vdirsyncconfig}" <<EOF
|
||||
[general]
|
||||
status_path = "$vdirstatdir"
|
||||
|
||||
[pair cal]
|
||||
a = "cal_local"
|
||||
b = "cal_remote"
|
||||
collections = ["from a", "from b"]
|
||||
|
||||
[storage cal_local]
|
||||
type = "filesystem"
|
||||
path = "$vdircaldir"
|
||||
fileext = ".vcf"
|
||||
|
||||
[storage cal_remote]
|
||||
type = "caldav"
|
||||
url = "$url"
|
||||
username = "$u"
|
||||
password = "$p"
|
||||
EOF
|
||||
unset u
|
||||
unset p
|
||||
info "Created vdirsyncer config in ${vdirsyncconfig}"
|
||||
fi
|
||||
|
||||
cals=$(ls -1q $vdircaldir 2>/dev/null)
|
||||
count=$(echo "$cals" | wc -l | tr -d ' ')
|
||||
|
||||
if [[ $count -eq 0 ]]; then
|
||||
action "Running initial vdirsyncer discover..."
|
||||
vdirsyncer discover
|
||||
action "Running initial vdirsyncer sync..."
|
||||
vdirsyncer sync
|
||||
|
||||
cals=$(ls -1q $vdircaldir 2>/dev/null)
|
||||
count=$(echo "$cals" | wc -l | tr -d ' ')
|
||||
fi
|
||||
|
||||
if [[ ! -e "${confdir}/docs" ]] ; then
|
||||
cals_arr=()
|
||||
selcal=""
|
||||
if [[ $count -gt 0 ]]; then
|
||||
local sel
|
||||
while read thiscal; do
|
||||
cals_arr+=("$thiscal")
|
||||
done <<< "$cals"
|
||||
|
||||
echo
|
||||
for d in ${!cals_arr[@]}; do
|
||||
echo -e "${MAGENTA}${BOLD}$((d + 1)). ${PLAIN}${MAGENTA}${cals_arr[$d]}${PLAIN}"
|
||||
done
|
||||
sel=-1
|
||||
while [[ $sel -le 0 || $sel -gt ${#cals_arr[@]} ]]; do
|
||||
echo -en "${MAGENTA}${BOLD}Select calendar: ${PLAIN}"
|
||||
read sel
|
||||
done
|
||||
selcal=${cals_arr[$(($sel - 1))]}
|
||||
else
|
||||
warn "No calendars found."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ! -d "$confdir" ]] ; then
|
||||
mkdir -p "$confdir"
|
||||
action "Created $confdir"
|
||||
fi
|
||||
|
||||
if [[ ! -e "${confdir}/docs" ]] ; then
|
||||
if [[ -n $selcal ]]; then
|
||||
ln -s "${vdircaldir}/${selcal}" "${confdir}/docs"
|
||||
action "Created symlink to $selcal"
|
||||
else
|
||||
warn "No calendar selected "
|
||||
echo "${YELLOW}Please manually symlink ${confdir}/docs to the required local directory under $vdircaldir"
|
||||
selcal="<none>"
|
||||
fi
|
||||
else
|
||||
warn "Calendar symlink ${confdir}/docs already exists. Not overwriting it."
|
||||
selcal=$(basename $(readlink -n ${confdir}/docs))
|
||||
fi
|
||||
|
||||
if [[ -e "$idfile" ]]; then
|
||||
warn "ID mapping file $idfile already exists. Not overwriting it."
|
||||
else
|
||||
touch "$idfile"
|
||||
info "Created ID mapping file in ${idfile}"
|
||||
fi
|
||||
|
||||
info "Initialisation complete"
|
||||
echo -e "${CYAN} vdirsyncer config is in ${BOLD}${vdirsyncdir}${PLAIN}"
|
||||
echo -e "${CYAN} task_cli config is in ${BOLD}${confdir}${PLAIN}"
|
||||
echo -e "${CYAN} selected calendar is '${BOLD}${selcal}${PLAIN}'"
|
||||
echo
|
||||
}
|
||||
|
||||
function tasksync() {
|
||||
local res upcount downcount noun
|
||||
|
@ -1182,11 +1324,12 @@ function tasksync() {
|
|||
|
||||
|
||||
VDIRSYNCER=/usr/local/bin/vdirsyncer
|
||||
VDS_LOCAL=cal_local
|
||||
VDS_REMOTE=cal_remote
|
||||
DEFAULT_VDS_LOCAL=cal_local
|
||||
DEFAULT_VDS_REMOTE=cal_remote
|
||||
basedir=/Users/rpearce/code/task_cli
|
||||
dir=$basedir/docs
|
||||
idfile=$basedir/idmappings.txt
|
||||
confdir=${HOME}/.task_cli
|
||||
dir=$confdir/docs # symlink to vdirsyncer/calendar/xxx/
|
||||
idfile=$confdir/idmappings.txt
|
||||
nextid=1
|
||||
indent=0
|
||||
indentamt=4
|
||||
|
@ -1195,6 +1338,11 @@ mode=list
|
|||
modes_that_support_all=""
|
||||
passive_modes="" # modes that do not change data
|
||||
|
||||
vdirsyncdir="${HOME}/.config/vdirsyncer"
|
||||
vdircaldir="${HOME}/.config/vdirsyncer/calendar"
|
||||
vdirstatdir="${HOME}/.config/vdirsyncer/status"
|
||||
vdirsyncconfig="${vdirsyncdir}/config"
|
||||
|
||||
# for pager
|
||||
printed=0
|
||||
rows=$(tput lines)
|
||||
|
@ -1221,13 +1369,23 @@ DEBUG=0
|
|||
TESTMODE=0
|
||||
AUTOSYNC=0
|
||||
|
||||
ARGS="fhdsty"
|
||||
ARGS="fhidstyl:r:"
|
||||
while getopts "$ARGS" i; do
|
||||
case "$i" in
|
||||
h)
|
||||
usage;
|
||||
exit 1;
|
||||
;;
|
||||
i)
|
||||
init
|
||||
exit $?
|
||||
;;
|
||||
l)
|
||||
VDS_LOCAL="$OPTARG"
|
||||
;;
|
||||
r)
|
||||
VDS_REMOTE="$OPTARG"
|
||||
;;
|
||||
d)
|
||||
DEBUG=1
|
||||
;;
|
||||
|
@ -1251,6 +1409,8 @@ done
|
|||
shift $((OPTIND - 1))
|
||||
|
||||
|
||||
[[ -z $VDS_LOCAL ]] && VDS_LOCAL="$DEFAULT_VDS_LOCAL"
|
||||
[[ -z $VDS_REMOTE ]] && VDS_REMOTE="$DEFAULT_VDS_REMOTE"
|
||||
|
||||
mode=""
|
||||
for x in $valid_modes; do
|
||||
|
|
Loading…
Reference in New Issue