FreeBSD対応
このコミットが含まれているのは:
コミット
634d1dd9ec
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"domain": "https://urlo.li"
|
||||||
|
}
|
|
@ -1,16 +1,30 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
su
|
|
||||||
mkdir /etc/urloli
|
|
||||||
cp links.sample.json /etc/urloli/links.json
|
|
||||||
|
|
||||||
go build
|
|
||||||
|
|
||||||
mv urloli /usr/local/bin
|
|
||||||
chown -R urloli:urloli /usr/local/bin/urloli
|
|
||||||
chown -R urloli:urloli /etc/urloli
|
|
||||||
|
|
||||||
unamestr=$(uname)
|
unamestr=$(uname)
|
||||||
|
domain="$1"
|
||||||
|
|
||||||
|
case "$domain" in
|
||||||
|
*.i2p) network="i2p" ;;
|
||||||
|
*.onion) network="tor" ;;
|
||||||
|
*) network="www" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ "$unamestr" = 'FreeBSD' ]; then
|
||||||
|
mkdir /usr/local/etc/urloli
|
||||||
|
cp -i links.sample.json /usr/local/etc/urloli/links.json
|
||||||
|
cp -i config.json /usr/local/etc/urloli/config.json
|
||||||
|
sed -i .orig "s/urlo\.li/$domain/g" /usr/local/etc/urloli/config.json
|
||||||
|
rm -rf /usr/local/etc/urloli/config.json.orig
|
||||||
|
go build -buildvcs=false
|
||||||
|
else
|
||||||
|
mkdir /etc/urloli
|
||||||
|
cp -i links.sample.json /etc/urloli/links.json
|
||||||
|
cp -i config.json /etc/urloli/config.json
|
||||||
|
sed -i "s/urlo\.li/$domain/g" /etc/urloli/config.json
|
||||||
|
go build
|
||||||
|
fi
|
||||||
|
|
||||||
|
mv -i urloli /usr/local/bin
|
||||||
|
|
||||||
if [ "$unamestr" = 'Linux' ]; then
|
if [ "$unamestr" = 'Linux' ]; then
|
||||||
platform=$(cat /etc/os-release | grep "^ID=")
|
platform=$(cat /etc/os-release | grep "^ID=")
|
||||||
|
@ -21,19 +35,44 @@ if [ "$unamestr" = 'Linux' ]; then
|
||||||
elif [ "$platform" = "ID=centos" -o "$platform" = "ID=rhel" ]; then
|
elif [ "$platform" = "ID=centos" -o "$platform" = "ID=rhel" ]; then
|
||||||
dnf install certbot
|
dnf install certbot
|
||||||
fi
|
fi
|
||||||
certbot certonly --webroot urlo.li www.urlo.li
|
if [ "$network" = 'www' ]; then
|
||||||
cp srv/linux/etc/nginx/sites-enabled/urloli.conf /etc/nginx/sites-enabled
|
certbot certonly --webroot -d $domain -d www.$domain
|
||||||
cp srv/linux/etc/init.d/urloli /etc/init.d
|
cp -i srv/linux/etc/nginx/sites-enabled/urloli-clear.conf /etc/nginx/sites-enabled/urloli.conf
|
||||||
|
else
|
||||||
|
cp -i srv/linux/etc/nginx/sites-enabled/urloli-dark.conf /etc/nginx/sites-enabled/urloli.conf
|
||||||
|
fi
|
||||||
|
sed -i "s/urlo\.li/$domain/g" /etc/nginx/sites-enabled/urloli.conf
|
||||||
|
cp -i srv/linux/etc/init.d/urloli /etc/init.d
|
||||||
chmod +x /etc/init.d/urloli
|
chmod +x /etc/init.d/urloli
|
||||||
/etc/init.d/urloli start
|
/etc/init.d/urloli start
|
||||||
elif [ "$unamestr" = 'OpenBSD' ]; then
|
elif [ "$unamestr" = 'OpenBSD' ]; then
|
||||||
cat /etc/acme-client.conf src/openbsd/etc/acme-client.conf > /etc/acme-client.conf
|
if [ "$network" = 'www' ]; then
|
||||||
|
cat /etc/acme-client.conf srv/openbsd/etc/acme-client.conf > /etc/acme-client.conf
|
||||||
|
sed -i "s/urlo\.li/$domain/g" /etc/acme-client.conf
|
||||||
|
fi
|
||||||
cat /etc/httpd.conf srv/openbsd/etc/httpd.conf > /etc/httpd.conf
|
cat /etc/httpd.conf srv/openbsd/etc/httpd.conf > /etc/httpd.conf
|
||||||
|
sed -i "s/urlo\.li/$domain/g" /etc/httpd.conf
|
||||||
rcctl restart httpd
|
rcctl restart httpd
|
||||||
acme-client -v urlo.li
|
if [ "$network" = 'www' ]; then
|
||||||
cp srv/openbsd/etc/rc.d/urloli /etc/rc.d
|
acme-client -v $domain
|
||||||
|
fi
|
||||||
|
cp -i srv/openbsd/etc/rc.d/urloli /etc/rc.d
|
||||||
chmod +x /etc/rc.d/urloli
|
chmod +x /etc/rc.d/urloli
|
||||||
rcctl start urloli
|
rcctl start urloli
|
||||||
|
elif [ "$unamestr" = 'FreeBSD' ]; then
|
||||||
|
pkg install py39-certbot
|
||||||
|
if [ "$network" = 'www' ]; then
|
||||||
|
certbot certonly --webroot -d $domain -d www.$domain
|
||||||
|
cp -i srv/linux/etc/nginx/sites-enabled/urloli-clear.conf /usr/local/etc/nginx/sites-enabled/urloli.conf
|
||||||
|
else
|
||||||
|
cp -i srv/linux/etc/nginx/sites-enabled/urloli-dark.conf /usr/local/etc/nginx/sites-enabled/urloli.conf
|
||||||
|
fi
|
||||||
|
sed -i .orig "s/urlo\.li/$domain/g" /usr/local/etc/nginx/sites-enabled/urloli.conf
|
||||||
|
rm -rf /usr/local/etc/nginx/sites-enabled/urloli.conf.orig
|
||||||
|
cp -i srv/freebsd/usr/local/etc/rc.d/urloli /usr/local/etc/rc.d
|
||||||
|
chmod +x /usr/local/etc/rc.d/urloli
|
||||||
|
sysrc urloli_enable=YES
|
||||||
|
service start urloli
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit
|
exit
|
||||||
|
|
42
main.go
42
main.go
|
@ -10,6 +10,12 @@ import (
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
linkpath string
|
||||||
|
configpath string
|
||||||
)
|
)
|
||||||
|
|
||||||
func mkstring () string {
|
func mkstring () string {
|
||||||
|
@ -49,7 +55,7 @@ func checkcharlim (url string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func geturl (key string) string {
|
func geturl (key string) string {
|
||||||
data, err := ioutil.ReadFile("/etc/urloli/links.json")
|
data, err := ioutil.ReadFile(linkpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("links.jsonを開けられません: ", err)
|
fmt.Println("links.jsonを開けられません: ", err)
|
||||||
}
|
}
|
||||||
|
@ -67,7 +73,7 @@ func geturl (key string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkjson (url string) bool {
|
func checkjson (url string) bool {
|
||||||
data, err := ioutil.ReadFile("/etc/urloli/links.json")
|
data, err := ioutil.ReadFile(linkpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("links.jsonを開けられません: ", err)
|
fmt.Println("links.jsonを開けられません: ", err)
|
||||||
}
|
}
|
||||||
|
@ -85,7 +91,7 @@ func checkjson (url string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func insertjson (url string) string {
|
func insertjson (url string) string {
|
||||||
data, err := ioutil.ReadFile("/etc/urloli/links.json")
|
data, err := ioutil.ReadFile(linkpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("links.jsonを開けられません: ", err)
|
fmt.Println("links.jsonを開けられません: ", err)
|
||||||
}
|
}
|
||||||
|
@ -96,7 +102,7 @@ func insertjson (url string) string {
|
||||||
newstring := mkstring()
|
newstring := mkstring()
|
||||||
payload[newstring] = url
|
payload[newstring] = url
|
||||||
m, _ := json.Marshal(&payload)
|
m, _ := json.Marshal(&payload)
|
||||||
ioutil.WriteFile("/etc/urloli/links.json", m, os.ModePerm)
|
ioutil.WriteFile(linkpath, m, os.ModePerm)
|
||||||
// fmt.Printf("%s\n", m)
|
// fmt.Printf("%s\n", m)
|
||||||
|
|
||||||
return newstring
|
return newstring
|
||||||
|
@ -106,10 +112,32 @@ type Page struct {
|
||||||
Tit string
|
Tit string
|
||||||
Err string
|
Err string
|
||||||
Url string
|
Url string
|
||||||
|
Dom string
|
||||||
Lan string
|
Lan string
|
||||||
}
|
}
|
||||||
|
|
||||||
func main () {
|
func main () {
|
||||||
|
if runtime.GOOS == "freebsd" {
|
||||||
|
linkpath = "/usr/local/etc/urloli/links.json"
|
||||||
|
configpath = "/usr/local/etc/urloli/config.json"
|
||||||
|
} else {
|
||||||
|
linkpath = "/etc/urloli/links.json"
|
||||||
|
configpath = "/etc/urloli/config.json"
|
||||||
|
}
|
||||||
|
var domain string
|
||||||
|
|
||||||
|
data, err := ioutil.ReadFile(configpath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("config.jsonを開けられません: ", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload map[string]interface{}
|
||||||
|
json.Unmarshal(data, &payload)
|
||||||
|
|
||||||
|
for k := range payload {
|
||||||
|
domain = payload[k].(string)
|
||||||
|
}
|
||||||
|
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
|
||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -163,9 +191,9 @@ func main () {
|
||||||
} else {
|
} else {
|
||||||
res := insertjson(addurl)
|
res := insertjson(addurl)
|
||||||
if cookie.Value == "ja" {
|
if cookie.Value == "ja" {
|
||||||
data = &Page{Tit: "短縮済み", Lan: cookie.Value, Url: res}
|
data = &Page{Tit: "短縮済み", Lan: cookie.Value, Url: res, Dom: domain}
|
||||||
} else {
|
} else {
|
||||||
data = &Page{Tit: "Shortened", Lan: cookie.Value, Url: res}
|
data = &Page{Tit: "Shortened", Lan: cookie.Value, Url: res, Dom: domain}
|
||||||
}
|
}
|
||||||
tmpl = template.Must(template.ParseFiles("view/submitted.html", "view/header.html", "view/footer.html"))
|
tmpl = template.Must(template.ParseFiles("view/submitted.html", "view/header.html", "view/footer.html"))
|
||||||
}
|
}
|
||||||
|
@ -204,7 +232,7 @@ func main () {
|
||||||
tmpl = template.Must(template.ParseFiles("view/404.html", "view/header.html", "view/footer.html"))
|
tmpl = template.Must(template.ParseFiles("view/404.html", "view/header.html", "view/footer.html"))
|
||||||
}
|
}
|
||||||
} else if uri == "/" && qnewurl != "" {
|
} else if uri == "/" && qnewurl != "" {
|
||||||
data = &Page{Tit: "短縮済み", Url: qnewurl}
|
data = &Page{Tit: "短縮済み", Url: qnewurl, Dom: domain}
|
||||||
tmpl = template.Must(template.ParseFiles("view/submitted.html", "view/header.html", "view/footer.html"))
|
tmpl = template.Must(template.ParseFiles("view/submitted.html", "view/header.html", "view/footer.html"))
|
||||||
} else {
|
} else {
|
||||||
if cookie.Value == "ja" {
|
if cookie.Value == "ja" {
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# PROVIDE: urloli
|
||||||
|
# REQUIRE: NETWORKING SYSLOG
|
||||||
|
# KEYWORD: shutdown
|
||||||
|
#
|
||||||
|
# Add the following lines to /etc/rc.conf to enable urloli:
|
||||||
|
#
|
||||||
|
#urloli_enable="YES"
|
||||||
|
|
||||||
|
. /etc/rc.subr
|
||||||
|
|
||||||
|
name="urloli"
|
||||||
|
rcvar="urloli_enable"
|
||||||
|
|
||||||
|
load_rc_config $name
|
||||||
|
|
||||||
|
: ${urloli_enable:="NO"}
|
||||||
|
: ${urloli_facility:="daemon"}
|
||||||
|
: ${urloli_priority:="debug"}
|
||||||
|
|
||||||
|
command="/usr/local/bin/${name}"
|
||||||
|
procname="/usr/local/bin/${name}"
|
||||||
|
|
||||||
|
pidfile="/var/run/${name}.pid"
|
||||||
|
|
||||||
|
start_cmd="${name}_start"
|
||||||
|
|
||||||
|
urloli_start() {
|
||||||
|
for d in /var/db/urloli /var/log/urloli; do
|
||||||
|
if [ ! -e "$d" ]; then
|
||||||
|
mkdir "$d"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
/usr/sbin/daemon -S -l ${urloli_facility} -s ${urloli_priority} -T ${name} \
|
||||||
|
-p ${pidfile} \
|
||||||
|
/usr/bin/env -i \
|
||||||
|
"PATH=/usr/local/bin:${PATH}" \
|
||||||
|
$command
|
||||||
|
}
|
||||||
|
|
||||||
|
run_rc_command "$1"
|
|
@ -0,0 +1,13 @@
|
||||||
|
server {
|
||||||
|
server_name urlo.li;
|
||||||
|
|
||||||
|
access_log off;
|
||||||
|
error_log off;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:9910;
|
||||||
|
}
|
||||||
|
|
||||||
|
listen 80;
|
||||||
|
listen [::]:80;
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
{{template "header" .}}
|
{{template "header" .}}
|
||||||
{{if eq .Lan "ja"}}下記のURLからアクセス出来ます。{{else}}Please enter a URL.{{end}}
|
{{if eq .Lan "ja"}}下記のURLからアクセス出来ます。{{else}}Please enter a URL.{{end}}
|
||||||
<br />
|
<br />
|
||||||
<a href="https://urlo.li/{{ .Url }}">https://urlo.li/{{ .Url }}</a>
|
<a href="{{ .Dom }}/{{ .Url }}">{{ .Dom }}/{{ .Url }}</a>
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<a href="/">{{if eq .Lan "ja"}}トップページに戻る{{else}}Return to toppage{{end}}</a>
|
<a href="/">{{if eq .Lan "ja"}}トップページに戻る{{else}}Return to toppage{{end}}</a>
|
||||||
{{template "footer" .}}
|
{{template "footer" .}}
|
||||||
|
|
読み込み中…
新しいイシューから参照