#!/bin/bash

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.

# Author: Jun Kobayashi <jkbys@ubuntu.com>
# Bugs to: https://bugs.launchpad.net/ubuntu-jp-improvement

# Author: sicklylife.jp <01@sicklylife.jp>
# Bugs to: https://sicklylife.hatenablog.com

TITLE="Cosmic専用PPAPlus"
ZENITY_CMD="zenity --title=$TITLE"

CURRENT_RELEASE="18.10"
NEXT_RELEASE="19.04"

RELEASE_CODE="cosmic"
NEXT_RELEASE_CODE="cosmic"

REPO_DIR="/etc/apt/sources.list.d/"
SOURCESLIST="/etc/apt/sources.list /etc/apt/sources.list.d/*.list"

function install_menu {
#  if [ -a /etc/apt/sources.list.d/clipgrab-team-ubuntu-ppa-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/clipgrab-team-ubuntu-ppa-cosmic.list ] ; then
#    clipgrab=True
#  else
#    clipgrab=False
#  fi

#  if [ -a /etc/apt/sources.list.d/danielrichter2007-ubuntu-grub-customizer-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/danielrichter2007-ubuntu-grub-customizer-cosmic.list ] ; then
#    grubc=True
#  else
#    grubc=False
#  fi

#  if [ -a /etc/apt/sources.list.d/flexiondotorg-ubuntu-audio-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/flexiondotorg-ubuntu-audio-cosmic.list ] ; then
#    mp3gain=True
#  else
#    mp3gain=False
#  fi

  if [ -a /etc/apt/sources.list.d/graphics-drivers-ubuntu-ppa-cosmic.list ] && \
     [ -s /etc/apt/sources.list.d/graphics-drivers-ubuntu-ppa-cosmic.list ] ; then
    geforce=True
  else
    geforce=False
  fi

#  if [ -a /etc/apt/sources.list.d/hluk-ubuntu-copyq-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/hluk-ubuntu-copyq-cosmic.list ] ; then
#    copyq=True
#  else
#    copyq=False
#  fi

#  if [ -a /etc/apt/sources.list.d/inkscape_dev-ubuntu-stable-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/inkscape_dev-ubuntu-stable-cosmic.list ] ; then
#    inkscape=True
#  else
#    inkscape=False
#  fi

#  if [ -a /etc/apt/sources.list.d/japaneseteam-ubuntu-ppa-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/japaneseteam-ubuntu-ppa-cosmic.list ] ; then
#    japanese=True
#  else
#    japanese=False
#  fi

  if [ -a /etc/apt/sources.list.d/kdenlive-ubuntu-kdenlive-stable-cosmic.list ] && \
     [ -s /etc/apt/sources.list.d/kdenlive-ubuntu-kdenlive-stable-cosmic.list ] ; then
    kdenlive=True
  else
    kdenlive=False
  fi

  if [ -a /etc/apt/sources.list.d/libreoffice-ubuntu-ppa-cosmic.list ] && \
     [ -s /etc/apt/sources.list.d/libreoffice-ubuntu-ppa-cosmic.list ] ; then
    libreoffice=True
  else
    libreoffice=False
  fi

  if [ -a /etc/apt/sources.list.d/mikhailnov-ubuntu-pulseeffects-cosmic.list ] && \
     [ -s /etc/apt/sources.list.d/mikhailnov-ubuntu-pulseeffects-cosmic.list ] ; then
    pulseeffects=True
  else
    pulseeffects=False
  fi

#  if [ -a /etc/apt/sources.list.d/nilarimogard-ubuntu-webupd8-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/nilarimogard-ubuntu-webupd8-cosmic.list ] ; then
#    webupd8=True
#  else
#    webupd8=False
#  fi

  if [ -a /etc/apt/sources.list.d/openshot_developers-ubuntu-ppa-cosmic.list ] && \
     [ -s /etc/apt/sources.list.d/openshot_developers-ubuntu-ppa-cosmic.list ] ; then
    openshot=True
  else
    openshot=False
  fi

  if [ -a /etc/apt/sources.list.d/otto-kesselgulasch-ubuntu-gimp-cosmic.list ] && \
     [ -s /etc/apt/sources.list.d/otto-kesselgulasch-ubuntu-gimp-cosmic.list ] ; then
    gimp=True
  else
    gimp=False
  fi

  if [ -a /etc/apt/sources.list.d/ozmartian-ubuntu-apps-cosmic.list ] && \
     [ -s /etc/apt/sources.list.d/ozmartian-ubuntu-apps-cosmic.list ] ; then
    vidcutter=True
  else
    vidcutter=False
  fi

#  if [ -a /etc/apt/sources.list.d/peek-developers-ubuntu-stable-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/peek-developers-ubuntu-stable-cosmic.list ] ; then
#    peek=True
#  else
#    peek=False
#  fi

#  if [ -a /etc/apt/sources.list.d/phoerious-ubuntu-keepassxc-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/phoerious-ubuntu-keepassxc-cosmic.list ] ; then
#    keepassxc=True
#  else
#    keepassxc=False
#  fi

  if [ -a /etc/apt/sources.list.d/rednotebook-ubuntu-stable-cosmic.list ] && \
     [ -s /etc/apt/sources.list.d/rednotebook-ubuntu-stable-cosmic.list ] ; then
    rednotebook=True
  else
    rednotebook=False
  fi

  if [ -a /etc/apt/sources.list.d/robert-tari-ubuntu-main-cosmic.list ] && \
     [ -s /etc/apt/sources.list.d/robert-tari-ubuntu-main-cosmic.list ] ; then
    aacgain=True
  else
    aacgain=False
  fi

#  if [ -a /etc/apt/sources.list.d/rvm-ubuntu-smplayer-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/rvm-ubuntu-smplayer-cosmic.list ] ; then
#    smplayer=True
#  else
#    smplayer=False
#  fi

#  if [ -a /etc/apt/sources.list.d/sicklylife-ubuntu-converseen-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/sicklylife-ubuntu-converseen-cosmic.list ] ; then
#    converseen=True
#  else
#    converseen=False
#  fi

#  if [ -a /etc/apt/sources.list.d/sicklylife-ubuntu-filezilla-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/sicklylife-ubuntu-filezilla-cosmic.list ] ; then
#    filezilla=True
#  else
#    filezilla=False
#  fi

#  if [ -a /etc/apt/sources.list.d/sicklylife-ubuntu-fslint-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/sicklylife-ubuntu-fslint-cosmic.list ] ; then
#    fslint=True
#  else
#    fslint=False
#  fi

#  if [ -a /etc/apt/sources.list.d/sicklylife-ubuntu-geany-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/sicklylife-ubuntu-geany-cosmic.list ] ; then
#    geany=True
#  else
#    geany=False
#  fi

#  if [ -a /etc/apt/sources.list.d/sicklylife-ubuntu-gnucash-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/sicklylife-ubuntu-gnucash-cosmic.list ] ; then
#    gnucash=True
#  else
#    gnucash=False
#  fi

#  if [ -a /etc/apt/sources.list.d/sicklylife-ubuntu-gshutdown-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/sicklylife-ubuntu-gshutdown-cosmic.list ] ; then
#    gshutdown=True
#  else
#    gshutdown=False
#  fi

#  if [ -a /etc/apt/sources.list.d/sicklylife-ubuntu-libgweather-ja-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/sicklylife-ubuntu-libgweather-ja-cosmic.list ] ; then
#    libgweather=True
#  else
#    libgweather=False
#  fi

#  if [ -a /etc/apt/sources.list.d/sicklylife-ubuntu-mozc-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/sicklylife-ubuntu-mozc-cosmic.list ] ; then
#    mozc=True
#  else
#    mozc=False
#  fi

#  if [ -a /etc/apt/sources.list.d/sicklylife-ubuntu-nomacs-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/sicklylife-ubuntu-nomacs-cosmic.list ] ; then
#    nomacs=True
#  else
#    nomacs=False
#  fi

  if [ -a /etc/apt/sources.list.d/sicklylife-ubuntu-ppa-cosmic.list ] && \
     [ -s /etc/apt/sources.list.d/sicklylife-ubuntu-ppa-cosmic.list ] ; then
    sicklylife=True
  else
    sicklylife=False
  fi

#  if [ -a /etc/apt/sources.list.d/sicklylife-ubuntu-qtgain-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/sicklylife-ubuntu-qtgain-cosmic.list ] ; then
#    qtgain=True
#  else
#    qtgain=False
#  fi

#  if [ -a /etc/apt/sources.list.d/stebbins-ubuntu-handbrake-releases-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/stebbins-ubuntu-handbrake-releases-cosmic.list ] ; then
#    handbrake=True
#  else
#    handbrake=False
#  fi

#  if [ -a /etc/apt/sources.list.d/transmissionbt-ubuntu-ppa-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/transmissionbt-ubuntu-ppa-cosmic.list ] ; then
#    transmission=True
#  else
#    transmission=False
#  fi

#  if [ -a /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-apps-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-apps-cosmic.list ] ; then
#    audacious=True
#  else
#    audacious=False
#  fi

#  if [ -a /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-audacity-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-audacity-cosmic.list ] ; then
#    audacity=True
#  else
#    audacity=False
#  fi

#  if [ -a /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-avidemux-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-avidemux-cosmic.list ] ; then
#    avidemux=True
#  else
#    avidemux=False
#  fi

#  if [ -a /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-cantata-qt-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-cantata-qt-cosmic.list ] ; then
#    cantata=True
#  else
#    cantata=False
#  fi

#  if [ -a /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-dvdstyler-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-dvdstyler-cosmic.list ] ; then
#    dvdstyler=True
#  else
#    dvdstyler=False
#  fi

#  if [ -a /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-lives-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-lives-cosmic.list ] ; then
#    lives=True
#  else
#    lives=False
#  fi

#  if [ -a /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-pragha-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-pragha-cosmic.list ] ; then
#    pragha=True
#  else
#    pragha=False
#  fi

  if [ -a /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-shutter-cosmic.list ] && \
     [ -s /etc/apt/sources.list.d/ubuntuhandbook1-ubuntu-shutter-cosmic.list ] ; then
    shutter=True
  else
    shutter=False
  fi

#  if [ -a /etc/apt/sources.list.d/ubuntu-x-swat-ubuntu-updates-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/ubuntu-x-swat-ubuntu-updates-cosmic.list ] ; then
#    mesa=True
#  else
#    mesa=False
#  fi

#  if [ -a /etc/apt/sources.list.d/webupd8team-ubuntu-atom-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/webupd8team-ubuntu-atom-cosmic.list ] ; then
#    atom=True
#  else
#    atom=False
#  fi

  if [ -a /etc/apt/sources.list.d/webupd8team-ubuntu-brackets-cosmic.list ] && \
     [ -s /etc/apt/sources.list.d/webupd8team-ubuntu-brackets-cosmic.list ] ; then
    brackets=True
  else
    brackets=False
  fi

  if [ -a /etc/apt/sources.list.d/webupd8team-ubuntu-java-cosmic.list ] && \
     [ -s /etc/apt/sources.list.d/webupd8team-ubuntu-java-cosmic.list ] ; then
    ojava=True
  else
    ojava=False
  fi

#  if [ -a /etc/apt/sources.list.d/webupd8team-ubuntu-y-ppa-manager-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/webupd8team-ubuntu-y-ppa-manager-cosmic.list ] ; then
#    yppam=True
#  else
#    yppam=False
#  fi

  if [ -a /etc/apt/sources.list.d/wereturtle-ubuntu-ppa-cosmic.list ] && \
     [ -s /etc/apt/sources.list.d/wereturtle-ubuntu-ppa-cosmic.list ] ; then
    ghostwriter=True
  else
    ghostwriter=False
  fi

#  if [ -a /etc/apt/sources.list.d/wireshark-dev-ubuntu-stable-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/wireshark-dev-ubuntu-stable-cosmic.list ] ; then
#    wireshark=True
#  else
#    wireshark=False
#  fi

#  if [ -a /etc/apt/sources.list.d/yannubuntu-ubuntu-boot-repair-cosmic.list ] && \
#     [ -s /etc/apt/sources.list.d/yannubuntu-ubuntu-boot-repair-cosmic.list ] ; then
#    bootre=True
#  else
#    bootre=False
#  fi

# $clipgrab "ppa:clipgrab-team/ppa" "ClipGrab"\
# $grubc "ppa:danielrichter2007/grub-customizer" "Grub Customizer"\
# $mp3gain "ppa:flexiondotorg/audio" "mp3gain"\
# $copyq "ppa:hluk/copyq" "CopyQ"\
# $inkscape "ppa:inkscape.dev/stable" "Inkscape"\
# $japanese "ppa:japaneseteam/ppa" "Ubuntu Japanese TeamのPPA"\
# $webupd8 "ppa:nilarimogard/webupd8" "Audacious / youtube-dlg / etc..."\
# $peek "ppa:peek-developers/stable" "Peek (デスクトップ録画 ＆ Gif アニメーション化アプリ)"\
# $keepassxc "ppa:phoerious/keepassxc" "KeePassXC"\
# $smplayer "ppa:rvm/smplayer" "SMPlayer"\
# $converseen "ppa:sicklylife/converseen" "Converseen"\
# $filezilla "ppa:sicklylife/filezilla" "FileZilla"\
# $fslint "ppa:sicklylife/fslint" "FSlint"\
# $geany "ppa:sicklylife/geany" "Geany"\
# $gnucash "ppa:sicklylife/gnucash" "GnuCash"\
# $gshutdown "ppa:sicklylife/gshutdown" "GShutdown"\
# $libgweather "ppa:sicklylife/libgweather-ja" "GNOME Weather (GNOME の天気アプリ)"\
# $mozc "ppa:sicklylife/mozc" "Mozc (日本語入力ソフト)"\
# $nomacs "ppa:sicklylife/nomacs" "Nomacs"\
# $qtgain "ppa:sicklylife/qtgain" "QtGain"\
# $handbrake "ppa:stebbins/handbrake-releases" "HandBrake"\
# $transmission "ppa:transmissionbt/ppa" "Transmission (BitTorrentクライアント)"\
# $audacious "ppa:ubuntuhandbook1/apps" "Audacious / MuPDF / Liferea / etc..."\
# $audacity "ppa:ubuntuhandbook1/audacity" "Audacity"\
# $avidemux "ppa:ubuntuhandbook1/avidemux" "Avidemux"\
# $cantata "ppa:ubuntuhandbook1/cantata-qt" "Cantata (MPDクライアント)"\
# $dvdstyler "ppa:ubuntuhandbook1/dvdstyler" "DVDStyler"\
# $lives "ppa:ubuntuhandbook1/lives" "LiVES (動画編集アプリ)"\
# $pragha "ppa:ubuntuhandbook1/pragha" "Pragha Music Player"\
# $mesa "ppa:ubuntu-x-swat/updates" "Mesa (グラフィクスライブラリ)"\
# $atom "ppa:webupd8team/atom" "ATOM (テキストエディター)"\
# $wireshark "ppa:wireshark-dev/stable" "Wireshark"\
# $bootre "ppa:yannubuntu/boot-repair" "Boot-Repair"\

  universe_packages=`
( $ZENITY_CMD --list --checklist --height=500 --width=600\
 --text="各項目にチェックを入れて OK ボタンをクリックすると、
PPA の追加を開始します (このウィンドウは非表示になります)。
PPA を1つ追加するのには大体5秒以上かかります。
処理が終了するとダイアログが表示されます。
(※このツールは Ubuntu 18.10 用です)" \
 --column="" --column="PPA" --column="説明" \
 $geforce "ppa:graphics-drivers/ppa" "NVIDIAのビデオカード用ドライバー"\
 $kdenlive "ppa:kdenlive/kdenlive-stable" "Kdenlive"\
 $libreoffice "ppa:libreoffice/ppa" "LibreOffice"\
 $pulseeffects "ppa:mikhailnov/pulseeffects" "PulseAudio用イコライザー"\
 $openshot "ppa:openshot.developers/ppa" "OpenShot Video Editor"\
 $gimp "ppa:otto-kesselgulasch/gimp" "GIMP"\
 $vidcutter "ppa:ozmartian/apps" "VidCutter"\
 $rednotebook "ppa:rednotebook/stable" "RedNotebook"\
 $aacgain "ppa:robert-tari/main" "aacgain / mac / neroaac / odio / sacd / etc..."\
 $sicklylife "ppa:sicklylife/ppa" "日本語化など"\
 $shutter "ppa:ubuntuhandbook1/shutter" "Shutter"\
 $brackets "ppa:webupd8team/brackets" "Brackets"\
 $ojava "ppa:webupd8team/java" "Java (Oracle Java)"\
 $ghostwriter "ppa:wereturtle/ppa" "ghostwriter"\
 || echo 'abort' ) | sed -e 's/|/ /g'
`
  echo "$universe_packages" | grep -q '^abort$' && abort "中止しました。"

  packages="${universe_packages}"
  if [[ `echo "$packages"| wc -w` -le 0 ]] ; then
    $ZENITY_CMD --info --width=300 --text "PPA は選択されませんでした。
$TITLE を終了します。"
    exit 0
  fi

#  if [ $clipgrab = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:clipgrab-team\/ppa"//g`
#  fi

#  if [ $grubc = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:danielrichter2007\/grub-customizer"//g`
#  fi

#  if [ $mp3gain = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:flexiondotorg\/audio"//g`
#  fi

  if [ $geforce = "True" ] ; then
    packages=`echo $packages | sed s/"ppa:graphics-drivers\/ppa"//g`
  fi

#  if [ $copyq = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:hluk\/copyq"//g`
#  fi

#  if [ $inkscape = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:inkscape.dev\/stable"//g`
#  fi

#  if [ $japanese = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:japaneseteam\/ppa"//g`
#  fi

  if [ $kdenlive = "True" ] ; then
    packages=`echo $packages | sed s/"ppa:kdenlive\/kdenlive-stable"//g`
  fi

  if [ $libreoffice = "True" ] ; then
    packages=`echo $packages | sed s/"ppa:libreoffice\/ppa"//g`
  fi

  if [ $pulseeffects = "True" ] ; then
    packages=`echo $packages | sed s/"ppa:mikhailnov\/pulseeffects"//g`
  fi

#  if [ $webupd8 = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:nilarimogard\/webupd8"//g`
#  fi

  if [ $openshot = "True" ] ; then
    packages=`echo $packages | sed s/"ppa:openshot.developers\/ppa"//g`
  fi

  if [ $gimp = "True" ] ; then
    packages=`echo $packages | sed s/"ppa:otto-kesselgulasch\/gimp"//g`
  fi

  if [ $vidcutter = "True" ] ; then
    packages=`echo $packages | sed s/"ppa:ozmartian\/apps"//g`
  fi

#  if [ $peek = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:peek-developers\/stable"//g`
#  fi

#  if [ $keepassxc = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:phoerious\/keepassxc"//g`
#  fi

  if [ $rednotebook = "True" ] ; then
    packages=`echo $packages | sed s/"ppa:rednotebook\/stable"//g`
  fi

  if [ $aacgain = "True" ] ; then
    packages=`echo $packages | sed s/"ppa:robert-tari\/main"//g`
  fi

#  if [ $smplayer = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:rvm\/smplayer"//g`
#  fi

#  if [ $converseen = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:sicklylife\/converseen"//g`
#  fi

#  if [ $filezilla = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:sicklylife\/filezilla"//g`
#  fi

#  if [ $fslint = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:sicklylife\/fslint"//g`
#  fi

#  if [ $geany = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:sicklylife\/geany"//g`
#  fi

#  if [ $gnucash = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:sicklylife\/gnucash"//g`
#  fi

#  if [ $gshutdown = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:sicklylife\/gshutdown"//g`
#  fi

#  if [ $libgweather = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:sicklylife\/libgweather-ja"//g`
#  fi

#  if [ $mozc = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:sicklylife\/mozc"//g`
#  fi

#  if [ $nomacs = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:sicklylife\/nomacs"//g`
#  fi

  if [ $sicklylife = "True" ] ; then
    packages=`echo $packages | sed s/"ppa:sicklylife\/ppa"//g`
  fi

#  if [ $qtgain = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:sicklylife\/qtgain"//g`
#  fi

#  if [ $handbrake = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:stebbins\/handbrake-releases"//g`
#  fi

#  if [ $transmission = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:transmissionbt\/ppa"//g`
#  fi

#  if [ $audacious = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:ubuntuhandbook1\/apps"//g`
#  fi

#  if [ $audacity = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:ubuntuhandbook1\/audacity"//g`
#  fi

#  if [ $avidemux = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:ubuntuhandbook1\/avidemux"//g`
#  fi

#  if [ $cantata = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:ubuntuhandbook1\/cantata-qt"//g`
#  fi

#  if [ $dvdstyler = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:ubuntuhandbook1\/dvdstyler"//g`
#  fi

#  if [ $lives = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:ubuntuhandbook1\/lives"//g`
#  fi

#  if [ $pragha = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:ubuntuhandbook1\/pragha"//g`
#  fi

  if [ $shutter = "True" ] ; then
    packages=`echo $packages | sed s/"ppa:ubuntuhandbook1\/shutter"//g`
  fi

#  if [ $mesa = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:ubuntu-x-swat\/updates"//g`
#  fi

#  if [ $atom = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:webupd8team\/atom"//g`
#  fi

  if [ $brackets = "True" ] ; then
    packages=`echo $packages | sed s/"ppa:webupd8team\/brackets"//g`
  fi

  if [ $ojava = "True" ] ; then
    packages=`echo $packages | sed s/"ppa:webupd8team\/java"//g`
  fi

#  if [ $yppam = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:webupd8team\/y-ppa-manager"//g`
#  fi

  if [ $ghostwriter = "True" ] ; then
    packages=`echo $packages | sed s/"ppa:wereturtle\/ppa"//g`
  fi

#  if [ $wireshark = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:wireshark-dev\/stable"//g`
#  fi

#  if [ $bootre = "True" ] ; then
#    packages=`echo $packages | sed s/"ppa:yannubuntu\/boot-repair"//g`
#  fi

  packages=`echo $packages | sed s/'|'/" "/g`
  packages=`echo $packages | sed s/"  "/" "/g`

  echo $packages | sed s/" "/" \; sudo add-apt-repository \-y \-n "/g | sed s/^/"sudo add-apt-repository \-y \-n "/g | (vv=$(cat); eval ${vv};)

  aar=`echo $?`
  packages=`echo $packages | sed s/" "//g`

  if [[ $aar -eq 0 ]] ; then
    echo
  elif [[ $packages = " sudoadd-apt-repository-y-n" ]] ; then
    echo
  elif [[ `echo "$packages"| wc -w` -le 0 ]] ; then
    echo
  else
    $ZENITY_CMD --info --width=400 --text="エラーが発生しました。PPA の追加に失敗した可能性があります。

アクティビティから「ソフトウェアとアップデート」を起動し、「他のソフトウェア」タブで PPA の追加を確認してください。"
    exit -1
  fi

  $ZENITY_CMD --info --width=200 --text="PPA の追加を完了しました。"
  exit 0
}

function finish {
	$ZENITY_CMD --info --width=200 --text="$TITLE を終了します。"
	return $?
}

function abort {
	reason="$1"
	$ZENITY_CMD --info --width=200 --text="$reason
$TITLE を終了します。"
	exit -1
}

#
# Main Routine
#

if [ $$ != `pgrep -fo $0` ]; then
  $ZENITY_CMD --info --width=200 --text="$TITLE は既に実行中です"
  exit 0
fi

install_menu
finish

exit 0

