#!/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="Bionic専用PPAPlus"
ZENITY_CMD="zenity --title=$TITLE"

CURRENT_RELEASE="18.04"
NEXT_RELEASE="18.10"

RELEASE_CODE="bionic"
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-bionic.list ] && \
     [ -s /etc/apt/sources.list.d/clipgrab-team-ubuntu-ppa-bionic.list ] ; then
    clipgrab=True
  else
    clipgrab=False
  fi

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  universe_packages=`
( $ZENITY_CMD --list --checklist --height=500 --width=600\
 --text="各項目にチェックを入れて OK ボタンをクリックすると、
PPA の追加を開始します (このウィンドウは非表示になります)。
PPA を1つ追加するのには大体5秒以上かかります。
処理が終了するとダイアログが表示されます。
(※このツールは Ubuntu 18.04 用です)" \
 --column="" --column="PPA" --column="説明" \
 $clipgrab "ppa:clipgrab-team/ppa" "ClipGrab"\
 $grubc "ppa:danielrichter2007/grub-customizer" "Grub Customizer"\
 $mp3gain "ppa:flexiondotorg/audio" "mp3gain"\
 $geforce "ppa:graphics-drivers/ppa" "NVIDIAのビデオカード用ドライバー"\
 $copyq "ppa:hluk/copyq" "CopyQ"\
 $inkscape "ppa:inkscape.dev/stable" "Inkscape"\
 $japanese "ppa:japaneseteam/ppa" "Ubuntu Japanese TeamのPPA"\
 $kdenlive "ppa:kdenlive/kdenlive-stable" "Kdenlive"\
 $libreoffice "ppa:libreoffice/ppa" "LibreOffice"\
 $pulseeffects "ppa:mikhailnov/pulseeffects" "PulseAudio用イコライザー"\
 $webupd8 "ppa:nilarimogard/webupd8" "Audacious / youtube-dlg / etc..."\
 $openshot "ppa:openshot.developers/ppa" "OpenShot Video Editor"\
 $gimp "ppa:otto-kesselgulasch/gimp" "GIMP"\
 $vidcutter "ppa:ozmartian/apps" "VidCutter"\
 $peek "ppa:peek-developers/stable" "Peek (デスクトップ録画 ＆ Gif アニメーション化アプリ)"\
 $keepassxc "ppa:phoerious/keepassxc" "KeePassXC"\
 $rednotebook "ppa:rednotebook/stable" "RedNotebook"\
 $aacgain "ppa:robert-tari/main" "aacgain / mac / neroaac / odio / sacd / etc..."\
 $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"\
 $sicklylife "ppa:sicklylife/ppa" "日本語化など"\
 $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 (テキストエディター)"\
 $brackets "ppa:webupd8team/brackets" "Brackets"\
 $ojava "ppa:webupd8team/java" "Java (Oracle Java)"\
 $yppam "ppa:webupd8team/y-ppa-manager" "Y PPA Manager (PPA管理アプリ)"\
 $ghostwriter "ppa:wereturtle/ppa" "ghostwriter"\
 $wireshark "ppa:wireshark-dev/stable" "Wireshark"\
 $bootre "ppa:yannubuntu/boot-repair" "Boot-Repair"\
 || 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 [ $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

